This is an automated email from the ASF dual-hosted git repository. tkalkirill pushed a commit to branch ignite-28223-add-rowid in repository https://gitbox.apache.org/repos/asf/ignite.git
commit d5456ad45777fb9dd65e7dc9886b860207a3c09d Author: Kirill Tkalenko <[email protected]> AuthorDate: Sat Mar 21 08:24:39 2026 +0300 IGNITE-28223-add-rowid wip --- .../calcite/integration/RowIdPseudoColumnTest.java | 59 ++++++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/RowIdPseudoColumnTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/RowIdPseudoColumnTest.java index f14f064ab9d..abf07392f40 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/RowIdPseudoColumnTest.java +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/RowIdPseudoColumnTest.java @@ -20,16 +20,25 @@ package org.apache.ignite.internal.processors.query.calcite.integration; import java.util.List; import org.apache.calcite.adapter.enumerable.NullPolicy; import org.apache.calcite.linq4j.tree.Expressions; +import org.apache.calcite.linq4j.tree.UnaryExpression; +import org.apache.calcite.sql.SqlBasicCall; +import org.apache.calcite.sql.SqlCall; import org.apache.calcite.sql.SqlFunction; import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.fun.SqlStdOperatorTable; +import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.sql.util.ReflectiveSqlOperatorTable; import org.apache.calcite.sql.util.SqlOperatorTables; +import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.tools.FrameworkConfig; import org.apache.calcite.tools.Frameworks; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.Ignition; import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; import org.apache.ignite.calcite.PseudoColumnDescriptor; import org.apache.ignite.calcite.PseudoColumnProvider; @@ -37,9 +46,14 @@ import org.apache.ignite.calcite.PseudoColumnValueExtractorContext; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.SqlConfiguration; import org.apache.ignite.indexing.IndexingQueryEngineConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; import org.apache.ignite.internal.processors.query.calcite.QueryChecker; +import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext; import org.apache.ignite.internal.processors.query.calcite.exec.exp.RexImpTable; +import org.apache.ignite.internal.processors.query.calcite.prepare.IgniteSqlCallRewriteTable; import org.apache.ignite.plugin.AbstractTestPluginProvider; import org.apache.ignite.plugin.PluginContext; import org.jetbrains.annotations.Nullable; @@ -65,13 +79,12 @@ public class RowIdPseudoColumnTest extends AbstractBasicIntegrationTest { } @Test - public void name() { + public void testSimplePrimaryKey() { sql("create table PUBLIC.PERSON(id int primary key, name varchar)"); for (int i = 0; i < 2; i++) sql("insert into PUBLIC.PERSON(id, name) values(?, ?)", i, "foo" + i); - // TODO: IGNITE-28223-add-rowid Вот тут теперь падает и можно дальше двигать assertQuery("select id, name, rowid from PUBLIC.PERSON where rowid = '0'") .columnNames("ID", "NAME", "ROWID") .matches(QueryChecker.containsIndexScan("PUBLIC", "PERSON", "_key_PK")) @@ -80,7 +93,9 @@ public class RowIdPseudoColumnTest extends AbstractBasicIntegrationTest { } /** */ - public static @Nullable Integer toKeyFromRowId(@Nullable String rowId) { + public static @Nullable Integer toKeyFromRowId(ExecutionContext<?> ctx, @Nullable String rowId) { + IgniteEx n = (IgniteEx) Ignition.ignite(ctx.localNodeId()); + return rowId == null ? null : Integer.parseInt(rowId); } @@ -113,13 +128,49 @@ public class RowIdPseudoColumnTest extends AbstractBasicIntegrationTest { RowIdPseudoColumnOperatorTable.TO_KEY_FROM_ROW_ID, RexImpTable.createRexCallImplementor((translator, call, translatedOperands) -> { var str = Expressions.convert_(translatedOperands.get(0), String.class); + var execCtx = Expressions.convert_(translator.getRoot(), ExecutionContext.class); - return Expressions.call(RowIdPseudoColumnTest.class, "toKeyFromRowId", str); + return Expressions.call(RowIdPseudoColumnTest.class, "toKeyFromRowId", execCtx, str); }, NullPolicy.ANY, false) ); + + IgniteSqlCallRewriteTable.INSTANCE.register( + SqlStdOperatorTable.EQUALS.getName(), + RowIdPseudoColumnTest::rewriteRowIdEquals + ); } } + /** */ + private static SqlCall rewriteRowIdEquals(SqlValidator validator, SqlCall call) { + List<SqlNode> operands = call.getOperandList(); + + if (operands.size() != 2) + return call; + + SqlNode left = operands.get(0); + SqlNode right = operands.get(1); + + if (!isRowId(left)) + return call; + + SqlParserPos pos = call.getParserPosition(); + SqlIdentifier keyId = new SqlIdentifier(QueryUtils.KEY_FIELD_NAME, pos); + SqlCall toKey = RowIdPseudoColumnOperatorTable.TO_KEY_FROM_ROW_ID.createCall(pos, right); + + return new SqlBasicCall(SqlStdOperatorTable.EQUALS, List.of(keyId, toKey), pos); + } + + /** */ + private static boolean isRowId(SqlNode node) { + if (!(node instanceof SqlIdentifier)) + return false; + + SqlIdentifier identifier = (SqlIdentifier)node; + + return identifier.names.size() == 1 && "ROWID".equalsIgnoreCase(identifier.getSimple()); + } + /** */ public static class RowIdPseudoColumnOperatorTable extends ReflectiveSqlOperatorTable { /** */
