Skip to content

Commit

Permalink
fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
gatorsmile committed Jun 22, 2017
1 parent 86ac975 commit 00a63b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ object FileFormatWriter extends Logging {
}
}
val partitionSet = AttributeSet(partitionColumns)
val dataColumns = queryExecution.executedPlan.output.filterNot(partitionSet.contains)
val dataColumns = allColumns.filterNot(partitionSet.contains)

val bucketIdExpression = bucketSpec.map { spec =>
val bucketColumns = spec.bucketColumnNames.map(c => dataColumns.find(_.name == c).get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,24 +470,22 @@ class InsertIntoHiveTableSuite extends QueryTest with TestHiveSingleton with Bef

test("SPARK-21165: the query schema of INSERT is changed after optimization") {
withSQLConf(("hive.exec.dynamic.partition.mode", "nonstrict")) {
withTempView("tempView") {
withTable("dest", "view1") {
Seq(("a", "b", 3)).toDF("word", "first", "length").write.saveAsTable("view1")

spark.sql(
"""
|CREATE TABLE dest (word string, length int)
|PARTITIONED BY (first string)
""".stripMargin)
withTable("tab1", "tab2") {
Seq(("a", "b", 3)).toDF("word", "first", "length").write.saveAsTable("tab1")

spark.sql(
"""
|INSERT INTO TABLE dest PARTITION(first)
|SELECT word, length, cast(first as string) as first FROM view1
""".stripMargin)
spark.sql(
"""
|CREATE TABLE tab2 (word string, length int)
|PARTITIONED BY (first string)
""".stripMargin)

checkAnswer(spark.table("dest"), Row("a", 3, "b"))
}
spark.sql(
"""
|INSERT INTO TABLE tab2 PARTITION(first)
|SELECT word, length, cast(first as string) as first FROM tab1
""".stripMargin)

checkAnswer(spark.table("tab2"), Row("a", 3, "b"))
}
}
}
Expand Down

0 comments on commit 00a63b2

Please sign in to comment.