urosstan-db commented on code in PR #57564:
URL: https://github.com/apache/spark/pull/57564#discussion_r3658700457
##########
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))
Review Comment:
Excellent comment,
Since we may support projection pushdown in the future (but I doubt that
would happen TBH), maybe it's good to preserve this check and also to add
aggregation query, since it is pushed, so we will cover filter, aggregates and
be future-proof for projections as well?
wdyt @marko-sisovic-db @uros-b
--
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]