Uh oh!
There was an error while loading. Please reload this page.
[SPARK-25271][SQL] Hive ctas commands should use data source if it is convertible - #22514
[SPARK-25271][SQL] Hive ctas commands should use data source if it is convertible#22514viirya wants to merge 17 commits into
Conversation
SparkQA
commented
Sep 21, 2018
Test build #96401 has finished for PR 22514 at commit
|
viirya
commented
Sep 21, 2018
retest this please. |
SparkQA
commented
Sep 21, 2018
Test build #96410 has finished for PR 22514 at commit
|
viirya
commented
Sep 21, 2018
viirya
commented
Sep 26, 2018
retest this please. |
SparkQA
commented
Sep 26, 2018
Test build #96595 has finished for PR 22514 at commit
|
viirya
commented
Sep 26, 2018
retest this please. |
SparkQA
commented
Sep 26, 2018
Test build #96614 has finished for PR 22514 at commit
|
viirya
commented
Sep 26, 2018
retest this please. |
SparkQA
commented
Sep 26, 2018
Test build #96618 has finished for PR 22514 at commit
|
viirya
commented
Sep 26, 2018
retest this please. |
SparkQA
commented
Sep 26, 2018
Test build #96625 has finished for PR 22514 at commit
|
SparkQA
commented
Sep 29, 2018
Test build #96784 has finished for PR 22514 at commit
|
viirya
commented
Sep 29, 2018
retest this please. |
SparkQA
commented
Sep 29, 2018
Test build #96792 has finished for PR 22514 at commit
|
dongjoon-hyun
commented
Oct 14, 2018
Retest this please. |
SparkQA
commented
Oct 14, 2018
Test build #97352 has finished for PR 22514 at commit
|
| * @param tableDesc the metadata of the table to be created. | ||
| * @param mode the data writing mode | ||
| * @param query an optional logical plan representing data to write into the created table. | ||
| * @param useExternalSerde whether to use external serde to write data, e.g., Hive Serde. Currently |
There was a problem hiding this comment.
This is too hacky. We should not leak hive specific knowledge to general logical plans.
There was a problem hiding this comment.
This is because all rules related to conversion to data source are located in RelationConversions. So now I need to set a flag at this logical plan and pass to CreateHiveTableAsSelectCommand.
If we loose this requirement, we can avoid this flag and let CreateHiveTableAsSelectCommand decide to convert it to data source or not.
There was a problem hiding this comment.
Do you think it is better to put all this conversion stuff of Hive CTAS into CreateHiveTableAsSelectCommand?
There was a problem hiding this comment.
I don't have a clear idea now, but CreateTable is a general logical plan for CREATE TABLE, we may even public in to data source/catalog APIs in the future, we should not put hive specific concept here.
HyukjinKwon
commented
Oct 23, 2018
@cloud-fan, is this a performance regression that affects users that use Hive serde tables as well? |
Yes this is a performance regression for users who run CTAS on Hive serde tables. This is a regression since Spark 2.3.1. |
cloud-fan
commented
Oct 23, 2018
@viirya can you explain the high-level idea about how to fix it? It seems hard to fix and we should get a consensus on the approach first. |
viirya
commented
Oct 24, 2018
@cloud-fan The high level idea is not to put expose conversion details to In |
cloud-fan
commented
Oct 24, 2018
sounds like a clean solution. please go ahead, thanks! |
| withTable(sourceTable, targetTable) { | ||
| sql(s"CREATE TABLE $sourceTable (i int,m map<int, string>) ROW FORMAT DELIMITED FIELDS " + | ||
| "TERMINATED BY ',' COLLECTION ITEMS TERMINATED BY ':' MAP KEYS TERMINATED BY '$'") | ||
| sql(s"LOAD DATA LOCAL INPATH '${testData.toURI}' INTO TABLE $sourceTable") |
There was a problem hiding this comment.
can we generate the input data with a temp view? e.g. create a dataframe with literals and register temp view.
| val metastoreCatalog = catalog.asInstanceOf[HiveSessionCatalog].metastoreCatalog | ||
| // Whether this table is convertible to data source relation. | ||
| val isConvertible = metastoreCatalog.isConvertible(tableDesc) |
There was a problem hiding this comment.
another idea: can we move this logic to the RelationConversions rule? e.g.
case CreateTable(tbl, mode, Some(query)) if DDLUtils.isHiveTable(tbl) && isConvertible(tbl) =>
Union(CreateTable(tbl, mode, None), InsertIntoTable ...)
There was a problem hiding this comment.
I feel CreateHiveTableAsSelectCommand is not useful. It simply creates the table first and then call InsertIntoHiveTable.run. Maybe we should just remove it and implement hive table CTAS as Union(CreateTable, InsertIntoTable).
There was a problem hiding this comment.
That is interesting idea. Let me try it.
There was a problem hiding this comment.
Made a try on this idea.
There is an issue that convertToLogicalRelation needs that the HiveTableRelation is an existing relation. It is good for InsertIntoTable case.
For CTAS now, this relation doesn't exist. Although we use an Union and CreateTable will be run first, the conversion is happened during analysis stage and the table is not created yet.
There was a problem hiding this comment.
ah makes sense, thanks for trying!
viirya
commented
Dec 6, 2018
@cloud-fan I've updated the PR description. Thanks. |
viirya
commented
Dec 11, 2018
Synced with master. |
Uh oh!
There was an error while loading. Please reload this page.
cloud-fan
commented
Dec 11, 2018
To be safe, let's add a |
viirya
commented
Dec 11, 2018
I see, we have discussed before. Is it good to add it here or a follow-up? |
cloud-fan
commented
Dec 11, 2018
Seems like a trivial change, let's do it in this PR. |
SparkQA
commented
Dec 11, 2018
Test build #99958 has finished for PR 22514 at commit
|
viirya
commented
Dec 19, 2018
@cloud-fan Added a SQL config for it. |
cloud-fan
commented
Dec 19, 2018
retest this please |
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Dec 19, 2018
Test build #100309 has finished for PR 22514 at commit
|
cloud-fan
commented
Dec 20, 2018
The last commit is only updating comment, I'm merging it to master, thanks! |
SparkQA
commented
Dec 20, 2018
Test build #100330 has finished for PR 22514 at commit
|
dongjoon-hyun
commented
Dec 20, 2018
Great! Thank you all! |
… convertible ## What changes were proposed in this pull request? In Spark 2.3.0 and previous versions, Hive CTAS command will convert to use data source to write data into the table when the table is convertible. This behavior is controlled by the configs like HiveUtils.CONVERT_METASTORE_ORC and HiveUtils.CONVERT_METASTORE_PARQUET. In 2.3.1, we drop this optimization by mistake in the PR [SPARK-22977](https://github.com/apache/spark/pull/20521/files#r217254430). Since that Hive CTAS command only uses Hive Serde to write data. This patch adds this optimization back to Hive CTAS command. This patch adds OptimizedCreateHiveTableAsSelectCommand which uses data source to write data. ## How was this patch tested? Added test. Closesapache#22514 from viirya/SPARK-25271-2. Authored-by: Liang-Chi Hsieh <viirya@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
… convertible ## What changes were proposed in this pull request? In Spark 2.3.0 and previous versions, Hive CTAS command will convert to use data source to write data into the table when the table is convertible. This behavior is controlled by the configs like HiveUtils.CONVERT_METASTORE_ORC and HiveUtils.CONVERT_METASTORE_PARQUET. In 2.3.1, we drop this optimization by mistake in the PR [SPARK-22977](https://github.com/apache/spark/pull/20521/files#r217254430). Since that Hive CTAS command only uses Hive Serde to write data. This patch adds this optimization back to Hive CTAS command. This patch adds OptimizedCreateHiveTableAsSelectCommand which uses data source to write data. ## How was this patch tested? Added test. Closesapache#22514 from viirya/SPARK-25271-2. Authored-by: Liang-Chi Hsieh <viirya@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Hi, @viirya and @cloud-fan . |
viirya
commented
Oct 7, 2020
It sounds correct to me. As this is reported a bug in 2.3.1, we should fix it in 2.4 too. I will create a backport PR then. |
dongjoon-hyun
commented
Oct 8, 2020
Thank you, @viirya . |
…it is convertible ### What changes were proposed in this pull request? In Spark 2.3.0 and previous versions, Hive CTAS command will convert to use data source to write data into the table when the table is convertible. This behavior is controlled by the configs like HiveUtils.CONVERT_METASTORE_ORC and HiveUtils.CONVERT_METASTORE_PARQUET. In 2.3.1, we drop this optimization by mistake in the PR [SPARK-22977](https://github.com/apache/spark/pull/20521/files#r217254430). Since that Hive CTAS command only uses Hive Serde to write data. This patch adds this optimization back to Hive CTAS command. This patch adds OptimizedCreateHiveTableAsSelectCommand which uses data source to write data. This is to backport #22514 to branch-2.4. ### Why are the changes needed? This bug was originally reported in 2.3.1, but only fixed in 3.0. We should have it in branch-2.4 because the branch is LTS. ### Does this PR introduce _any_ user-facing change? Yes. Users can use the config to use built-in data source writer instead of Hive serde in CTAS. ### How was this patch tested? Unit tests. Closes#30017 from viirya/SPARK-25271-2.4. Authored-by: Liang-Chi Hsieh <viirya@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
What changes were proposed in this pull request?
In Spark 2.3.0 and previous versions, Hive CTAS command will convert to use data source to write data into the table when the table is convertible. This behavior is controlled by the configs like HiveUtils.CONVERT_METASTORE_ORC and HiveUtils.CONVERT_METASTORE_PARQUET.
In 2.3.1, we drop this optimization by mistake in the PR SPARK-22977. Since that Hive CTAS command only uses Hive Serde to write data.
This patch adds this optimization back to Hive CTAS command. This patch adds OptimizedCreateHiveTableAsSelectCommand which uses data source to write data.
How was this patch tested?
Added test.