Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions java/src/main/java/ai/rapids/cudf/VariantUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class VariantUtils {
// cpp/include/cudf/io/experimental/variant.hpp and
// cpp/src/io/parquet/experimental/variant_extract.cu:is_variant_castable.
private static final List<DType> SUPPORTED_TYPES = Arrays.asList(
DType.STRING, DType.INT8, DType.INT16, DType.INT32, DType.INT64);
DType.STRING, DType.INT8, DType.INT16, DType.INT32, DType.INT64,
DType.FLOAT32, DType.FLOAT64, DType.BOOL8);

private VariantUtils() {}

Expand All @@ -38,8 +39,11 @@ private static void validateTargetType(DType targetType) {
*
* @param variantStruct Variant materialization: STRUCT(metadata LIST&lt;UINT8&gt;,
* value LIST&lt;UINT8&gt;, optional shredded children...)
* @param path JSONPath-like path accepted by cuDF's Variant extractor. Paths are expected to
* be ASCII object-field paths like {@code x}, {@code $.x}, or {@code $.x.y}.
* @param path JSONPath-like path accepted by cuDF's Variant extractor. Object-field steps use
* dot notation and zero-based array-index steps use bracket notation, for example
* {@code x}, {@code $.x.y}, {@code $[0]}, or {@code $.a[0].b}. Missing fields,
* out-of-bounds indices, and container mismatches produce null rows. Wildcards,
* negative indices, and quoted names inside brackets are not supported.
* @return LIST&lt;UINT8&gt; column of raw encoded Variant values
*/
public static ColumnVector getVariantFieldValue(ColumnView variantStruct, String path) {
Expand All @@ -50,8 +54,11 @@ public static ColumnVector getVariantFieldValue(ColumnView variantStruct, String

/**
* Decode raw Variant-encoded value bytes into {@code targetType}. Supported target types are
* {@link DType#STRING}, {@link DType#INT8}, {@link DType#INT16}, {@link DType#INT32}, and
* {@link DType#INT64}.
* {@link DType#STRING}, {@link DType#INT8}, {@link DType#INT16}, {@link DType#INT32},
* {@link DType#INT64}, {@link DType#FLOAT32}, {@link DType#FLOAT64}, and {@link DType#BOOL8}.
* Decoding requires the encoded physical type to exactly match {@code targetType}; no numeric
* conversions are performed. Input nulls, encoded Variant nulls, and physical-type mismatches
* produce null output rows.
*/
public static ColumnVector castVariantValue(ColumnView valueBytes, DType targetType) {
Objects.requireNonNull(valueBytes, "valueBytes");
Expand All @@ -63,7 +70,20 @@ public static ColumnVector castVariantValue(ColumnView valueBytes, DType targetT
/**
* Extract a Variant field and decode it into {@code targetType} in one native call.
* Supported target types are {@link DType#STRING}, {@link DType#INT8}, {@link DType#INT16},
* {@link DType#INT32}, and {@link DType#INT64}.
* {@link DType#INT32}, {@link DType#INT64}, {@link DType#FLOAT32}, {@link DType#FLOAT64}, and
* {@link DType#BOOL8}.
* Decoding requires the encoded physical type to exactly match {@code targetType}; no numeric
* conversions are performed. Missing fields, input nulls, encoded Variant nulls, and
* physical-type mismatches produce null output rows.
*
* @param variantStruct Variant materialization: STRUCT(metadata LIST&lt;UINT8&gt;,
* value LIST&lt;UINT8&gt;, optional shredded children...)
* @param path JSONPath-like path accepted by cuDF's Variant extractor. Object-field steps use
* dot notation and zero-based array-index steps use bracket notation, for example
* {@code x}, {@code $.x.y}, {@code $[0]}, or {@code $.a[0].b}. Missing fields,
* out-of-bounds indices, and container mismatches produce null rows. Wildcards,
* negative indices, and quoted names inside brackets are not supported.
* @param targetType decoded output type
*/
public static ColumnVector extractVariantField(
ColumnView variantStruct, String path, DType targetType) {
Expand Down
Loading
Loading