LuciferYang opened a new pull request, #9518:
URL: https://github.com/apache/paimon/pull/9518

   ### Purpose
   
   close #9517
   
   In a variant shredding schema, every field of an object's `typed_value` is 
itself a group of `value` / `typed_value`. `buildVariantSchema` cast each inner 
field to `RowType` without checking it, so a physical schema whose inner field 
is a scalar died on a bare `ClassCastException` naming two class names, instead 
of the `Invalid variant shredding schema: <rowType>` error the method raises 
for every other malformed shape. That path now checks the type and raises the 
same error as the rest.
   
   Two checks in the same branch are removed because they cannot fire:
   
   - `if (!(dataType instanceof RowType))` sits inside `case ROW:` of a switch 
on `field.type().getTypeRoot()`, and `RowType` is the only type in paimon-api 
with `DataTypeRoot.ROW`.
   - `if (fields.isEmpty() || fields.stream().distinct().count() != 
fields.size())` tests the *outer* field list, not the inner struct it appears 
to guard. Emptiness is already rejected at the top of the method; duplicates 
cannot exist because `RowType`'s constructor calls `validateFields`, which 
throws on duplicate field names. Duplicate `typed_value` / `value` / `metadata` 
are caught by the `typedIdx != -1` style checks, and any other outer name falls 
into the throwing `default:` of the name switch.
   
   An empty inner struct stays legal, exactly as before: the removed check 
never guarded the inner list, so nothing changes there. It yields a zero-length 
`objectSchema`, which is what `ShreddingUtils` and `VariantShreddingWriter` 
already consume by looping on `.length`.
   
   ### Tests
   
   Both cases live in `PaimonShreddingUtilsTest`.
   
   - `testBuildVariantSchemaRejectsNonStructInnerField` builds a schema that is 
valid except for a scalar inner field and asserts the message is the 
invalid-schema one. Verified red before the change, where it fails with 
`ClassCastException: org.apache.paimon.types.IntType cannot be cast to 
org.apache.paimon.types.RowType`. The message is what separates the two 
outcomes, since `ClassCastException` is itself a `RuntimeException`.
   - `testBuildVariantSchemaAcceptsEmptyInnerStruct` pins that an empty 
`typed_value` struct produces a zero-length `objectSchema` rather than null, 
which is the shape the two consumers above depend on. This one passes before 
the change as well; it is there to hold that behavior still.
   
   `mvn -pl paimon-common test` on JDK 8: 12467 tests, 0 failures, 0 errors. 
checkstyle, spotless, enforcer and rat run clean.
   


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