JingsongLi commented on code in PR #11237:
URL: https://github.com/apache/paimon/pull/11237#discussion_r4610185304


##########
paimon-spark/paimon-spark-4.2/src/main/scala/org/apache/spark/sql/paimon/OssieToSparkMetricView.scala:
##########
@@ -119,6 +126,18 @@ private[paimon] object OssieToSparkMetricView {
     mapper.writeValueAsString(root)
   }
 
+  def validateDateTruncInputs(plan: LogicalPlan): Unit = {
+    // Spark inserts the session-zone cast during analysis, including for 
computed arguments.
+    val truncatesLocalTimestamp = plan.exists {
+      node =>
+        node.expressions.exists(_.exists {
+          case TruncTimestamp(_, cast: Cast, _) => cast.child.dataType == 
TimestampNTZType

Review Comment:
   **[P2] Scope the NTZ check to `DATE_TRUNC` calls written in the Ossie 
model.** Spark inlines SQL UDF bodies during analysis. This traversal also 
visits `TruncTimestamp` inside those bodies, so an existing model can start 
failing even when its only function call in the affected field is `FLOOR`.
   
   I reproduced this in `OssieSemanticViewTest` with the existing 
`order_metrics` fixture and the following session setup:
   
   ```sql
   SET spark.sql.session.timeZone=UTC;
   SET spark.sql.path.enabled=true;
   CREATE FUNCTION spark_catalog.default.floor(ts TIMESTAMP_NTZ)
   RETURNS TIMESTAMP_LTZ RETURN date_trunc('day', ts);
   SET PATH = spark_catalog.default, system.builtin;
   ```
   
   Set the `region` field expression to `FLOOR(TIMESTAMP_NTZ '2026-06-12 
10:11:12')`, then run:
   
   ```sql
   SELECT region, MEASURE(gross)
   FROM paimon.sales.order_metrics
   GROUP BY region;
   ```
   
   On the base revision this returns one row, `(2026-06-12 00:00:00, 280.00)`. 
On this PR analysis fails with `Ossie DATE_TRUNC does not support TIMESTAMP_NTZ 
inputs`. The `DATE_TRUNC` belongs to the SQL UDF, whose declared return type is 
`TIMESTAMP_LTZ`.
   
   Could we track the `DATE_TRUNC` calls emitted by the Ossie translator and 
validate their resolved second arguments? This query would make a regression 
test alongside the existing test that rejects a direct `DATE_TRUNC('day', 
ntz_column)` in the model.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to