Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,9 @@ public Schema convertINT64(PrimitiveTypeName primitiveTypeName) {
@Override
public Schema convertINT96(PrimitiveTypeName primitiveTypeName) {
if (readInt96AsFixed) {
return Schema.createFixed("INT96", "INT96 represented as byte[12]", null, 12);
String name = parquetType.getName();
String ns = namespace(name, names);
return Schema.createFixed(name, "INT96 represented as byte[12]", ns, 12);
}
throw new IllegalArgumentException(
"INT96 is deprecated. As interim enable READ_INT96_AS_FIXED flag to read as byte array.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public void testParquetInt96AsFixed12AvroType() throws Exception {
enableInt96ReadingConfig.setBoolean(AvroReadSupport.READ_INT96_AS_FIXED, true);

Schema schema = Schema.createRecord("myrecord", null, null, false);
Schema int96schema = Schema.createFixed("INT96", "INT96 represented as byte[12]", null, 12);
Schema int96schema = Schema.createFixed("int96_field", "INT96 represented as byte[12]", null, 12);
schema.setFields(Collections.singletonList(new Schema.Field("int96_field", int96schema, null, null)));

testParquetToAvroConversion(
Expand All @@ -599,6 +599,33 @@ public void testParquetInt96DefaultFail() throws Exception {
() -> new AvroSchemaConverter().convert(parquetSchemaWithInt96));
}

@Test
public void testMultipleInt96FieldsToStringConversion() throws Exception {
Configuration enableInt96ReadingConfig = new Configuration();
enableInt96ReadingConfig.setBoolean(AvroReadSupport.READ_INT96_AS_FIXED, true);

Types.MessageTypeBuilder builder = Types.buildMessage();
builder.optional(PrimitiveType.PrimitiveTypeName.INT96).named("timestamp_1");
builder.optional(PrimitiveType.PrimitiveTypeName.INT96).named("timestamp_2");
MessageType int96Schema = builder.named("int96Schema");

AvroSchemaConverter converter = new AvroSchemaConverter(enableInt96ReadingConfig);
Schema avroSchema = converter.convert(int96Schema);

String schemaString = avroSchema.toString(true);

Assert.assertTrue(
"First field should have full timestamp_1 definition",
schemaString.contains("\"name\" : \"timestamp_1\""));
Assert.assertTrue(
"Second field should have full timestamp_2 definition",
schemaString.contains("\"name\" : \"timestamp_2\""));

Assert.assertFalse(
"Should not reference bare 'INT96' type anymore",
schemaString.contains("\"type\" : [ \"null\", \"INT96\" ]"));
}

@Test
public void testDateType() throws Exception {
Schema date = LogicalTypes.date().addToSchema(Schema.create(INT));
Expand Down