Skip to content

[SPARK-43980][SQL] introducing select * except syntax - #43843

Closed
milastdbx wants to merge 6 commits into
apache:masterfrom
milastdbx:feature/selectStarExcept
Closed

[SPARK-43980][SQL] introducing select * except syntax#43843
milastdbx wants to merge 6 commits into
apache:masterfrom
milastdbx:feature/selectStarExcept

Conversation

@milastdbx

@milastdbxmilastdbx commented Nov 16, 2023

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Changing parser to support new syntax when using * to fetch columns from source.
Introducing new expression UnresolvedStarExcept in visit method when newly introduced syntax is created.
Expansion of this expression is core logic of feature.

Why are the changes needed?

Introducing new SELECT * EXCEPT (col1, col2)

Does this PR introduce any user-facing change?

Yes, this PR introduces new SQL syntax, which is used to explicitly exclude columns from star projection.

How was this patch tested?

Unit tests.
Generated new golden files.

Was this patch authored or co-authored using generative AI tooling?

No

@milastdbx
milastdbxforce-pushed the feature/selectStarExcept branch from 2ea05b3 to 18dd5b2CompareNovember 16, 2023 16:25

@dongjoon-hyundongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for making a PR, @milastdbx . Could you provide some references for this syntax in other SQL environments?

@milastdbx

Copy link
Copy Markdown
ContributorAuthor

Thank you for making a PR, @milastdbx . Could you provide some references for this syntax in other SQL environments?

When you say other SQL environments, what exactly are you referring to ?

@dongjoon-hyun

Copy link
Copy Markdown
Member

Popular ones like Apache Hive, Apache Flink, Presto, MySQL, PostgreSQL, MySQL, Oracle, Teradata?

@milastdbx

Copy link
Copy Markdown
ContributorAuthor

Popular ones like Apache Hive, Apache Flink, Presto, MySQL, PostgreSQL, MySQL, Oracle, Teradata?

I don't think any other platform supports it. I maybe rushed the comment saying its ansii standard. I'll update PR description

@dongjoon-hyundongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apache Spark community want to be as compatible as possible other SQL environments in order to avoid potential lock-ins effects. Given that context, this new syntax looks too esoteric to be accepted from my perspective.

Some other Apache Spark committers may have different opinions.

@HyukjinKwon

Copy link
Copy Markdown
Member

Yeah, i wouldn't add this as a dialect but better stick to other DBMSes or ANSI standard

@cloud-fan

Copy link
Copy Markdown
Contributor

I think this is a useful feature, see https://stackoverflow.com/questions/29095281/select-all-the-columns-of-a-table-except-one-column and https://dba.stackexchange.com/questions/1957/sql-select-all-columns-except-some

In fact, Spark already has a SELECT regex feature: #18023 . We can't ignore the need to flexibly select some but not all columns.

If we have to follow an example, Databricks SQL supports this syntax: https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select.html

@HyukjinKwon

Copy link
Copy Markdown
Member

im okay if we already have the variant.

@surjikal

surjikal commented Nov 21, 2023

Copy link
Copy Markdown
Contributor

Bigquery supports SELECT * EXCEPT:

On the other hand, Snowflake and DuckDB use SELECT * EXCLUDE:


For what it's worth, I do things like df.drop('foo')['*'] very often to achieve a similar thing in dataframe land.

My app's DB (not spark) doesn't support the EXCEPT feature and I wish it did, there's a fair amount of extra SQL generated as a workaround. Definitely a good feature from my perspective.

Comment threadsql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala Outdated
Comment threadsql/core/src/test/resources/sql-tests/results/selectExcept.sql.out Outdated
Comment threadsql/core/src/test/resources/sql-tests/results/selectExcept.sql.out Outdated
Comment threadcommon/utils/src/main/resources/error/error-classes.json Outdated
Comment threadsql/core/src/test/resources/sql-tests/results/selectExcept.sql.out Outdated
@cloud-fan

Copy link
Copy Markdown
Contributor

there is a test failure: SparkThrowableSuite.Error classes are correctly formatted

@cloud-fan

Copy link
Copy Markdown
Contributor

The error in docker-integration-tests is unrelated, thanks, merging to master!

sunchao pushed a commit that referenced this pull request Mar 10, 2026
* changelog
* [SPARK-43980][SQL] introducing `select * except` syntax
Changing parser to support new syntax when using * to fetch columns from source.
Introducing new expression `UnresolvedStarExcept` in visit method when newly introduced syntax is created.
Expansion of this expression is core logic of feature.
Introducing new `SELECT * EXCEPT (col1, col2)`
Yes, this PR introduces new SQL syntax, which is used to explicitly exclude columns from star projection.
Unit tests.
Generated new golden files.
No
Closes#43843 from milastdbx/feature/selectStarExcept.
Authored-by: milastdbx <milan.stefanovic@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
---------
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Co-authored-by: milastdbx <milan.stefanovic@databricks.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@milastdbx@dongjoon-hyun@HyukjinKwon@cloud-fan@surjikal