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
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ class ParquetFilters(
Binary.fromConstantByteArray(fixedLengthBytes, 0, numBytes)
}

private def timestampToMillis(v: Any): JLong = {
val timestamp = v.asInstanceOf[Timestamp]
val micros = DateTimeUtils.fromJavaTimestamp(timestamp)
val millis = DateTimeUtils.toMillis(micros)
Copy link
Member Author

Choose a reason for hiding this comment

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

This line causes the problem.

millis.asInstanceOf[JLong]
}

private val makeEq:
PartialFunction[ParquetSchemaType, (Array[String], Any) => FilterPredicate] = {
case ParquetBooleanType =>
Expand Down Expand Up @@ -184,7 +191,7 @@ class ParquetFilters(
case ParquetTimestampMillisType if pushDownTimestamp =>
(n: Array[String], v: Any) => FilterApi.eq(
longColumn(n),
Option(v).map(_.asInstanceOf[Timestamp].getTime.asInstanceOf[JLong]).orNull)
Option(v).map(timestampToMillis).orNull)

case ParquetSchemaType(DECIMAL, INT32, _, _) if pushDownDecimal =>
(n: Array[String], v: Any) => FilterApi.eq(
Expand Down Expand Up @@ -235,7 +242,7 @@ class ParquetFilters(
case ParquetTimestampMillisType if pushDownTimestamp =>
(n: Array[String], v: Any) => FilterApi.notEq(
longColumn(n),
Option(v).map(_.asInstanceOf[Timestamp].getTime.asInstanceOf[JLong]).orNull)
Option(v).map(timestampToMillis).orNull)

case ParquetSchemaType(DECIMAL, INT32, _, _) if pushDownDecimal =>
(n: Array[String], v: Any) => FilterApi.notEq(
Expand Down Expand Up @@ -277,9 +284,7 @@ class ParquetFilters(
longColumn(n),
DateTimeUtils.fromJavaTimestamp(v.asInstanceOf[Timestamp]).asInstanceOf[JLong])
case ParquetTimestampMillisType if pushDownTimestamp =>
(n: Array[String], v: Any) => FilterApi.lt(
longColumn(n),
v.asInstanceOf[Timestamp].getTime.asInstanceOf[JLong])
(n: Array[String], v: Any) => FilterApi.lt(longColumn(n), timestampToMillis(v))

case ParquetSchemaType(DECIMAL, INT32, _, _) if pushDownDecimal =>
(n: Array[String], v: Any) =>
Expand Down Expand Up @@ -318,9 +323,7 @@ class ParquetFilters(
longColumn(n),
DateTimeUtils.fromJavaTimestamp(v.asInstanceOf[Timestamp]).asInstanceOf[JLong])
case ParquetTimestampMillisType if pushDownTimestamp =>
(n: Array[String], v: Any) => FilterApi.ltEq(
longColumn(n),
v.asInstanceOf[Timestamp].getTime.asInstanceOf[JLong])
(n: Array[String], v: Any) => FilterApi.ltEq(longColumn(n), timestampToMillis(v))

case ParquetSchemaType(DECIMAL, INT32, _, _) if pushDownDecimal =>
(n: Array[String], v: Any) =>
Expand Down Expand Up @@ -359,9 +362,7 @@ class ParquetFilters(
longColumn(n),
DateTimeUtils.fromJavaTimestamp(v.asInstanceOf[Timestamp]).asInstanceOf[JLong])
case ParquetTimestampMillisType if pushDownTimestamp =>
(n: Array[String], v: Any) => FilterApi.gt(
longColumn(n),
v.asInstanceOf[Timestamp].getTime.asInstanceOf[JLong])
(n: Array[String], v: Any) => FilterApi.gt(longColumn(n), timestampToMillis(v))

case ParquetSchemaType(DECIMAL, INT32, _, _) if pushDownDecimal =>
(n: Array[String], v: Any) =>
Expand Down Expand Up @@ -400,9 +401,7 @@ class ParquetFilters(
longColumn(n),
DateTimeUtils.fromJavaTimestamp(v.asInstanceOf[Timestamp]).asInstanceOf[JLong])
case ParquetTimestampMillisType if pushDownTimestamp =>
(n: Array[String], v: Any) => FilterApi.gtEq(
longColumn(n),
v.asInstanceOf[Timestamp].getTime.asInstanceOf[JLong])
(n: Array[String], v: Any) => FilterApi.gtEq(longColumn(n), timestampToMillis(v))

case ParquetSchemaType(DECIMAL, INT32, _, _) if pushDownDecimal =>
(n: Array[String], v: Any) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,21 @@ abstract class ParquetFilterSuite extends QueryTest with ParquetTest with Shared

test("filter pushdown - timestamp") {
// spark.sql.parquet.outputTimestampType = TIMESTAMP_MILLIS
val millisData = Seq(Timestamp.valueOf("2018-06-14 08:28:53.123"),
Timestamp.valueOf("2018-06-15 08:28:53.123"),
Timestamp.valueOf("2018-06-16 08:28:53.123"),
Timestamp.valueOf("2018-06-17 08:28:53.123"))
val millisData = Seq(
Timestamp.valueOf("1000-06-14 08:28:53.123"),
Timestamp.valueOf("1582-06-15 08:28:53.001"),
Timestamp.valueOf("1900-06-16 08:28:53.0"),
Timestamp.valueOf("2018-06-17 08:28:53.999"))
withSQLConf(SQLConf.PARQUET_OUTPUT_TIMESTAMP_TYPE.key ->
ParquetOutputTimestampType.TIMESTAMP_MILLIS.toString) {
testTimestampPushdown(millisData)
}

// spark.sql.parquet.outputTimestampType = TIMESTAMP_MICROS
val microsData = Seq(Timestamp.valueOf("2018-06-14 08:28:53.123456"),
Timestamp.valueOf("2018-06-15 08:28:53.123456"),
Timestamp.valueOf("2018-06-16 08:28:53.123456"),
val microsData = Seq(
Timestamp.valueOf("1000-06-14 08:28:53.123456"),
Timestamp.valueOf("1582-06-15 08:28:53.123456"),
Timestamp.valueOf("1900-06-16 08:28:53.123456"),
Timestamp.valueOf("2018-06-17 08:28:53.123456"))
withSQLConf(SQLConf.PARQUET_OUTPUT_TIMESTAMP_TYPE.key ->
ParquetOutputTimestampType.TIMESTAMP_MICROS.toString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ private[sql] trait ParquetTest extends FileBasedDataSourceTest {
protected def withParquetDataFrame(df: DataFrame, testVectorized: Boolean = true)
(f: DataFrame => Unit): Unit = {
withTempPath { file =>
df.write.format(dataSourceName).save(file.getCanonicalPath)
withSQLConf(SQLConf.LEGACY_PARQUET_REBASE_MODE_IN_WRITE.key -> "CORRECTED") {
df.write.format(dataSourceName).save(file.getCanonicalPath)
}
readFile(file.getCanonicalPath, testVectorized)(f)
}
}
Expand Down