Skip to content

Commit f50dd6c

Browse files
authored
GH-2972: Fix incomplete avro metadata on INT96 schema converter (#3311)
1 parent 9db6236 commit f50dd6c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

parquet-avro/src/main/java/org/apache/parquet/avro/AvroSchemaConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,9 @@ public Schema convertINT64(PrimitiveTypeName primitiveTypeName) {
404404
@Override
405405
public Schema convertINT96(PrimitiveTypeName primitiveTypeName) {
406406
if (readInt96AsFixed) {
407-
return Schema.createFixed("INT96", "INT96 represented as byte[12]", null, 12);
407+
String name = parquetType.getName();
408+
String ns = namespace(name, names);
409+
return Schema.createFixed(name, "INT96 represented as byte[12]", ns, 12);
408410
}
409411
throw new IllegalArgumentException(
410412
"INT96 is deprecated. As interim enable READ_INT96_AS_FIXED flag to read as byte array.");

parquet-avro/src/test/java/org/apache/parquet/avro/TestAvroSchemaConverter.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ public void testParquetInt96AsFixed12AvroType() throws Exception {
579579
enableInt96ReadingConfig.setBoolean(AvroReadSupport.READ_INT96_AS_FIXED, true);
580580

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

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

602+
@Test
603+
public void testMultipleInt96FieldsToStringConversion() throws Exception {
604+
Configuration enableInt96ReadingConfig = new Configuration();
605+
enableInt96ReadingConfig.setBoolean(AvroReadSupport.READ_INT96_AS_FIXED, true);
606+
607+
Types.MessageTypeBuilder builder = Types.buildMessage();
608+
builder.optional(PrimitiveType.PrimitiveTypeName.INT96).named("timestamp_1");
609+
builder.optional(PrimitiveType.PrimitiveTypeName.INT96).named("timestamp_2");
610+
MessageType int96Schema = builder.named("int96Schema");
611+
612+
AvroSchemaConverter converter = new AvroSchemaConverter(enableInt96ReadingConfig);
613+
Schema avroSchema = converter.convert(int96Schema);
614+
615+
String schemaString = avroSchema.toString(true);
616+
617+
Assert.assertTrue(
618+
"First field should have full timestamp_1 definition",
619+
schemaString.contains("\"name\" : \"timestamp_1\""));
620+
Assert.assertTrue(
621+
"Second field should have full timestamp_2 definition",
622+
schemaString.contains("\"name\" : \"timestamp_2\""));
623+
624+
Assert.assertFalse(
625+
"Should not reference bare 'INT96' type anymore",
626+
schemaString.contains("\"type\" : [ \"null\", \"INT96\" ]"));
627+
}
628+
602629
@Test
603630
public void testDateType() throws Exception {
604631
Schema date = LogicalTypes.date().addToSchema(Schema.create(INT));

0 commit comments

Comments
 (0)