MaxGekk commented on code in PR #38251:
URL: https://github.com/apache/spark/pull/38251#discussion_r996009592


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/BloomFilterMightContain.scala:
##########
@@ -59,12 +61,24 @@ case class BloomFilterMightContain(
             if !subquery.containsPattern(OUTER_REFERENCE) =>
             TypeCheckResult.TypeCheckSuccess
           case _ =>
-            TypeCheckResult.TypeCheckFailure(s"The Bloom filter binary input 
to $prettyName " +
-              "should be either a constant value or a scalar subquery 
expression")
+            DataTypeMismatch(
+              errorSubClass = "BLOOM_FILTER_BINARY_OP_WRONG_TYPE",
+              messageParameters = Map(
+                "functionName" -> toSQLId(prettyName),
+                "actual" -> toSQLType(bloomFilterExpression.dataType)
+              )
+            )
         }
-      case _ => TypeCheckResult.TypeCheckFailure(s"Input to function 
$prettyName should have " +
-        s"been ${BinaryType.simpleString} followed by a value with 
${LongType.simpleString}, " +
-        s"but it's [${left.dataType.catalogString}, 
${right.dataType.catalogString}].")
+      case _ =>
+        DataTypeMismatch(
+          errorSubClass = "BLOOM_FILTER_WRONG_TYPE",
+          messageParameters = Map(
+            "functionName" -> toSQLId(prettyName),
+            "required" -> (s"${toSQLType(BinaryType)} followed by " +

Review Comment:
   Could you pass only `toSQLType(BinaryType)` and `toSQLType(LongType)`, and 
move the text around to error-classes.json



##########
sql/core/src/test/scala/org/apache/spark/sql/BloomFilterAggregateQuerySuite.scala:
##########
@@ -170,19 +196,44 @@ class BloomFilterAggregateQuerySuite extends QueryTest 
with SharedSparkSession {
                   |FROM values (cast(1 as string)), (cast(2 as string)) as 
t(a)"""
         .stripMargin)
     }
-    assert(exception1.getMessage.contains(
-      "The Bloom filter binary input to might_contain should be either a 
constant value or " +
-        "a scalar subquery expression"))
+    checkError(
+      exception = exception1,
+      errorClass = "DATATYPE_MISMATCH.BLOOM_FILTER_BINARY_OP_WRONG_TYPE",
+      parameters = Map(
+        "sqlExpr" -> "\"might_contain(CAST(a AS BINARY), CAST(5 AS BIGINT))\"",
+        "functionName" -> "`might_contain`",
+        "actual" -> "\"BINARY\""
+      ),
+      context = ExpectedContext(
+        fragment = "might_contain(cast(a as binary), cast(5 as long))",
+        start = 8,
+        stop = 56
+      )
+    )
 
     val exception2 = intercept[AnalysisException] {
       spark.sql("""
                   |SELECT might_contain((select cast(a as binary)), cast(5 as 
long))
                   |FROM values (cast(1 as string)), (cast(2 as string)) as 
t(a)"""
         .stripMargin)
     }
-    assert(exception2.getMessage.contains(
-      "The Bloom filter binary input to might_contain should be either a 
constant value or " +
-        "a scalar subquery expression"))
+    checkError(
+      exception = exception2,
+      errorClass = "DATATYPE_MISMATCH.BLOOM_FILTER_BINARY_OP_WRONG_TYPE",
+      parameters = Map(
+        "sqlExpr" -> "\"might_contain(scalarsubquery(a), CAST(5 AS BIGINT))\"",
+        "functionName" -> "`might_contain`",
+        "actual" -> "\"BINARY\""
+      ),
+      context = ExpectedContext(
+        fragment = "might_contain((select cast(a as binary)), cast(5 as 
long))",
+        start = 8,
+        stop = 65
+      )
+    )
+//    assert(exception2.getMessage.contains(
+//      "The Bloom filter binary input to might_contain should be either a 
constant value or " +
+//        "a scalar subquery expression"))

Review Comment:
   Could you remove this, please.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/BloomFilterMightContain.scala:
##########
@@ -59,12 +61,24 @@ case class BloomFilterMightContain(
             if !subquery.containsPattern(OUTER_REFERENCE) =>
             TypeCheckResult.TypeCheckSuccess
           case _ =>
-            TypeCheckResult.TypeCheckFailure(s"The Bloom filter binary input 
to $prettyName " +
-              "should be either a constant value or a scalar subquery 
expression")
+            DataTypeMismatch(
+              errorSubClass = "BLOOM_FILTER_BINARY_OP_WRONG_TYPE",
+              messageParameters = Map(
+                "functionName" -> toSQLId(prettyName),
+                "actual" -> toSQLType(bloomFilterExpression.dataType)
+              )
+            )
         }
-      case _ => TypeCheckResult.TypeCheckFailure(s"Input to function 
$prettyName should have " +
-        s"been ${BinaryType.simpleString} followed by a value with 
${LongType.simpleString}, " +
-        s"but it's [${left.dataType.catalogString}, 
${right.dataType.catalogString}].")
+      case _ =>
+        DataTypeMismatch(
+          errorSubClass = "BLOOM_FILTER_WRONG_TYPE",
+          messageParameters = Map(
+            "functionName" -> toSQLId(prettyName),
+            "required" -> (s"${toSQLType(BinaryType)} followed by " +
+              s"a value with ${toSQLType(LongType)}"),
+            "actual" -> s"[${toSQLType(left.dataType)}, 
${toSQLType(right.dataType)}]"

Review Comment:
   Leave only `toSQLType(left.dataType)`, and move `[]` to error-classes.json, 
please.



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