From eccd8778745a46f5ca94e92857a0d946e6a67da0 Mon Sep 17 00:00:00 2001 From: aandres3 Date: Mon, 6 Jan 2025 09:15:03 +0000 Subject: [PATCH] Fix reading of proto Uint32Value --- .../org/apache/parquet/proto/ProtoMessageConverter.java | 7 +++++++ .../org/apache/parquet/proto/ProtoSchemaConverter.java | 2 +- .../java/org/apache/parquet/proto/ProtoWriteSupport.java | 2 +- .../org/apache/parquet/proto/ProtoSchemaConverterTest.java | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoMessageConverter.java b/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoMessageConverter.java index d446598f06..e9e42e24a0 100644 --- a/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoMessageConverter.java +++ b/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoMessageConverter.java @@ -763,6 +763,13 @@ public ProtoUInt32ValueConverter(ParentValueContainer parent) { this.parent = parent; } + + @Override + public void addInt(int value) { + parent.add(UInt32Value.of(value)); + } + + // This is left for backward compatibility with the old implementation which used int64 for uint32 @Override public void addLong(long value) { parent.add(UInt32Value.of(Math.toIntExact(value))); diff --git a/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoSchemaConverter.java b/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoSchemaConverter.java index 74bb4235a2..ff27b263e9 100644 --- a/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoSchemaConverter.java +++ b/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoSchemaConverter.java @@ -260,7 +260,7 @@ private Builder>, GroupBuilder> addF return builder.primitive(INT32, getRepetition(descriptor)); } if (messageType.equals(UInt32Value.getDescriptor())) { - return builder.primitive(INT64, getRepetition(descriptor)); + return builder.primitive(INT32, getRepetition(descriptor)); } if (messageType.equals(BytesValue.getDescriptor())) { return builder.primitive(BINARY, getRepetition(descriptor)); diff --git a/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java b/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java index 637f6fda91..b9fe4bf9e1 100644 --- a/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java +++ b/parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java @@ -763,7 +763,7 @@ void writeRawValue(Object value) { class UInt32ValueWriter extends FieldWriter { @Override void writeRawValue(Object value) { - recordConsumer.addLong(((UInt32Value) value).getValue()); + recordConsumer.addInteger(((UInt32Value) value).getValue()); } } diff --git a/parquet-protobuf/src/test/java/org/apache/parquet/proto/ProtoSchemaConverterTest.java b/parquet-protobuf/src/test/java/org/apache/parquet/proto/ProtoSchemaConverterTest.java index 5240be5a36..e9f08f33f7 100644 --- a/parquet-protobuf/src/test/java/org/apache/parquet/proto/ProtoSchemaConverterTest.java +++ b/parquet-protobuf/src/test/java/org/apache/parquet/proto/ProtoSchemaConverterTest.java @@ -400,7 +400,7 @@ public void testProto3ConvertWrappedMessageUnwrapped() throws Exception { + " optional int64 wrappedInt64 = 3;\n" + " optional int64 wrappedUInt64 = 4;\n" + " optional int32 wrappedInt32 = 5;\n" - + " optional int64 wrappedUInt32 = 6;\n" + + " optional int32 wrappedUInt32 = 6;\n" + " optional boolean wrappedBool = 7;\n" + " optional binary wrappedString (UTF8) = 8;\n" + " optional binary wrappedBytes = 9;\n"