Skip to content

[SPARK-28659][SQL] Use data source if convertible in insert overwrite directory - #25398

Closed
Udbhav30 wants to merge 5 commits into
apache:masterfrom
Udbhav30:master
Closed

[SPARK-28659][SQL] Use data source if convertible in insert overwrite directory#25398
Udbhav30 wants to merge 5 commits into
apache:masterfrom
Udbhav30:master

Conversation

@Udbhav30

@Udbhav30Udbhav30 commented Aug 9, 2019

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

In insert overwrite directory while using STORED AS file_format, files are not compressed.
In this PR it is converted to datasource if it is convertible, to make it inline withCTAS behavior which is fixed in this PR

Why are the changes needed?

To make the behavior inline with CTAS while using STORED AS file_format

Does this PR introduce any user-facing change?

Yes, After the fix of this PR now STORED AS file_format will be converted to datasource if it is convertible
Before
before

After
after

How was this patch tested?

New testcase is added

@maropu

Copy link
Copy Markdown
Member

Can you add tests?

@maropumaropu changed the title [SPARK-28659] Use data source if convertible in insert overwrite dire…[SPARK-28659] Use data source if convertible in insert overwrite directoryAug 10, 2019
@maropumaropu changed the title [SPARK-28659] Use data source if convertible in insert overwrite directory[SPARK-28659][SQL] Use data source if convertible in insert overwrite directoryAug 10, 2019
@Udbhav30

Copy link
Copy Markdown
ContributorAuthor

Can you add tests?

yes i will add tests and update the PR

@Udbhav30

Copy link
Copy Markdown
ContributorAuthor

@maropu added the testcase!

@maropu

Copy link
Copy Markdown
Member

ok to test

@maropu

Copy link
Copy Markdown
Member

Thanks!

@SparkQA

Copy link
Copy Markdown

Test build #108912 has finished for PR 25398 at commit 36913da.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA

Copy link
Copy Markdown

Test build #108920 has finished for PR 25398 at commit 68db457.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

(ctx.LOCAL != null, storage, Some(DDLUtils.HIVE_PROVIDER))
val fileFormat = extractFileFormat(fileStorage.serde)
(ctx.LOCAL != null, storage, Some(fileFormat))
}

@maropumaropuAug 11, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is correct? It seems a valid value is Some(DDLUtils.HIVE_PROVIDER) or None for the third parameter.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of parquet and orc we can use the respective file format instead of hive.
In case of ctas also we convert to use data source https://github.com/viirya/spark-1/blob/839a6ce1732fa37b5f8ec9afa2d51730fc6ca691/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveStrategies.scala#L188
This will make it inline with that behavior.

sql(
s"""
|INSERT OVERWRITE LOCAL DIRECTORY '$path'
|STORED AS orc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you delete this?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we use stored as and file format is orc or parquet it will be converted to data source flow.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the test case name should be modified correspondingly and a new test case for (orc/parquet) should be added.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@advancedxy i have updated the testcase name and for orc and parquet testcase was already added. As they will be converted to data source, the data in the directory would be compressed.

sql(
s"""
|INSERT OVERWRITE LOCAL DIRECTORY '$path'
|STORED AS orc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the test case name should be modified correspondingly and a new test case for (orc/parquet) should be added.

}

private def extractFileFormat(serde: Option[String]): String = {
if (serde.toString.contains("parquet")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although None.toString is "None", this looks like a hack to me.

How about:

serde.map({ x =>
val lowerCaseSerde = x.toLowerCase(Locale.ROOT)
if (lowerCaseSerde.contains("parquet") "parquet"
else if (lowerCaseSerde.contains("orc") "orc"
else DDLUtils.HIVE_PROVIDER
}).getOrElse( DDLUtils.HIVE_PROVIDER)

@SparkQA

Copy link
Copy Markdown

Test build #108968 has finished for PR 25398 at commit b432b39.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA

Copy link
Copy Markdown

Test build #108972 has finished for PR 25398 at commit 72d6dd4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@Udbhav30

Copy link
Copy Markdown
ContributorAuthor

cc @HyukjinKwon

@HyukjinKwon

Copy link
Copy Markdown
Member

ok to test

@SparkQA

Copy link
Copy Markdown

Test build #110698 has finished for PR 25398 at commit 72d6dd4.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@Udbhav30

Copy link
Copy Markdown
ContributorAuthor

failed test doesn't look related to this PR @HyukjinKwon

@HyukjinKwon

Copy link
Copy Markdown
Member

retest this please

@SparkQA

Copy link
Copy Markdown

Test build #110857 has finished for PR 25398 at commit 72d6dd4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@Udbhav30

Copy link
Copy Markdown
ContributorAuthor

retest this please

1 similar comment
@maropu

Copy link
Copy Markdown
Member

retest this please

@SparkQA

Copy link
Copy Markdown

Test build #110880 has finished for PR 25398 at commit 72d6dd4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon

HyukjinKwon commented Oct 11, 2019

Copy link
Copy Markdown
Member

If you only target to fix Hive ser/de to respect compression, why don't you set Hive compression properly?

@Udbhav30

Udbhav30 commented Oct 11, 2019

Copy link
Copy Markdown
ContributorAuthor

If you only target to fix Hive ser/de to respect compression, why don't you set Hive compression properly?

Yes compression can be achieved by setting Hive ser/de or USING file_format , but as i mentioned this PR is more towards making the behavior inline to CTAS and to use datasource if it is convertible. Let me know if you have any suggestions :)

@HyukjinKwonHyukjinKwon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, if we want to do the conversion, it should have a configuration like spark.sql.hive.convertMetastoreCtas which respects spark.sql.hive.convertMetastoreParquet or spark.sql.hive.convertMetastoreOrc.

cc @viirya, @dongjoon-hyun, @cloud-fan

@AmplabJenkins

Copy link
Copy Markdown

Can one of the admins verify this patch?

@github-actions

Copy link
Copy Markdown

We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@Udbhav30@maropu@SparkQA@HyukjinKwon@AmplabJenkins@advancedxy@dongjoon-hyun