当前位置: 首页>>代码示例>>Java>>正文


Java SchemaBuilder类代码示例

本文整理汇总了Java中org.apache.avro.SchemaBuilder的典型用法代码示例。如果您正苦于以下问题:Java SchemaBuilder类的具体用法?Java SchemaBuilder怎么用?Java SchemaBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SchemaBuilder类属于org.apache.avro包,在下文中一共展示了SchemaBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recursiveRecord

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
@Test
public void recursiveRecord() throws Exception {
  Schema schema = SchemaBuilder
      .record("X")
      .fields()
      .name("a")
      .type(SchemaBuilder
          .record("R")
          .fields()
          .name("b")
          .type(Schema.create(Type.BYTES))
          .noDefault()
          .name("r")
          .type("R")
          .noDefault()
          .endRecord())
      .noDefault()
      .endRecord();
  assertThat(SchemaValidator.isValid(schema), is(true));
}
 
开发者ID:HotelsDotCom,项目名称:jasvorno,代码行数:21,代码来源:SchemaValidatorTest.java

示例2: 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();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:AvroTestUtils.java

示例3: 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();
  }
 
开发者ID:cloudera-labs,项目名称:envelope,代码行数:24,代码来源:AvroUtils.java

示例4: complexUnion

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
public static Schema complexUnion() {
  return SchemaBuilder
      .record("mine")
      .fields()
      .requiredLong("id")
      .name("str")
      .type(SchemaBuilder
          .unionOf()
          .stringType()
          .and()
          .longType()
          .and()
          .type(SchemaBuilder.record("inner").fields().requiredLong("a").requiredLong("b").endRecord())
          .and()
          .nullType()
          .endUnion())
      .noDefault()
      .endRecord();
}
 
开发者ID:HotelsDotCom,项目名称:jasvorno,代码行数:20,代码来源:Schemas.java

示例5: toDataTypeRecordNested

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
@Test
public void toDataTypeRecordNested() {
  Schema inner = SchemaBuilder.record("inner").fields()
      .name("field1").type().intType().noDefault()
      .endRecord();

  Schema outer = SchemaBuilder.record("outer").fields()
      .name("inner").type(inner).noDefault()
      .endRecord();

  assertEquals("Invalid DataType",
      DataTypes.createStructType(Lists.newArrayList(
        // Outer
        DataTypes.createStructField("inner",
          // Inner
          DataTypes.createStructType(Lists.newArrayList(
            DataTypes.createStructField("field1", DataTypes.IntegerType, false)
          )), false))
      ),
      AvroUtils.dataTypeFor(outer));
}
 
开发者ID:cloudera-labs,项目名称:envelope,代码行数:22,代码来源:TestAvroUtils.java

示例6: testAvroCoderStrings

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
@Test
public void testAvroCoderStrings() {
  // Custom Strings in Records
  assertDeterministic(AvroCoder.of(SchemaBuilder.record("someRecord").fields()
      .name("string").prop(SpecificData.CLASS_PROP, "java.lang.String")
      .type().stringType().noDefault()
      .endRecord()));
  assertNonDeterministic(AvroCoder.of(SchemaBuilder.record("someRecord").fields()
      .name("string").prop(SpecificData.CLASS_PROP, "unknownString")
      .type().stringType().noDefault()
      .endRecord()),
      reason("someRecord.string", "unknownString is not known to be deterministic"));

  // Custom Strings in Unions
  assertNonDeterministic(AvroCoder.of(SchemaBuilder.unionOf()
      .intType().and()
      .record("someRecord").fields()
      .name("someField").prop(SpecificData.CLASS_PROP, "unknownString")
      .type().stringType().noDefault().endRecord()
      .endUnion()),
      reason("someRecord.someField", "unknownString is not known to be deterministic"));
}
 
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:AvroCoderTest.java

示例7: testCustomObjectDynamicSchema

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
@Test
public void testCustomObjectDynamicSchema() throws Exception {
    TMarketoInputProperties props = getRESTProperties();
    String coName = "smartphone_c";
    String brand = "Apple";
    String models = "iPhone 7";
    props.inputOperation.setValue(CustomObject);
    props.customObjectAction.setValue(CustomObjectAction.get);
    props.batchSize.setValue(1);
    props.afterCustomObjectAction();
    props.customObjectName.setValue(coName);
    props.customObjectFilterType.setValue("model");
    props.customObjectFilterValues.setValue(models);
    Schema design = SchemaBuilder.builder().record("test").prop(SchemaConstants.INCLUDE_ALL_FIELDS, "true").fields()
            .endRecord();
    design.addProp(SchemaConstants.INCLUDE_ALL_FIELDS, "true");
    props.schemaInput.schema.setValue(design);
    reader = getReader(props);
    assertTrue(reader.start());
    IndexedRecord r = reader.getCurrent();
    assertNotNull(r);
    assertTrue(r.getSchema().getFields().size() > 6);
    assertFalse(reader.advance());
}
 
开发者ID:Talend,项目名称:components,代码行数:25,代码来源:MarketoInputReaderTestIT.java

示例8: testGetMultipleLeadsLeadKeyWithIdRESTTDI39008

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
@Test
public void testGetMultipleLeadsLeadKeyWithIdRESTTDI39008() throws Exception {
    propsREST.leadKeyTypeREST.setValue(LeadKeyTypeREST.id);
    propsREST.leadKeyValues.setValue("id");
    sink.initialize(null, propsREST);
    Writer tmpWriter = sink.createWriteOperation().createWriter(null);
    assertTrue(tmpWriter instanceof MarketoInputWriter);
    MarketoInputWriter writer = (MarketoInputWriter) tmpWriter;
    Schema s = SchemaBuilder.builder().record("input").fields().name("id").type().intType().noDefault().endRecord();
    IndexedRecord input = new GenericData.Record(s);
    writer.open("RESTTests");
    input.put(0, 4221930);
    writer.write(input);
    input.put(0, 4221931);
    writer.write(input);
    writer.close();
    assertEquals(2, writer.result.successCount);
}
 
开发者ID:Talend,项目名称:components,代码行数:19,代码来源:MarketoInputWriterTestIT.java

示例9: setupProperties

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
@Override
public void setupProperties() {
    super.setupProperties();

    Schema schema = SchemaBuilder.builder().record(GoogleDriveCreateDefinition.COMPONENT_NAME).fields() //
            .name(GoogleDriveCreateDefinition.RETURN_PARENT_FOLDER_ID)//
            .prop(SchemaConstants.TALEND_IS_LOCKED, "true")//
            .type().nullable().stringType().noDefault() //
            .name(GoogleDriveCreateDefinition.RETURN_NEW_FOLDER_ID)//
            .prop(SchemaConstants.TALEND_IS_LOCKED, "true")//
            .type().nullable().stringType().noDefault() //
            .endRecord();
    schema.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
    schemaMain.schema.setValue(schema);

    parentFolderAccessMethod.setPossibleValues(AccessMethod.values());
    parentFolderAccessMethod.setValue(AccessMethod.Name);
    parentFolder.setValue("root");
    newFolder.setValue("");
}
 
开发者ID:Talend,项目名称:components,代码行数:21,代码来源:GoogleDriveCreateProperties.java

示例10: testStringToDecimalConverter

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
@Test
public void testStringToDecimalConverter() {
    Schema schema = SchemaBuilder.builder().record("Schema").fields() //
            .name("Field_A").type(AvroUtils._decimal()).noDefault() //
            .endRecord();

    AvroConverter<String, ?> converter = sRegistry.getConverterFromString(schema.getField("Field_A"));
    assertNotNull(converter);
    assertEquals(String.class, converter.getDatumClass());
    assertEquals(schema.getField("Field_A").schema(), converter.getSchema());

    Object value = converter.convertToAvro("20000000000000000000000000.123456789");
    assertNotNull(value);
    assertThat(value, instanceOf(BigDecimal.class));
    assertThat((BigDecimal) value, equalTo(new BigDecimal("20000000000000000000000000.123456789")));

    assertNull(converter.convertToAvro(""));
    assertNull(converter.convertToAvro(null));

    String sValue = ((AvroConverter<String, BigDecimal>) converter).convertToDatum(
            new BigDecimal("20000000000000000000000000.123456789"));
    assertNotNull(sValue);
    assertThat(sValue, equalTo("20000000000000000000000000.123456789"));
}
 
开发者ID:Talend,项目名称:components,代码行数:25,代码来源:SalesforceAvroRegistryTest.java

示例11: getCampaignSchema

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
/**
 * Campaign Operations
 */
public static Schema getCampaignSchema() {
    Schema s = SchemaBuilder.builder().record("campaign").fields() //
            .name("id").prop(SchemaConstants.TALEND_COLUMN_IS_KEY, "true").type().nullable().intType().noDefault() //
            .name("name").type().nullable().stringType().noDefault() //
            .name("active").type().nullable().booleanType().noDefault() //
            .name("description").type().nullable().stringType().noDefault() //
            .name("programId").type().nullable().intType().noDefault() //
            .name("programName").type().nullable().stringType().noDefault() //
            .name("type").type().nullable().stringType().noDefault() //
            .name("workspaceName").type().nullable().stringType().noDefault() //
            .name(FIELD_CREATED_AT)//
            .prop(SchemaConstants.TALEND_COLUMN_PATTERN, DATETIME_PATTERN_REST)//
            .prop(SchemaConstants.JAVA_CLASS_FLAG, Date.class.getCanonicalName()) //
            .type(AvroUtils._date()).noDefault()//
            .name(FIELD_UPDATED_AT)//
            .prop(SchemaConstants.TALEND_COLUMN_PATTERN, DATETIME_PATTERN_REST)//
            .prop(SchemaConstants.JAVA_CLASS_FLAG, Date.class.getCanonicalName()) //
            .type(AvroUtils._date()).noDefault()//
            .endRecord();
    s.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
    return s;
}
 
开发者ID:Talend,项目名称:components,代码行数:26,代码来源:MarketoConstants.java

示例12: getAvroSchema

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
private static Schema getAvroSchema() {
    Schema s4 = SchemaBuilder.record(AVRO_TYPENAME + "_4").fields().requiredInt("lvl4").endRecord();
    Schema s3 = SchemaBuilder.record(AVRO_TYPENAME + "_3").fields()
            .name("l4").type(s4).noDefault()
            .requiredInt("lvl3")
            .endRecord();
    Schema s2 = SchemaBuilder.record(AVRO_TYPENAME + "_2").fields()
            .name("l3").type(s3).noDefault()
            .requiredInt("lvl2")
            .endRecord();
    Schema s1 = SchemaBuilder.record(AVRO_TYPENAME + "_1").fields()
            .name("l2").type(s2).noDefault()
            .requiredInt("lvl1")
            .endRecord();
    return SchemaBuilder.record(AVRO_TYPENAME).fields().name("l1").type(s1).noDefault().endRecord();
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:17,代码来源:ExecEventInfraPropertyNestedSimple.java

示例13: testSwitchName

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
@Test
public void testSwitchName() {
  String originalName = "originalName";
  String newName = "newName";
  Schema schema = SchemaBuilder.record(originalName).fields().
      requiredDouble("double").optionalFloat("float").endRecord();

  Schema newSchema = AvroUtils.switchName(schema, newName);

  Assert.assertEquals(newSchema.getName(), newName);
  for(Schema.Field field : newSchema.getFields()) {
    Assert.assertEquals(field, schema.getField(field.name()));
  }

  Assert.assertEquals(newName, AvroUtils.switchName(schema, newName).getName());
  Assert.assertEquals(schema,
      AvroUtils.switchName(AvroUtils.switchName(schema, newName), schema.getName()));

}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:20,代码来源:AvroUtilsTest.java

示例14: createSchemaFor

import org.apache.avro.SchemaBuilder; //导入依赖的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;
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:24,代码来源:AvroTestUtil.java

示例15: getMappingSchema

import org.apache.avro.SchemaBuilder; //导入依赖的package包/类
public Schema getMappingSchema() {
    return SchemaBuilder.record("mappingtest").fields()
            //
            .name("PartitionKey").type(AvroUtils._string()).noDefault()//
            .name("RowKey").type(AvroUtils._string()).noDefault()//
            .name("Timestamp").type(AvroUtils._date()).noDefault() //
            .name("daty").type(AvroUtils._date()).noDefault() //
            .name("booly").type(AvroUtils._boolean()).noDefault()//
            .name("inty").type(AvroUtils._int()).noDefault()//
            .name("stringy").type(AvroUtils._string()).noDefault()//
            .name("longy").type(AvroUtils._long()).noDefault()//
            .name("doubly").type(AvroUtils._double()).noDefault()//
            .name("bytys").type(AvroUtils._bytes()).noDefault()//
            //
            .endRecord();
}
 
开发者ID:Talend,项目名称:components,代码行数:17,代码来源:TAzureStorageOuputTableTestIT.java


注:本文中的org.apache.avro.SchemaBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。