You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "xuzifu666 (via GitHub)" <gi...@apache.org> on 2025/04/28 11:22:48 UTC
[PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
xuzifu666 opened a new pull request, #4342:
URL: https://github.com/apache/calcite/pull/4342
As description in JIRA: https://issues.apache.org/jira/browse/CALCITE-6988
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2835117988
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [93.6% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_coverage&view=list)
 [15.2% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342)
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2067631991
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
Review Comment:
OK, had added the link to the code~ @mihaibudiu
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2063550204
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -5361,52 +5362,92 @@ private void checkLiteral2(String expression, String expected) {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6949">[CALCITE-6949]
- * ClickHouse not support floor date to SECOND/MILLISECOND/MICROSECOND/NANOSECOND</a>. */
+ * ClickHouse not support floor date to SECOND/MILLISECOND/MICROSECOND/NANOSECOND</a>,
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-6988">[CALCITE-6988]
+ * DuckDB dialect implementation</a>.
+ * */
@Test void testFloorClickHouse() {
Review Comment:
Change the method name to testFloorXxx?
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -7842,9 +7890,12 @@ private void checkLiteral2(String expression, String expected) {
// since it seems to be used across more dialects.
final String expectedSnowflake = "SELECT LENGTH(\"brand_name\")\n"
+ "FROM \"foodmart\".\"product\"";
+ final String expectedDuckDB = "SELECT LENGTH(\"brand_name\")\n"
Review Comment:
same as expectedSnowflake?
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2835033798
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [93.6% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_coverage&view=list)
 [15.2% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342)
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2065320581
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
+ .withDataTypeSystem(TYPE_SYSTEM);
+
+ public static final SqlDialect DEFAULT = new DuckDBSqlDialect(DEFAULT_CONTEXT);
+
+ /** Creates a DuckDBSqlDialect. */
+ public DuckDBSqlDialect(SqlDialect.Context context) {
+ super(context);
+ }
+
+ @Override public boolean supportsApproxCountDistinct() {
+ return true;
+ }
+
+ @Override public void unparseCall(SqlWriter writer, SqlCall call,
+ int leftPrec, int rightPrec) {
+ switch (call.getKind()) {
+ 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 FLOOR:
+ if (call.operandCount() != 2) {
+ super.unparseCall(writer, call, leftPrec, rightPrec);
+ return;
+ }
+ unparseFloor(writer, call);
+ break;
+ case CHAR_LENGTH:
+ SqlCall lengthCall = SqlLibraryOperators.LENGTH
+ .createCall(SqlParserPos.ZERO, call.getOperandList());
+ super.unparseCall(writer, lengthCall, leftPrec, rightPrec);
+ break;
+ default:
+ super.unparseCall(writer, call, leftPrec, rightPrec);
+ }
+ }
+
+ private static void unparseFloor(SqlWriter writer, SqlCall call) {
+ SqlLiteral node = call.operand(1);
+ TimeUnitRange unit = node.getValueAs(TimeUnitRange.class);
+
+ String format;
+ switch (unit) {
+ case YEAR:
+ format = "year";
+ break;
+ case MONTH:
+ format = "month";
+ break;
+ case WEEK:
+ format = "week";
+ break;
+ case DAY:
+ format = "day";
+ break;
+ case HOUR:
+ format = "hour";
+ break;
+ case MINUTE:
+ format = "minute";
+ break;
+ case SECOND:
+ format = "second";
+ break;
+ case MILLISECOND:
+ format = "milliseconds";
+ break;
+ case MICROSECOND:
+ format = "microseconds";
+ break;
+ default:
+ throw new AssertionError("MYSQL does not support FLOOR for time unit: "
Review Comment:
It's my mistake, had fixed it, thanks. @mihaibudiu
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -5958,6 +5999,13 @@ private void checkLiteral2(String expression, String expected) {
.ok(expected);
}
+ @Test void testDuckDBDecimalPrecision() {
+ final String sql = "SELECT CAST(1.23 AS DECIMAL(38, 37))";
+ final String expected = "SELECT 1.2300000000000000000000000000000000000";
Review Comment:
From definition:
LAST:Nulls last for DESC and ASC.
HIGH:Nulls first for DESC, nulls last for ASC.
system env test:
before query
insert into t3 select 1,'aa';
insert into t3 select 1,'bb';
insert into t3 select 1,NULL;
insert into t3 select 1,NULL;
then query order by desc/asc
D select * from t3 order by data asc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ aa │
│ 1 │ bb │
│ 1 │ │
└───────┴─────────┘
D select * from t3 order by data desc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ bb │
│ 1 │ aa │
│ 1 │ │
└───────┴─────────┘
we can find that NULL is always at last, so here should be LAST.
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu merged PR #4342:
URL: https://github.com/apache/calcite/pull/4342
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2840539881
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [93.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_coverage&view=list)
 [14.8% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342)
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2065321682
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -5958,6 +5999,13 @@ private void checkLiteral2(String expression, String expected) {
.ok(expected);
}
+ @Test void testDuckDBDecimalPrecision() {
+ final String sql = "SELECT CAST(1.23 AS DECIMAL(38, 37))";
+ final String expected = "SELECT 1.2300000000000000000000000000000000000";
Review Comment:
Thanks for the reminder, had add a case with non-zero at last. @mihaibudiu
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2835238930
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [93.6% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_coverage&view=list)
 [15.2% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342)
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2065320937
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
Review Comment:
From definition:
**LAST**:Nulls last for DESC and ASC.
**HIGH**:Nulls first for DESC, nulls last for ASC.
system env test:
**before query**
```
insert into t3 select 1,'aa';
insert into t3 select 1,'bb';
insert into t3 select 1,NULL;
insert into t3 select 1,NULL;
```
then query order by desc/asc
```
D select * from t3 order by data asc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ aa │
│ 1 │ bb │
│ 1 │ │
└───────┴─────────┘
```
```
D select * from t3 order by data desc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ bb │
│ 1 │ aa │
│ 1 │ │
└───────┴─────────┘
```
we can find that NULL is always at last, so here should be LAST.
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2063610379
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -7842,9 +7890,12 @@ private void checkLiteral2(String expression, String expected) {
// since it seems to be used across more dialects.
final String expectedSnowflake = "SELECT LENGTH(\"brand_name\")\n"
+ "FROM \"foodmart\".\"product\"";
+ final String expectedDuckDB = "SELECT LENGTH(\"brand_name\")\n"
Review Comment:
Thanks~ had changed the code.
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2065320937
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
Review Comment:
From definition:
**LAST**:Nulls last for DESC and ASC.
**HIGH**:Nulls first for DESC, nulls last for ASC.
system env test:
**before query**
insert into t3 select 1,'aa';
insert into t3 select 1,'bb';
insert into t3 select 1,NULL;
insert into t3 select 1,NULL;
then query order by desc/asc
D select * from t3 order by data asc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ aa │
│ 1 │ bb │
│ 1 │ │
└───────┴─────────┘
D select * from t3 order by data desc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ bb │
│ 1 │ aa │
│ 1 │ │
└───────┴─────────┘
we can find that NULL is always at last, so here should be LAST.
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2840513872
> I think you can also squash the commits so we can merge this
Had squashed the commits, thanks @mihaibudiu
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2066921611
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
Review Comment:
Can you add a link to https://duckdb.org/docs/stable/sql/query_syntax/orderby.html so that people can check easily?
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2065320937
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
Review Comment:
From definition:
**LAST**:Nulls last for DESC and ASC.
**HIGH**:Nulls first for DESC, nulls last for ASC.
system env test:
**before query**
```
insert into t3 select 1,'aa';
insert into t3 select 1,'bb';
insert into t3 select 1,NULL;
insert into t3 select 1,NULL;
```
then query order by desc/asc
```
D select * from t3 order by data asc;
D select * from t3 order by data desc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ bb │
│ 1 │ aa │
│ 1 │ │
│ 1 │ │
└───────┴─────────┘
```
```
D select * from t3 order by data desc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ aa │
│ 1 │ bb │
│ 1 │ │
│ 1 │ │
└───────┴─────────┘
```
we can find that NULL is always at last, so here should be LAST.
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2837321351
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [93.6% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_coverage&view=list)
 [15.2% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342)
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2063541548
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
+ .withDataTypeSystem(TYPE_SYSTEM);
+
+ public static final SqlDialect DEFAULT = new DuckDBSqlDialect(DEFAULT_CONTEXT);
+
+ /** Creates a PhoenixSqlDialect. */
Review Comment:
Thanks for the catch~ done.
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
+ .withDataTypeSystem(TYPE_SYSTEM);
+
+ public static final SqlDialect DEFAULT = new DuckDBSqlDialect(DEFAULT_CONTEXT);
+
+ /** Creates a PhoenixSqlDialect. */
Review Comment:
Thanks for the catch~ done. @xiedeyantu
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2837363041
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [93.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_coverage&view=list)
 [14.9% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342)
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2065320733
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -5958,6 +5999,13 @@ private void checkLiteral2(String expression, String expected) {
.ok(expected);
}
+ @Test void testDuckDBDecimalPrecision() {
+ final String sql = "SELECT CAST(1.23 AS DECIMAL(38, 37))";
+ final String expected = "SELECT 1.2300000000000000000000000000000000000";
Review Comment:
From definition:
LAST:Nulls last for DESC and ASC.
HIGH:Nulls first for DESC, nulls last for ASC.
system env test:
before query
insert into t3 select 1,'aa';
insert into t3 select 1,'bb';
insert into t3 select 1,NULL;
insert into t3 select 1,NULL;
then query order by desc/asc
D select * from t3 order by data asc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ aa │
│ 1 │ bb │
│ 1 │ │
└───────┴─────────┘
D select * from t3 order by data desc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ bb │
│ 1 │ aa │
│ 1 │ │
└───────┴─────────┘
we can find that NULL is always at last, so here should be LAST.
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
Review Comment:
From definition:
LAST:Nulls last for DESC and ASC.
HIGH:Nulls first for DESC, nulls last for ASC.
system env test:
before query
insert into t3 select 1,'aa';
insert into t3 select 1,'bb';
insert into t3 select 1,NULL;
insert into t3 select 1,NULL;
then query order by desc/asc
D select * from t3 order by data asc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ aa │
│ 1 │ bb │
│ 1 │ │
└───────┴─────────┘
D select * from t3 order by data desc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ bb │
│ 1 │ aa │
│ 1 │ │
└───────┴─────────┘
we can find that NULL is always at last, so here should be LAST.
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2840498644
I think you can also squash the commits so we can merge this
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2065320937
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
Review Comment:
From definition:
### LAST:Nulls last for DESC and ASC.
HIGH:Nulls first for DESC, nulls last for ASC.
system env test:
**before query**
insert into t3 select 1,'aa';
insert into t3 select 1,'bb';
insert into t3 select 1,NULL;
insert into t3 select 1,NULL;
then query order by desc/asc
D select * from t3 order by data asc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ aa │
│ 1 │ bb │
│ 1 │ │
└───────┴─────────┘
D select * from t3 order by data desc;
┌───────┬─────────┐
│ id │ data │
│ int32 │ varchar │
├───────┼─────────┤
│ 1 │ bb │
│ 1 │ aa │
│ 1 │ │
└───────┴─────────┘
we can find that NULL is always at last, so here should be LAST.
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2063610900
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -5361,52 +5362,92 @@ private void checkLiteral2(String expression, String expected) {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6949">[CALCITE-6949]
- * ClickHouse not support floor date to SECOND/MILLISECOND/MICROSECOND/NANOSECOND</a>. */
+ * ClickHouse not support floor date to SECOND/MILLISECOND/MICROSECOND/NANOSECOND</a>,
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-6988">[CALCITE-6988]
+ * DuckDB dialect implementation</a>.
+ * */
@Test void testFloorClickHouse() {
Review Comment:
+1, had changed the name to testFloorFunction. @xiedeyantu
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2835267307
LGTM
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2063536283
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
+ .withDataTypeSystem(TYPE_SYSTEM);
+
+ public static final SqlDialect DEFAULT = new DuckDBSqlDialect(DEFAULT_CONTEXT);
+
+ /** Creates a PhoenixSqlDialect. */
Review Comment:
DuckDBSqlDialect
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4342:
URL: https://github.com/apache/calcite/pull/4342#issuecomment-2840523250
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4342&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4342&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [93.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_coverage&view=list)
 [14.8% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4342&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4342)
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6988] DuckDB dialect implementation [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4342:
URL: https://github.com/apache/calcite/pull/4342#discussion_r2064191222
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
Review Comment:
Is this LAST or HIGH?
These are not the same.
##########
core/src/main/java/org/apache/calcite/sql/dialect/DuckDBSqlDialect.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.avatica.util.TimeUnitRange;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.fun.SqlLibraryOperators;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * A <code>SqlDialect</code> implementation for the DuckDB database.
+ */
+public class DuckDBSqlDialect extends StarRocksSqlDialect {
+ public static final RelDataTypeSystem TYPE_SYSTEM =
+ new RelDataTypeSystemImpl() {
+
+ // We can refer to document of DuckDB 1.2.x:
+ // https://duckdb.org/docs/stable/sql/data_types/numeric#fixed-point-decimals
+ @Override public int getMaxPrecision(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxPrecision(typeName);
+ }
+ }
+
+ @Override public int getMaxScale(SqlTypeName typeName) {
+ switch (typeName) {
+ case DECIMAL:
+ return 38;
+ default:
+ return super.getMaxScale(typeName);
+ }
+ }
+
+ @Override public int getMaxNumericScale() {
+ return getMaxScale(SqlTypeName.DECIMAL);
+ }
+ };
+
+ public static final SqlDialect.Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
+ .withDatabaseProduct(SqlDialect.DatabaseProduct.DUCKDB)
+ .withIdentifierQuoteString("\"")
+ .withNullCollation(NullCollation.LAST)
+ .withDataTypeSystem(TYPE_SYSTEM);
+
+ public static final SqlDialect DEFAULT = new DuckDBSqlDialect(DEFAULT_CONTEXT);
+
+ /** Creates a DuckDBSqlDialect. */
+ public DuckDBSqlDialect(SqlDialect.Context context) {
+ super(context);
+ }
+
+ @Override public boolean supportsApproxCountDistinct() {
+ return true;
+ }
+
+ @Override public void unparseCall(SqlWriter writer, SqlCall call,
+ int leftPrec, int rightPrec) {
+ switch (call.getKind()) {
+ 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 FLOOR:
+ if (call.operandCount() != 2) {
+ super.unparseCall(writer, call, leftPrec, rightPrec);
+ return;
+ }
+ unparseFloor(writer, call);
+ break;
+ case CHAR_LENGTH:
+ SqlCall lengthCall = SqlLibraryOperators.LENGTH
+ .createCall(SqlParserPos.ZERO, call.getOperandList());
+ super.unparseCall(writer, lengthCall, leftPrec, rightPrec);
+ break;
+ default:
+ super.unparseCall(writer, call, leftPrec, rightPrec);
+ }
+ }
+
+ private static void unparseFloor(SqlWriter writer, SqlCall call) {
+ SqlLiteral node = call.operand(1);
+ TimeUnitRange unit = node.getValueAs(TimeUnitRange.class);
+
+ String format;
+ switch (unit) {
+ case YEAR:
+ format = "year";
+ break;
+ case MONTH:
+ format = "month";
+ break;
+ case WEEK:
+ format = "week";
+ break;
+ case DAY:
+ format = "day";
+ break;
+ case HOUR:
+ format = "hour";
+ break;
+ case MINUTE:
+ format = "minute";
+ break;
+ case SECOND:
+ format = "second";
+ break;
+ case MILLISECOND:
+ format = "milliseconds";
+ break;
+ case MICROSECOND:
+ format = "microseconds";
+ break;
+ default:
+ throw new AssertionError("MYSQL does not support FLOOR for time unit: "
Review Comment:
Why MYSQL?
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -5958,6 +5999,13 @@ private void checkLiteral2(String expression, String expected) {
.ok(expected);
}
+ @Test void testDuckDBDecimalPrecision() {
+ final String sql = "SELECT CAST(1.23 AS DECIMAL(38, 37))";
+ final String expected = "SELECT 1.2300000000000000000000000000000000000";
Review Comment:
I think this test would be more robust if the last digit was not 0
you are relying on the formatting to print zeros which are not significant, and this may not always be true
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org