Skip to content

Commit

Permalink
Adds tests to verify dynamic partitioning folder layout
Browse files Browse the repository at this point in the history
  • Loading branch information
liancheng committed Sep 22, 2014
1 parent b20a3dc commit e69ce88
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package org.apache.spark.sql.hive.execution

import scala.util.Try

import org.apache.hadoop.hive.conf.HiveConf.ConfVars

import org.apache.spark.SparkException
import org.apache.spark.sql.hive._
import org.apache.spark.sql.hive.test.TestHive
Expand Down Expand Up @@ -545,6 +547,45 @@ class HiveQuerySuite extends HiveComparisonTest {
|DROP TABLE IF EXISTS dynamic_part_table;
""".stripMargin)

test("Dynamic partition folder layout") {
sql("DROP TABLE IF EXISTS dynamic_part_table")
sql("CREATE TABLE dynamic_part_table(intcol INT) PARTITIONED BY (partcol1 INT, partcol2 INT)")
sql("SET hive.exec.dynamic.partition.mode=nonstrict")

val data = Map(
Seq("1", "1") -> 1,
Seq("1", "NULL") -> 2,
Seq("NULL", "1") -> 3,
Seq("NULL", "NULL") -> 4)

data.foreach { case (parts, value) =>
sql(
s"""INSERT INTO TABLE dynamic_part_table PARTITION(partcol1, partcol2)
|SELECT $value, ${parts.mkString(", ")} FROM src WHERE key=150
""".stripMargin)

val partFolder = Seq("partcol1", "partcol2")
.zip(parts)
.map { case (k, v) =>
if (v == "NULL") {
s"$k=${ConfVars.DEFAULTPARTITIONNAME.defaultVal}"
} else {
s"$k=$v"
}
}
.mkString("/")

// Loads partition data to a temporary table to verify contents
val path = s"$warehousePath/dynamic_part_table/$partFolder/part-00000"

sql("DROP TABLE IF EXISTS dp_verify")
sql("CREATE TABLE dp_verify(intcol INT)")
sql(s"LOAD DATA LOCAL INPATH '$path' INTO TABLE dp_verify")

assert(sql("SELECT * FROM dp_verify").collect() === Array(Row(value)))
}
}

test("Partition spec validation") {
sql("DROP TABLE IF EXISTS dp_test")
sql("CREATE TABLE dp_test(key INT, value STRING) PARTITIONED BY (dp INT, sp INT)")
Expand Down

0 comments on commit e69ce88

Please sign in to comment.