This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 992e32cb24b IGNITE-23426 SQL Calcite: Fix 'CREATE TABLE' failure if
'DEFAULT' is null. (#11591)
992e32cb24b is described below
commit 992e32cb24be2b09fbe13dc47d4f727a82b19e51
Author: Vladimir Steshin <[email protected]>
AuthorDate: Wed Oct 16 18:27:21 2024 +0300
IGNITE-23426 SQL Calcite: Fix 'CREATE TABLE' failure if 'DEFAULT' is null.
(#11591)
---
.../prepare/ddl/DdlSqlToCommandConverter.java | 14 ++++++-----
.../integration/TableDmlIntegrationTest.java | 29 +++++++++++++++++++++-
2 files changed, 36 insertions(+), 7 deletions(-)
diff --git
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/DdlSqlToCommandConverter.java
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/DdlSqlToCommandConverter.java
index c2c4f521d14..2e59be33c0d 100644
---
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/DdlSqlToCommandConverter.java
+++
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/DdlSqlToCommandConverter.java
@@ -42,6 +42,7 @@ import org.apache.calcite.sql.SqlNumericLiteral;
import org.apache.calcite.sql.ddl.SqlColumnDeclaration;
import org.apache.calcite.sql.ddl.SqlDropTable;
import org.apache.calcite.sql.ddl.SqlKeyConstraint;
+import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheWriteSynchronizationMode;
import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
@@ -219,18 +220,19 @@ public class DdlSqlToCommandConverter {
String name = col.name.getSimple();
RelDataType type = planner.convert(col.dataType);
-
Object dflt = null;
- if (col.expression != null) {
- assert col.expression instanceof SqlLiteral;
-
- Type storageType = ctx.typeFactory().getResultClass(type);
- DataContext dataCtx = new
BaseDataContext(ctx.typeFactory());
+ assert col.expression == null || col.expression instanceof
SqlLiteral;
+ if (col.expression != null
+ && (((SqlLiteral)col.expression).getTypeName() !=
SqlTypeName.NULL || type instanceof OtherType)) {
if (type instanceof OtherType)
throw new IgniteSQLException("Type '" + type + "'
doesn't support default value.");
+ Type storageType = ctx.typeFactory().getResultClass(type);
+
+ DataContext dataCtx = new
BaseDataContext(ctx.typeFactory());
+
dflt = TypeUtils.fromLiteral(dataCtx, storageType,
(SqlLiteral)col.expression);
}
diff --git
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDmlIntegrationTest.java
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDmlIntegrationTest.java
index fee20993422..b8f28c278fe 100644
---
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDmlIntegrationTest.java
+++
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDmlIntegrationTest.java
@@ -496,6 +496,33 @@ public class TableDmlIntegrationTest extends
AbstractBasicIntegrationTransaction
});
}
+ /** */
+ @Test
+ public void testDefaultNullValue() {
+ checkDefaultValue("TINYINT", null, null);
+ checkDefaultValue("SMALLINT", null, null);
+ checkDefaultValue("INTEGER", null, null);
+ checkDefaultValue("BIGINT", null, null);
+ checkDefaultValue("FLOAT", null, null);
+ checkDefaultValue("REAL", null, null);
+ checkDefaultValue("DOUBLE", null, null);
+ checkDefaultValue("DECIMAL", null, null);
+ checkDefaultValue("DECIMAL(5)", null, null);
+ checkDefaultValue("DECIMAL(6, 1)", null, null);
+ checkDefaultValue("CHAR(5)", null, null);
+ checkDefaultValue("VARCHAR", null, null);
+ checkDefaultValue("VARCHAR(5)", null, null);
+ checkDefaultValue("INTERVAL DAYS TO SECONDS", null, null);
+ checkDefaultValue("INTERVAL YEARS TO MONTHS", null, null);
+ checkDefaultValue("INTERVAL MONTHS", null, null);
+ checkDefaultValue("DATE", null, null);
+ checkDefaultValue("TIME", null, null);
+ checkDefaultValue("TIMESTAMP", null, null);
+ checkDefaultValue("BINARY(3)", null, null);
+ checkDefaultValue("VARBINARY", null, null);
+ checkDefaultValue("UUID", null, null);
+ }
+
/** */
@Test
public void testInsertDefaultValue() {
@@ -624,7 +651,7 @@ public class TableDmlIntegrationTest extends
AbstractBasicIntegrationTransaction
/** */
private void checkQueryResult(String sql, Object expectedVal) {
- if (expectedVal.getClass().isArray()) {
+ if (expectedVal != null && expectedVal.getClass().isArray()) {
List<List<?>> res = executeSql(sql);
assertEquals(1, res.size());