本文整理汇总了Java中org.apache.avro.SchemaBuilder.FieldAssembler.endRecord方法的典型用法代码示例。如果您正苦于以下问题:Java FieldAssembler.endRecord方法的具体用法?Java FieldAssembler.endRecord怎么用?Java FieldAssembler.endRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.SchemaBuilder.FieldAssembler
的用法示例。
在下文中一共展示了FieldAssembler.endRecord方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSchemaFor
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
/**
* Generate a schema with given schema name and has one field of STRING type
* for each dimension and one field of LONG type for each metric
* @param schemaName
* @param dimensions
* @param metrics
* @return
*/
public static Schema createSchemaFor(String schemaName, String[] dimensions,
String[] metrics) {
FieldAssembler<Schema> fields;
RecordBuilder<Schema> record = SchemaBuilder.record(schemaName);
fields = record.namespace("com.linkedin.thirdeye.join").fields();
for (String dimension : dimensions) {
fields = fields.name(dimension).type().nullable().stringType()
.noDefault();
}
for (String metric : metrics) {
fields = fields.name(metric).type().nullable().longType().longDefault(0);
}
Schema schema = fields.endRecord();
return schema;
}
示例2: initDefaultSchema
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
private Schema initDefaultSchema(Schema designSchema) {
AvroRegistry avroReg = new AvroRegistry();
FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields();
for (SplunkJSONEventField metadataField : SplunkJSONEventField.getMetadataFields()) {
Schema base = avroReg.getConverter(metadataField.getDataType()).getSchema();
FieldBuilder<Schema> fieldBuilder = record.name(metadataField.getName());
if (metadataField.getName().equals(SplunkJSONEventField.TIME.getName())) {
String datePattern;
Field designField = designSchema.getField(metadataField.getName());
if (designField != null) {
datePattern = designField.getProp(SchemaConstants.TALEND_COLUMN_PATTERN);
} else {
datePattern = designSchema.getProp(SchemaConstants.TALEND_COLUMN_PATTERN);
}
if (datePattern == null || datePattern.isEmpty()) {
datePattern = "dd-MM-yyyy";
}
fieldBuilder.prop(SchemaConstants.TALEND_COLUMN_PATTERN, datePattern);
}
fieldBuilder.type(AvroUtils.wrapAsNullable(base)).noDefault();
}
Schema defaultSchema = record.endRecord();
return defaultSchema;
}
示例3: createTestSchema5
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
public static Schema createTestSchema5() {
FieldAssembler<Schema> builder = SchemaBuilder.builder().record("TEST").fields();
Schema schema = AvroUtils._int();
schema = wrap(schema);
builder = builder.name("ID").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "ID").type(schema).noDefault();
schema = AvroUtils._string();
schema = wrap(schema);
builder = builder.name("NAME").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "NAME").type(schema).noDefault();
schema = AvroUtils._string();// TODO : fix it as should be object type
schema = wrap(schema);
builder = builder.name("RESULTSET").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "RESULTSET").type(schema)
.noDefault();
return builder.endRecord();
}
示例4: getGranularityBasedSchema
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
@SuppressWarnings("fallthrough")
private Schema getGranularityBasedSchema() {
FieldAssembler<Schema> assembler =
SchemaBuilder.record("GenericRecordTimePartition").namespace("gobblin.writer.partitioner").fields();
// Construct the fields in reverse order
if (!Strings.isNullOrEmpty(this.writerPartitionSuffix)) {
assembler = assembler.name(SUFFIX).type(Schema.create(Schema.Type.STRING)).noDefault();
}
assembler = assembler.name(this.granularity.toString()).type(Schema.create(Schema.Type.STRING)).noDefault();
if (!Strings.isNullOrEmpty(this.writerPartitionPrefix)) {
assembler = assembler.name(PREFIX).type(Schema.create(Schema.Type.STRING)).noDefault();
}
Schema schema = assembler.endRecord();
Collections.reverse(schema.getFields());
return schema;
}
示例5: schemaFor
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
private Schema schemaFor(List<String> fieldNames, List<String> fieldTypes) {
FieldAssembler<Schema> assembler = SchemaBuilder.record("t").fields();
for (int i = 0; i < fieldNames.size(); i++) {
String fieldName = fieldNames.get(i);
String fieldType = fieldTypes.get(i);
switch (fieldType) {
case "string":
assembler = assembler.optionalString(fieldName);
break;
case "float":
assembler = assembler.optionalFloat(fieldName);
break;
case "double":
assembler = assembler.optionalDouble(fieldName);
break;
case "int":
assembler = assembler.optionalInt(fieldName);
break;
case "long":
assembler = assembler.optionalLong(fieldName);
break;
case "boolean":
assembler = assembler.optionalBoolean(fieldName);
break;
case "binary":
assembler = assembler.optionalBytes(fieldName);
break;
default:
throw new RuntimeException("Unsupported provided field type: " + fieldType);
}
}
return assembler.endRecord();
}
示例6: inferSchemaRecord
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
private Schema inferSchemaRecord(IndexedRecord in) {
FieldAssembler<Schema> builder = SchemaBuilder.builder().record(in.getSchema().getName()).fields();
for (Schema.Field field : in.getSchema().getFields()) {
Schema fieldSchema = inferSchema(field);
Object fieldDefault = field.defaultVal();
if (null == fieldDefault) {
builder = builder.name(field.name()).type(fieldSchema).noDefault();
} else {
builder = builder.name(field.name()).type(fieldSchema).withDefault(fieldDefault);
}
}
return builder.endRecord();
}
示例7: createTestSchema
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
public static Schema createTestSchema() {
FieldAssembler<Schema> builder = SchemaBuilder.builder().record("TEST").fields();
Schema schema = AvroUtils._int();
schema = wrap(schema);
builder = builder.name("ID").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "ID").type(schema).noDefault();
schema = AvroUtils._string();
schema = wrap(schema);
builder = builder.name("NAME").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "NAME").type(schema).noDefault();
return builder.endRecord();
}
示例8: setupDefaultSchema
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
private void setupDefaultSchema() {
AvroRegistry avroReg = new AvroRegistry();
FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields();
for (SplunkJSONEventField metadataField : SplunkJSONEventField.getMetadataFields()) {
Schema base = avroReg.getConverter(metadataField.getDataType()).getSchema();
FieldBuilder<Schema> fieldBuilder = record.name(metadataField.getName());
if (metadataField.getName().equals(SplunkJSONEventField.TIME.getName())) {
fieldBuilder.prop(SchemaConstants.TALEND_COLUMN_PATTERN, "dd-MM-yyyy");
}
fieldBuilder.type(AvroUtils.wrapAsNullable(base)).noDefault();
}
Schema defaultSchema = record.endRecord();
schema.schema.setValue(defaultSchema);
}
示例9: createSchema
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
/**
* Create default static schema for indexed record.
*/
private Schema createSchema() {
AvroRegistry avroReg = new AvroRegistry();
FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields();
addField(record, "FieldString", String.class, avroReg);
addField(record, "FieldInt", Integer.class, avroReg);
Schema defaultSchema = record.endRecord();
return defaultSchema;
}
示例10: createSchemaWithTimeAsString
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
/**
* create schema for indexed record with Date presented as String.
*/
private Schema createSchemaWithTimeAsString() {
AvroRegistry avroReg = new AvroRegistry();
FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields();
addField(record, "FieldString", String.class, avroReg);
addField(record, "FieldInt", Integer.class, avroReg);
addField(record, "Description", String.class, avroReg);
addField(record, "time", String.class, avroReg);
Schema defaultSchema = record.endRecord();
return defaultSchema;
}
示例11: createDynamicSchemaWithDatePattern
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
/**
* Create dynamic schema with date pattern in dynamic column. Required to test parsing of Date presented as String.
*/
private Schema createDynamicSchemaWithDatePattern() {
FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields();
Schema defaultSchema = record.endRecord();
AvroUtils.setIncludeAllFields(defaultSchema, true);
AvroUtils.setProperty(defaultSchema, SchemaConstants.TALEND_COLUMN_PATTERN, DATE_PATTERN);
return defaultSchema;
}
示例12: getMakeRowSchema
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
public Schema getMakeRowSchema(boolean isDynamic) {
FieldAssembler<Schema> fa = SchemaBuilder.builder().record("MakeRowRecord").fields() //
.name("Name").type().nullable().stringType().noDefault() //
.name("ShippingStreet").type().nullable().stringType().noDefault() //
.name("ShippingPostalCode").type().nullable().intType().noDefault() //
.name("BillingStreet").type().nullable().stringType().noDefault() //
.name("BillingState").type().nullable().stringType().noDefault() //
.name("BillingPostalCode").type().nullable().stringType().noDefault();
if (isDynamic) {
fa = fa.name("ShippingState").type().nullable().stringType().noDefault();
}
return fa.endRecord();
}
示例13: createTestSchema2
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
public static Schema createTestSchema2() {
FieldAssembler<Schema> builder = SchemaBuilder.builder().record("TEST").fields();
Schema schema = AvroUtils._int();
schema = wrap(schema);
builder = builder.name("ID").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "ID")
.prop(SchemaConstants.TALEND_COLUMN_IS_KEY, "true").type(schema).noDefault();
schema = AvroUtils._string();
schema = wrap(schema);
builder = builder.name("NAME").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "NAME").type(schema).noDefault();
return builder.endRecord();
}
示例14: createTestSchema4
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
public static Schema createTestSchema4() {
FieldAssembler<Schema> builder = SchemaBuilder.builder().record("TEST").fields();
Schema schema = AvroUtils._string();// TODO : fix it as should be object type
schema = wrap(schema);
builder = builder.name("RESULTSET").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "RESULTSET").type(schema)
.noDefault();
return builder.endRecord();
}
示例15: getDateTimeFormatBasedSchema
import org.apache.avro.SchemaBuilder.FieldAssembler; //导入方法依赖的package包/类
private Schema getDateTimeFormatBasedSchema() {
FieldAssembler<Schema> assembler =
SchemaBuilder.record("GenericRecordTimePartition").namespace("gobblin.writer.partitioner").fields();
if (!Strings.isNullOrEmpty(this.writerPartitionPrefix)) {
assembler = assembler.name(PREFIX).type(Schema.create(Schema.Type.STRING)).noDefault();
}
assembler = assembler.name(PARTITIONED_PATH).type(Schema.create(Schema.Type.STRING)).noDefault();
if (!Strings.isNullOrEmpty(this.writerPartitionSuffix)) {
assembler = assembler.name(SUFFIX).type(Schema.create(Schema.Type.STRING)).noDefault();
}
return assembler.endRecord();
}