-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-17860][SQL] SHOW COLUMN's database conflict check should respect case sensitivity configuration #15423
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
58 changes: 58 additions & 0 deletions
58
sql/core/src/test/resources/sql-tests/inputs/show_columns.sql
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| CREATE DATABASE showdb; | ||
|
|
||
| USE showdb; | ||
|
|
||
| CREATE TABLE showcolumn1 (col1 int, `col 2` int); | ||
| CREATE TABLE showcolumn2 (price int, qty int) partitioned by (year int, month int); | ||
|
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. can we also test temp view? |
||
| CREATE TEMPORARY VIEW showColumn3 (col3 int, `col 4` int) USING parquet; | ||
| CREATE GLOBAL TEMP VIEW showColumn4 AS SELECT 1 as col1, 'abc' as `col 5`; | ||
|
|
||
|
|
||
| -- only table name | ||
| SHOW COLUMNS IN showcolumn1; | ||
|
|
||
| -- qualified table name | ||
| SHOW COLUMNS IN showdb.showcolumn1; | ||
|
|
||
| -- table name and database name | ||
| SHOW COLUMNS IN showcolumn1 FROM showdb; | ||
|
|
||
| -- partitioned table | ||
| SHOW COLUMNS IN showcolumn2 IN showdb; | ||
|
|
||
| -- Non-existent table. Raise an error in this case | ||
| SHOW COLUMNS IN badtable FROM showdb; | ||
|
|
||
| -- database in table identifier and database name in different case | ||
| SHOW COLUMNS IN showdb.showcolumn1 from SHOWDB; | ||
|
|
||
| -- different database name in table identifier and database name. | ||
| -- Raise an error in this case. | ||
| SHOW COLUMNS IN showdb.showcolumn1 FROM baddb; | ||
|
|
||
| -- show column on temporary view | ||
| SHOW COLUMNS IN showcolumn3; | ||
|
|
||
| -- error temp view can't be qualified with a database | ||
| SHOW COLUMNS IN showdb.showcolumn3; | ||
|
|
||
| -- error temp view can't be qualified with a database | ||
| SHOW COLUMNS IN showcolumn3 FROM showdb; | ||
|
|
||
| -- error global temp view needs to be qualified | ||
| SHOW COLUMNS IN showcolumn4; | ||
|
|
||
| -- global temp view qualified with database | ||
| SHOW COLUMNS IN global_temp.showcolumn4; | ||
|
|
||
| -- global temp view qualified with database | ||
| SHOW COLUMNS IN showcolumn4 FROM global_temp; | ||
|
|
||
| DROP TABLE showcolumn1; | ||
| DROP TABLE showColumn2; | ||
| DROP VIEW showcolumn3; | ||
| DROP VIEW global_temp.showcolumn4; | ||
|
|
||
| use default; | ||
|
|
||
| DROP DATABASE showdb; | ||
217 changes: 217 additions & 0 deletions
217
sql/core/src/test/resources/sql-tests/results/show_columns.sql.out
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 |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 25 | ||
|
|
||
|
|
||
| -- !query 0 | ||
| CREATE DATABASE showdb | ||
| -- !query 0 schema | ||
| struct<> | ||
| -- !query 0 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 1 | ||
| USE showdb | ||
| -- !query 1 schema | ||
| struct<> | ||
| -- !query 1 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 2 | ||
| CREATE TABLE showcolumn1 (col1 int, `col 2` int) | ||
| -- !query 2 schema | ||
| struct<> | ||
| -- !query 2 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 3 | ||
| CREATE TABLE showcolumn2 (price int, qty int) partitioned by (year int, month int) | ||
| -- !query 3 schema | ||
| struct<> | ||
| -- !query 3 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 4 | ||
| CREATE TEMPORARY VIEW showColumn3 (col3 int, `col 4` int) USING parquet | ||
| -- !query 4 schema | ||
| struct<> | ||
| -- !query 4 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 5 | ||
| CREATE GLOBAL TEMP VIEW showColumn4 AS SELECT 1 as col1, 'abc' as `col 5` | ||
| -- !query 5 schema | ||
| struct<> | ||
| -- !query 5 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 6 | ||
| SHOW COLUMNS IN showcolumn1 | ||
| -- !query 6 schema | ||
| struct<col_name:string> | ||
| -- !query 6 output | ||
| col 2 | ||
| col1 | ||
|
|
||
|
|
||
| -- !query 7 | ||
| SHOW COLUMNS IN showdb.showcolumn1 | ||
| -- !query 7 schema | ||
| struct<col_name:string> | ||
| -- !query 7 output | ||
| col 2 | ||
| col1 | ||
|
|
||
|
|
||
| -- !query 8 | ||
| SHOW COLUMNS IN showcolumn1 FROM showdb | ||
| -- !query 8 schema | ||
| struct<col_name:string> | ||
| -- !query 8 output | ||
| col 2 | ||
| col1 | ||
|
|
||
|
|
||
| -- !query 9 | ||
| SHOW COLUMNS IN showcolumn2 IN showdb | ||
| -- !query 9 schema | ||
| struct<col_name:string> | ||
| -- !query 9 output | ||
| month | ||
| price | ||
| qty | ||
| year | ||
|
|
||
|
|
||
| -- !query 10 | ||
| SHOW COLUMNS IN badtable FROM showdb | ||
| -- !query 10 schema | ||
| struct<> | ||
| -- !query 10 output | ||
| org.apache.spark.sql.catalyst.analysis.NoSuchTableException | ||
| Table or view 'badtable' not found in database 'showdb'; | ||
|
|
||
|
|
||
| -- !query 11 | ||
| SHOW COLUMNS IN showdb.showcolumn1 from SHOWDB | ||
| -- !query 11 schema | ||
| struct<col_name:string> | ||
| -- !query 11 output | ||
| col 2 | ||
| col1 | ||
|
|
||
|
|
||
| -- !query 12 | ||
| SHOW COLUMNS IN showdb.showcolumn1 FROM baddb | ||
| -- !query 12 schema | ||
| struct<> | ||
| -- !query 12 output | ||
| org.apache.spark.sql.AnalysisException | ||
| SHOW COLUMNS with conflicting databases: 'baddb' != 'showdb'; | ||
|
|
||
|
|
||
| -- !query 13 | ||
| SHOW COLUMNS IN showcolumn3 | ||
| -- !query 13 schema | ||
| struct<col_name:string> | ||
| -- !query 13 output | ||
| col 4 | ||
| col3 | ||
|
|
||
|
|
||
| -- !query 14 | ||
| SHOW COLUMNS IN showdb.showcolumn3 | ||
| -- !query 14 schema | ||
| struct<> | ||
| -- !query 14 output | ||
| org.apache.spark.sql.catalyst.analysis.NoSuchTableException | ||
| Table or view 'showcolumn3' not found in database 'showdb'; | ||
|
|
||
|
|
||
| -- !query 15 | ||
| SHOW COLUMNS IN showcolumn3 FROM showdb | ||
| -- !query 15 schema | ||
| struct<> | ||
| -- !query 15 output | ||
| org.apache.spark.sql.catalyst.analysis.NoSuchTableException | ||
| Table or view 'showcolumn3' not found in database 'showdb'; | ||
|
|
||
|
|
||
| -- !query 16 | ||
| SHOW COLUMNS IN showcolumn4 | ||
| -- !query 16 schema | ||
| struct<> | ||
| -- !query 16 output | ||
| org.apache.spark.sql.catalyst.analysis.NoSuchTableException | ||
| Table or view 'showcolumn4' not found in database 'showdb'; | ||
|
|
||
|
|
||
| -- !query 17 | ||
| SHOW COLUMNS IN global_temp.showcolumn4 | ||
| -- !query 17 schema | ||
| struct<col_name:string> | ||
| -- !query 17 output | ||
| col 5 | ||
| col1 | ||
|
|
||
|
|
||
| -- !query 18 | ||
| SHOW COLUMNS IN showcolumn4 FROM global_temp | ||
| -- !query 18 schema | ||
| struct<col_name:string> | ||
| -- !query 18 output | ||
| col 5 | ||
| col1 | ||
|
|
||
|
|
||
| -- !query 19 | ||
| DROP TABLE showcolumn1 | ||
| -- !query 19 schema | ||
| struct<> | ||
| -- !query 19 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 20 | ||
| DROP TABLE showColumn2 | ||
| -- !query 20 schema | ||
| struct<> | ||
| -- !query 20 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 21 | ||
| DROP VIEW showcolumn3 | ||
| -- !query 21 schema | ||
| struct<> | ||
| -- !query 21 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 22 | ||
| DROP VIEW global_temp.showcolumn4 | ||
| -- !query 22 schema | ||
| struct<> | ||
| -- !query 22 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 23 | ||
| use default | ||
| -- !query 23 schema | ||
| struct<> | ||
| -- !query 23 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 24 | ||
| DROP DATABASE showdb | ||
| -- !query 24 schema | ||
| struct<> | ||
| -- !query 24 output | ||
|
|
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
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
Oops, something went wrong.
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.
FYI, MySQL will treat
SHOW COLUMNS FROM db1.tbl1 FROM db2asSHOW COLUMNS FROM tbl1 FROM db2, i.e. ifFROM databaseis specified, it will just ignore the database specified in table name, instead of reporting error.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 should investigate more databases to see how they handle this case.
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.
Good point!
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.
BTW, what @dilipbiswal does in this is following previous behavior, do we want to break it?
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.
Seems Hive doesn't allow specifying duplicate databases no matter they are the same or not.
https://github.com/apache/hive/blob/21a0142f333fba231f2648db53a48dc41384ad72/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java#L2215
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.
Thanks @viirya for checking hive. Yeah, when we implemented the SHOW columns native command, wde went through the the above hive code. We decided to improve up on the above check and report an error only when the database names are different.
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.
I have no strong option towards this. From my point, MySQL's way might be little confusing users if they don't notice the database name is different.