org.apache.avro.LogicalTypes.fromSchema()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(132)

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

LogicalTypes.fromSchema介绍

[英]Returns the LogicalType from the schema, if one is present.
[中]从架构返回LogicalType(如果存在)。

代码示例

代码示例来源:origin: apache/avro

@Test
public void testDecimalFixed() throws IOException {
 Schema schema = REFLECT.getSchema(DecimalRecordFixed.class);
 Assert.assertEquals("Should have the correct record name",
   "org.apache.avro.reflect.TestReflectLogicalTypes",
   schema.getNamespace());
 Assert.assertEquals("Should have the correct record name",
   "DecimalRecordFixed",
   schema.getName());
 Assert.assertEquals("Should have the correct logical type",
   LogicalTypes.decimal(9, 2),
   LogicalTypes.fromSchema(schema.getField("decimal").schema()));
 DecimalRecordFixed record = new DecimalRecordFixed();
 record.decimal = new BigDecimal("3.14");
 File test = write(REFLECT, schema, record);
 Assert.assertEquals("Should match the decimal after round trip",
   Arrays.asList(record),
   read(REFLECT.createDatumReader(schema), test));
}

代码示例来源:origin: apache/avro

@Test
public void testDecimalBytes() throws IOException {
 Schema schema = REFLECT.getSchema(DecimalRecordBytes.class);
 Assert.assertEquals("Should have the correct record name",
   "org.apache.avro.reflect.TestReflectLogicalTypes",
   schema.getNamespace());
 Assert.assertEquals("Should have the correct record name",
   "DecimalRecordBytes",
   schema.getName());
 Assert.assertEquals("Should have the correct logical type",
   LogicalTypes.decimal(9, 2),
   LogicalTypes.fromSchema(schema.getField("decimal").schema()));
 DecimalRecordBytes record = new DecimalRecordBytes();
 record.decimal = new BigDecimal("3.14");
 File test = write(REFLECT, schema, record);
 Assert.assertEquals("Should match the decimal after round trip",
   Arrays.asList(record),
   read(REFLECT.createDatumReader(schema), test));
}

代码示例来源:origin: apache/avro

Assert.assertEquals("Should have the correct logical type",
  "pair",
  LogicalTypes.fromSchema(schema.getField("pair").schema()).getName());

代码示例来源:origin: com.hotels.road/road-schema

@Override
public void onVisit(Schema schema, Collection<String> breadcrumb) {
 try {
  LogicalTypes.fromSchema(schema);
 } catch (Exception e) {
  String path = breadcrumb.stream().collect(joining("/", "/", ""));
  throw new IllegalArgumentException("Invalid logical type declared at " + path, e);
 }
}

代码示例来源:origin: GoogleCloudPlatform/DataflowTemplates

private com.google.cloud.spanner.Type inferType(Schema f, boolean supportArrays) {
 Schema.Type type = f.getType();
 LogicalType logicalType = LogicalTypes.fromSchema(f);

代码示例来源:origin: GoogleCloudPlatform/DataflowTemplates

LogicalType logicalType = LogicalTypes.fromSchema(avroFieldSchema);
Schema.Type avroType = avroFieldSchema.getType();
   LogicalType arrayLogicalType = LogicalTypes.fromSchema(arraySchema);
   Schema.Type arrayType = arraySchema.getType();
   switch (column.type().getArrayElementType().getCode()) {

相关文章