You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2025/07/07 07:38:26 UTC
(spark) branch master updated: [SPARK-52692][SQL] Support caching the TIME type
This is an automated email from the ASF dual-hosted git repository.
maxgekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 46b6ccbd93c4 [SPARK-52692][SQL] Support caching the TIME type
46b6ccbd93c4 is described below
commit 46b6ccbd93c4fe5c2b72f730a776a2739bdbc7b4
Author: Bruce Robbins <be...@gmail.com>
AuthorDate: Mon Jul 7 09:38:07 2025 +0200
[SPARK-52692][SQL] Support caching the TIME type
### What changes were proposed in this pull request?
The proposed changes are largely based on commit 067432705fbec970bd713adf37d2aa17c6bcf5a0, which added caching support for TIMESTAMP_NTZ. This PR makes the same changes, except for the TIME type.
### Why are the changes needed?
To support caching the TIME type, e.g.:
```
CACHE TABLE v1 AS SELECT TIME'22:00:00';
```
### Does this PR introduce _any_ user-facing change?
No. The TIME type is not released yet.
### How was this patch tested?
New unit test.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #51385 from bersprockets/time_cache.
Authored-by: Bruce Robbins <be...@gmail.com>
Signed-off-by: Max Gekk <ma...@gmail.com>
---
.../spark/sql/execution/columnar/ColumnBuilder.scala | 2 +-
.../apache/spark/sql/execution/columnar/ColumnType.scala | 3 ++-
.../sql/execution/columnar/GenerateColumnAccessor.scala | 2 +-
.../scala/org/apache/spark/sql/CachedTableSuite.scala | 15 ++++++++++++++-
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnBuilder.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnBuilder.scala
index b65ef12f12d5..a63569b19a01 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnBuilder.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnBuilder.scala
@@ -185,7 +185,7 @@ private[columnar] object ColumnBuilder {
case ByteType => new ByteColumnBuilder
case ShortType => new ShortColumnBuilder
case IntegerType | DateType | _: YearMonthIntervalType => new IntColumnBuilder
- case LongType | TimestampType | TimestampNTZType | _: DayTimeIntervalType =>
+ case LongType | TimestampType | TimestampNTZType | _: DayTimeIntervalType | _: TimeType =>
new LongColumnBuilder
case FloatType => new FloatColumnBuilder
case DoubleType => new DoubleColumnBuilder
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnType.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnType.scala
index 60695a6c5d49..df250e529e2c 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnType.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnType.scala
@@ -869,7 +869,8 @@ private[columnar] object ColumnType {
case ByteType => BYTE
case ShortType => SHORT
case IntegerType | DateType | _: YearMonthIntervalType => INT
- case LongType | TimestampType | TimestampNTZType | _: DayTimeIntervalType => LONG
+ case LongType | TimestampType | TimestampNTZType | _: DayTimeIntervalType | _: TimeType =>
+ LONG
case FloatType => FLOAT
case DoubleType => DOUBLE
case s: StringType => STRING(s)
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/GenerateColumnAccessor.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/GenerateColumnAccessor.scala
index d07ebeb843bb..dd64d92bed71 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/GenerateColumnAccessor.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/GenerateColumnAccessor.scala
@@ -82,7 +82,7 @@ object GenerateColumnAccessor extends CodeGenerator[Seq[DataType], ColumnarItera
case ByteType => classOf[ByteColumnAccessor].getName
case ShortType => classOf[ShortColumnAccessor].getName
case IntegerType | DateType | _: YearMonthIntervalType => classOf[IntColumnAccessor].getName
- case LongType | TimestampType | TimestampNTZType | _: DayTimeIntervalType =>
+ case LongType | TimestampType | TimestampNTZType | _: DayTimeIntervalType | _: TimeType =>
classOf[LongColumnAccessor].getName
case FloatType => classOf[FloatColumnAccessor].getName
case DoubleType => classOf[DoubleColumnAccessor].getName
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
index 53844be265c5..484025c8935c 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
@@ -19,7 +19,7 @@ package org.apache.spark.sql
import java.io.{File, FilenameFilter}
import java.nio.file.{Files, Paths}
-import java.time.{Duration, LocalDateTime, Period}
+import java.time.{Duration, LocalDateTime, LocalTime, Period}
import java.util.concurrent.atomic.AtomicBoolean
import scala.collection.mutable.HashSet
@@ -1792,6 +1792,19 @@ class CachedTableSuite extends QueryTest with SQLTestUtils
}
}
+ test("SPARK-52692: Support cache/uncache table with Time type") {
+ val tableName = "timeCache"
+ withTable(tableName) {
+ sql(s"CACHE TABLE $tableName AS SELECT TIME'22:00:00'")
+ checkAnswer(spark.table(tableName), Row(LocalTime.parse("22:00:00")))
+ spark.table(tableName).queryExecution.withCachedData.collect {
+ case cached: InMemoryRelation =>
+ assert(cached.stats.sizeInBytes === 8)
+ }
+ sql(s"UNCACHE TABLE $tableName")
+ }
+ }
+
Seq(true, false).foreach { callerEnableAQE =>
test(s"SPARK-49982: AQE negative caching with in memory table cache - callerEnableAQE=" +
callerEnableAQE) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org