本文整理汇总了Java中org.apache.avro.SchemaBuilder.FieldAssembler方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaBuilder.FieldAssembler方法的具体用法?Java SchemaBuilder.FieldAssembler怎么用?Java SchemaBuilder.FieldAssembler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.SchemaBuilder
的用法示例。
在下文中一共展示了SchemaBuilder.FieldAssembler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFlatAvroSchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
/**
* Creates a flat Avro Schema for testing.
*/
public static Schema createFlatAvroSchema(String[] fieldNames, TypeInformation[] fieldTypes) {
final SchemaBuilder.FieldAssembler<Schema> fieldAssembler = SchemaBuilder
.record("BasicAvroRecord")
.namespace(NAMESPACE)
.fields();
final Schema nullSchema = Schema.create(Schema.Type.NULL);
for (int i = 0; i < fieldNames.length; i++) {
Schema schema = ReflectData.get().getSchema(fieldTypes[i].getTypeClass());
Schema unionSchema = Schema.createUnion(Arrays.asList(nullSchema, schema));
fieldAssembler.name(fieldNames[i]).type(unionSchema).noDefault();
}
return fieldAssembler.endRecord();
}
示例2: schemaFor
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
private static Schema schemaFor(StructType structType, String record, String namespace, int recordCount) {
// Increment after using the recordCount
record = (null == record) ? "record" + recordCount++ : record;
LOG.debug("Converting {} to Avro Record schema [{}:{}]", structType, record, namespace);
SchemaBuilder.RecordBuilder<Schema> schema = SchemaBuilder.record(record);
if (null != namespace) {
schema.namespace(namespace);
}
schema.doc("Auto-generated from Spark DataFrame");
SchemaBuilder.FieldAssembler<Schema> assembler = schema.fields();
StructField[] structFields = structType.fields();
for (StructField f : structFields) {
assembler.name(f.name()).type(typeFor(f.dataType(), f.nullable(), recordCount)).noDefault();
}
return assembler.endRecord();
}
示例3: getMakeRowSchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
public Schema getMakeRowSchema() {
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.builder().record("MakeRowRecord").fields() //
.name("ID").type(AvroUtils._decimal()).noDefault() //
.name("C1").type().nullable().stringType().noDefault() //
.name("C2").type().nullable().booleanType().noDefault() //
.name("C3").type().nullable().doubleType().noDefault() //
// date
.name("C4").type(AvroUtils._logicalDate()).noDefault() //
// time
.name("C5").type(AvroUtils._logicalTime()).noDefault() //
// timestamp
.name("C6").type(AvroUtils._logicalTimestamp()).noDefault() //
// variant
.name("C7").type().nullable().stringType().noDefault();
return fa.endRecord();
}
示例4: getMakeRowSchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
@Override
public Schema getMakeRowSchema(boolean isDynamic) {
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.builder().record("MakeRowRecord").fields() //
.name("Id").type(AvroUtils._string()).noDefault() //
.name("Name").type(AvroUtils._string()).noDefault() //
.name("ShippingStreet").type(AvroUtils._string()).noDefault() //
.name("ShippingPostalCode").type(AvroUtils._int()).noDefault() //
.name("BillingStreet").type(AvroUtils._string()).noDefault() //
.name("BillingState").type(AvroUtils._string()).noDefault() //
.name("BillingPostalCode").type(AvroUtils._string()).noDefault();
if (isDynamic) {
fa = fa.name("ShippingState").type(AvroUtils._string()).noDefault();
}
return fa.endRecord();
}
示例5: getMakeRowSchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
@Override
public Schema getMakeRowSchema(boolean isDynamic) {
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.builder().record("MakeRowRecord").fields() //
.name("Id").type().nullable().stringType().noDefault() //
.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() //
.name("BillingCity").type().nullable().stringType().noDefault();
if (isDynamic) {
fa = fa.name("ShippingState").type().nullable().stringType().noDefault();
}
return fa.endRecord();
}
示例6: assembleNestedSchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
private static Schema assembleNestedSchema(MapEventType mapEventType, ConfigurationEngineDefaults.EventMeta.AvroSettings avroSettings, Annotation[] annotations, EventAdapterService eventAdapterService, String statementName, String engineURI, TypeRepresentationMapper optionalMapper) {
SchemaBuilder.FieldAssembler<Schema> assembler = record(mapEventType.getName()).fields();
for (Map.Entry<String, Object> prop : mapEventType.getTypes().entrySet()) {
AvroSchemaUtil.assembleField(prop.getKey(), prop.getValue(), assembler, annotations, avroSettings, eventAdapterService, statementName, engineURI, optionalMapper);
}
return assembler.endRecord();
}
示例7: getMakeRowSchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
private Schema getMakeRowSchema() {
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.builder().record("MakeRowRecord").fields() //
.name("col_1").type().nullable().stringType().noDefault() //
.name("col_2").type().nullable().stringType().noDefault() //
.name("col_3").type().nullable().intType().noDefault() //
.name("col_4").type().nullable().doubleType().noDefault() //
.name("col_5").prop(SchemaConstants.TALEND_COLUMN_PATTERN, "yyyy-MM-dd'T'HH:mm:ss'.000Z'").type(AvroUtils._date()).noDefault() //
.name("col_6").type().nullable().stringType().noDefault()
//the UI model may pass a empty string as the pattern, please see MetadataToolAvroHelper
.name("col_7").prop(SchemaConstants.TALEND_COLUMN_PATTERN, "").type().nullable().longType().noDefault();
Schema schema = fa.endRecord();
return schema;
}
示例8: inferStringArray
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
/**
* Infers an Avro schema for the given DescribeSObjectResult. This can be an expensive operation so the schema
* should be cached where possible. This is always an {@link Schema.Type#RECORD}.
*
* @param in the DescribeSObjectResult to analyse.
* @return the schema for data given from the object.
*/
private Schema inferStringArray(String[] in) {
List<Schema.Field> fields = new ArrayList<>();
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.record(RECORD_NAME).fields();
for (int i = 0; i < in.length; i++) {
fa = fa.name(FIELD_PREFIX + i).type(Schema.create(Schema.Type.STRING)).noDefault();
}
return fa.endRecord();
}
示例9: inferStringArray
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
/**
* Infers an Avro schema for the given String array. This can be an expensive operation so the schema should be
* cached where possible. This is always an {@link Schema.Type#RECORD}.
*
* @param in the String array to analyse.
* @return the schema for data given from the object.
*/
private Schema inferStringArray(String[] in) {
List<Schema.Field> fields = new ArrayList<>();
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.record(RECORD_NAME).fields();
for (int i = 0; i < in.length; i++) {
fa = fa.name(FIELD_PREFIX + i).type(Schema.create(Schema.Type.STRING)).noDefault();
}
return fa.endRecord();
}
示例10: inferCsvRecord
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
/**
* Infers an Avro schema for the given String array. This can be an expensive operation so the schema should be
* cached where possible. This is always an {@link Schema.Type#RECORD}.
*
* @param in the DescribeSObjectResult to analyse.
* @return the schema for data given from the object.
*/
private Schema inferCsvRecord(CSVRecord in) {
List<Schema.Field> fields = new ArrayList<>();
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.record(RECORD_NAME).fields();
for (int i = 0; i < in.size(); i++) {
fa = fa.name(FIELD_PREFIX + i).type(Schema.create(Schema.Type.STRING)).noDefault();
}
return fa.endRecord();
}
示例11: inferBigQuerySchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
private org.apache.avro.Schema inferBigQuerySchema(Schema schema) {
List<Field> bqFields = schema.getFields();
if (bqFields.size() == 0) {
return SchemaBuilder.builder().record("EmptyRecord").fields().endRecord();
}
SchemaBuilder.FieldAssembler<org.apache.avro.Schema> fieldAssembler = SchemaBuilder.record("BigQuerySchema").fields();
for (Field bqField : bqFields) {
String name = bqField.getName();
org.apache.avro.Schema fieldSchema = inferSchemaField(bqField);
fieldAssembler = fieldAssembler.name(name).type(fieldSchema).noDefault();
}
return fieldAssembler.endRecord();
}
示例12: getSchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
public static Schema getSchema(boolean isDynamic) {
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.builder().record("MakeRowRecord").fields() //
.name("Id").type().nullable().stringType().noDefault() //
.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: guessSchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
@Override
public Schema guessSchema(String soqlQuery) throws IOException {
SoqlQuery query = SoqlQuery.getInstance();
query.init(soqlQuery);
SchemaBuilder.FieldAssembler fieldAssembler = SchemaBuilder.record("GuessedSchema").fields();
DescribeSObjectResult describeSObjectResult = null;
try {
describeSObjectResult = connect(null).connection.describeSObject(query.getDrivingEntityName());
} catch (ConnectionException e) {
throw new RuntimeException(e.getMessage());
}
Schema entitySchema = SalesforceAvroRegistry.get().inferSchema(describeSObjectResult);
for (FieldDescription fieldDescription : query.getFieldDescriptions()) {
Schema.Field schemaField = entitySchema.getField(fieldDescription.getSimpleName());
SchemaBuilder.FieldBuilder builder = fieldAssembler.name(fieldDescription.getFullName());
Schema fieldType = null;
if (schemaField != null) {
Map<String, Object> props = schemaField.getObjectProps();
for (Map.Entry<String, Object> entry : props.entrySet()) {
builder.prop(entry.getKey(), String.valueOf(entry.getValue()));
}
fieldType = schemaField.schema();
} else {
fieldType = DEFAULT_GUESS_SCHEMA_TYPE;
}
builder.type(fieldType).noDefault();
}
return (Schema) fieldAssembler.endRecord();
}
示例14: inferStringArray
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
public Schema inferStringArray(String[] in) {
List<Schema.Field> fields = new ArrayList<>();
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.record(RECORD_NAME).fields();
for (int i = 0; i < in.length; i++) {
fa = fa.name(FIELD_PREFIX + i).type(Schema.create(Schema.Type.STRING)).noDefault();
}
return fa.endRecord();
}
示例15: inferSchema
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
/**
* Infers an Avro schema for the given String array. This can be an expensive operation so the schema should be
* cached where possible. This is always an {@link Schema.Type#RECORD}.
*
* @param in the DescribeSObjectResult to analyse.
* @return the schema for data given from the object.
*/
static Schema inferSchema(CSVRecord in) {
List<Schema.Field> fields = new ArrayList<>();
SchemaBuilder.FieldAssembler<Schema> fa = SchemaBuilder.record(RECORD_NAME).fields();
for (int i = 0; i < in.size(); i++) {
fa = fa.name(in.get(i)).type(Schema.create(Schema.Type.STRING)).noDefault();
}
return fa.endRecord();
}