-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-30782][SQL] Column resolution doesn't respect current catalog/namespace for v2 tables. #27532
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
Closed
Closed
[SPARK-30782][SQL] Column resolution doesn't respect current catalog/namespace for v2 tables. #27532
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5706a3e
initial commit
imback82 10b19d9
fix for v1 tables
imback82 13baa18
Merge branch 'master' into qualifed_col_respect_current
imback82 44d43e5
Merge branch 'master' into qualifed_col_respect_current
imback82 9a0cd68
Merge branch 'master' into qualifed_col_respect_current
imback82 6660d5c
remove hack
imback82 f23ded6
address PR comments
imback82 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -685,12 +685,21 @@ class DataSourceV2SQLSuite | |
| sql(s"CREATE TABLE $t (id bigint, point struct<x: bigint, y: bigint>) USING foo") | ||
| sql(s"INSERT INTO $t VALUES (1, (10, 20))") | ||
|
|
||
| checkAnswer( | ||
| sql(s"SELECT testcat.ns1.ns2.tbl.id, testcat.ns1.ns2.tbl.point.x FROM $t"), | ||
| Row(1, 10)) | ||
| checkAnswer(sql(s"SELECT ns1.ns2.tbl.id, ns1.ns2.tbl.point.x FROM $t"), Row(1, 10)) | ||
| checkAnswer(sql(s"SELECT ns2.tbl.id, ns2.tbl.point.x FROM $t"), Row(1, 10)) | ||
| checkAnswer(sql(s"SELECT tbl.id, tbl.point.x FROM $t"), Row(1, 10)) | ||
| def check(tbl: String): Unit = { | ||
| checkAnswer( | ||
| sql(s"SELECT testcat.ns1.ns2.tbl.id, testcat.ns1.ns2.tbl.point.x FROM $tbl"), | ||
| Row(1, 10)) | ||
| checkAnswer(sql(s"SELECT ns1.ns2.tbl.id, ns1.ns2.tbl.point.x FROM $tbl"), Row(1, 10)) | ||
| checkAnswer(sql(s"SELECT ns2.tbl.id, ns2.tbl.point.x FROM $tbl"), Row(1, 10)) | ||
| checkAnswer(sql(s"SELECT tbl.id, tbl.point.x FROM $tbl"), Row(1, 10)) | ||
| } | ||
|
|
||
| // Test with qualified table name "testcat.ns1.ns2.tbl". | ||
| check(t) | ||
|
|
||
| // Test if current catalog and namespace is respected in column resolution. | ||
| sql("USE testcat.ns1.ns2") | ||
| check("tbl") | ||
|
|
||
| val ex = intercept[AnalysisException] { | ||
| sql(s"SELECT ns1.ns2.ns3.tbl.id from $t") | ||
|
|
@@ -700,19 +709,30 @@ class DataSourceV2SQLSuite | |
| } | ||
|
|
||
| test("qualified column names for v1 tables") { | ||
| // unset this config to use the default v2 session catalog. | ||
| spark.conf.unset(V2_SESSION_CATALOG_IMPLEMENTATION.key) | ||
|
|
||
| withTable("t") { | ||
| sql("CREATE TABLE t USING json AS SELECT 1 AS i") | ||
| checkAnswer(sql("select t.i from spark_catalog.default.t"), Row(1)) | ||
| checkAnswer(sql("select default.t.i from spark_catalog.default.t"), Row(1)) | ||
| Seq(true, false).foreach { useV1Table => | ||
| val format = if (useV1Table) "json" else v2Format | ||
| if (useV1Table) { | ||
| // unset this config to use the default v2 session catalog. | ||
| spark.conf.unset(V2_SESSION_CATALOG_IMPLEMENTATION.key) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we keep this comment: |
||
| } else { | ||
| spark.conf.set( | ||
| V2_SESSION_CATALOG_IMPLEMENTATION.key, classOf[InMemoryTableSessionCatalog].getName) | ||
| } | ||
|
|
||
| // catalog name cannot be used for v1 tables. | ||
| val ex = intercept[AnalysisException] { | ||
| sql(s"select spark_catalog.default.t.i from spark_catalog.default.t") | ||
| withTable("t") { | ||
| sql(s"CREATE TABLE t USING $format AS SELECT 1 AS i") | ||
| checkAnswer(sql("select i from t"), Row(1)) | ||
| checkAnswer(sql("select t.i from t"), Row(1)) | ||
| checkAnswer(sql("select default.t.i from t"), Row(1)) | ||
| checkAnswer(sql("select t.i from spark_catalog.default.t"), Row(1)) | ||
| checkAnswer(sql("select default.t.i from spark_catalog.default.t"), Row(1)) | ||
|
|
||
| // catalog name cannot be used for tables in the session catalog. | ||
| val ex = intercept[AnalysisException] { | ||
| sql(s"select spark_catalog.default.t.i from spark_catalog.default.t") | ||
| } | ||
| assert(ex.getMessage.contains("cannot resolve '`spark_catalog.default.t.i`")) | ||
| } | ||
| assert(ex.getMessage.contains("cannot resolve '`spark_catalog.default.t.i`")) | ||
| } | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we add catalog name too? to support cases like
select spark_catalog.default.t.i from t.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but it would not be consistent with v1 table behavior. I was thinking about adding this support when I update the resolution rule for session catalogs: #27391 (comment). What do you think, should I do it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok. Let's leave it for now.