Skip to content

[variant] Introduce assemble shredded variant struct function - #6652

Merged
JingsongLi merged 3 commits into
apache:masterfrom
Zouxxyy:dev/variant-pru
Nov 24, 2025
Merged

JingsongLi merged 3 commits into
apache:masterfrom
Zouxxyy:dev/variant-pru

Conversation

@Zouxxyy

@Zouxxyy Zouxxyy commented Nov 21, 2025 •

Copy link
Copy Markdown
Contributor

Purpose

Subtask of #4471

Add in Variant

Object variantGet(String path, DataType dataType, VariantCastArgs castArgs);

Add in PaimonShreddingUtils

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

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 = buildFieldsToExtract(DataTypes.INT(), "$.a", castArgs, variantSchema);
FieldToExtract f2 = buildFieldsToExtract(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

API and Format

Documentation

@Zouxxyy
Zouxxyy force-pushed the dev/variant-pru branch 2 times, most recently from 0cb852e to 02d77e9 Compare November 22, 2025 03:02
@JingsongLi

Copy link
Copy Markdown
Contributor

+1

@JingsongLi
JingsongLi merged commit 5949538 into apache:master Nov 24, 2025
22 checks passed
discivigour pushed a commit to discivigour/paimon that referenced this pull request Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants