mihaibudiu commented on code in PR #3682:
URL: https://github.com/apache/calcite/pull/3682#discussion_r1486629721


##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -4506,13 +4600,16 @@ private void checkLiteral2(String expression, String 
expected) {
     String expectedPresto = "SELECT DATE_TRUNC('MINUTE', \"hire_date\")\n"
         + "FROM \"foodmart\".\"employee\"";
     String expectedFirebolt = expectedPostgresql;
+    String expectedStarRocks = "SELECT DATE_FORMAT(`hire_date`, '%Y-%m-%d 
%H:%i:00')\n"

Review Comment:
   This looks wrong, DATE_FORMAT returns a string, while DATE_TRUNC returns a 
date.



##########
core/src/main/java/org/apache/calcite/sql/dialect/StarRocksSqlDialect.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.dialect;
+
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.sql.SqlAlienSystemTypeNameSpec;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDataTypeSpec;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlIntervalQualifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.parser.SqlParserPos;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import static org.apache.calcite.util.RelToSqlConverterUtil.unparseHiveTrim;
+
+/**
+ * A <code>SqlDialect</code> implementation for the StarRocks database.
+ */
+public class StarRocksSqlDialect extends SqlDialect {

Review Comment:
   I don't know anything about the StarRocks dialect, so my review will assume 
that these choices are correct for that dialect. I am reviewing only from the 
Calcite side.



##########
core/src/main/java/org/apache/calcite/sql/dialect/StarRocksSqlDialect.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.dialect;
+
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.sql.SqlAlienSystemTypeNameSpec;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDataTypeSpec;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlIntervalQualifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.parser.SqlParserPos;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import static org.apache.calcite.util.RelToSqlConverterUtil.unparseHiveTrim;
+
+/**
+ * A <code>SqlDialect</code> implementation for the StarRocks database.
+ */
+public class StarRocksSqlDialect extends SqlDialect {
+
+  public static final SqlDialect.Context DEFAULT_CONTEXT = 
SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.STARROCKS)
+      .withIdentifierQuoteString("`")
+      .withNullCollation(NullCollation.LOW);
+
+  public static final SqlDialect DEFAULT = new 
StarRocksSqlDialect(DEFAULT_CONTEXT);
+
+  /**
+   * Creates a StarRocksSqlDialect.
+   */
+  public StarRocksSqlDialect(Context context) {
+    super(context);
+  }
+
+
+  @Override public boolean supportsCharSet() {
+    return false;
+  }
+
+  @Override public void unparseOffsetFetch(SqlWriter writer, @Nullable SqlNode 
offset,
+      @Nullable SqlNode fetch) {
+    unparseFetchUsingLimit(writer, offset, fetch);
+  }
+
+  @Override public @Nullable SqlNode emulateNullDirection(SqlNode node,
+      boolean nullsFirst, boolean desc) {
+    return emulateNullDirectionWithIsNull(node, nullsFirst, desc);
+  }
+
+  @Override public boolean supportsApproxCountDistinct() {
+    return true;
+  }
+
+  @Override public boolean supportsNestedAggregations() {
+    return false;
+  }
+
+  @Override public boolean supportsTimestampPrecision() {
+    return false;
+  }
+
+  @Override public CalendarPolicy getCalendarPolicy() {
+    return CalendarPolicy.SHIFT;
+  }
+
+  @Override public void unparseCall(SqlWriter writer, SqlCall call, int 
leftPrec, int rightPrec) {
+    switch (call.getKind()) {
+    case ARRAY_VALUE_CONSTRUCTOR:
+      final SqlWriter.Frame arrayFrame = writer.startList("[", "]");
+      for (SqlNode operand : call.getOperandList()) {
+        writer.sep(",");
+        operand.unparse(writer, leftPrec, rightPrec);
+      }
+      writer.endList(arrayFrame);
+      break;
+    case MAP_VALUE_CONSTRUCTOR:
+      writer.keyword(call.getOperator().getName());
+      final SqlWriter.Frame mapFrame = writer.startList("{", "}");
+      for (int i = 0; i < call.operandCount(); i++) {
+        String sep = i % 2 == 0 ? "," : ":";
+        writer.sep(sep);
+        call.operand(i).unparse(writer, leftPrec, rightPrec);
+      }
+      writer.endList(mapFrame);
+      break;
+    case TRIM:
+      unparseHiveTrim(writer, call, leftPrec, rightPrec);
+      break;
+    case FLOOR:
+      MysqlSqlDialect.DEFAULT.unparseCall(writer, call, leftPrec, rightPrec);
+      break;
+    default:
+      super.unparseCall(writer, call, leftPrec, rightPrec);
+      break;
+    }
+  }
+
+  @Override public @Nullable SqlNode getCastSpec(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case TIMESTAMP:

Review Comment:
   I am confused what's going on here.
   If the Calcite TIMESTAMP type is called "DATETIME" in StarRocks, I am not 
sure whether this is the only case that needs changing. Can you write some 
tests that use TIMESTAMP?



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