Skip to content

Add logical type inspection for raw Parquet VARIANT values - #23491

Open
abigalekim wants to merge 25 commits into
NVIDIA:mainfrom
abigalekim:ak/variant-type-id
Open

Add logical type inspection for raw Parquet VARIANT values#23491
abigalekim wants to merge 25 commits into
NVIDIA:mainfrom
abigalekim:ak/variant-type-id

Conversation

@abigalekim

@abigalekim abigalekim commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

Implements feature mentioned in #23183. Adds an experimental libcudf operation, cudf::io::parquet::experimental::get_variant_type_id, that takes a raw Variant list column and returns an int32 column of logical type identifiers. This PR also introduces a new variant_logical_type enum covering all Variant categories.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@abigalekim
abigalekim requested a review from a team as a code owner July 31, 2026 03:03
@copy-pr-bot

copy-pr-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@abigalekim abigalekim added the feature request New feature or request label Jul 31, 2026
@abigalekim abigalekim added the non-breaking Non-breaking change label Jul 31, 2026
@github-actions github-actions Bot added the libcudf Affects libcudf (C++/CUDA) code. label Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for identifying the logical type of each VARIANT value, including objects, arrays, strings, numbers, dates, timestamps, binary values, UUIDs, and nulls.
    • Results are returned as integer type identifiers while preserving input nulls and explicitly representing encoded null values.
    • Added handling for empty, sliced, mixed, malformed, and unsupported VARIANT data.
  • Tests

    • Added comprehensive coverage across supported logical types, null handling, malformed inputs, and large datasets.

Walkthrough

Adds the public variant_logical_type enum and get_variant_type_id API. CUDA code decodes VARIANT headers into nullable INT32 type IDs. Tests cover mappings, malformed values, nulls, empty inputs, slicing, mixed types, and large columns.

Changes

VARIANT type-ID extraction

Layer / File(s) Summary
Logical type contract
cpp/include/cudf/io/experimental/variant_spec.hpp, cpp/include/cudf/io/experimental/variant.hpp
Defines variant_logical_type and declares get_variant_type_id with null and invalid-input behavior.
Type-ID classification and output
cpp/src/io/parquet/experimental/variant_extract.cu
Classifies VARIANT headers on the device and returns nullable INT32 output.
Classification and edge-case coverage
cpp/tests/io/experimental/variant_extract_test.cpp
Tests fixture mappings, malformed and unknown values, encoded nulls, empty inputs, slicing, mixed types, and large columns.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

  • rapidsai/cudf#23183 — Covers the variant_logical_type and get_variant_type_id feature.
  • rapidsai/cudf#23182 — Covers the corresponding libcudf logical-type inspection operation.
  • rapidsai/cudf#23184 — Covers the API proposed for Java bindings.
  • rapidsai/cudf#22312 — Covers related VARIANT logical-type decoding APIs.

Possibly related PRs

Suggested labels: tests

Suggested reviewers: vuule, mattgara, davidwendt

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding logical type inspection for raw Parquet VARIANT values.
Description check ✅ Passed The description directly explains the new API, enum, input and output types, tests, and documentation updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
cpp/include/cudf/io/experimental/variant_spec.hpp (1)

56-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assign explicit values to variant_logical_type.

The enumerators of variant_logical_type rely on implicit sequential values. get_variant_type_id casts these values to int32_t and returns them as output data. If a new logical type is inserted in the middle of this list later, every subsequent numeric ID shifts silently. This can break downstream consumers that persist or compare these IDs.

Assign each enumerator an explicit value now, while the API is new, to fix the wire contract.

♻️ Proposed fix to pin enumerator values
 enum class variant_logical_type : uint8_t {
-  object,
-  array,
-  null_value,
-  boolean,
-  long_value,
-  string,
-  double_value,
-  decimal,
-  date,
-  timestamp,
-  timestamp_ntz,
-  float_value,
-  binary,
-  uuid
+  object        = 0,
+  array         = 1,
+  null_value    = 2,
+  boolean       = 3,
+  long_value    = 4,
+  string        = 5,
+  double_value  = 6,
+  decimal       = 7,
+  date          = 8,
+  timestamp     = 9,
+  timestamp_ntz = 10,
+  float_value   = 11,
+  binary        = 12,
+  uuid          = 13
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/include/cudf/io/experimental/variant_spec.hpp` around lines 56 - 71,
Update the variant_logical_type enum so every enumerator has an explicit numeric
value, preserving its current sequential IDs and establishing a stable wire
contract for get_variant_type_id. Use the existing declaration order and assign
values starting at zero through uuid; do not change the enum members or their
ordering.
cpp/src/io/parquet/experimental/variant_extract.cu (1)

790-817: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the repeated value-span construction into a helper.

Lines 803-806 repeat the same offset/span construction already used in cast_variant_primitive_kernel (lines 632-636) and cast_variant_string_fn::operator() (lines 670-674). This is now the third copy of the same three-line idiom.

Extract a small __device__ helper that returns the value device_span<uint8_t const> for a row, and call it from all three sites. This reduces duplication and keeps future changes to the span-lookup logic in one place.

♻️ Proposed helper extraction
__device__ inline device_span<uint8_t const> value_span_at(
  cudf::lists_column_device_view const& values, size_type row)
{
  auto const val_begin = values.offset_at(row);
  auto const val_end   = values.offset_at(row + 1);
  return {values.child().data<uint8_t>() + val_begin,
          static_cast<std::size_t>(val_end - val_begin)};
}
     auto const val_begin = values.offset_at(row);
     auto const val_end   = values.offset_at(row + 1);
-    device_span<uint8_t const> const val{values.child().data<uint8_t>() + val_begin,
-                                         static_cast<std::size_t>(val_end - val_begin)};
+    auto const val = value_span_at(values, row);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/src/io/parquet/experimental/variant_extract.cu` around lines 790 - 817,
Extract the repeated value offset/span construction into a shared __device__
helper, such as value_span_at, accepting the lists_column_device_view and row
and returning device_span<uint8_t const>. Replace the duplicated three-line
logic in get_variant_type_id_kernel, cast_variant_primitive_kernel, and
cast_variant_string_fn::operator() with calls to this helper, preserving the
existing span contents and behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/tests/io/experimental/variant_extract_test.cpp`:
- Around line 1621-1657: Increase num_rows in
GetVariantTypeIdTest.LargeMultiRowColumn from 128 to a value above the kernel
block size, such as 600, so get_variant_type_id exercises the multi-block
grid-stride path while preserving the existing cycling type coverage and
expected_ids generation.

---

Nitpick comments:
In `@cpp/include/cudf/io/experimental/variant_spec.hpp`:
- Around line 56-71: Update the variant_logical_type enum so every enumerator
has an explicit numeric value, preserving its current sequential IDs and
establishing a stable wire contract for get_variant_type_id. Use the existing
declaration order and assign values starting at zero through uuid; do not change
the enum members or their ordering.

In `@cpp/src/io/parquet/experimental/variant_extract.cu`:
- Around line 790-817: Extract the repeated value offset/span construction into
a shared __device__ helper, such as value_span_at, accepting the
lists_column_device_view and row and returning device_span<uint8_t const>.
Replace the duplicated three-line logic in get_variant_type_id_kernel,
cast_variant_primitive_kernel, and cast_variant_string_fn::operator() with calls
to this helper, preserving the existing span contents and behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f1423210-95f8-4ad2-ab54-2d2cafd21e53

📥 Commits

Reviewing files that changed from the base of the PR and between 7f58752 and 7bbdfb7.

📒 Files selected for processing (4)
  • cpp/include/cudf/io/experimental/variant.hpp
  • cpp/include/cudf/io/experimental/variant_spec.hpp
  • cpp/src/io/parquet/experimental/variant_extract.cu
  • cpp/tests/io/experimental/variant_extract_test.cpp

Comment thread cpp/tests/io/experimental/variant_extract_test.cpp
@abigalekim
abigalekim marked this pull request as draft August 4, 2026 18:58
@abigalekim
abigalekim marked this pull request as ready for review August 5, 2026 01:51
Comment thread cpp/src/io/parquet/experimental/variant_extract.cu Outdated
Comment thread cpp/tests/io/experimental/variant_extract_test.cpp Outdated
Comment thread cpp/tests/io/experimental/variant_extract_test.cpp
Comment thread cpp/src/io/parquet/experimental/variant_extract.cu
abigalekim and others added 4 commits August 5, 2026 14:00
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>
@abigalekim
abigalekim requested a review from mhaseeb123 August 5, 2026 19:51
@abigalekim

Copy link
Copy Markdown
Contributor Author

/ok to test 2dc6168

@nartal1 nartal1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall LGTM. Just a couple of nits.

Comment thread cpp/include/cudf/io/experimental/variant.hpp
Comment thread cpp/include/cudf/io/experimental/variant_spec.hpp
Comment thread cpp/include/cudf/io/experimental/variant.hpp Outdated
Comment thread cpp/include/cudf/io/experimental/variant.hpp
Comment thread cpp/include/cudf/io/experimental/variant_spec.hpp Outdated
Comment thread cpp/src/io/parquet/experimental/variant_extract.cu
inline std::unique_ptr<cudf::column> make_list_u8_nullable(
std::vector<std::vector<uint8_t>> const& blobs, std::vector<bool> const& valid)
{
auto const n = static_cast<cudf::size_type>(blobs.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please avoid single letter variable names

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to change a lot of these in the codebase! Thank you for the pointer.

Comment thread cpp/include/cudf/io/experimental/variant_spec.hpp Outdated
Comment thread cpp/tests/io/experimental/variant_extract_test.cpp Outdated
Comment thread cpp/tests/io/experimental/variant_extract_test.cpp Outdated
Comment thread cpp/tests/io/experimental/variant_extract_test.cpp Outdated
Comment thread cpp/tests/io/experimental/variant_extract_test.cpp Outdated
@mhaseeb123

mhaseeb123 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@abigalekim I will be OOO next week so please feel free to dismiss my Request Changes review once all my comments (+ comments from @nartal1 and @coderabbitai) are addressed and you get two approvals.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@mhaseeb123 Acknowledged. Your review guidance is clear. The Request Changes review can be discarded after the specified comments are addressed and the pull request has two approvals.

You are interacting with an AI system.

@NVIDIA NVIDIA deleted a comment from coderabbitai Bot Aug 7, 2026
@NVIDIA NVIDIA deleted a comment from coderabbitai Bot Aug 7, 2026
@NVIDIA NVIDIA deleted a comment from coderabbitai Bot Aug 7, 2026
abigalekim and others added 8 commits August 7, 2026 16:38
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>
Co-authored-by: Muhammad Haseeb <14217455+mhaseeb123@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
cpp/tests/io/experimental/variant_extract_test.cpp (3)

1696-1696: ⚠️ Potential issue | 🔴 Critical

Use the declared stream for get_sliced_child.

Line 1696 passes stream2, but this test no longer declares stream2. Replace it with stream; otherwise the test fails to compile.

-  auto const value_child = cudf::structs_column_view{col}.get_sliced_child(1, stream2);
+  auto const value_child = cudf::structs_column_view{col}.get_sliced_child(1, stream);

Run:

#!/usr/bin/env bash
set -euo pipefail
file=cpp/tests/io/experimental/variant_extract_test.cpp
if rg -q '\bstream2\b' "$file"; then
  echo "stream2 reference remains" >&2
  exit 1
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tests/io/experimental/variant_extract_test.cpp` at line 1696, Update the
get_sliced_child call in the variant extraction test to pass the declared stream
variable instead of the undeclared stream2 symbol, and ensure no stream2
references remain in the file.

1451-1574: ⚠️ Potential issue | 🔴 Critical

Use vlt consistently after the alias rename.

Line 1451 declares using vlt = ..., but the later assertions still use LT::.... LT is undefined, so the test translation unit cannot compile. Replace all remaining LT:: references with vlt::.

- static_cast<int32_t>(LT::long_value)
+ static_cast<int32_t>(vlt::long_value)

Run:

#!/usr/bin/env bash
set -euo pipefail
file=cpp/tests/io/experimental/variant_extract_test.cpp
if rg -q '\busing vlt\b' "$file" && rg -q '\bLT::' "$file"; then
  echo "stale LT references remain" >&2
  exit 1
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tests/io/experimental/variant_extract_test.cpp` around lines 1451 - 1574,
Replace every remaining LT:: reference in the GetVariantTypeIdTest cases,
including NullValue through ObjectAndArray, with the declared vlt:: alias so the
test compiles and uses the renamed alias consistently.

17-17: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add direct includes for all new test symbols.

Include cudf_test/cudf_gtest.hpp, <algorithm>, and <stdexcept> directly. Do not rely on transitive includes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tests/io/experimental/variant_extract_test.cpp` at line 17, Add direct
includes for the test symbols used in variant_extract_test.cpp:
cudf_test/cudf_gtest.hpp, <algorithm>, and <stdexcept>. Place them with the
existing include directives and avoid relying on transitive headers.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@cpp/tests/io/experimental/variant_extract_test.cpp`:
- Line 1696: Update the get_sliced_child call in the variant extraction test to
pass the declared stream variable instead of the undeclared stream2 symbol, and
ensure no stream2 references remain in the file.
- Around line 1451-1574: Replace every remaining LT:: reference in the
GetVariantTypeIdTest cases, including NullValue through ObjectAndArray, with the
declared vlt:: alias so the test compiles and uses the renamed alias
consistently.
- Line 17: Add direct includes for the test symbols used in
variant_extract_test.cpp: cudf_test/cudf_gtest.hpp, <algorithm>, and
<stdexcept>. Place them with the existing include directives and avoid relying
on transitive headers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5f5ddb72-0a49-4aeb-8a27-2d00f7e2f584

📥 Commits

Reviewing files that changed from the base of the PR and between 512ffdc and ff660ee.

📒 Files selected for processing (2)
  • cpp/include/cudf/io/experimental/variant_spec.hpp
  • cpp/tests/io/experimental/variant_extract_test.cpp
💤 Files with no reviewable changes (1)
  • cpp/include/cudf/io/experimental/variant_spec.hpp

@mhaseeb123 mhaseeb123 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Few nits

Comment thread cpp/src/io/parquet/experimental/variant_extract.cu Outdated
Comment thread cpp/tests/io/experimental/variant_extract_test.cpp Outdated
Comment thread cpp/tests/io/experimental/variant_extract_test.cpp Outdated
Comment thread cpp/include/cudf/io/experimental/variant_spec.hpp Outdated
@abigalekim

Copy link
Copy Markdown
Contributor Author

/ok to test b0dfd69

@vuule vuule left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Few API design questions, mostly for the feature requester :)

Comment on lines +62 to +63
TIMESTAMP = 9,
TIMESTAMP_NTZ = 10,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@nartal1 do we need values for nanosecond types?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The above looks good. Both TIMESTAMP_MICROS and TIMESTAMP_NANOS maps to TIMESTAMP logical ID.

* Classifies only the value_metadata header byte; does not validate the remaining payload.
* A recognized header returns its logical type even when the payload is truncated. A null output
* row is produced when the input row is null, the blob is empty, or the header carries an
* unrecognized type. An encoded Variant null (NULLVAL) produces a valid `NULL_VALUE` row.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@nartal1 is it okay that this API returns null in multiple cases, i.e.
the input row was null, the blob was empty, or the header was unrecognized/malformed.
I assume this is what the status column is for, but want to confirm.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This behavior is sufficient here from cudf-spark perspective. We can handle the above from the status column from PR 23560. Thanks for checking.

Comment thread cpp/include/cudf/io/experimental/variant.hpp Outdated
* @throws std::invalid_argument if `values` is not a `list<uint8>` column
*/
[[nodiscard]] std::unique_ptr<column> get_variant_type_id(
column_view const& values,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@nartal1 do to expect to need a "batched" version of this API, i.e. something that takes a table view and returns a table? If you expect to regularly run this on multiple columns , it could even be the only API, and the caller would create a single column table when we need the current capability.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the current tasks, we only need the single-column API.

But later, Spark scan pushdown can request several fields from one Variant and can reference multiple Variant columns in the same scan, so a batched classifier overload may become useful.
However, the primary requirement there is batched multi-field extraction - tracked in #22897. I think that path can also provide any required per-field type or status information without a separate classification pass. Do you have any thoughts on how you would be handling the multi field extraction in cudf?

@abigalekim

Copy link
Copy Markdown
Contributor Author

/ok to test e5246f8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants