LuciferYang commented on code in PR #38394:
URL: https://github.com/apache/spark/pull/38394#discussion_r1005546819


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala:
##########
@@ -433,67 +433,131 @@ class AnalysisErrorSuite extends AnalysisTest {
     "UNRESOLVED_COLUMN.WITH_SUGGESTION",
     Map("objectName" -> "`bad_column`", "proposal" -> "`a`, `b`, `c`, `d`, 
`e`"))
 
-  errorTest(
+  errorClassTest(
     "slide duration greater than window in time window",
     testRelation2.select(
       TimeWindow(Literal("2016-01-01 01:01:01"), "1 second", "2 second", "0 
second").as("window")),
-      s"The slide duration " :: " must be less than or equal to the 
windowDuration " :: Nil
+    "DATATYPE_MISMATCH.PARAMETER_CONSTRAINT_VIOLATION",
+    Map(
+      "sqlExpr" -> "\"window(2016-01-01 01:01:01, 1000000, 2000000, 0)\"",
+      "leftExprName" -> "`slide_duration`",
+      "leftExprValue" -> "2000000L",
+      "constraint" -> "<=",
+      "rightExprName" -> "`window_duration`",
+      "rightExprValue" -> "1000000L"
+    )
   )
 
-  errorTest(
+  errorClassTest(
     "start time greater than slide duration in time window",
     testRelation.select(
       TimeWindow(Literal("2016-01-01 01:01:01"), "1 second", "1 second", "1 
minute").as("window")),
-      "The absolute value of start time " :: " must be less than the 
slideDuration " :: Nil
+    "DATATYPE_MISMATCH.PARAMETER_CONSTRAINT_VIOLATION",
+    Map(
+      "sqlExpr" -> "\"window(2016-01-01 01:01:01, 1000000, 1000000, 
60000000)\"",
+      "leftExprName" -> "`start_time`",
+      "leftExprValue" -> "60000000L",
+      "constraint" -> "<",
+      "rightExprName" -> "`slide_duration`",
+      "rightExprValue" -> "1000000L"
+    )
   )
 
-  errorTest(
+  errorClassTest(
     "start time equal to slide duration in time window",
     testRelation.select(
       TimeWindow(Literal("2016-01-01 01:01:01"), "1 second", "1 second", "1 
second").as("window")),
-      "The absolute value of start time " :: " must be less than the 
slideDuration " :: Nil
+    "DATATYPE_MISMATCH.PARAMETER_CONSTRAINT_VIOLATION",
+    Map(
+      "sqlExpr" -> "\"window(2016-01-01 01:01:01, 1000000, 1000000, 
1000000)\"",
+      "leftExprName" -> "`start_time`",
+      "leftExprValue" -> "1000000L",
+      "constraint" -> "<",
+      "rightExprName" -> "`slide_duration`",
+      "rightExprValue" -> "1000000L"
+    )
   )
 
-  errorTest(
+  errorClassTest(
     "SPARK-21590: absolute value of start time greater than slide duration in 
time window",
     testRelation.select(
       TimeWindow(Literal("2016-01-01 01:01:01"), "1 second", "1 second", "-1 
minute").as("window")),
-    "The absolute value of start time " :: " must be less than the 
slideDuration " :: Nil
+    "DATATYPE_MISMATCH.PARAMETER_CONSTRAINT_VIOLATION",
+    Map(
+      "sqlExpr" -> "\"window(2016-01-01 01:01:01, 1000000, 1000000, 
-60000000)\"",
+      "leftExprName" -> "`start_time`",
+      "leftExprValue" -> "-60000000L",
+      "constraint" -> "<",
+      "rightExprName" -> "`slide_duration`",
+      "rightExprValue" -> "1000000L"
+    )
   )
 
-  errorTest(
+  errorClassTest(
     "SPARK-21590: absolute value of start time equal to slide duration in time 
window",
     testRelation.select(
       TimeWindow(Literal("2016-01-01 01:01:01"), "1 second", "1 second", "-1 
second").as("window")),
-    "The absolute value of start time " :: " must be less than the 
slideDuration " :: Nil
+    "DATATYPE_MISMATCH.PARAMETER_CONSTRAINT_VIOLATION",
+    Map(
+      "sqlExpr" -> "\"window(2016-01-01 01:01:01, 1000000, 1000000, 
-1000000)\"",
+      "leftExprName" -> "`start_time`",
+      "leftExprValue" -> "-1000000L",
+      "constraint" -> "<",
+      "rightExprName" -> "`slide_duration`",
+      "rightExprValue" -> "1000000L"
+    )
   )
 
-  errorTest(
+  errorClassTest(
     "negative window duration in time window",
     testRelation.select(
       TimeWindow(Literal("2016-01-01 01:01:01"), "-1 second", "1 second", "0 
second").as("window")),
-      "The window duration " :: " must be greater than 0." :: Nil
+      "DATATYPE_MISMATCH.VALUE_OUT_OF_RANGE",
+    Map(

Review Comment:
   But if the ` map If size>4 ', the result of `sameElements` is independent of 
the order:
   
   For example:
   
   ```scala
   val map1 = Map(
         "exprName" -> "`window_duration`",
         "valueRange" -> s"(0, 9223372036854775807]",
         "currentValue" -> "-1000000L",
         "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\""
       )
   val map2 =  Map(
         "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\"",
         "exprName" -> "`window_duration`",
         "valueRange" -> s"(0, 9223372036854775807]",
         "currentValue" -> "-1000000L"
       )
   
   map1.sameElements(map2)
   ```
   the result is `false`.
   
   but
   
   ```scala
   val map1 = Map(
         "exprName" -> "`window_duration`",
         "valueRange" -> s"(0, 9223372036854775807]",
         "currentValue" -> "-1000000L",
         "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\"",
          "1" -> "1"
       )
   val map2 =  Map(
         "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\"",
         "exprName" -> "`window_duration`",
         "valueRange" -> s"(0, 9223372036854775807]",
         "currentValue" -> "-1000000L",
         "1" -> "1"
       )
   
   map1.sameElements(map2)
   ```
   the result is `true`.
   
   I think we should refactor the check logic, I will do it later:
   
   
https://github.com/apache/spark/blob/bef979757bd12ecbe706aa14ec7e09cd84d03d76/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisTest.scala#L197-L202
   
   



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

Reply via email to