aleksandar-trajkovic-db commented on code in PR #58809:
URL: https://github.com/apache/spark/pull/58809#discussion_r4025426227


##########
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:
   Even though right now the stamp has no effect, I have removed it for the 
nanos type. I added test cases to verify the stamp is not presetn for the nanos 
type. I also added an integration test.



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