Skip to content

Commit 2bee70f

Browse files
fix DeltaCDCSQLSuite
1 parent f35fc92 commit 2bee70f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

spark/src/main/scala/org/apache/spark/sql/delta/DeltaTableValueFunctions.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import scala.collection.JavaConverters._
2525
import org.apache.spark.sql.delta.catalog.DeltaTableV2
2626
import org.apache.spark.sql.delta.commands.cdc.CDCReader
2727
import org.apache.spark.sql.delta.sources.DeltaDataSource
28+
import org.apache.spark.sql.delta.util.AnalysisHelper
2829

2930
import org.apache.spark.sql.SparkSession
3031
import org.apache.spark.sql.catalyst.FunctionIdentifier
3132
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistryBase, NamedRelation, TableFunctionRegistry, UnresolvedLeafNode, UnresolvedRelation}
3233
import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression, ExpressionInfo, StringLiteral}
34+
import org.apache.spark.sql.catalyst.optimizer.ComputeCurrentTime
3335
import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, LogicalPlan, UnaryNode}
3436
import org.apache.spark.sql.connector.catalog.V1Table
3537
import org.apache.spark.sql.execution.datasources.LogicalRelation
@@ -115,7 +117,10 @@ trait CDCStatementBase extends DeltaTableValueFunction {
115117
case _: IntegerType | LongType => (keyPrefix + "Version") -> value.eval().toString
116118
case _: StringType => (keyPrefix + "Timestamp") -> value.eval().toString
117119
case _: TimestampType => (keyPrefix + "Timestamp") -> {
118-
val time = value.eval().toString
120+
// Resolve current time.
121+
val fakePlan = AnalysisHelper.FakeLogicalPlan(Seq(value), Nil)
122+
val timestampExpression = ComputeCurrentTime(fakePlan).expressions.head
123+
val time = timestampExpression.eval().toString
119124
val fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
120125
// when evaluated the time is represented with microseconds, which needs to be trimmed.
121126
fmt.format(new Date(time.toLong / 1000))

0 commit comments

Comments
 (0)