Skip to content

Add support for qualified column names in JOIN ... USING #1663

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

Merged
merged 2 commits into from
Jan 19, 2025

Conversation

yoavcloud
Copy link
Contributor

@yoavcloud yoavcloud commented Jan 17, 2025

It appears that Snowflake allows specifying qualified column names in the USING column list. For example:
SELECT * FROM tbl1 AS t1 JOIN tbl2 AS t2 USING(t2.col1)

BTW, it's worthwhile exploring changing all occurrences to parse column lists as Vec instead of Vec, there are likely other statement patterns that get rejected...

@yoavcloud yoavcloud force-pushed the sf_join_using_qualified_cols branch from 3b4b69e to 22182a2 Compare January 17, 2025 12:47
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

Thanks @yoavcloud! Left some comments

allow_empty: bool,
) -> Result<Vec<ObjectName>, ParserError> {
self.parse_parenthesized_column_list_inner(optional, allow_empty, |p| {
p.parse_object_name(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the in_table_clause be configurable here? I thinking it's supposed to be set to true when parsing a USING clause given the behavior being fixed

Comment on lines 2654 to 2655
// Snowflake allows fully-qualified column names inside USING
snowflake().verified_stmt("SELECT * FROM tbl1 AS t1 JOIN tbl2 AS t2 USING(t2.col1)");
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can add this scenario to the parse_joins_using test in common.rs instead?

self.parse_parenthesized_column_list_inner(optional, allow_empty, |p| p.parse_identifier())
}

/// Parses a parenthesized comma-separated list of unqualified, possibly quoted identifiers
Copy link
Contributor

Choose a reason for hiding this comment

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

The doc comment doesn't seem to match the behavior (unqualified vs qualified)? also it could be nice if the doc highlights that the parenthesis is also expected in the input (maybe with an example)

@yoavcloud yoavcloud requested a review from iffyio January 18, 2025 15:06
Copy link
Contributor

@iffyio iffyio 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 @yoavcloud!
cc @alamb

@iffyio iffyio merged commit 44df6d6 into apache:main Jan 19, 2025
9 checks passed
hansott added a commit to hansott/datafusion-sqlparser-rs that referenced this pull request Jan 23, 2025
…o escape-literals

* 'main' of github.com:hansott/datafusion-sqlparser-rs:
  National strings: check if dialect supports backslash escape (apache#1672)
  Add support for Create Iceberg Table statement for Snowflake parser (apache#1664)
  Add support for Snowflake account privileges (apache#1666)
  Update rat_exclude_file.txt (apache#1670)
  Update verson to 0.54.0 and update changelog (apache#1668)
  Add support for Snowflake AT/BEFORE (apache#1667)
  Add support for qualified column names in JOIN ... USING (apache#1663)
  Add support for `IS [NOT] [form] NORMALIZED` (apache#1655)
  fix parsing of `INSERT INTO ... SELECT ... RETURNING ` (apache#1661)
  Add support for Snowflake column aliases that use SQL keywords (apache#1632)
Vedin pushed a commit to Embucket/datafusion-sqlparser-rs that referenced this pull request Feb 3, 2025
Vedin pushed a commit to Embucket/datafusion-sqlparser-rs that referenced this pull request Feb 3, 2025
Vedin added a commit to Embucket/datafusion-sqlparser-rs that referenced this pull request Feb 3, 2025
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Apr 10, 2025
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.

2 participants