Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.hive.execution

import org.apache.spark.sql.Row
import org.apache.spark.sql.hive.MetastoreRelation
import org.apache.spark.sql.hive.test.{TestHive, TestHiveSingleton}
import org.apache.spark.sql.hive.test.TestHive._
import org.apache.spark.sql.hive.test.TestHive.implicits._
Expand Down Expand Up @@ -143,4 +144,38 @@ class HiveTableScanSuite extends HiveComparisonTest with SQLTestUtils with TestH
}
}
}

test("SPARK-16926: number of table and partition columns match for new partitioned table") {
val view = "src"
withTempView(view) {
spark.range(1, 5).createOrReplaceTempView(view)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we should alway use createTempView in test, to make sure the view we created is what we want, rather than some existing view.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that createOrReplaceTempView should ensure the same thing because any existing view would be replaced. I'm I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh sorry I read the code wrong...

val table = "table_with_partition"
withTable(table) {
sql(
s"""
|CREATE TABLE $table(id string)
|PARTITIONED BY (p1 string,p2 string,p3 string,p4 string,p5 string)
""".stripMargin)
sql(
s"""
|FROM $view v
|INSERT INTO TABLE $table
|PARTITION (p1='a',p2='b',p3='c',p4='d',p5='e')
|SELECT v.id
|INSERT INTO TABLE $table
|PARTITION (p1='a',p2='c',p3='c',p4='d',p5='e')
|SELECT v.id
""".stripMargin)
val plan = sql(
s"""
|SELECT * FROM $table
""".stripMargin).queryExecution.sparkPlan
val relation = plan.collectFirst {
case p: HiveTableScanExec => p.relation
}.get
val tableCols = relation.hiveQlTable.getCols
relation.getHiveQlPartitions().foreach(p => assert(p.getCols.size == tableCols.size))
}
}
}
}