Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,16 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder(conf) {
compressed = false,
properties = rowStorage.properties ++ fileStorage.properties)

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

@maropu maropu Aug 11, 2019

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
Contributor Author

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.


private def extractFileFormat(serde: Option[String]): String = {
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)
}
}
3 changes: 1 addition & 2 deletions sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,13 @@ class InsertSuite extends DataSourceTest with SharedSQLContext {
}
}

test("Insert overwrite directory using Hive serde without turning on Hive support") {
test("Insert overwrite directory in hive table without turning on Hive support") {
withTempDir { dir =>
val path = dir.toURI.getPath
val e = intercept[AnalysisException] {
sql(
s"""
|INSERT OVERWRITE LOCAL DIRECTORY '$path'
|STORED AS orc
Copy link
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
Contributor Author

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
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
Contributor Author

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.

|SELECT 1, 2
""".stripMargin)
}.getMessage
Expand Down
21 changes: 21 additions & 0 deletions sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2516,4 +2516,25 @@ class HiveDDLSuite
}
}
}

test("SPARK-28659: hive insert overwrite directory should use data source " +
"if it is convertible") {
Seq("orc", "parquet").foreach { format =>
withTable("t1") {
sql(s"CREATE TABLE t1 (id int)")
sql(s"INSERT INTO t1 SELECT * FROM range(1, 100, 1, 10)")
withTempDir { dir =>
val pathUri = dir.toURI
sql(
s"""
|INSERT OVERWRITE DIRECTORY '${pathUri}'
|STORED AS $format
|SELECT * FROM t1
""".stripMargin)
val snappyFile = dir.listFiles().find(_.getName.startsWith("part"))
assertCompression(snappyFile, format, "SNAPPY")
}
}
}
}
}