cloud-fan commented on code in PR #56425:
URL: https://github.com/apache/spark/pull/56425#discussion_r3398956112
##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala:
##########
@@ -1430,6 +1430,35 @@ class JDBCSuite extends SharedSparkSession {
assert(getJdbcType(oracleDialect, TimestampNTZType) == "TIMESTAMP")
}
+ test("Oracle TRUNC pushdown should map Spark format strings to Oracle
format") {
+ val oracleDialect = JdbcDialects.get("jdbc:oracle://127.0.0.1/db")
+ val dateRef = FieldReference("d")
+
+ // LiteralValue for StringType must use UTF8String (Spark's internal
string type)
+ // to match what V2ExpressionBuilder produces in the real pushdown path.
+ import org.apache.spark.unsafe.types.UTF8String
+ def truncExpr(fmt: String): GeneralScalarExpression = new
GeneralScalarExpression("TRUNC",
+ Array[V2Expression](dateRef, LiteralValue(UTF8String.fromString(fmt),
StringType)))
+
+ val monthSql = oracleDialect.compileExpression(truncExpr("MONTH")).get
+ assert(monthSql.contains("'MM'"),
+ s"trunc(d, 'MONTH') should produce Oracle 'MM', got: $monthSql")
+ assert(!monthSql.contains("'IW'"),
+ s"trunc(d, 'MONTH') should NOT produce 'IW', got: $monthSql")
+
+ val weekSql = oracleDialect.compileExpression(truncExpr("WEEK")).get
Review Comment:
Once the match handles case and rejects unmapped formats, it's worth
covering both here: a lowercase format (e.g. `trunc(d, 'week')` — the exact
shape OracleIntegrationSuite.scala:337 pushes) and an unmapped format asserting
`compileExpression` returns `None`.
--
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]