-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-20460][SQL] Make it more consistent to handle column name duplication #17758
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 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1e647ee
Share code to check column name duplication
maropu 4467077
Apply reviews
maropu 33ab217
Make code more consistent
maropu d8efb9d
Apply review comments
maropu 11d1818
Apply xiao's reviews
maropu 22e1e4f
Apply more xiao's reviews
maropu 743a069
Replace map with foreach
maropu f6eab2d
Add tests for data schema + parititon schema
maropu 09da8d6
Drop name dplication checks in HiveMetastoreCatalog.scala
maropu 6d03f31
Modify exception messages
maropu a0b9b05
Revert logic to check name duplication
maropu 91b6424
Add tests for write paths
maropu 37ad3f3
Add tests for stream sink paths
maropu d0d9d3e
Burhs up code and adds more tests
maropu cbe9c71
Apply reviews
maropu c69270f
Apply more comments
maropu af959f6
Add more tests in create.sql
maropu 8d3e10a
Move duplication checks in constructor
maropu 9b386d5
Brush up code
maropu a878510
[WIP] Add DataSourceValidator trait to validate schema in write path
maropu be20127
Revert "Brush up code"
maropu f41bf80
Fix more issues
maropu 0526391
Revert DataSourceValidator
maropu 9e199bc
Add the check for external relation providers
maropu 1ae132d
[WIP] Handle DataSource name duplication in one place
maropu 5c29a75
Fix more
maropu 5ed2c0d
Move some tests to DDLSuite
maropu 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
Apply review comments
- Loading branch information
commit d8efb9d17fbc75d4d756f66bd84a3d9697ee0c0b
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,10 @@ | |
|
|
||
| package org.apache.spark.sql.util | ||
|
|
||
| import scala.collection.mutable | ||
|
|
||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.catalyst.analysis._ | ||
| import org.apache.spark.sql.types.StructType | ||
|
|
||
|
|
||
|
|
@@ -30,22 +33,26 @@ private[spark] object SchemaUtils { | |
|
|
||
| def checkSchemaColumnNameDuplication( | ||
| schema: StructType, colType: String, caseSensitiveAnalysis: Boolean = false): Unit = { | ||
| checkColumnNameDuplication(schema.map(_.name), colType, caseSensitiveAnalysis) | ||
| val resolver = if (caseSensitiveAnalysis) { | ||
| caseSensitiveResolution | ||
| } else { | ||
| caseInsensitiveResolution | ||
| } | ||
| checkColumnNameDuplication(schema.map(_.name), colType, resolver) | ||
| } | ||
|
|
||
| def checkColumnNameDuplication( | ||
|
||
| names: Seq[String], colType: String, caseSensitiveAnalysis: Boolean = false): Unit = { | ||
| val colNames = if (caseSensitiveAnalysis) { | ||
| names | ||
| } else { | ||
| names.map(_.toLowerCase) | ||
| } | ||
| if (colNames.distinct.length != colNames.length) { | ||
| val duplicateColumns = colNames.groupBy(identity).collect { | ||
| case (x, ys) if ys.length > 1 => "\"" + x + "\"" | ||
| names: Seq[String], colType: String, resolver: Resolver): Unit = { | ||
| val duplicateColumns = mutable.ArrayBuffer[String]() | ||
| names.foreach { name => | ||
| val sameColNames = names.filter(resolver(_, name)) | ||
| if (sameColNames.size > 1 && !duplicateColumns.exists(resolver(_, name))) { | ||
| duplicateColumns.append(name) | ||
| } | ||
| } | ||
| if (duplicateColumns.size > 0) { | ||
| throw new AnalysisException(s"Found duplicate column(s) in $colType: " + | ||
| duplicateColumns.mkString(", ")) | ||
| duplicateColumns.map(colName => s""""$colName"""").mkString(", ")) | ||
| } | ||
| } | ||
| } | ||
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
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
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 |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| -- Check name duplication in a regular case | ||
| CREATE TABLE t (c STRING, c INT) USING parquet; | ||
| -- Catch case-sensitive name duplication | ||
| SET spark.sql.caseSensitive=true; | ||
|
|
||
| -- Check multiple name duplication | ||
| CREATE TABLE t (c0 STRING, c1 INT, c1 DOUBLE, c0 INT) USING parquet; | ||
|
|
||
| -- Catch case-insensitive name duplication | ||
| SET spark.sql.caseSensitive=false; | ||
|
|
||
| CREATE TABLE t (c0 STRING, c1 INT, c1 DOUBLE, c0 INT) USING parquet; | ||
|
|
||
| CREATE TABLE t (ab STRING, cd INT, ef DOUBLE, Ab INT) USING parquet; |
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
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.
Could you add the function description and parameter description?
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.
ok