本文整理汇总了Java中org.apache.kafka.connect.data.SchemaBuilder.map方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaBuilder.map方法的具体用法?Java SchemaBuilder.map怎么用?Java SchemaBuilder.map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.kafka.connect.data.SchemaBuilder
的用法示例。
在下文中一共展示了SchemaBuilder.map方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKsqlComplexType
import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
private static Schema getKsqlComplexType(final String sqlType) {
if (sqlType.startsWith(ARRAY)) {
return SchemaBuilder.array(getTypeSchema(sqlType.substring(ARRAY.length() + 1, sqlType.length() - 1)));
} else if (sqlType.startsWith(MAP)) {
//TODO: For now only primitive data types for map are supported. Will have to add nested types.
String[] mapTypesStrs = sqlType.substring("MAP".length() + 1, sqlType.length() - 1)
.trim().split(",");
if (mapTypesStrs.length != 2) {
throw new KsqlException("Map type is not defined correctly.: " + sqlType);
}
String keyType = mapTypesStrs[0].trim();
String valueType = mapTypesStrs[1].trim();
return SchemaBuilder.map(getTypeSchema(keyType), getTypeSchema(valueType));
}
throw new KsqlException("Unsupported type: " + sqlType);
}
示例2: getKSQLSchemaForAvroSchema
import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
private static Schema getKSQLSchemaForAvroSchema(org.apache.avro.Schema avroSchema) {
switch (avroSchema.getType()) {
case INT:
return Schema.INT32_SCHEMA;
case LONG:
return Schema.INT64_SCHEMA;
case DOUBLE:
case FLOAT:
return Schema.FLOAT64_SCHEMA;
case BOOLEAN:
return Schema.BOOLEAN_SCHEMA;
case STRING:
return Schema.STRING_SCHEMA;
case ARRAY:
return SchemaBuilder.array(getKSQLSchemaForAvroSchema(avroSchema.getElementType()));
case MAP:
return SchemaBuilder.map(Schema.STRING_SCHEMA,
getKSQLSchemaForAvroSchema(avroSchema.getValueType()));
case UNION:
List<org.apache.avro.Schema> schemaList = avroSchema.getTypes();
if (schemaList.size() == 1) {
return getKSQLSchemaForAvroSchema(schemaList.get(0));
} else if (schemaList.size() == 2) {
if (schemaList.get(0).getType() == org.apache.avro.Schema.Type.NULL) {
return getKSQLSchemaForAvroSchema(schemaList.get(1));
} else if (schemaList.get(1).getType() == org.apache.avro.Schema.Type.NULL) {
return getKSQLSchemaForAvroSchema(schemaList.get(0));
}
}
throw new KsqlException(String.format("Union type cannot have more than two types and "
+ "one of them should be null."));
default:
throw new KsqlException(String.format("Cannot find correct type for avro type: %s",
avroSchema.getFullName()));
}
}
示例3: build
import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
public Schema build() {
log.trace(this.toString());
SchemaBuilder builder;
switch (this.type) {
case MAP:
Preconditions.checkNotNull(this.keySchema, "keySchema cannot be null.");
Preconditions.checkNotNull(this.valueSchema, "valueSchema cannot be null.");
builder = SchemaBuilder.map(this.keySchema, this.valueSchema);
break;
case ARRAY:
Preconditions.checkNotNull(this.valueSchema, "valueSchema cannot be null.");
builder = SchemaBuilder.array(this.valueSchema);
break;
default:
builder = SchemaBuilder.type(this.type);
break;
}
if (Schema.Type.STRUCT == this.type) {
for (Map.Entry<String, Schema> kvp : this.fieldSchemas.entrySet()) {
builder.field(kvp.getKey(), kvp.getValue());
}
}
if (!Strings.isNullOrEmpty(this.name)) {
builder.name(this.name);
}
if (!Strings.isNullOrEmpty(this.doc)) {
builder.doc(this.doc);
}
if (null != this.defaultValue) {
Object value;
switch (this.type) {
case INT8:
value = ((Number) this.defaultValue).byteValue();
break;
case INT16:
value = ((Number) this.defaultValue).shortValue();
break;
case INT32:
value = ((Number) this.defaultValue).intValue();
break;
case INT64:
value = ((Number) this.defaultValue).longValue();
break;
case FLOAT32:
value = ((Number) this.defaultValue).floatValue();
break;
case FLOAT64:
value = ((Number) this.defaultValue).doubleValue();
break;
default:
value = this.defaultValue;
break;
}
builder.defaultValue(value);
}
if (null != this.parameters) {
builder.parameters(this.parameters);
}
if (this.isOptional) {
builder.optional();
}
if (null != this.version) {
builder.version(this.version);
}
return builder.build();
}
示例4: shouldGetTheCorrectJavaTypeForMap
import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test
public void shouldGetTheCorrectJavaTypeForMap() {
Schema schema = SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.FLOAT64_SCHEMA);
Class javaClass = SchemaUtil.getJavaType(schema);
assertThat(javaClass, equalTo(HashMap.class));
}