sunxiaoguang commented on code in PR #49452:
URL: https://github.com/apache/spark/pull/49452#discussion_r1913063805


##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/OracleDialect.scala:
##########
@@ -61,6 +61,34 @@ private case class OracleDialect() extends JdbcDialect with 
SQLConfHelper with N
       } else {
         super.visitAggregateFunction(funcName, isDistinct, inputs)
       }
+
+    private def compareBlob(lhs: Expression, operator: String, rhs: 
Expression): String = {
+      val l = inputToSQL(lhs)
+      val r = inputToSQL(rhs)
+      val op = if (operator == "<=>") "=" else operator
+      val compare = s"DBMS_LOB.COMPARE($l, $r) $op 0"
+      if (operator == "<=>") {
+        s"(($l IS NOT NULL AND $r IS NOT NULL AND $compare) OR ($l IS NULL AND 
$r IS NULL))"
+      } else {
+        compare
+      }
+    }
+
+    override def build(expr: Expression): String = expr match {

Review Comment:
   We can only rewrite comparison when one of the arguments is BLOB. For other 
cases, we have to use existing implementation. But unfortunately, the signature 
of visitBinaryComparison is accepting everything in string which loss the type 
information to understand if one of the arguments is binary type.
   
   ```scala
     protected String visitBinaryComparison(String name, String l, String r) {
       if (name.equals("<=>")) {
         return "((" + l + " IS NOT NULL AND " + r + " IS NOT NULL AND " + l + 
" = " + r + ") " +
                 "OR (" + l + " IS NULL AND " + r + " IS NULL))";
       }
       return l + " " + name + " " + r;
     }
   ```



##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/OracleDialect.scala:
##########
@@ -61,6 +61,34 @@ private case class OracleDialect() extends JdbcDialect with 
SQLConfHelper with N
       } else {
         super.visitAggregateFunction(funcName, isDistinct, inputs)
       }
+
+    private def compareBlob(lhs: Expression, operator: String, rhs: 
Expression): String = {
+      val l = inputToSQL(lhs)
+      val r = inputToSQL(rhs)
+      val op = if (operator == "<=>") "=" else operator
+      val compare = s"DBMS_LOB.COMPARE($l, $r) $op 0"
+      if (operator == "<=>") {
+        s"(($l IS NOT NULL AND $r IS NOT NULL AND $compare) OR ($l IS NULL AND 
$r IS NULL))"
+      } else {
+        compare
+      }
+    }
+
+    override def build(expr: Expression): String = expr match {

Review Comment:
   We can only rewrite comparison when one of the arguments is BLOB. For other 
cases, we have to use existing implementation.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to