uros-b commented on code in PR #58809:
URL: https://github.com/apache/spark/pull/58809#discussion_r4015131760
##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala:
##########
@@ -1901,16 +1901,35 @@ class JDBCSuite extends SharedSparkSession {
"{ts '2018-07-06 06:00:00.0'}")
}
- test("SPARK-58876: Oracle TIMESTAMP stays microsecond TimestampNTZType under
the nanos preview") {
- val oracleDialect = JdbcDialects.get("jdbc:oracle")
- // Even with the nanosecond timestamp preview enabled, the Oracle mapping
is microsecond
- // TimestampNTZType and does not engage that preview (no nanosecond type,
no deferral).
- withSQLConf(SQLConf.TIMESTAMP_NANOS_TYPES_ENABLED.key -> "true") {
- val md = new MetadataBuilder()
- .putBoolean("preferTimestampNanos", value = true).putLong("scale", 9)
- assert(oracleDialect.getCatalystType(java.sql.Types.TIMESTAMP,
"TIMESTAMP", 0, md) ===
- Some(TimestampNTZType))
+ test("SPARK-58876: Oracle TIMESTAMP(7-9) resolves to nanosecond NTZ under
the nanos preview") {
+ // scale/preferTimestampNanos reach the dialect only as metadata getSchema
stamps, so resolve a
+ // mocked Oracle TIMESTAMP column via getSchema for each (scale, option,
preview) combination.
+ def resolve(scale: Int, preferNanos: Boolean, nanosEnabled: Boolean):
DataType = {
+ val rsmd = mock(classOf[java.sql.ResultSetMetaData])
+ when(rsmd.getColumnCount).thenReturn(1)
+ when(rsmd.getColumnLabel(anyInt())).thenReturn("T")
+ when(rsmd.getColumnType(anyInt())).thenReturn(java.sql.Types.TIMESTAMP)
+ when(rsmd.getColumnTypeName(anyInt())).thenReturn("TIMESTAMP")
+ when(rsmd.getPrecision(anyInt())).thenReturn(0)
+ when(rsmd.getScale(anyInt())).thenReturn(scale)
+ when(rsmd.isSigned(anyInt())).thenReturn(false)
+
when(rsmd.isNullable(anyInt())).thenReturn(java.sql.ResultSetMetaData.columnNullable)
+ val rs = mock(classOf[ResultSet])
+ when(rs.getMetaData).thenReturn(rsmd)
+ withSQLConf(SQLConf.TIMESTAMP_NANOS_TYPES_ENABLED.key ->
nanosEnabled.toString) {
+ JdbcUtils.getSchema(mock(classOf[Connection]), rs, OracleDialect(),
+ preferTimestampNanos = preferNanos).fields.head.dataType
+ }
+ }
Review Comment:
Nit: `resolve` only returns the data type. SPARK-58876 also stamps
`READ_TIMESTAMP_NTZ_WALL_CLOCK` so a later flag flip cannot desync the
microsecond NTZ read. That marker is redundant for `TimestampNTZNanosType` (the
nanos getter already uses `getObject(LocalDateTime)`), but it is still part of
the Oracle contract.
Consider returning the `StructField` (as the nearby preferTimestampNTZ test
does) and asserting the marker is still present for both the nanos and
microsecond outcomes, e.g. scale=9 with both flags on and scale=6 / flags off.
--
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]