-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21354] [SQL] INPUT FILE related functions do not support more than one sources #18580
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 3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,15 @@ trait CheckAnalysis extends PredicateHelper { | |
| } | ||
| } | ||
|
|
||
| private def getNumInputFileBlockSources(operator: LogicalPlan): Int = { | ||
| operator match { | ||
| case _: LeafNode => 1 | ||
| // UNION ALL has multiple children, but these children do not concurrently use InputFileBlock. | ||
| case u: Union => u.children.map(getNumInputFileBlockSources).sum - u.children.length + 1 | ||
| case o => o.children.map(getNumInputFileBlockSources).sum | ||
| } | ||
| } | ||
|
|
||
| def checkAnalysis(plan: LogicalPlan): Unit = { | ||
| // We transform up and order the rules so as to catch the first possible failure instead | ||
| // of the result of cascading resolution failures. | ||
|
|
@@ -100,6 +109,10 @@ trait CheckAnalysis extends PredicateHelper { | |
| failAnalysis( | ||
| s"invalid cast from ${c.child.dataType.simpleString} to ${c.dataType.simpleString}") | ||
|
|
||
| case e @ (_: InputFileName | _: InputFileBlockLength | _: InputFileBlockStart) | ||
| if getNumInputFileBlockSources(operator) > 1 => | ||
| e.failAnalysis(s"'${e.prettyName}' does not support more than one sources") | ||
|
||
|
|
||
| case g: Grouping => | ||
| failAnalysis("grouping() can only be used with GroupingSets/Cube/Rollup") | ||
| case g: GroupingID => | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -530,6 +530,45 @@ class ColumnExpressionSuite extends QueryTest with SharedSQLContext { | |
| ) | ||
| } | ||
|
|
||
| test("input_file_name, input_file_block_start, input_file_block_length - more than one sources") { | ||
| withTable("tab1", "tab2") { | ||
| val data = sparkContext.parallelize(0 to 9).toDF("id") | ||
| data.write.saveAsTable("tab1") | ||
| data.write.saveAsTable("tab2") | ||
| Seq("input_file_name", "input_file_block_start", "input_file_block_length").foreach { func => | ||
| val e = intercept[AnalysisException] { | ||
| sql(s"SELECT *, $func() FROM tab1 JOIN tab2 ON tab1.id = tab2.id") | ||
| }.getMessage | ||
| assert(e.contains(s"'$func' does not support more than one sources")) | ||
|
||
| } | ||
|
|
||
| val df = sql( | ||
| """ | ||
| |SELECT *, input_file_name() | ||
| |FROM (SELECT * FROM tab1 UNION ALL SELECT * FROM tab2 UNION ALL SELECT * FROM tab2) | ||
| """.stripMargin) | ||
| assert(df.count() == 30) | ||
|
|
||
| var e = intercept[AnalysisException] { | ||
| sql( | ||
| """ | ||
| |SELECT *, input_file_name() | ||
| |FROM (SELECT * FROM tab1 NATURAL JOIN tab2) UNION ALL SELECT * FROM tab2 | ||
| """.stripMargin) | ||
| }.getMessage | ||
| assert(e.contains("'input_file_name' does not support more than one sources")) | ||
|
|
||
| e = intercept[AnalysisException] { | ||
| sql( | ||
| """ | ||
| |SELECT *, input_file_name() | ||
| |FROM (SELECT * FROM tab1 UNION ALL SELECT * FROM tab2) NATURAL JOIN tab2 | ||
| """.stripMargin) | ||
| }.getMessage | ||
| assert(e.contains("'input_file_name' does not support more than one sources")) | ||
| } | ||
| } | ||
|
|
||
| test("input_file_name, input_file_block_start, input_file_block_length - FileScanRDD") { | ||
| withTempPath { dir => | ||
| val data = sparkContext.parallelize(0 to 10).toDF("id") | ||
|
|
||
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 only consider file data source leaf node?
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.
Unable to check it in
CheckAnalysis. BothHadoopRDDandFileScanRDDhave the same issues. To block both, we need to add the check as another rule.