[SQL] Cast of a VARIANT to string should work for most variant types by mihaibudiu · Pull Request #6044 · feldera/feldera · GitHub
Skip to content

[SQL] Cast of a VARIANT to string should work for most variant types#6044

Merged
mihaibudiu merged 1 commit intofeldera:mainfrom
mihaibudiu:issue5938
Apr 21, 2026
Merged

[SQL] Cast of a VARIANT to string should work for most variant types#6044
mihaibudiu merged 1 commit intofeldera:mainfrom
mihaibudiu:issue5938

Conversation

@mihaibudiu
Copy link
Copy Markdown
Contributor

@mihaibudiu mihaibudiu commented Apr 15, 2026

Fixes #5938

Describe Manual Test Plan

Implemented conversion of VARIANT to CHAR types. Previously this conversion would return NULL for all values except Variant::String values. Now it will behave roughly as a CAST of the underlying value to the CHAR type.

E.g. CAST(CAST(TRUE AS VARIANT) AS VARCHAR) used to return NULL and now will return true.

Checklist

  • Unit tests added/updated
  • Changelog updated

Breaking Changes?

Mark if you think the answer is yes for any of these components:

  • Feldera SQL (Syntax, Semantics)

Describe Incompatible Changes

See first paragraph above and changelog.

Copy link
Copy Markdown

@mythical-fred mythical-fred left a comment

Choose a reason for hiding this comment

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

The runtime behavior change here spans more scalar variant families than the new test covers; see inline.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This match now defines CAST(variant AS VARCHAR) semantics for every scalar branch here, but the new regression only exercises a subset of them (INT, VARCHAR, REAL/DOUBLE, BOOLEAN, UUID, and one short interval). Please add coverage for the other newly-supported scalar families too -- at least DECIMAL, DATE, TIME, TIMESTAMP, LONG INTERVAL, and VARBINARY, plus one negative case such as ARRAY/MAP still failing. This codepath is all hand-written formatting logic, so the untested branches are exactly where drift will hide.


#[doc(hidden)]
const fn sign(negative: bool) -> &'static str {
pub(crate) const fn sign(negative: bool) -> &'static str {
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.

you probably dont need doc(hidden) on pub(crate)things since it won't get exposed

Comment thread crates/sqllib/src/variant.rs Outdated
let sign = sign(months < 0);
let years = months.unsigned_abs() / 12;
let months = months.unsigned_abs() % 12;
Ok(SqlString::from(format!("{sign}{years}-{months:02}")))
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.

maybe whatever type of x is should have a .into() for sqlstring

Comment thread crates/sqllib/src/variant.rs Outdated
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.

does clippy not complain about this? format!("{}", x) seems like somehting it would have a problem with

it would be nice to optimize this, it will do two allocations (to make astring then to make a SqlString

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.

There may be a third string allocation, if this is called from a cast, which may truncate the string after producing it.
You mean, optimize the Boolean case or all cases?

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.

ideally all of the

@mihaibudiu mihaibudiu force-pushed the issue5938 branch 2 times, most recently from 9534e12 to aef5b24 Compare April 18, 2026 00:09
@mihaibudiu mihaibudiu enabled auto-merge April 18, 2026 00:09
@mihaibudiu mihaibudiu added this pull request to the merge queue Apr 18, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 18, 2026
@mihaibudiu mihaibudiu force-pushed the issue5938 branch 3 times, most recently from 89d2565 to 9d59d11 Compare April 18, 2026 06:33
@mihaibudiu mihaibudiu enabled auto-merge April 18, 2026 06:33
@mihaibudiu mihaibudiu added this pull request to the merge queue Apr 18, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 18, 2026
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@mihaibudiu mihaibudiu added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@mihaibudiu mihaibudiu added this pull request to the merge queue Apr 20, 2026
Merged via the queue into feldera:main with commit 8725ea5 Apr 21, 2026
1 check passed
@mihaibudiu mihaibudiu deleted the issue5938 branch April 21, 2026 01:15
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.

[SQL] CAST(VARIANT AS VARCHAR) returns NULL for a BOOLEAN variant

3 participants