yihua commented on code in PR #19132:
URL: https://github.com/apache/hudi/pull/19132#discussion_r3669853130
##########
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:
Fixed. Switched the assertion to the version-agnostic substring `contain
subqueries`, which appears both in Spark 3.3's parse-time message (`Invalid
time travel spec: timestamp expression cannot contain subqueries`) and in the
Hudi analysis-rule message that Spark 3.4+ produce (`timestamp expression
cannot refer to any columns or contain subqueries`). This was also the CI
failure on 3.4/3.5/4.x, where the old exact `cannot contain subqueries` never
matched. Verified green locally on Spark 3.5.
--
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]