NopeCharon opened a new pull request, #3887:
URL: https://github.com/apache/parquet-java/pull/3887

   ### Rationale for this change
   
   `ParentValueContainer.getConversionContainer` casts fixed values to 
`GenericData.Fixed` before passing them to `Conversion#fromFixed`. With a 
`SpecificData` model, both fixed converters 
(`AvroConverters.FieldFixedConverter` and the compat-mode 
`AvroIndexedRecordConverter.FieldFixedConverter`) build the generated class for 
a named fixed schema. That class extends `SpecificFixed`, not 
`GenericData.Fixed`.
   
   So reading a specific record whose named fixed type has a logical type with 
a registered conversion fails. A common example is a decimal compiled with 
`enableDecimalLogicalType`:
   
   ```
   java.lang.ClassCastException: class org.apache.parquet.avro.Decimal9Fixed 
cannot be cast to class org.apache.avro.generic.GenericData$Fixed
        at org.apache.parquet.avro.ParentValueContainer$...add
   ```
   
   ### What changes are included in this PR?
   
   - Cast to `GenericFixed`. That is the parameter type of 
`Conversion#fromFixed`, and both `GenericData.Fixed` and `SpecificFixed` 
implement it.
   - Test support: a new `decimalFixed.avsc` test schema (a record with a 
`decimal(9, 2)` on a named `fixed`). The `compile-avsc` test execution now sets 
`enableDecimalLogicalType`, so the generated record's `SpecificData` model 
includes the decimal conversion. No other test schema uses decimals, so the 
code generated for them is unchanged.
   
   ### Are these changes tested?
   
   Yes. The new test `TestSpecificReadWrite#testReadSpecificDecimalFixed` 
writes generated `DecimalFixedTest` records, including negative values, with 
`AvroParquetWriter`. It reads them back with `AvroParquetReader` with 
compatibility mode on and off. Without the fix, both cases fail with the 
`ClassCastException` above. With the fix, they pass. `./mvnw verify -pl 
parquet-avro` passes: 420 tests, Spotless, RAT and japicmp.
   
   ### Are there any user-facing changes?
   
   Yes. Specific records with logical-type conversions on named fixed types, 
such as decimals, can now be read. There are no API changes.
   
   Closes #2270
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to