wombatu-kun commented on code in PR #19132:
URL: https://github.com/apache/hudi/pull/19132#discussion_r3618951596


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestTimeTravelTable.scala:
##########
@@ -338,4 +338,71 @@ class TestTimeTravelTable extends HoodieSparkSqlTestBase {
       }
     })
   }
+
+  test("Test time travel with SQL:2011 temporal clause spellings") {
+    withTempDir { tmp =>
+      val tableName = generateTableName
+      spark.sql(
+        s"""
+           |create table $tableName (
+           |  id int,
+           |  name string,
+           |  price double,
+           |  ts long
+           |) using hudi
+           | tblproperties (
+           |  primaryKey = 'id',
+           |  preCombineField = 'ts'
+           | )
+           | location '${tmp.getCanonicalPath}/$tableName'
+       """.stripMargin)
+
+      spark.sql(s"insert into $tableName values(1, 'a1', 10, 1000)")
+
+      val metaClient = createMetaClient(spark, 
s"${tmp.getCanonicalPath}/$tableName")
+      val instant1 = metaClient.getActiveTimeline.getAllCommitsTimeline
+        .lastInstant().get().requestedTime
+
+      spark.sql(s"insert into $tableName values(1, 'a2', 20, 2000)")
+
+      Seq(
+        s"select id, name, price, ts from $tableName SYSTEM_TIME AS OF 
'$instant1'",
+        s"select id, name, price, ts from $tableName FOR SYSTEM_TIME AS OF 
'$instant1'",
+        s"select id, name, price, ts from $tableName FOR TIMESTAMP AS OF 
'$instant1'"
+      ).foreach { sql =>
+        checkAnswer(sql)(Seq(1, "a1", 10.0, 1000))
+      }
+    }
+  }
+
+  test("Test time travel validation errors surface at analysis time") {
+    withTempDir { tmp =>
+      val tableName = generateTableName
+      spark.sql(
+        s"""
+           |create table $tableName (
+           |  id int,
+           |  name string,
+           |  price double,
+           |  ts long
+           |) using hudi
+           | tblproperties (
+           |  primaryKey = 'id',
+           |  preCombineField = 'ts'
+           | )
+           | location '${tmp.getCanonicalPath}/$tableName'
+       """.stripMargin)
+      spark.sql(s"insert into $tableName values(1, 'a1', 10, 1000)")
+
+      // VERSION AS OF (a version with no timestamp) is not supported for Hudi 
tables.
+      checkExceptionContain(s"select * from $tableName VERSION AS OF 1")(
+        "Version expression is not supported for time travel")
+
+      // A timestamp expression containing a subquery is rejected, since time 
travel needs a
+      // constant instant. This validation now runs in the analysis rule 
rather than the parser.
+      checkExceptionContain(
+        s"select * from $tableName TIMESTAMP AS OF (select max(ts) from 
$tableName)")(
+        "timestamp expression cannot refer to any columns or contain 
subqueries")

Review Comment:
   This assertion fails on Spark 3.3: its native parser rejects the subquery 
time-travel timestamp at parse time with "Invalid time travel spec: timestamp 
expression cannot contain subqueries", so the moved analysis-time guard never 
runs and this exact message never appears (Spark 3.5+ defer to the guard, hence 
green there). Assert a version-agnostic substring like "contain subqueries", or 
gate the exact-message check by Spark version.



-- 
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