This is an automated email from the ASF dual-hosted git repository.
zhehu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 2143c6b106 [CALCITE-7067] Maximum precision of UNSIGNED BIGINT type in
MysqlSqlDialect should be 20
2143c6b106 is described below
commit 2143c6b106581176cdb369f4b60223374d29353b
Author: Zhe Hu <[email protected]>
AuthorDate: Mon Jun 23 14:34:29 2025 +0800
[CALCITE-7067] Maximum precision of UNSIGNED BIGINT type in MysqlSqlDialect
should be 20
---
.../org/apache/calcite/sql/dialect/MysqlSqlDialect.java | 2 ++
.../apache/calcite/sql/validate/SqlValidatorImpl.java | 2 +-
.../calcite/rel/rel2sql/RelToSqlConverterTest.java | 16 ++++++++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git
a/core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java
b/core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java
index 609403a983..35ea8c9311 100644
--- a/core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java
@@ -74,6 +74,8 @@ public class MysqlSqlDialect extends SqlDialect {
return 6;
case DECIMAL:
return 65;
+ case UBIGINT:
+ return 20;
default:
return super.getMaxPrecision(typeName);
}
diff --git
a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index c3d93072b7..7ad1aefeb3 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -3387,7 +3387,7 @@ private void registerOperandSubQueries(
final BigDecimal noTrailingZeros = bd.stripTrailingZeros();
// If we don't strip trailing zeros we may reject values such as
1.000....0.
- final int maxPrecision = typeSystem.getMaxNumericPrecision();
+ final int maxPrecision = typeSystem.getMaxPrecision(SqlTypeName.DECIMAL);
if (noTrailingZeros.precision() > maxPrecision) {
throw newValidationError(literal,
RESOURCE.numberLiteralOutOfRange(bd.toString()));
diff --git
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index f71da9a47c..5539e4436c 100644
---
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -4131,6 +4131,22 @@ private SqlDialect nonOrdinalDialect() {
.withClickHouse().ok(expectedClickHouse);
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7067">[CALCITE-7067]
+ * Maximum precision of unsigned bigint type in MysqlSqlDialect should be
20</a>. */
+ @Test void testCastToUBigInt() {
+ String query = "select cast(18446744073709551615 as bigint unsigned) from
\"product\"";
+ final String expectedMysql = "SELECT CAST(18446744073709551615 AS BIGINT
UNSIGNED)\n"
+ + "FROM `foodmart`.`product`";
+ final String errMsg = "org.apache.calcite.runtime.CalciteContextException:
"
+ + "From line 1, column 13 to line 1, column 32: "
+ + "Numeric literal '18446744073709551615' out of range";
+ sql(query)
+ .withMysql().ok(expectedMysql)
+ .withPostgresql().throws_(errMsg)
+ .withOracle().throws_(errMsg);
+ }
+
@Test void testSelectQueryWithLimitClauseWithoutOrder() {
String query = "select \"product_id\" from \"product\" limit 100 offset
10";
final String expected = "SELECT \"product_id\"\n"