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

Update to sqlparser 0.17.0 #2500

Merged
merged 4 commits into from
May 10, 2022
Merged

Conversation

alamb
Copy link
Contributor

@alamb alamb commented May 10, 2022

I am preparing a sqlparser release and this PR tests the new code with DataFusion as a double check. See apache/datafusion-sqlparser-rs#488

Upgrades to newly released sqlparser 0.17

I did need to make some changes to sql parser to handle changes to ArrayAccess which was partially based on changes from @ovr 's PR #2196

@alamb alamb marked this pull request as draft May 10, 2022 10:50
@alamb alamb changed the title TEMP: Update to pre-release SQL parser NOT FOR MERGING: Update to pre-release SQL parser May 10, 2022
@@ -1645,6 +1646,11 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
}

SQLExpr::ArrayIndex { obj, indexs } => {
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 @ovr

@github-actions github-actions bot added the datafusion Changes in the datafusion crate label May 10, 2022
@alamb alamb changed the title NOT FOR MERGING: Update to pre-release SQL parser Update to sqlparser 0.17.0 May 10, 2022
@@ -97,9 +97,10 @@ fn plan_key(key: SQLExpr) -> Result<ScalarValue> {
ScalarValue::Int64(Some(s.parse().unwrap()))
}
SQLExpr::Value(Value::SingleQuotedString(s)) => ScalarValue::Utf8(Some(s)),
SQLExpr::Identifier(Ident { value, .. }) => ScalarValue::Utf8(Some(value)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks likes, there are mistakes in tests, I found that current tests are not valid:

In select.rs, you need to do some changes:

// " - is used for identifiers, but in this test, should be some_struct['bar'], because it's a name of the field, not an identifier.
let sql = "SELECT some_struct[\"bar\"] as l0 FROM structs LIMIT 3";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shall we do this as part of a follow on PR? Or would you like to do it as part of this one?

Copy link
Contributor

@ovr ovr May 10, 2022

Choose a reason for hiding this comment

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

You can do it in your PR. Probably, it's a good idea to drop this line and change tests to correct variant: some_struct['bar']. Right now, GetIndexedExpr doesn't support dynamic expression as key, and converting Identifier to ScalarValue::Utf8 is not correct, because it can be a variable for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In 09d9722

@alamb alamb marked this pull request as ready for review May 10, 2022 13:39
@ovr
Copy link
Contributor

ovr commented May 10, 2022

Awesome! I am planning to submit a PR with dynamic key for GetIndexedExpr, I already did a draft - https://github.com/cube-js/arrow-datafusion/commits/get-indexed-expr-our-v2

I will do it tomorrow.

@@ -639,7 +639,7 @@ async fn query_nested_get_indexed_field_on_struct() -> Result<()> {
ctx.register_table("structs", table_a)?;

// Original column is micros, convert to millis and check timestamp
let sql = "SELECT some_struct[\"bar\"] as l0 FROM structs LIMIT 3";
let sql = "SELECT some_struct['bar'] as l0 FROM structs LIMIT 3";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #2500 (comment) for an explanation of this change

Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @alamb

@andygrove andygrove merged commit 06fa7cc into apache:master May 10, 2022
@alamb alamb deleted the alamb/update_sqlparser2 branch May 10, 2022 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants