anew commented on code in PR #57612:
URL: https://github.com/apache/spark/pull/57612#discussion_r3670984681
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AutoCdcParserSuite.scala:
##########
@@ -592,70 +594,151 @@ class AutoCdcParserSuite extends CommandSuiteBase with
AnalysisTest {
//
---------------------------------------------------------------------------
test("CREATE FLOW AS AUTO CDC INTO - SEQUENCE BY is required") {
- checkError(
- intercept[ParseException] {
- parser.parsePlan(
- """CREATE FLOW f AS AUTO CDC INTO target
- |FROM STREAM(source)
- |KEYS (id)""".stripMargin)
- },
- condition = "PARSE_SYNTAX_ERROR",
- sqlState = "42601",
- parameters = Map("error" -> "end of input", "hint" -> "")
- )
+ val ex = intercept[ParseException] {
+ parser.parsePlan(
+ """CREATE FLOW f AS AUTO CDC INTO target
+ |FROM STREAM(source)
+ |KEYS (id)""".stripMargin)
+ }
+ assert(ex.getMessage.contains("AUTO CDC requires a SEQUENCE BY clause."))
}
test("CREATE STREAMING TABLE FLOW AUTO CDC - SEQUENCE BY is required") {
- checkError(
- intercept[ParseException] {
- parser.parsePlan(
- """CREATE STREAMING TABLE target
- |FLOW AUTO CDC
- |FROM STREAM(source)
- |KEYS (id)""".stripMargin)
- },
- condition = "PARSE_SYNTAX_ERROR",
- sqlState = "42601",
- parameters = Map("error" -> "end of input", "hint" -> "")
- )
+ val ex = intercept[ParseException] {
+ parser.parsePlan(
+ """CREATE STREAMING TABLE target
+ |FLOW AUTO CDC
+ |FROM STREAM(source)
+ |KEYS (id)""".stripMargin)
+ }
+ assert(ex.getMessage.contains("AUTO CDC requires a SEQUENCE BY clause."))
}
//
---------------------------------------------------------------------------
- // Error cases: wrong clause order
+ // Clause ordering: the optional clauses may appear in any order
//
---------------------------------------------------------------------------
- test("SEQUENCE BY before APPLY AS DELETE is not allowed") {
- checkError(
- intercept[ParseException] {
- parser.parsePlan(
- """CREATE FLOW f AS AUTO CDC INTO target
- |FROM STREAM(source)
- |KEYS (id)
- |SEQUENCE BY ts
- |APPLY AS DELETE WHEN a = 1""".stripMargin)
- },
- condition = "PARSE_SYNTAX_ERROR",
- sqlState = "42601",
- parameters = Map("error" -> "'APPLY'", "hint" -> "")
- )
+ test("AUTO CDC - SEQUENCE BY before APPLY AS DELETE is allowed") {
+ val plan = parser.parsePlan(
+ """CREATE FLOW f AS AUTO CDC INTO target
+ |FROM STREAM(source)
+ |KEYS (id)
+ |SEQUENCE BY ts
+ |APPLY AS DELETE WHEN a = 1""".stripMargin)
+
+ val cdc =
plan.asInstanceOf[CreateFlowCommand].flowOperation.asInstanceOf[AutoCdcInto]
+ assert(cdc.sequenceByExpr == UnresolvedAttribute("ts"))
+ assert(cdc.deleteCondition.isDefined)
+ assert(cdc.deleteCondition.get.sql.contains("a"))
}
- test("COLUMNS before SEQUENCE BY is not allowed") {
+ test("AUTO CDC - COLUMNS before SEQUENCE BY is allowed") {
+ val plan = parser.parsePlan(
+ """CREATE FLOW f AS AUTO CDC INTO target
+ |FROM STREAM(source)
+ |KEYS (id)
+ |COLUMNS (a, b)
+ |SEQUENCE BY ts""".stripMargin)
+
+ val cdc =
plan.asInstanceOf[CreateFlowCommand].flowOperation.asInstanceOf[AutoCdcInto]
+ assert(cdc.includeColumns.get.map(_.name) == Seq("a", "b"))
+ assert(cdc.sequenceByExpr == UnresolvedAttribute("ts"))
+ }
+
+ test("AUTO CDC - clauses supplied in fully reversed order are all honored") {
Review Comment:
and added a new mirrored test..
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]