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
[SPARK-30150][SQL] ADD FILE, ADD JAR, LIST FILE & LIST JAR Command do not accept quoted path #26779
Conversation
cc @cloud-fan |
@@ -357,7 +357,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder(conf) { | |||
* }}} | |||
*/ | |||
override def visitManageResource(ctx: ManageResourceContext): LogicalPlan = withOrigin(ctx) { | |||
val mayebePaths = remainder(ctx.identifier).trim | |||
val mayebePaths = pathWrapper(remainder(ctx.identifier).trim) |
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.
Can we use string literal or identifier rule in ANTLER rather than manually fixing here from identifer? BTW, does Hive support that case as well?
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.
Yea, that approach @HyukjinKwon addressed above looks nicer to me.
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 changed the grammar to take string literal as well for ADD/LIST.
Now all of add file abc.txt
, add file 'abc.txt'
and add file "abc.txt"
are supported.
Can you add tests for that? |
Yeah Sure. |
Test Cases Added For all the 4 commands. |
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
Show resolved
Hide resolved
Can you update the title to make it clearer? Is this pr not only for |
sql/core/src/test/scala/org/apache/spark/sql/execution/SparkSqlParserSuite.scala
Outdated
Show resolved
Hide resolved
ok to test |
@iRakson does Hive support this case? |
@HyukjinKwon No. Path passed in hive is unquoted i.e not as string literal. |
sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
Show resolved
Hide resolved
Test build #115061 has finished for PR 26779 at commit
|
Test build #115084 has finished for PR 26779 at commit
|
please re-test this one. |
retest this please |
Test build #115100 has finished for PR 26779 at commit
|
|
||
test("manage resources") { | ||
assertEqual("ADD FILE abc.txt", AddFileCommand("abc.txt")) | ||
assertEqual("ADD FILE \'abc.txt\'", AddFileCommand("abc.txt")) |
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.
is \'
the same as '
here?
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.
yes.
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 use '
? it's easier to read
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.
@cloud-fan Yes, Its better that way. I have made the changes.
assertEqual("ADD FILE abc.txt", AddFileCommand("abc.txt")) | ||
assertEqual("ADD FILE \'abc.txt\'", AddFileCommand("abc.txt")) | ||
assertEqual("ADD FILE \"/path/to/abc.txt\"", AddFileCommand("/path/to/abc.txt")) | ||
assertEqual("LIST FILE abc.txt", ListFilesCommand("abc.txt".split("\\s+"))) |
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 use simply Array("/path//abc.txt")
instead of "abc.txt".split("\\s+")
? (here and the below LIST
test cases)
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.
List commands are using .split("\\s+")
on path given to them. Thus we have to do same here. @dongjoon-hyun
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.
No. This is a test case. You can use the result of .split("\\s+")
.
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. I will use the result of .split("\s+").
assertEqual("LIST JAR \'abc.jar\'", ListJarsCommand("abc.jar".split("\\s+"))) | ||
assertEqual("LIST JAR \"abc.jar\"", ListJarsCommand("abc.jar".split("\\s+"))) | ||
assertEqual("ADD FILE /path with space/abc.txt", AddFileCommand("/path with space/abc.txt")) | ||
assertEqual("ADD JAR /path with space/abc.jar", AddJarCommand("/path with space/abc.jar")) |
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.
Although our parser will accept without any differences, shall we have a test case for Window-path, too?
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.
@dongjoon-hyun Is it required to add test cases for window-path?
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 think it's OK. We know that the parser accepts anything, we just need to prove that quoted path works.
Test build #115163 has finished for PR 26779 at commit
|
thanks, merging to master! |
Thanks all for reviewing this PR :) and merging it. |
What changes were proposed in this pull request?
add file "abc.txt"
andadd file 'abc.txt'
are not supported.For these two spark sql gives
FileNotFoundException
.Only
add file abc.txt
is supported currently.After these changes path can be given as quoted text for ADD FILE, ADD JAR, LIST FILE, LIST JAR commands in spark-sql
Why are the changes needed?
In many of the spark-sql commands (like create table ,etc )we write path in quoted format only. To maintain this consistency we should support quoted format with this command as well.
Does this PR introduce any user-facing change?
Yes. Now users can write path with quotes.
How was this patch tested?
Manually tested.