Skip to content

feat: enhance-CLI-query-header-for-cast-expressions-with-literals #15736

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

qstommyshu
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

Stated in #5221

What changes are included in this PR?

SQL parser modification

Are these changes tested?

Not yet

Are there any user-facing changes?

Yes

@github-actions github-actions bot added the sql SQL Planner label Apr 16, 2025
@qstommyshu qstommyshu changed the title POC: parser modification attempt feat: enhance-CLI-query-header-for-cast-expressions-with-literals Apr 16, 2025
DataType::Float(_) => "FLOAT",
DataType::Double(_) => "DOUBLE",
DataType::Text => "TEXT",
// TODO: need to support more DataType, probably use an Extension Trait
Copy link
Contributor Author

@qstommyshu qstommyshu Apr 16, 2025

Choose a reason for hiding this comment

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

We need to support a full list of enum elements for DataType here, this DataType comes from an external library. This probably means everything we update this API, we need to make accommodation as well.

Or we can look into using strum crate to auto derive ToString for all DataType, we are currently using it for the datafusion proto crate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, supported data type result would look like this:
select cast('1' as int);

+------------------+
| cast('1' as int) |
+------------------+
| 1                |
+------------------+

unsupported data type result would look like this:
select cast(1 as string);

+-------------------------+
| cast(1 as string(none)) |
+-------------------------+
| 1                       |
+-------------------------+

Expr::Value(sqlparser::ast::ValueWithSpan { value: Value::Number(n, _), .. }) => {
n.clone()
},
// TODO: need to take care of other types of values, like TimeStamp, etc...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is currently only matching specific case for select cast('1' as int), we need to support other types as well if we want to go with this idea. I'm thinking about a way to generalize the Value extraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For enum Value, there are 22 types to support, I can write them into a function if we want to go ahead with this.

Copy link
Contributor Author

@qstommyshu qstommyshu Apr 16, 2025

Choose a reason for hiding this comment

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

This whole code modification will be turn into several functions for code readability and maintainability, I'm leaving for now just to validate the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI query result header for cast expressions with literals is confusing
1 participant