LuciferYang opened a new issue, #9517:
URL: https://github.com/apache/paimon/issues/9517

   ### Search before asking
   
   - [x] I searched in the [issues](https://github.com/apache/paimon/issues) 
and found nothing similar.
   
   ### Paimon version
   
   master, `9c7deebbd` (2.1-SNAPSHOT)
   
   ### Compute Engine
   
   Java API / Parquet read path. `PaimonShreddingUtils.buildVariantSchema` runs 
on the physical schema of a shredded variant column, from 
`VariantShreddingReadPlanFactory.assembleVariantVector` on read and 
`VariantShreddingWritePlan` on write.
   
   ### Minimal reproduce step
   
   In a variant shredding schema, every field of an object's `typed_value` is 
itself a group of `value` / `typed_value`. `buildVariantSchema` casts each 
inner field to `RowType` without checking it first:
   
   ```java
   for (int index = 0; index < rFields.size(); index++) {
       DataField f = rFields.get(index);
       objectSchema[index] =
               new VariantSchema.ObjectField(
                       f.name(), buildVariantSchema((RowType) f.type(), false));
   }
   ```
   
   So a physical schema whose inner field is a scalar dies on the cast:
   
   ```java
   RowType physicalType =
           RowType.of(
                   new DataType[] {
                       DataTypes.BYTES(),
                       DataTypes.BYTES(),
                       RowType.of(new DataType[] {DataTypes.INT()}, new 
String[] {"x"})
                   },
                   new String[] {"metadata", "value", "typed_value"});
   
   buildVariantSchema(physicalType);
   // java.lang.ClassCastException: org.apache.paimon.types.IntType cannot be 
cast to
   // org.apache.paimon.types.RowType
   ```
   
   ### What doesn't meet your expectations?
   
   Every other malformed shape in that method raises `RuntimeException("Invalid 
variant shredding schema: " + rowType)`, which names the schema that was 
rejected. This one path raises a bare `ClassCastException` naming two class 
names and nothing else, so a reader hitting a shredded variant column that 
Paimon does not recognize gets a stack trace that says nothing about the schema 
or the column.
   
   I have not produced such a file from another engine, so I am reporting this 
as the error-reporting defect it is rather than claiming a live read failure. 
The method is reached with a schema read from the file on every shredded 
variant read, so the input is not fully under Paimon's control.
   
   ### Anything else?
   
   Two checks in the same branch are dead and can go at the same time. `if 
(!(dataType instanceof RowType))` sits inside `case ROW:` of a switch on 
`getTypeRoot()`, and `RowType` is the only type with that root. The other check 
tests the outer field list for emptiness and duplicates: emptiness is already 
rejected at the top of the method, and `RowType`'s constructor calls 
`validateFields`, which rejects duplicate field names outright, so neither 
condition can hold by the time that line runs.
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!
   


-- 
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]

Reply via email to