marko-sisovic-db commented on code in PR #57564:
URL: https://github.com/apache/spark/pull/57564#discussion_r3682801335


##########
connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/V2JDBCTest.scala:
##########
@@ -1362,6 +1362,27 @@ private[v2] trait V2JDBCTest
     }
   }
 
+  test("fractional to integral cast pushed down truncates toward zero like 
Spark") {
+    val tbl = s"$catalogName.integral_cast"
+    withTable(tbl) {
+      // label is a string so the result type is the same across dialects (a 
numeric column
+      // comes back as BigDecimal on some engines such as Oracle).
+      sql(s"CREATE TABLE $tbl (double_col DOUBLE, decimal_col DECIMAL(10, 2), 
label VARCHAR(8))")
+      sql(s"INSERT INTO $tbl VALUES (1.5, 1.5, 'a'), (2.5, 2.5, 'b'), (-1.5, 
-1.5, 'c')")
+
+      // Spark truncates toward zero, so 1.5, 2.5 and -1.5 become 1, 2 and -1. 
A database that
+      // rounds half away from zero would return 2, 3 and -2 instead.
+      Seq("double_col", "decimal_col").foreach { col =>
+        val projected = sql(s"SELECT CAST($col AS INT) FROM $tbl ORDER BY 
$col")
+        assert(projected.collect().map(_.getInt(0)) === Array(-1, 1, 2))
+
+        val filtered = sql(s"SELECT label FROM $tbl WHERE CAST($col AS INT) = 
2")
+        checkFilterPushed(filtered)
+        assert(filtered.collect().map(_.getString(0)) === Array("b"))
+      }
+    }
+  }
+

Review Comment:
   Didn't know about this, thanks!. I've added separate tests in `JDBCSuite`, 
including a case for snowflake.



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