Skip to content

Commit bef83fc

Browse files
committed
Partitioning by dates/timestamps works with Parquet vectorized reader
1 parent adaaffa commit bef83fc

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/ColumnVectorUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ public static void populate(ColumnVector col, InternalRow row, int fieldIdx) {
8686
col.getChildColumn(0).putInts(0, capacity, c.months);
8787
col.getChildColumn(1).putLongs(0, capacity, c.microseconds);
8888
} else if (t instanceof DateType) {
89-
Date date = (Date)row.get(fieldIdx, t);
90-
col.putInts(0, capacity, DateTimeUtils.fromJavaDate(date));
89+
col.putInts(0, capacity, row.getInt(fieldIdx));
90+
} else if (t instanceof TimestampType) {
91+
col.putLongs(0, capacity, row.getLong(fieldIdx));
9192
}
9293
}
9394
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,27 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
17871787
}
17881788
}
17891789

1790+
test("SPARK-17354: Partitioning by dates/timestamps works with Parquet vectorized reader") {
1791+
withSQLConf(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "true") {
1792+
sql(
1793+
"""CREATE TABLE order(id INT)
1794+
|PARTITIONED BY (pd DATE, pt TIMESTAMP)
1795+
|STORED AS PARQUET
1796+
""".stripMargin)
1797+
1798+
sql("set hive.exec.dynamic.partition.mode=nonstrict")
1799+
sql(
1800+
"""INSERT INTO TABLE order PARTITION(pd, pt)
1801+
|SELECT 1 AS id, CAST('1990-02-24' AS DATE) AS pd, CAST('1990-02-24' AS TIMESTAMP) AS pt
1802+
""".stripMargin)
1803+
val actual = sql("SELECT * FROM order")
1804+
val expected = sql(
1805+
"SELECT 1 AS id, CAST('1990-02-24' AS DATE) AS pd, CAST('1990-02-24' AS TIMESTAMP) AS pt")
1806+
checkAnswer(actual, expected)
1807+
sql("DROP TABLE order")
1808+
}
1809+
}
1810+
17901811
def testCommandAvailable(command: String): Boolean = {
17911812
val attempt = Try(Process(command).run(ProcessLogger(_ => ())).exitValue())
17921813
attempt.isSuccess && attempt.get == 0

0 commit comments

Comments
 (0)