Skip to content
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

Add basic support for cast in expressions #957

Merged
merged 6 commits into from
Jun 8, 2023
Merged

Conversation

wjones127
Copy link
Contributor

@wjones127 wjones127 commented Jun 8, 2023

Fixed #956. Allows casting, but also "typed literals" where you just put the type you want in front of the string.

@wjones127 wjones127 marked this pull request as ready for review June 8, 2023 17:42
@wjones127 wjones127 requested a review from eddyxu June 8, 2023 17:43
Ok(ArrowDataType::Timestamp(time_unit, None))
}
_ => Err(Error::IO {
message: format!("Unsupported data type: {:?}. Supports: float, double, boolean, int, integer, date, datetime", data_type),
Copy link
Contributor

Choose a reason for hiding this comment

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

Also supports binary / string / booleans, right? I mean just in the error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -186,6 +250,13 @@ impl Planner {
SQLExpr::BinaryOp { left, op, right } => self.binary_expr(left, op, right),
SQLExpr::UnaryOp { op, expr } => self.unary_expr(op, expr),
SQLExpr::Value(value) => self.value(value),
// For example, DATE '2020-01-01'
SQLExpr::TypedString { data_type, value } => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it mean we can actually do INT '1231' to cast an integer? Is there any restriction on the data_type supported?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a few tests in rust?

Also , should we maintain a doc to describe what expression we support? Can be a follow up issue tho.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah other types work. I think the other one that is good to have is decimal.

I'll add some docs and tests in Rust.

- Time unit
* - ``timestamp(0)``
- Seconds
* - ``timestamp(3)``
Copy link
Contributor

Choose a reason for hiding this comment

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

is the precision a limitation by the parser? Feel that timestamp(s), timestamp(ms) are easier to use. Curious how much effort to make it happen?

https://arrow.apache.org/docs/python/generated/pyarrow.timestamp.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's unfortunately something that's not built in; it only allows integers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, if this cannot be done in a few hours, let's just 🚢 it for now.

@eddyxu
Copy link
Contributor

eddyxu commented Jun 8, 2023

The rest LGTM

@wjones127 wjones127 force-pushed the wjones127/basic-cast branch from 04852e2 to a9b8ebf Compare June 8, 2023 21:28
@wjones127 wjones127 merged commit 2882d83 into main Jun 8, 2023
@wjones127 wjones127 deleted the wjones127/basic-cast branch June 8, 2023 21:56
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.

Some data types can't be filtered on
2 participants