AlexisCubilla commented on code in PR #5097:
URL: https://github.com/apache/calcite/pull/5097#discussion_r3573556750


##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -1617,6 +1617,18 @@ private static String toSql(RelNode root, SqlDialect 
dialect,
     sql(query).ok(expected);
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7652";>[CALCITE-7652]
+   * MssqlSqlDialect unparses CAST to TIMESTAMP as "TIMESTAMP", which is 
invalid
+   * in SQL Server (should be DATETIME2)</a>. */
+  @Test void testCastToTimestampMssql() {
+    final String query = "select cast(\"hire_date\" as timestamp(3))\n"

Review Comment:
   With Calcite's default type system this can't happen: 
SqlTypeName.MAX_DATETIME_PRECISION is 3 and SqlTypeFactoryImpl.createSqlType 
clamps precision to the type system's maximum, so TIMESTAMP(9) is reduced to 
TIMESTAMP(3) before it reaches the dialect (→ DATETIME2(3)).
   
   A precision above 7 is only reachable through a custom type system that 
raises the maximum. Since SQL Server's DATETIME2/DATETIMEOFFSET support at most 
7 fractional-seconds digits, I now clamp the precision to 7 (e.g. DATETIME2(7)) 
so the generated SQL stays valid. Added a test with a custom type system 
covering that case.



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

Reply via email to