This is an automated email from the ASF dual-hosted git repository. tkalkirill pushed a commit to branch ignite-xxxxx-try-add-sql-exp-for-default in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 55090e8c33f6d808fac98ee2b65fc12e67f79f75 Author: Kirill Tkalenko <[email protected]> AuthorDate: Tue Mar 17 11:54:43 2026 +0300 ignite-xxxxx-try-add-sql-exp-for-default --- .../src/main/codegen/includes/parserImpls.ftl | 2 +- .../prepare/ddl/DdlSqlToCommandConverter.java | 13 +++++---- .../calcite/sql/generated/IgniteSqlParserImpl.java | 4 +-- .../calcite/schema/AboutDefaultValueTest.java | 33 ++++++++++++++++++++++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/modules/calcite/src/main/codegen/includes/parserImpls.ftl b/modules/calcite/src/main/codegen/includes/parserImpls.ftl index 4aa92e168fe..e2f60f736d4 100644 --- a/modules/calcite/src/main/codegen/includes/parserImpls.ftl +++ b/modules/calcite/src/main/codegen/includes/parserImpls.ftl @@ -137,7 +137,7 @@ void TableElement(List<SqlNode> list) : { id = SimpleIdentifier() type = DataTypeEx() nullable = NullableOptDefaultTrue() ( - <DEFAULT_> { s.add(this); } dflt = Literal() { + <DEFAULT_> { s.add(this); } dflt = Expression(ExprContext.ACCEPT_ALL) { strategy = ColumnStrategy.DEFAULT; } | 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 2e59be33c0d..28d856ab116 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 @@ -29,6 +29,7 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; +import com.google.common.util.concurrent.AtomicDouble; import org.apache.calcite.DataContext; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeField; @@ -222,17 +223,17 @@ public class DdlSqlToCommandConverter { RelDataType type = planner.convert(col.dataType); Object dflt = null; - assert col.expression == null || col.expression instanceof SqlLiteral; + // assert col.expression == null || col.expression instanceof SqlLiteral; - if (col.expression != null + if (col.expression != null) { + Type storageType = ctx.typeFactory().getResultClass(type); + DataContext dataCtx = new BaseDataContext(ctx.typeFactory()); + + // TODO: 17.03.2026 Надо будет тут что-то поменять дополнительно && (((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/main/java/org/apache/ignite/internal/processors/query/calcite/sql/generated/IgniteSqlParserImpl.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/generated/IgniteSqlParserImpl.java index 6929e12448d..f9e1e7d6014 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/generated/IgniteSqlParserImpl.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/generated/IgniteSqlParserImpl.java @@ -1287,7 +1287,7 @@ public class IgniteSqlParserImpl extends SqlAbstractParserImpl implements Ignite if (jj_2_97(2)) { jj_consume_token(DEFAULT_); s.add(this); - dflt = Literal(); + dflt = Expression(ExprContext.ACCEPT_ALL); strategy = ColumnStrategy.DEFAULT; } else { dflt = null; @@ -30440,7 +30440,7 @@ final String p; final private boolean jj_3_97() { if (jj_scan_token(DEFAULT_)) return true; - if (jj_3R_117()) return true; + if (jj_3R_81()) return true; return false; } diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/schema/AboutDefaultValueTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/schema/AboutDefaultValueTest.java new file mode 100644 index 00000000000..a68d6071a47 --- /dev/null +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/schema/AboutDefaultValueTest.java @@ -0,0 +1,33 @@ +package org.apache.ignite.internal.processors.query.calcite.schema; + +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.SqlConfiguration; +import org.apache.ignite.indexing.IndexingQueryEngineConfiguration; +import org.apache.ignite.internal.processors.query.calcite.integration.AbstractBasicIntegrationTest; +import org.junit.Test; + +public class AboutDefaultValueTest extends AbstractBasicIntegrationTest { + @Override protected int nodeCount() { + return 1; + } + + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + SqlConfiguration sqlCfg = new SqlConfiguration().setQueryEnginesConfiguration( + new CalciteQueryEngineConfiguration().setDefault(true), + new IndexingQueryEngineConfiguration() + ); + + return super.getConfiguration(igniteInstanceName) + .setSqlConfiguration(sqlCfg); + } + + @Test + public void name() { + sql("create table PERSON(id int primary key, birth_date TIMESTAMP DEFAULT (CURRENT_TIMESTAMP))"); + + sql("insert into PERSON(id) values(?)", 1); + + log.info(">>>> select: " + sql("select * from PERSON order by id")); + } +}
