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

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... 
-->
   
   ### Purpose
   
   Add in `Variant`
   
   ```java
   Object variantGet(String path, DataType dataType, VariantCastArgs castArgs);
   ```
   
   Add in `PaimonShreddingUtils`
   ```java
   /**
    * Represent a single field in a variant struct, that is a single requested 
field that the scan
    * should produce by extracting from the variant column.
    */
   public static class FieldToExtract {
   
       private final SchemaPathSegment[] path;
       private final BaseVariantReader reader;
   }
   
   /** Assemble a variant struct, in which each field is extracted from the 
variant value. */
   public static InternalRow assembleVariantStruct(
           InternalRow inputRow, VariantSchema schema, FieldToExtract[] fields)
   )
   ```
   
   Usage
   ```java
   VariantCastArgs castArgs = new VariantCastArgs(true, ZoneOffset.UTC);
   
   // shreddedType: ROW<a INT, b STRING>
   RowType shreddedType =
           RowType.of(
                   new DataType[] {DataTypes.INT(), DataTypes.STRING()},
                   new String[] {"a", "b"});
   RowType shreddingSchema = variantShreddingSchema(shreddedType);
   VariantSchema variantSchema = buildVariantSchema(shreddingSchema);
   
   // fieldsToExtract: $.a : int, $.b : string
   FieldToExtract f1 = getFieldsToExtract(DataTypes.INT(), "$.a", castArgs, 
variantSchema);
   FieldToExtract f2 = getFieldsToExtract(DataTypes.STRING(), "$.b", castArgs, 
variantSchema);
   FieldToExtract[] fields = new FieldToExtract[] {f1, f2};
   
   GenericVariant v = GenericVariant.fromJson("{\"a\": 1, \"b\": \"hello\"}");
   assertThat(assembleVariantStruct(castShredded(v, variantSchema), 
variantSchema, fields))
           .isEqualTo(GenericRow.of(1, BinaryString.fromString("hello")));
   ```
   
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


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