org.apache.gobblin.util.AvroUtils.getFieldSchema()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中org.apache.gobblin.util.AvroUtils.getFieldSchema()方法的一些代码示例,展示了AvroUtils.getFieldSchema()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AvroUtils.getFieldSchema()方法的具体详情如下:
包路径:org.apache.gobblin.util.AvroUtils
类名称:AvroUtils
方法名:getFieldSchema

AvroUtils.getFieldSchema介绍

[英]Given a GenericRecord, this method will return the schema of the field specified by the path parameter. The fieldLocation parameter is an ordered string specifying the location of the nested field to retrieve. For example, field1.nestedField1 takes the the schema of the field "field1", and retrieves the schema "nestedField1" from it.
[中]给定GenericRecord,此方法将返回path参数指定的字段的架构。fieldLocation参数是一个有序字符串,指定要检索的嵌套字段的位置。例如,field1。nestedField1获取字段“field1”的架构,并从中检索架构“nestedField1”。

代码示例

代码示例来源:origin: apache/incubator-gobblin

@Override
public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException {
 Optional<Schema> schema = AvroUtils.getFieldSchema(inputSchema, this.fieldLocation);
 return schema.orNull();
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * In case of complex data types in union {@link AvroUtils#getFieldSchema(Schema, String)} should throw {@link AvroRuntimeException}
 * @throws IOException
 */
@Test(expectedExceptions = AvroRuntimeException.class)
public void testComplexTypesInUnionNotSupported()
  throws IOException {
 final String TEST_LOCATION = "TestUnionObject.RecordInUnion";
 String avroFilePath = this.AVRO_DIR + "avroDir/avroUtilsTestFile.avro";
 GenericRecord record = getRecordFromFile(avroFilePath).get(0);
 AvroUtils.getFieldSchema(record.getSchema(), TEST_LOCATION);
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * This is a test to validate support of maps in {@link org.apache.gobblin.util.AvroUtils#getFieldValue(GenericRecord, String)}
 * and {@link org.apache.gobblin.util.AvroUtils#getFieldSchema(Schema, String)}
 * @throws IOException
 */
@Test
public void testGetObjectFromMap()
  throws IOException {
 final String TEST_FIELD_LOCATION = "Map.stringKey.Field";
 String avroFilePath = this.AVRO_DIR + "avroDir/avroUtilsTestFile.avro";
 GenericRecord record = getRecordFromFile(avroFilePath).get(0);
 Assert.assertEquals(AvroUtils.getFieldValue(record, TEST_FIELD_LOCATION).get().toString(), "stringValue2");
 Assert.assertEquals(AvroUtils.getFieldSchema(record.getSchema(), TEST_FIELD_LOCATION).get().getType(),
   Schema.Type.STRING);
}

代码示例来源:origin: apache/incubator-gobblin

@Test
 public void testUnionWithNull() {
  Schema nestedRecord = SchemaBuilder.record("nested").fields().requiredDouble("double")
    .requiredString("string").endRecord();
  Schema union = SchemaBuilder.unionOf().nullType().and().type(nestedRecord).endUnion();
  Schema schema = SchemaBuilder.record("record").fields().name("union").type(union).noDefault().endRecord();

  Schema doubleSchema = AvroUtils.getFieldSchema(schema, "union.double").get();
  Assert.assertEquals(doubleSchema.getType(), Schema.Type.DOUBLE);

  GenericRecord nested = new GenericData.Record(nestedRecord);
  nested.put("double", 10);
  nested.put("string", "testString");
  GenericRecord record = new GenericData.Record(schema);
  record.put("union", nested);

  String stringValue = AvroUtils.getFieldValue(record, "union.string").get().toString();
  Assert.assertEquals(stringValue, "testString");
 }
}

代码示例来源:origin: org.apache.gobblin/gobblin-core

@Override
public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException {
 Optional<Schema> schema = AvroUtils.getFieldSchema(inputSchema, this.fieldLocation);
 return schema.orNull();
}

相关文章