-
Notifications
You must be signed in to change notification settings - Fork 1.5k
GH-3149: Enable ParquetAvroReader to handle decimal types for int32/64 #3306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gszadovszky
merged 3 commits into
apache:master
from
ArnavBalyan:arnavb/avrodecimal-int-support
Sep 6, 2025
+120
−0
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| package org.apache.parquet.avro; | ||
|
|
||
| import static org.apache.parquet.avro.AvroTestUtil.optional; | ||
| import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64; | ||
| import static org.apache.parquet.schema.Type.Repetition.REQUIRED; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
|
|
||
|
|
@@ -61,17 +63,23 @@ | |
| import org.apache.parquet.conf.ParquetConfiguration; | ||
| import org.apache.parquet.conf.PlainParquetConfiguration; | ||
| import org.apache.parquet.example.data.Group; | ||
| import org.apache.parquet.example.data.GroupFactory; | ||
| import org.apache.parquet.example.data.simple.SimpleGroupFactory; | ||
| import org.apache.parquet.hadoop.ParquetReader; | ||
| import org.apache.parquet.hadoop.ParquetWriter; | ||
| import org.apache.parquet.hadoop.api.WriteSupport; | ||
| import org.apache.parquet.hadoop.example.ExampleParquetWriter; | ||
| import org.apache.parquet.hadoop.example.GroupReadSupport; | ||
| import org.apache.parquet.hadoop.util.HadoopCodecs; | ||
| import org.apache.parquet.io.InputFile; | ||
| import org.apache.parquet.io.LocalInputFile; | ||
| import org.apache.parquet.io.LocalOutputFile; | ||
| import org.apache.parquet.io.api.Binary; | ||
| import org.apache.parquet.io.api.RecordConsumer; | ||
| import org.apache.parquet.schema.LogicalTypeAnnotation; | ||
| import org.apache.parquet.schema.MessageType; | ||
| import org.apache.parquet.schema.MessageTypeParser; | ||
| import org.apache.parquet.schema.PrimitiveType; | ||
| import org.junit.Assert; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
|
|
@@ -400,6 +408,55 @@ public void testFixedDecimalValues() throws Exception { | |
| Assert.assertEquals("Content should match", expected, records); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDecimalInt64Values() throws Exception { | ||
|
||
|
|
||
| File file = temp.newFile("test_decimal_int64_values.parquet"); | ||
| file.delete(); | ||
| Path path = new Path(file.toString()); | ||
|
|
||
| MessageType parquetSchema = new MessageType( | ||
| "test_decimal_int64_values", | ||
| new PrimitiveType(REQUIRED, INT64, "decimal_salary") | ||
| .withLogicalTypeAnnotation(LogicalTypeAnnotation.decimalType(1, 10))); | ||
|
|
||
| try (ParquetWriter<Group> writer = | ||
| ExampleParquetWriter.builder(path).withType(parquetSchema).build()) { | ||
|
|
||
| GroupFactory factory = new SimpleGroupFactory(parquetSchema); | ||
|
|
||
| Group group1 = factory.newGroup(); | ||
| group1.add("decimal_salary", 234L); | ||
| writer.write(group1); | ||
|
|
||
| Group group2 = factory.newGroup(); | ||
| group2.add("decimal_salary", 1203L); | ||
| writer.write(group2); | ||
| } | ||
|
|
||
| GenericData decimalSupport = new GenericData(); | ||
| decimalSupport.addLogicalTypeConversion(new Conversions.DecimalConversion()); | ||
|
|
||
| List<GenericRecord> records = Lists.newArrayList(); | ||
| try (ParquetReader<GenericRecord> reader = AvroParquetReader.<GenericRecord>builder(path) | ||
| .withDataModel(decimalSupport) | ||
| .build()) { | ||
| GenericRecord rec; | ||
| while ((rec = reader.read()) != null) { | ||
| records.add(rec); | ||
| } | ||
| } | ||
|
|
||
| Assert.assertEquals("Should read 2 records", 2, records.size()); | ||
|
|
||
| Object firstSalary = records.get(0).get("decimal_salary"); | ||
| Object secondSalary = records.get(1).get("decimal_salary"); | ||
|
|
||
| Assert.assertTrue("Should be BigDecimal, but is " + firstSalary.getClass(), firstSalary instanceof BigDecimal); | ||
| Assert.assertEquals("Should be 23.4, but is " + firstSalary, new BigDecimal("23.4"), firstSalary); | ||
| Assert.assertEquals("Should be 120.3, but is " + secondSalary, new BigDecimal("120.3"), secondSalary); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAll() throws Exception { | ||
| Schema schema = | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other primitive converters does not have dictionary support by default because they just write the original value as is. Dictionary support makes sense only if you cache the converted (
BigDecimal) values to spare the time of the conversion when the same value (dictionary index) appears.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, removed the dictionary support for now