You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "stevomitric (via GitHub)" <gi...@apache.org> on 2026/07/22 11:33:34 UTC
[PR] [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps [spark]
stevomitric opened a new pull request, #57430:
URL: https://github.com/apache/spark/pull/57430
### What changes were proposed in this pull request?
Add `TIMESTAMP(NANOS)` arms to `ParquetFilters` so equality/range/in predicates on nanosecond-precision timestamp columns (`TIMESTAMP_NTZ(p)`/`TIMESTAMP_LTZ(p)`, p in [7, 9]) are pushed down as Parquet row-group filters. LTZ (`java.time.Instant`) and NTZ (`java.time.LocalDateTime`) get separate schema-type constants and value converters;
values are encoded to signed INT64 epoch-nanoseconds using the same encoding `TimestampNanosParquetOps` writes (not truncated to micros). `valueCanMakeFilterOn` gates on int64-representability, so an out-of-range value falls back to a full scan instead of throwing or mis-skipping row groups. Part of SPARK-56822.
### Why are the changes needed?
There was no nanos arm in `ParquetFilters`, so predicates on nanosecond timestamp columns were silently never pushed down and every row group was scanned.
### Does this PR introduce _any_ user-facing change?
Yes. Filters on nanosecond timestamp columns are now pushed to Parquet and prune row groups (preview `spark.sql.timestampNanosTypes.enabled`); results are unchanged.
### How was this patch tested?
`ParquetFilterSuite` (new nanos NTZ/LTZ pushdown cases) and `ParquetTimestampNanosSuite`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps [spark]
Posted by "stevomitric (via GitHub)" <gi...@apache.org>.
stevomitric commented on PR #57430:
URL: https://github.com/apache/spark/pull/57430#issuecomment-5063700237
cc @uros-b PTAL when you get a chance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps [spark]
Posted by "stevomitric (via GitHub)" <gi...@apache.org>.
stevomitric commented on code in PR #57430:
URL: https://github.com/apache/spark/pull/57430#discussion_r3673795518
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/types/ops/TimestampNanosParquetOpsSuite.scala:
##########
@@ -136,6 +140,108 @@ class TimestampNanosParquetOpsSuite extends SparkFunSuite {
}
}
+ // ---------- filter-pushdown ops ----------
+
+ test("filterOps accepts the matching Java time value and rejects others") {
+ // LTZ pushes down java.time.Instant; NTZ pushes down java.time.LocalDateTime. Each rejects
+ // the other type (and non-temporal values) so a mismatched literal falls through to no
+ // pushdown rather than a ClassCastException in the converter.
+ val ltzOps = TimestampNanosParquetOps.ltzFilterOps
+ val ntzOps = TimestampNanosParquetOps.ntzFilterOps
+ assert(ltzOps.acceptsValue(Instant.parse("2020-01-01T00:00:00Z")))
+ assert(!ltzOps.acceptsValue(LocalDateTime.parse("2020-01-01T00:00:00")))
+ assert(!ltzOps.acceptsValue(java.lang.Long.valueOf(1L)))
+ assert(ntzOps.acceptsValue(LocalDateTime.parse("2020-01-01T00:00:00")))
+ assert(!ntzOps.acceptsValue(Instant.parse("2020-01-01T00:00:00Z")))
+ assert(!ntzOps.acceptsValue("2020-01-01"))
+ }
+
+ test("filterOps rejects values outside the INT64 epoch-nanos range (falls back to full scan)") {
+ // Year 2300 is past the ~2262 int64 epoch-nanos cutoff: encoding would overflow, so
+ // acceptsValue must reject it (SPARK-46092-style guard) instead of throwing during filter
+ // creation. An in-range value is accepted.
+ val ltzOps = TimestampNanosParquetOps.ltzFilterOps
+ val ntzOps = TimestampNanosParquetOps.ntzFilterOps
+ assert(!ltzOps.acceptsValue(Instant.parse("2300-01-01T00:00:00Z")))
+ assert(!ntzOps.acceptsValue(LocalDateTime.parse("2300-01-01T00:00:00")))
+ assert(ltzOps.acceptsValue(Instant.parse("2020-01-01T00:00:00Z")))
+ assert(ntzOps.acceptsValue(LocalDateTime.parse("2020-01-01T00:00:00")))
+ }
+
+ test("filterOps declares the canonical nanos-timestamp Parquet encoding") {
+ // LTZ is isAdjustedToUTC=true, NTZ is false; both INT64 TIMESTAMP(NANOS). These are the keys
+ // the ParquetFilters reverse lookup matches against the file schema.
+ val ltzOps = TimestampNanosParquetOps.ltzFilterOps
+ val ntzOps = TimestampNanosParquetOps.ntzFilterOps
+ assert(ltzOps.primitiveTypeName === INT64)
+ assert(ltzOps.logicalTypeAnnotation ===
+ LogicalTypeAnnotation.timestampType(true, TimeUnit.NANOS))
+ assert(ntzOps.primitiveTypeName === INT64)
+ assert(ntzOps.logicalTypeAnnotation ===
+ LogicalTypeAnnotation.timestampType(false, TimeUnit.NANOS))
+ }
+
+ test("filterOps builds predicates converting to signed INT64 epoch-nanoseconds") {
+ val path = Array("c")
+ val col = longColumn(path)
+
+ // LTZ: Instant -> epoch-nanos. Sub-microsecond digits are preserved (not truncated to micros).
+ val ltzOps = TimestampNanosParquetOps.ltzFilterOps
+ val instant = Instant.parse("2020-01-01T12:34:56.000000789Z")
+ val ltzNanos = java.lang.Long.valueOf(
+ instant.getEpochSecond * DateTimeConstants.NANOS_PER_SECOND + instant.getNano)
+ assert(ltzOps.makeEq(path, instant) === FilterApi.eq(col, ltzNanos))
+ assert(ltzOps.makeNotEq(path, instant) === FilterApi.notEq(col, ltzNanos))
+ assert(ltzOps.makeLt(path, instant) === FilterApi.lt(col, ltzNanos))
+ assert(ltzOps.makeLtEq(path, instant) === FilterApi.ltEq(col, ltzNanos))
+ assert(ltzOps.makeGt(path, instant) === FilterApi.gt(col, ltzNanos))
+ assert(ltzOps.makeGtEq(path, instant) === FilterApi.gtEq(col, ltzNanos))
+
+ // NTZ: LocalDateTime (interpreted at UTC) -> epoch-nanos.
+ val ntzOps = TimestampNanosParquetOps.ntzFilterOps
+ val ldt = LocalDateTime.parse("2020-01-01T12:34:56.000000789")
+ val ntzInstant = ldt.toInstant(ZoneOffset.UTC)
+ val ntzNanos = java.lang.Long.valueOf(
+ ntzInstant.getEpochSecond * DateTimeConstants.NANOS_PER_SECOND + ntzInstant.getNano)
+ assert(ntzOps.makeEq(path, ldt) === FilterApi.eq(col, ntzNanos))
+ assert(ntzOps.makeIn(path, Array[Any](ldt)) === {
+ val set = new java.util.HashSet[java.lang.Long]()
+ set.add(ntzNanos)
+ FilterApi.in(col, set)
+ })
+ }
+
+ test("filterOps eq/notEq/in tolerate a null value (IsNull / IsNotNull)") {
+ val path = Array("c")
+ val col = longColumn(path)
+ val nullLong = null.asInstanceOf[java.lang.Long]
+ // null value -> null Long comparand; used by ParquetFilters for IsNull / IsNotNull.
+ Seq(TimestampNanosParquetOps.ltzFilterOps, TimestampNanosParquetOps.ntzFilterOps).foreach {
+ ops =>
+ assert(ops.makeEq(path, null) === FilterApi.eq(col, nullLong))
+ assert(ops.makeNotEq(path, null) === FilterApi.notEq(col, nullLong))
+ val set = new java.util.HashSet[java.lang.Long]()
+ set.add(null)
+ assert(ops.makeIn(path, Array[Any](null)) === FilterApi.in(col, set))
+ }
+ }
+
+ test("ParquetTypeOps.filterOpsFor resolves each nanos encoding and nothing else") {
+ // The LTZ and NTZ encodings differ only in isAdjustedToUTC; each resolves to its own ops.
+ assert(ParquetTypeOps.filterOpsFor(
+ LogicalTypeAnnotation.timestampType(true, TimeUnit.NANOS), INT64)
+ .contains(TimestampNanosParquetOps.ltzFilterOps))
+ assert(ParquetTypeOps.filterOpsFor(
+ LogicalTypeAnnotation.timestampType(false, TimeUnit.NANOS), INT64)
+ .contains(TimestampNanosParquetOps.ntzFilterOps))
+ // MICROS unit, or an INT32 primitive, is not a nanos-timestamp encoding (pushdown falls
+ // through to no framework ops).
+ assert(ParquetTypeOps.filterOpsFor(
+ LogicalTypeAnnotation.timestampType(true, TimeUnit.MICROS), INT64).isEmpty)
+ assert(ParquetTypeOps.filterOpsFor(
+ LogicalTypeAnnotation.timestampType(false, TimeUnit.NANOS), INT32).isEmpty)
+ }
+
Review Comment:
expanded coverage.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps [spark]
Posted by "stevomitric (via GitHub)" <gi...@apache.org>.
stevomitric commented on code in PR #57430:
URL: https://github.com/apache/spark/pull/57430#discussion_r3673794197
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/types/ops/TimestampNanosParquetOps.scala:
##########
@@ -185,6 +188,62 @@ private[ops] object TimestampNanosParquetOps {
case ts: TimestampLogicalTypeAnnotation => ts.getUnit == TimeUnit.NANOS
case _ => false
})
+
+ // Repacks an externalized nanos filter value into the signed INT64 epoch-nanoseconds the write
+ // path produces. Conversion is at precision 9 (a lossless repack): the literal has already been
+ // floored to the column precision upstream, so no sub-microsecond digits are dropped here. The
+ // single-arg `timestampNanosToEpochNanos` throws `ArithmeticException` outside the int64 range;
+ // callers reach it only after `acceptsValue` has cleared the value (see [[epochNanosInRange]]).
+ private def instantToEpochNanos(v: Instant): JLong =
+ DateTimeUtils.timestampNanosToEpochNanos(
+ DateTimeUtils.instantToTimestampNanos(v, TimestampLTZNanosType.NANOS_PRECISION))
+
+ private def localDateTimeToEpochNanos(v: LocalDateTime): JLong =
+ DateTimeUtils.timestampNanosToEpochNanos(
+ DateTimeUtils.localDateTimeToTimestampNanos(v, TimestampNTZNanosType.NANOS_PRECISION))
+
+ // SPARK-46092-style guard: only push down when the value is representable as int64
+ // epoch-nanoseconds. An out-of-range value would throw in the encoder, and -- worse -- a
+ // wrapped/truncated encoding could silently mis-skip row groups; rejecting it falls back to a
+ // full scan, which is always correct.
+ private def epochNanosInRange(encode: => JLong): Boolean =
+ try { encode; true } catch { case _: ArithmeticException => false }
+
+ /**
+ * Parquet filter-pushdown ops for the nanosecond timestamp types, registered in
+ * [[ParquetTypeOps.filterOpsList]]. Filter dispatch is keyed on the file's on-disk encoding, so
+ * each type gets its own ops: both are stored as INT64 TIMESTAMP(NANOS) and differ only in the
+ * `isAdjustedToUTC` flag (LTZ = true, NTZ = false), which also fixes the externalized filter
+ * value (`java.time.Instant` for LTZ, `java.time.LocalDateTime` for NTZ). Values are encoded to
+ * the same signed INT64 epoch-nanoseconds `TimestampNanosParquetOps` writes, never truncated to
+ * micros. This replaces the inline nanos arms once carried in `ParquetFilters`, matching how
+ * TimeType routes its pushdown through [[TimeTypeParquetOps.filterOps]].
+ */
+ private[ops] val ltzFilterOps: ParquetFilterOps = new LongParquetFilterOps {
+ override val logicalTypeAnnotation: LogicalTypeAnnotation =
+ LogicalTypeAnnotation.timestampType(true, TimeUnit.NANOS)
+
+ override def acceptsValue(value: Any): Boolean = value match {
+ case i: Instant => epochNanosInRange(instantToEpochNanos(i))
+ case _ => false
+ }
+
+ override protected def toLong(value: Any): JLong =
+ instantToEpochNanos(value.asInstanceOf[Instant])
+ }
+
Review Comment:
yea you are right, error would propagate. i added a more strict check `alues.forall(canMakeFilterOn(name, _)).`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps [spark]
Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b closed pull request #57430: [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps
URL: https://github.com/apache/spark/pull/57430
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps [spark]
Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on code in PR #57430:
URL: https://github.com/apache/spark/pull/57430#discussion_r3645250894
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/types/ops/TimestampNanosParquetOpsSuite.scala:
##########
@@ -136,6 +140,108 @@ class TimestampNanosParquetOpsSuite extends SparkFunSuite {
}
}
+ // ---------- filter-pushdown ops ----------
+
+ test("filterOps accepts the matching Java time value and rejects others") {
+ // LTZ pushes down java.time.Instant; NTZ pushes down java.time.LocalDateTime. Each rejects
+ // the other type (and non-temporal values) so a mismatched literal falls through to no
+ // pushdown rather than a ClassCastException in the converter.
+ val ltzOps = TimestampNanosParquetOps.ltzFilterOps
+ val ntzOps = TimestampNanosParquetOps.ntzFilterOps
+ assert(ltzOps.acceptsValue(Instant.parse("2020-01-01T00:00:00Z")))
+ assert(!ltzOps.acceptsValue(LocalDateTime.parse("2020-01-01T00:00:00")))
+ assert(!ltzOps.acceptsValue(java.lang.Long.valueOf(1L)))
+ assert(ntzOps.acceptsValue(LocalDateTime.parse("2020-01-01T00:00:00")))
+ assert(!ntzOps.acceptsValue(Instant.parse("2020-01-01T00:00:00Z")))
+ assert(!ntzOps.acceptsValue("2020-01-01"))
+ }
+
+ test("filterOps rejects values outside the INT64 epoch-nanos range (falls back to full scan)") {
+ // Year 2300 is past the ~2262 int64 epoch-nanos cutoff: encoding would overflow, so
+ // acceptsValue must reject it (SPARK-46092-style guard) instead of throwing during filter
+ // creation. An in-range value is accepted.
+ val ltzOps = TimestampNanosParquetOps.ltzFilterOps
+ val ntzOps = TimestampNanosParquetOps.ntzFilterOps
+ assert(!ltzOps.acceptsValue(Instant.parse("2300-01-01T00:00:00Z")))
+ assert(!ntzOps.acceptsValue(LocalDateTime.parse("2300-01-01T00:00:00")))
+ assert(ltzOps.acceptsValue(Instant.parse("2020-01-01T00:00:00Z")))
+ assert(ntzOps.acceptsValue(LocalDateTime.parse("2020-01-01T00:00:00")))
+ }
+
+ test("filterOps declares the canonical nanos-timestamp Parquet encoding") {
+ // LTZ is isAdjustedToUTC=true, NTZ is false; both INT64 TIMESTAMP(NANOS). These are the keys
+ // the ParquetFilters reverse lookup matches against the file schema.
+ val ltzOps = TimestampNanosParquetOps.ltzFilterOps
+ val ntzOps = TimestampNanosParquetOps.ntzFilterOps
+ assert(ltzOps.primitiveTypeName === INT64)
+ assert(ltzOps.logicalTypeAnnotation ===
+ LogicalTypeAnnotation.timestampType(true, TimeUnit.NANOS))
+ assert(ntzOps.primitiveTypeName === INT64)
+ assert(ntzOps.logicalTypeAnnotation ===
+ LogicalTypeAnnotation.timestampType(false, TimeUnit.NANOS))
+ }
+
+ test("filterOps builds predicates converting to signed INT64 epoch-nanoseconds") {
+ val path = Array("c")
+ val col = longColumn(path)
+
+ // LTZ: Instant -> epoch-nanos. Sub-microsecond digits are preserved (not truncated to micros).
+ val ltzOps = TimestampNanosParquetOps.ltzFilterOps
+ val instant = Instant.parse("2020-01-01T12:34:56.000000789Z")
+ val ltzNanos = java.lang.Long.valueOf(
+ instant.getEpochSecond * DateTimeConstants.NANOS_PER_SECOND + instant.getNano)
+ assert(ltzOps.makeEq(path, instant) === FilterApi.eq(col, ltzNanos))
+ assert(ltzOps.makeNotEq(path, instant) === FilterApi.notEq(col, ltzNanos))
+ assert(ltzOps.makeLt(path, instant) === FilterApi.lt(col, ltzNanos))
+ assert(ltzOps.makeLtEq(path, instant) === FilterApi.ltEq(col, ltzNanos))
+ assert(ltzOps.makeGt(path, instant) === FilterApi.gt(col, ltzNanos))
+ assert(ltzOps.makeGtEq(path, instant) === FilterApi.gtEq(col, ltzNanos))
+
+ // NTZ: LocalDateTime (interpreted at UTC) -> epoch-nanos.
+ val ntzOps = TimestampNanosParquetOps.ntzFilterOps
+ val ldt = LocalDateTime.parse("2020-01-01T12:34:56.000000789")
+ val ntzInstant = ldt.toInstant(ZoneOffset.UTC)
+ val ntzNanos = java.lang.Long.valueOf(
+ ntzInstant.getEpochSecond * DateTimeConstants.NANOS_PER_SECOND + ntzInstant.getNano)
+ assert(ntzOps.makeEq(path, ldt) === FilterApi.eq(col, ntzNanos))
+ assert(ntzOps.makeIn(path, Array[Any](ldt)) === {
+ val set = new java.util.HashSet[java.lang.Long]()
+ set.add(ntzNanos)
+ FilterApi.in(col, set)
+ })
+ }
+
+ test("filterOps eq/notEq/in tolerate a null value (IsNull / IsNotNull)") {
+ val path = Array("c")
+ val col = longColumn(path)
+ val nullLong = null.asInstanceOf[java.lang.Long]
+ // null value -> null Long comparand; used by ParquetFilters for IsNull / IsNotNull.
+ Seq(TimestampNanosParquetOps.ltzFilterOps, TimestampNanosParquetOps.ntzFilterOps).foreach {
+ ops =>
+ assert(ops.makeEq(path, null) === FilterApi.eq(col, nullLong))
+ assert(ops.makeNotEq(path, null) === FilterApi.notEq(col, nullLong))
+ val set = new java.util.HashSet[java.lang.Long]()
+ set.add(null)
+ assert(ops.makeIn(path, Array[Any](null)) === FilterApi.in(col, set))
+ }
+ }
+
+ test("ParquetTypeOps.filterOpsFor resolves each nanos encoding and nothing else") {
+ // The LTZ and NTZ encodings differ only in isAdjustedToUTC; each resolves to its own ops.
+ assert(ParquetTypeOps.filterOpsFor(
+ LogicalTypeAnnotation.timestampType(true, TimeUnit.NANOS), INT64)
+ .contains(TimestampNanosParquetOps.ltzFilterOps))
+ assert(ParquetTypeOps.filterOpsFor(
+ LogicalTypeAnnotation.timestampType(false, TimeUnit.NANOS), INT64)
+ .contains(TimestampNanosParquetOps.ntzFilterOps))
+ // MICROS unit, or an INT32 primitive, is not a nanos-timestamp encoding (pushdown falls
+ // through to no framework ops).
+ assert(ParquetTypeOps.filterOpsFor(
+ LogicalTypeAnnotation.timestampType(true, TimeUnit.MICROS), INT64).isEmpty)
+ assert(ParquetTypeOps.filterOpsFor(
+ LogicalTypeAnnotation.timestampType(false, TimeUnit.NANOS), INT32).isEmpty)
+ }
+
Review Comment:
In TimestampNanosParquetOpsSuite / ParquetFilterSuite, please add test-coverage for the above issue (https://github.com/apache/spark/pull/57430/changes#r3645247046). The overflow tests only cover single-element or all-out-of-range In (Array[Any](ntzOverflow)), where the head guard already rejects; no test exercises the in-range-head + out-of-range-tail IN list that crashes. This gap gates confidence in the new code path and should be closed alongside the fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps [spark]
Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on code in PR #57430:
URL: https://github.com/apache/spark/pull/57430#discussion_r3645247046
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/types/ops/TimestampNanosParquetOps.scala:
##########
@@ -185,6 +188,62 @@ private[ops] object TimestampNanosParquetOps {
case ts: TimestampLogicalTypeAnnotation => ts.getUnit == TimeUnit.NANOS
case _ => false
})
+
+ // Repacks an externalized nanos filter value into the signed INT64 epoch-nanoseconds the write
+ // path produces. Conversion is at precision 9 (a lossless repack): the literal has already been
+ // floored to the column precision upstream, so no sub-microsecond digits are dropped here. The
+ // single-arg `timestampNanosToEpochNanos` throws `ArithmeticException` outside the int64 range;
+ // callers reach it only after `acceptsValue` has cleared the value (see [[epochNanosInRange]]).
+ private def instantToEpochNanos(v: Instant): JLong =
+ DateTimeUtils.timestampNanosToEpochNanos(
+ DateTimeUtils.instantToTimestampNanos(v, TimestampLTZNanosType.NANOS_PRECISION))
+
+ private def localDateTimeToEpochNanos(v: LocalDateTime): JLong =
+ DateTimeUtils.timestampNanosToEpochNanos(
+ DateTimeUtils.localDateTimeToTimestampNanos(v, TimestampNTZNanosType.NANOS_PRECISION))
+
+ // SPARK-46092-style guard: only push down when the value is representable as int64
+ // epoch-nanoseconds. An out-of-range value would throw in the encoder, and -- worse -- a
+ // wrapped/truncated encoding could silently mis-skip row groups; rejecting it falls back to a
+ // full scan, which is always correct.
+ private def epochNanosInRange(encode: => JLong): Boolean =
+ try { encode; true } catch { case _: ArithmeticException => false }
+
+ /**
+ * Parquet filter-pushdown ops for the nanosecond timestamp types, registered in
+ * [[ParquetTypeOps.filterOpsList]]. Filter dispatch is keyed on the file's on-disk encoding, so
+ * each type gets its own ops: both are stored as INT64 TIMESTAMP(NANOS) and differ only in the
+ * `isAdjustedToUTC` flag (LTZ = true, NTZ = false), which also fixes the externalized filter
+ * value (`java.time.Instant` for LTZ, `java.time.LocalDateTime` for NTZ). Values are encoded to
+ * the same signed INT64 epoch-nanoseconds `TimestampNanosParquetOps` writes, never truncated to
+ * micros. This replaces the inline nanos arms once carried in `ParquetFilters`, matching how
+ * TimeType routes its pushdown through [[TimeTypeParquetOps.filterOps]].
+ */
+ private[ops] val ltzFilterOps: ParquetFilterOps = new LongParquetFilterOps {
+ override val logicalTypeAnnotation: LogicalTypeAnnotation =
+ LogicalTypeAnnotation.timestampType(true, TimeUnit.NANOS)
+
+ override def acceptsValue(value: Any): Boolean = value match {
+ case i: Instant => epochNanosInRange(instantToEpochNanos(i))
+ case _ => false
+ }
+
+ override protected def toLong(value: Any): JLong =
+ instantToEpochNanos(value.asInstanceOf[Instant])
+ }
+
Review Comment:
TimestampNanosParquetOps.scala (ltz/ntzFilterOps) via ParquetFilters.scala In arm (master ~L803-818); a mixed IN list with an in-range head but an out-of-range tail element crashes the query, violating the PR's own SPARK-46092 invariant ("out-of-range → full scan, never throw"). Verified end-to-end against master: the In arm gates only on canMakeFilterOn(name, values.head), so the head passes; then makeEq (list <= threshold, default 10) or makeIn calls TypedParquetFilterOps.toPhysical -> toLong on every element, and the encoder (timestampNanosToEpochNanos -> Math.addExact/multiplyExact) throws ArithmeticException on the year-2300 tail.
The call site ParquetFileFormat.scala:240-264 (and the V2 ParquetPartitionReaderFactory path) wraps .flatMap(parquetFilters.createFilter) in a try/finally with no catch, so the exception propagates and fails the query. acceptsValue/epochNanosInRange guard only single-value operators. Unlike the pre-existing INT32 arm (which silently truncates via .intValue, never throws), this is the first framework encoder that throws; and the narrow int64-nanos window (~1677..2262) makes a mixed list like WHERE c IN (TIMESTAMP_NTZ '2020-...', TIMESTAMP_NTZ '2300-...') realistic under default config. Fix: range-check every In element (or have the framework In arm reject on any non-acceptable element).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps [spark]
Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on PR #57430:
URL: https://github.com/apache/spark/pull/57430#issuecomment-5252137777
**Merge Summary:**
- merged into master https://github.com/apache/spark/commit/6dfac55e3beb5693f158e4a59ec57b595b283a78
- merged into branch-4.x https://github.com/apache/spark/commit/a098f6569c5d8601f144a91923e686a6a10a5e87
- merged into branch-4.3 https://github.com/apache/spark/commit/96e77635a5c349237bf18e3324918ff3f0be5026
*Posted by `merge_spark_pr.py`*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-57822][SQL] Support Parquet predicate pushdown for nanosecond-precision timestamps [spark]
Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on PR #57430:
URL: https://github.com/apache/spark/pull/57430#issuecomment-5252124181
Thank you for addressing all comments @stevomitric! LGTM.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org