NobiGo commented on code in PR #3799:
URL: https://github.com/apache/calcite/pull/3799#discussion_r1616619173


##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -3519,9 +3519,57 @@ private SqlDialect nonOrdinalDialect() {
         + "FROM `foodmart`.`product`";
     final String expectedMysql = "SELECT CAST(`product_id` AS CHAR)\n"
         + "FROM `foodmart`.`product`";
+    final String expectedHive = "SELECT CAST(product_id AS STRING)\n"
+        + "FROM foodmart.product";
+    final String expectedSpark = "SELECT CAST(product_id AS STRING)\n"
+        + "FROM foodmart.product";
     sql(query)
         .withClickHouse().ok(expectedClickHouse)
-        .withMysql().ok(expectedMysql);
+        .withMysql().ok(expectedMysql)
+        .withHive().ok(expectedHive)
+        .withSpark().ok(expectedSpark);
+  }
+
+  @Test void testCastToVarcharWithPrecision() {
+    String query = "select cast(\"product_id\" as varchar(5)) from 
\"product\"";
+    final String expectedMysql = "SELECT CAST(`product_id` AS CHAR(5))\n"
+        + "FROM `foodmart`.`product`";
+    final String expectedHive = "SELECT CAST(product_id AS VARCHAR(5))\n"
+        + "FROM foodmart.product";
+    final String expectedSpark = "SELECT CAST(product_id AS STRING)\n"
+        + "FROM foodmart.product";
+    sql(query)
+        .withMysql().ok(expectedMysql)
+        .withHive().ok(expectedHive)
+        .withSpark().ok(expectedSpark);
+  }
+
+  @Test void testCastToChar() {
+    String query = "select cast(\"product_id\" as char) from \"product\"";
+    final String expectedMysql = "SELECT CAST(`product_id` AS CHAR(1))\n"

Review Comment:
   I will check this.



##########
core/src/main/java/org/apache/calcite/sql/dialect/SparkSqlDialect.java:
##########
@@ -146,4 +152,15 @@ public SparkSqlDialect(SqlDialect.Context context) {
       super.unparseCall(writer, call, leftPrec, rightPrec);
     }
   }
+
+  @Override public @Nullable SqlNode getCastSpec(RelDataType type) {
+    if (type instanceof BasicSqlType) {
+      if (type.getSqlTypeName() == SqlTypeName.VARCHAR) {

Review Comment:
   Thanks for the review @YiwenWu . I will use if to replace nested ifs.



-- 
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: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to