Uh oh!
There was an error while loading. Please reload this page.
[SPARK-4131] Support "Writing data into the filesystem from queries" - #18975
[SPARK-4131] Support "Writing data into the filesystem from queries"#18975janewangfb wants to merge 64 commits into
Conversation
gatorsmile
commented
Aug 17, 2017
ok to test |
| * operation to the logical plan. | ||
| */ | ||
| protected override def withInsertInto(ctx: InsertIntoContext, | ||
| query: LogicalPlan): LogicalPlan = withOrigin(ctx) { |
gatorsmile
commented
Aug 17, 2017
@janewangfb Thank you for working on it! The implementation in the current PR is very specific to Hive table. To support such a command, could you also support data source tables? |
SparkQA
commented
Aug 17, 2017
Test build #80804 has finished for PR 18975 at commit
|
janewangfb
commented
Aug 18, 2017
@gatorsmile Originally, because we have alot of hive sqls that we wanted to support in spark, I implemented hive syntax for this command: But now I see that in SparkSqlParser.scala, we have both visitCreateTable and visitCreateHiveTable. |
gatorsmile
commented
Aug 18, 2017
Since our native data source tables perform faster than the Hive serde tables, we expect our Spark users might prefer using data source tables. Thanks for your work! |
SparkQA
commented
Aug 19, 2017
Test build #80874 has finished for PR 18975 at commit
|
janewangfb
commented
Aug 21, 2017
still need to implement the data source table portion. |
SparkQA
commented
Aug 21, 2017
Test build #80917 has finished for PR 18975 at commit
|
janewangfb
commented
Aug 21, 2017
Added the support for write out data source format. |
| ctx: InsertOverwriteDirContext): InsertDirParams = withOrigin(ctx) { | ||
| if (ctx.LOCAL != null) { | ||
| throw new ParseException( | ||
| "LOCAL is not supported in INSERT OVERWRITE DIRECTORY to data source", ctx) |
There was a problem hiding this comment.
If we don't support LOCAL for data source, should we remove it from the parsing rule?
There was a problem hiding this comment.
Originally, LOCAL was not added.
@gatorsmile had some comment that the parser might have some weird exception and he requested to add it.
| tmpFile => fs.rename(tmpFile.getPath, writeToPath) | ||
| } | ||
| deleteExternalTmpPath(hadoopConf) |
There was a problem hiding this comment.
We should also try to remove the external tmp path when an exception happens.
viirya
commented
Sep 9, 2017
Looks pretty well, left few minor comments. Thanks for working on this. |
SparkQA
commented
Sep 9, 2017
Test build #81576 has finished for PR 18975 at commit
|
gatorsmile
commented
Sep 9, 2017
LGTM pending Jenkins Thanks again! |
SparkQA
commented
Sep 9, 2017
Test build #81593 has finished for PR 18975 at commit
|
SparkQA
commented
Sep 9, 2017
Test build #81594 has finished for PR 18975 at commit
|
gatorsmile
commented
Sep 9, 2017
Thanks! Merged to master. |
| isLocal: Boolean, | ||
| storage: CatalogStorageFormat, | ||
| query: LogicalPlan, | ||
| overwrite: Boolean) extends SaveAsHiveFile with HiveTmpPath { |
There was a problem hiding this comment.
why do we separate SaveAsHiveFile and HiveTmpPath, while we always use them together?
There was a problem hiding this comment.
Sure, will submit a follow-up PR soon.
There was a problem hiding this comment.
@cloud-fan and gatorsmile, I will merge them together and submit a PR.
## What changes were proposed in this pull request? The code is already merged to master: apache#18975 This is a following up PR to merge HiveTmpFile.scala to SaveAsHiveFile. ## How was this patch tested? Build successfully Author: Jane Wang <janewang@fb.com> Closesapache#19221 from janewangfb/merge_savehivefile_hivetmpfile.
…m queries" ## What changes were proposed in this pull request? This PR is clean the codes in apache#18975 ## How was this patch tested? N/A Author: gatorsmile <gatorsmile@gmail.com> Closesapache#19225 from gatorsmile/refactorSPARK-4131.
| val saveMode = if (overwrite) SaveMode.Overwrite else SaveMode.ErrorIfExists | ||
| try { | ||
| sparkSession.sessionState.executePlan(dataSource.planForWriting(saveMode, query)) | ||
| dataSource.writeAndRead(saveMode, query) |
There was a problem hiding this comment.
The implementation here confused me, just want to leave a question here why we should call both writeAndRead and planForWriting?
@janewangfb@gatorsmile@cloud-fan
There was a problem hiding this comment.
Yes. We should get rid of dataSource.writeAndRead@xuanyuanking Could you submit a PR to fix the issue?
There was a problem hiding this comment.
@gatorsmile Thanks for you reply, I'll try to fix this.
## What changes were proposed in this pull request? As the discussion in #16481 and #18975 (comment) Currently the BaseRelation returned by `dataSource.writeAndRead` only used in `CreateDataSourceTableAsSelect`, planForWriting and writeAndRead has some common code paths. In this patch I removed the writeAndRead function and added the getRelation function which only use in `CreateDataSourceTableAsSelectCommand` while saving data to non-existing table. ## How was this patch tested? Existing UT Author: Yuanjian Li <xyliyuanjian@gmail.com> Closes#19941 from xuanyuanking/SPARK-22753.
@gatorsmile@janewangfb i have a question as i see insert overwrite directory 'file:///opt/table2' using parquet select * from table1; is still ok |
…a source ### What changes were proposed in this pull request? `INSERT OVERWRITE LOCAL DIRECTORY` is supported with ensuring the provided path is always using `file://` as scheme and removing the check which throws exception if we do insert overwrite by mentioning directory with `LOCAL` syntax ### Why are the changes needed? without the modification in PR, ``` insert overwrite local directory <location> using ``` throws exception ``` Error: org.apache.spark.sql.catalyst.parser.ParseException: LOCAL is not supported in INSERT OVERWRITE DIRECTORY to data source(line 1, pos 0) ``` which was introduced in #18975, but this restriction is not needed, hence dropping the same. Keep behaviour consistent for local and remote file-system in `INSERT OVERWRITE DIRECTORY` ### Does this PR introduce any user-facing change? Yes, after this change `INSERT OVERWRITE LOCAL DIRECTORY` will not throw exception ### How was this patch tested? Added UT Closes#27039 from ajithme/insertoverwrite2. Authored-by: Ajith <ajith2489@gmail.com> Signed-off-by: HyukjinKwon <gurwls223@apache.org>
…a source ### What changes were proposed in this pull request? `INSERT OVERWRITE LOCAL DIRECTORY` is supported with ensuring the provided path is always using `file://` as scheme and removing the check which throws exception if we do insert overwrite by mentioning directory with `LOCAL` syntax ### Why are the changes needed? without the modification in PR, ``` insert overwrite local directory <location> using ``` throws exception ``` Error: org.apache.spark.sql.catalyst.parser.ParseException: LOCAL is not supported in INSERT OVERWRITE DIRECTORY to data source(line 1, pos 0) ``` which was introduced in apache#18975, but this restriction is not needed, hence dropping the same. Keep behaviour consistent for local and remote file-system in `INSERT OVERWRITE DIRECTORY` ### Does this PR introduce any user-facing change? Yes, after this change `INSERT OVERWRITE LOCAL DIRECTORY` will not throw exception ### How was this patch tested? Added UT Closesapache#27039 from ajithme/insertoverwrite2. Authored-by: Ajith <ajith2489@gmail.com> Signed-off-by: HyukjinKwon <gurwls223@apache.org>
What changes were proposed in this pull request?
This PR implements the sql feature:
INSERT OVERWRITE [LOCAL] DIRECTORY directory1
[ROW FORMAT row_format] [STORED AS file_format]
SELECT ... FROM ...
How was this patch tested?
Added new unittests and also pulled the code to fb-spark so that we could test writing to hdfs directory.