Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Introduce VariantType #4757

Merged
merged 1 commit into from
Dec 23, 2024
Merged

Conversation

Zouxxyy
Copy link
Contributor

@Zouxxyy Zouxxyy commented Dec 23, 2024

Purpose

Subtask of #4471

  • Add a new data type VariantType
/**
 * Data type of {@link Variant}.
 *
 * @since 1.1.0
 */
@Public
public class VariantType extends DataType {

    private static final String FORMAT = "VARIANT";
}
  • Support reading and writing Variant into parquet with java api
FileFormat format = new ParquetFileFormat(new FileFormatFactory.FormatContext(new Options(), 1024, 1024));

RowType writeType = DataTypes.ROW(DataTypes.FIELD(0, "v", DataTypes.VARIANT()));

try (PositionOutputStream out = fileIO.newOutputStream(file, false);
        FormatWriter writer = format.createWriterFactory(writeType).create(out, "zstd")) {
    writer.addElement(
            GenericRow.of(GenericVariant.fromJson("{\"age\":35,\"city\":\"Chicago\"}")));
}

List<InternalRow> result = new ArrayList<>();
try (RecordReader<InternalRow> reader =  format.createReaderFactory(writeType) 
         .createReader( new FormatReaderContext(fileIO, file, fileIO.getFileSize(file)))) {
    InternalRowSerializer serializer = new InternalRowSerializer(writeType);
    reader.forEachRemaining(row -> result.add(serializer.copy(row)));
}

assertThat(result.get(0).getVariant(0).toJson()) .isEqualTo("{\"age\":35,\"city\":\"Chicago\"}");

Tests

API and Format

Documentation

@Zouxxyy Zouxxyy force-pushed the variant/add-type-new branch from 622b02f to dcd758a Compare December 23, 2024 11:57
@Zouxxyy Zouxxyy changed the title [WIP] Introduce variant type Introduce VariantType Dec 23, 2024
@Zouxxyy Zouxxyy changed the title Introduce VariantType [core] Introduce VariantType Dec 23, 2024
Copy link
Contributor

@JingsongLi JingsongLi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@JingsongLi JingsongLi merged commit c0023f0 into apache:master Dec 23, 2024
12 checks passed
@raphaelauv
Copy link

before hudi,delta,iceberg :)

@Zouxxyy Zouxxyy deleted the variant/add-type-new branch December 23, 2024 14:11
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.

3 participants