Skip to content

Make is_supported_cast fail for variable-width inputs - #23613

Open
JohnZed wants to merge 5 commits into
NVIDIA:mainfrom
JohnZed:fix-is-supported-cast
Open

Make is_supported_cast fail for variable-width inputs#23613
JohnZed wants to merge 5 commits into
NVIDIA:mainfrom
JohnZed:fix-is-supported-cast

Conversation

@JohnZed

@JohnZed JohnZed commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Description

cudf is_supported_cast returns true for string inputs. But cudf cast operator does not support variable-width types.

This leads to an issue in velox (facebookincubator/velox#18450) where the engine thinks it can
use cudf cast to convert varchars to ints, though that will ultimately need an exception. Velox will eventually need to use
a different strings API for this conversion, but at least changing is_supported_cast will allow it to no longer route conversions
through this path.

Checklist

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

@copy-pr-bot

copy-pr-bot Bot commented Aug 10, 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.

@github-actions github-actions Bot added the libcudf Affects libcudf (C++/CUDA) code. label Aug 10, 2026
@JohnZed JohnZed added bug Something isn't working non-breaking Non-breaking change labels Aug 10, 2026

@bdice bdice 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.

Thanks!

@PointKernel

Copy link
Copy Markdown
Member

pre-commit.ci autofix

@PointKernel

Copy link
Copy Markdown
Member

/ok to test 52419b5

@JohnZed
JohnZed marked this pull request as ready for review August 10, 2026 21:52
@JohnZed
JohnZed requested a review from a team as a code owner August 10, 2026 21:52
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9954ce5a-00b2-40f7-84bb-68f17be31ed6

📥 Commits

Reviewing files that changed from the base of the PR and between 27483d6 and ce63ee8.

📒 Files selected for processing (1)
  • cpp/include/cudf/unary.hpp

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Corrected cast support validation to require both source and target types to be fixed-width.
    • Casting STRING, LIST, STRUCT, and DICTIONARY32 values to INT32 is now correctly reported as unsupported.
  • Documentation

    • Clarified that casting with a non-fixed-width input or output type raises an error.
  • Tests

    • Added coverage for unsupported casts from non-fixed-width types to INT32.

Walkthrough

The cast support check now requires fixed-width source and target types. The cast documentation describes this condition. Tests verify unsupported casts from STRING, LIST, STRUCT, and DICTIONARY32 to INT32. SPDX notices were updated.

Changes

Cast support validation

Layer / File(s) Summary
Fixed-width cast predicate and regression test
cpp/src/unary/cast_ops.cu, cpp/include/cudf/unary.hpp, cpp/tests/unary/cast_tests.cpp
is_supported_non_fixed_point_cast now checks both source and target fixed-width types. The cast documentation describes the error condition for non-fixed-width input or output types. Tests verify unsupported casts from STRING, LIST, STRUCT, and DICTIONARY32 to INT32. SPDX notices were updated.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: 🟡 Moderate · up to ce63e

The PR narrows cast support for variable-width inputs, but the added regression test still does not use the repository-required BaseFixture pattern. That test issue should be fixed or explicitly accepted before merge.

Suggested reviewers: abigalekim, bdice, pointkernel

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states that is_supported_cast will reject variable-width inputs, which is the main change.
Description check ✅ Passed The description explains the unsupported variable-width cast issue, its impact on Velox, and the related 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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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.

🧹 Nitpick comments (1)
cpp/tests/unary/cast_tests.cpp (1)

204-208: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover variable-width targets too.

The implementation checks both From and To, but this test only checks a variable-width source. Add an INT32 to STRING assertion so a regression in the target check cannot pass unnoticed.

Proposed test extension
+  EXPECT_FALSE(cudf::is_supported_cast(cudf::data_type{cudf::type_id::INT32},
+                                       cudf::data_type{cudf::type_id::STRING}));
🤖 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/unary/cast_tests.cpp` around lines 204 - 208, Extend the
StringToInt32IsUnsupported test to also assert that an INT32 source to STRING
target is unsupported, covering the variable-width target path while preserving
the existing assertion.
🤖 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.

Nitpick comments:
In `@cpp/tests/unary/cast_tests.cpp`:
- Around line 204-208: Extend the StringToInt32IsUnsupported test to also assert
that an INT32 source to STRING target is unsupported, covering the
variable-width target path while preserving the existing assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d85c5012-f405-490c-8203-2bd7700e60d6

📥 Commits

Reviewing files that changed from the base of the PR and between 463fba2 and 52419b5.

📒 Files selected for processing (2)
  • cpp/src/unary/cast_ops.cu
  • cpp/tests/unary/cast_tests.cpp

@JohnZed

JohnZed commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 34b1762

@JohnZed

JohnZed commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2b79f91

@JohnZed
JohnZed force-pushed the fix-is-supported-cast branch from 2b79f91 to e8ca74d Compare August 12, 2026 23:08
@JohnZed
JohnZed requested a review from a team as a code owner August 12, 2026 23:08
@JohnZed

JohnZed commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e8ca74d

@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: 2

🤖 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/unary/cast_tests.cpp`:
- Around line 204-208: Update the IsSupportedCast.StringToInt32IsUnsupported
test to use TEST_F with a fixture derived from cudf::test::BaseFixture, adding
or reusing an appropriate fixture while preserving the existing assertion.
- Around line 204-208: Update the StringToInt32IsUnsupported test to use TEST_F
with cudf::test::BaseFixture, and add direct NVBench coverage invoking
cudf::is_supported_cast rather than relying on the existing intcast benchmark,
which exercises different APIs.
🪄 Autofix

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: Pro Plus

Run ID: 36b11fdf-974b-4a49-a66e-904f6f76faa7

📥 Commits

Reviewing files that changed from the base of the PR and between 4ec7b3b and e8ca74d.

📒 Files selected for processing (2)
  • cpp/src/unary/cast_ops.cu
  • cpp/tests/unary/cast_tests.cpp

Comment thread cpp/tests/unary/cast_tests.cpp Outdated
Comment on lines +204 to +208
TEST(IsSupportedCast, StringToInt32IsUnsupported)
{
EXPECT_FALSE(cudf::is_supported_cast(cudf::data_type{cudf::type_id::STRING},
cudf::data_type{cudf::type_id::INT32}));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use a BaseFixture-derived test.

Replace TEST with TEST_F and attach the test to a fixture that inherits from cudf::test::BaseFixture.

Based on learnings: “All libcudf unit tests should make use of a GTest Test Fixture” and “Even if the fixture is empty, it should inherit from the base fixture cudf::test::BaseFixture.”

Proposed fix
-TEST(IsSupportedCast, StringToInt32IsUnsupported)
+class IsSupportedCastTest : public cudf::test::BaseFixture {};
+
+TEST_F(IsSupportedCastTest, StringToInt32IsUnsupported)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
TEST(IsSupportedCast, StringToInt32IsUnsupported)
{
EXPECT_FALSE(cudf::is_supported_cast(cudf::data_type{cudf::type_id::STRING},
cudf::data_type{cudf::type_id::INT32}));
}
class IsSupportedCastTest : public cudf::test::BaseFixture {};
TEST_F(IsSupportedCastTest, StringToInt32IsUnsupported)
{
EXPECT_FALSE(cudf::is_supported_cast(cudf::data_type{cudf::type_id::STRING},
cudf::data_type{cudf::type_id::INT32}));
}
🤖 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/unary/cast_tests.cpp` around lines 204 - 208, Update the
IsSupportedCast.StringToInt32IsUnsupported test to use TEST_F with a fixture
derived from cudf::test::BaseFixture, adding or reusing an appropriate fixture
while preserving the existing assertion.

Source: Learnings


📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n 'is_supported_cast|BENCHMARK' cpp

Repository: NVIDIA/cudf

Length of output: 19219


🏁 Script executed:

#!/bin/bash
set -euo pipefail
printf '%s\n' '--- cast test structure and nearby cases ---'
sed -n '1,235p' cpp/tests/unary/cast_tests.cpp
printf '%s\n' '--- cast implementation and declarations ---'
sed -n '120,160p' cpp/include/cudf/unary.hpp
sed -n '420,465p' cpp/src/unary/cast_ops.cu
printf '%s\n' '--- benchmark files with cast-related names ---'
git ls-files cpp/benchmarks | rg -i 'cast|unary'
printf '%s\n' '--- test fixture and benchmark guidance ---'
rg -n -C 3 'BaseFixture|fixture|unit benchmark|benchmark' cpp/tests/unary/cast_tests.cpp cpp/doxygen/developer_guide/TESTING.md cpp/doxygen/developer_guide/BENCHMARKING.md cpp/REVIEW_GUIDELINES.md CONTRIBUTING.md

Repository: NVIDIA/cudf

Length of output: 30777


🏁 Script executed:

#!/bin/bash
set -euo pipefail
printf '%s\n' '--- existing intcast benchmark ---'
wc -l cpp/benchmarks/string/intcast.cpp
sed -n '1,240p' cpp/benchmarks/string/intcast.cpp
printf '%s\n' '--- support predicate implementation ---'
sed -n '125,175p' cpp/src/unary/cast_ops.cu
printf '%s\n' '--- all is_supported_cast tests and nearby test declarations ---'
rg -n -C 5 'IsSupportedCast|is_supported_cast|TEST(_F)?\(' cpp/tests

Repository: NVIDIA/cudf

Length of output: 50368


🏁 Script executed:

#!/bin/bash
set -euo pipefail
printf '%s\n' '--- existing intcast benchmark ---'
sed -n '1,220p' cpp/benchmarks/string/intcast.cpp
printf '%s\n' '--- support predicate body ---'
rg -n -A 45 -B 8 'constexpr inline auto is_supported_cast' cpp/src/unary/cast_ops.cu
printf '%s\n' '--- exact API references in tests and benchmarks ---'
rg -n 'cudf::is_supported_cast|is_supported_cast<' cpp/tests cpp/benchmarks

Repository: NVIDIA/cudf

Length of output: 5337


🏁 Script executed:

#!/bin/bash
set -euo pipefail
printf '%s\n' '--- non-fixed-point support predicate ---'
sed -n '90,145p' cpp/src/unary/cast_ops.cu
printf '%s\n' '--- test target configuration ---'
rg -n -C 4 'cast_tests|unary' cpp/tests/CMakeLists.txt cpp/tests/unary/CMakeLists.txt 2>/dev/null || true
printf '%s\n' '--- concise support-test references ---'
rg -n 'IsSupportedCast|is_supported_cast' cpp/tests cpp/benchmarks cpp/src cpp/include

Repository: NVIDIA/cudf

Length of output: 6462


Use a BaseFixture and add direct benchmark coverage.

  • Change TEST(IsSupportedCast, ...) to a TEST_F using cudf::test::BaseFixture.
  • Add an NVBench benchmark for cudf::is_supported_cast; the existing intcast benchmark measures different APIs.
🤖 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/unary/cast_tests.cpp` around lines 204 - 208, Update the
StringToInt32IsUnsupported test to use TEST_F with cudf::test::BaseFixture, and
add direct NVBench coverage invoking cudf::is_supported_cast rather than relying
on the existing intcast benchmark, which exercises different APIs.

Source: Coding guidelines

@igorpeshansky igorpeshansky 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.

A couple of notes on the PR description and suggested tests.

Comment thread cpp/tests/unary/cast_tests.cpp Outdated
Comment thread cpp/src/unary/cast_ops.cu
constexpr inline auto is_supported_non_fixed_point_cast()
{
return cudf::is_fixed_width<To>() &&
return cudf::is_fixed_width<From>() && cudf::is_fixed_width<To>() &&

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.

Note

Your PR description says that you're matching the "cudf cast documentation", but the cast will, in fact, fail for those non-fixed-width types, so you're in fact matching the cast implementation. Might be worth a tweak to the PR description…

[Optional] Might also be worth it to update the is_supported_cast function doc in unary.hpp (lines 129-136)…

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.

@igorpeshansky - agreed about expanding the test above and took your suggestion there. Changed the PR description too. Thanks!
Not sure I see a change to the header docs for is_supported_cast as necessary here though. I feel like the current description of "Check if a cast between two datatypes is supported." is a good one - nice and concise, and I don't know that it needs to spell out all the possible cast failure paths.
The documentation of cast in unary.hpp was a little funny though - it mentioned failing on variable width output_type, but not variable-width inputs. So I updated that one.

@JohnZed
JohnZed force-pushed the fix-is-supported-cast branch from ce63ee8 to 8914db2 Compare August 14, 2026 01:24
@JohnZed

JohnZed commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8914db2

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

Labels

bug Something isn't working 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