YiwenWu commented on code in PR #3682: URL: https://github.com/apache/calcite/pull/3682#discussion_r1493764295
########## 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: Exactly, Similar to MySQL, the Calcite TIMESTAMP type is called "DATETIME" in StarRocks. This processing refers to `MysqlSqlDialect#getCastSpec`. -- 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]
