This is an automated email from the ASF dual-hosted git repository.

korlov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 71bdb3b6adc IGNITE-26943 Sql. NPE when running aggregated query over 
system view (#6904)
71bdb3b6adc is described below

commit 71bdb3b6adcb5b6479a070098d3dd56a0cc44a20
Author: korlov42 <[email protected]>
AuthorDate: Thu Nov 6 11:38:16 2025 +0200

    IGNITE-26943 Sql. NPE when running aggregated query over system view (#6904)
---
 .../sql/engine/systemviews/ItSystemViewsTest.java        | 11 +++++++++--
 .../sql/engine/rel/ProjectableFilterableTableScan.java   | 16 ++++++++++------
 .../apache/ignite/internal/sql/engine/util/RexUtils.java | 13 ++++---------
 3 files changed, 23 insertions(+), 17 deletions(-)

diff --git 
a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/systemviews/ItSystemViewsTest.java
 
b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/systemviews/ItSystemViewsTest.java
index bab9f693091..946e998758c 100644
--- 
a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/systemviews/ItSystemViewsTest.java
+++ 
b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/systemviews/ItSystemViewsTest.java
@@ -52,7 +52,7 @@ public class ItSystemViewsTest extends AbstractSystemViewTest 
{
 
     @ParameterizedTest
     @EnumSource(KnownSystemView.class)
-    public void systemViewWithGivenNameExists(KnownSystemView view) {
+    void systemViewWithGivenNameExists(KnownSystemView view) {
         assertQuery(format("SELECT count(*) FROM {}", view.canonicalName()))
                 // for this test it's enough to check presence of the row,
                 // because we are interested in whether the view is available 
for
@@ -63,7 +63,7 @@ public class ItSystemViewsTest extends AbstractSystemViewTest 
{
 
     @ParameterizedTest
     @EnumSource(KnownSystemView.class)
-    public void 
systemViewWithGivenNamePresentedInSystemViewsView(KnownSystemView view) {
+    void systemViewWithGivenNamePresentedInSystemViewsView(KnownSystemView 
view) {
         assertQuery(format("SELECT * FROM {} WHERE schema = ? AND name = ?", 
SYSTEM_VIEWS.canonicalName()))
                 .withParams(view.schema, view.name)
                 .returnSomething()
@@ -124,4 +124,11 @@ public class ItSystemViewsTest extends 
AbstractSystemViewTest {
                 .returnSomething()
                 .check();
     }
+
+    @Test
+    void aggregatedQueryOverSystemViewDoesntThrow() {
+        assertQuery("SELECT COUNT(*) FROM system.system_view_columns WHERE 
view_name LIKE '%' GROUP BY view_id")
+                .returnSomething()
+                .check();
+    }
 }
diff --git 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/ProjectableFilterableTableScan.java
 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/ProjectableFilterableTableScan.java
index ca2f298b1b1..3a3f61b02e4 100644
--- 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/ProjectableFilterableTableScan.java
+++ 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/ProjectableFilterableTableScan.java
@@ -49,7 +49,6 @@ import org.apache.calcite.util.mapping.Mappings;
 import org.apache.ignite.internal.sql.engine.metadata.cost.IgniteCost;
 import org.apache.ignite.internal.sql.engine.rel.explain.IgniteRelWriter;
 import org.apache.ignite.internal.sql.engine.schema.IgniteDataSource;
-import org.apache.ignite.internal.sql.engine.schema.IgniteTable;
 import org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory;
 import org.apache.ignite.internal.sql.engine.util.Commons;
 import org.apache.ignite.internal.sql.engine.util.RexUtils;
@@ -207,16 +206,21 @@ public abstract class ProjectableFilterableTableScan 
extends TableScan {
      * PushUpPredicate.
      * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
      */
-    public RexNode pushUpPredicate() {
+    public @Nullable RexNode pushUpPredicate() {
         if (condition == null || projects == null) {
             return replaceLocalRefs(condition);
         }
 
         IgniteTypeFactory typeFactory = Commons.typeFactory(getCluster());
-        IgniteTable tbl = getTable().unwrap(IgniteTable.class);
-
-        Mappings.TargetMapping mapping = RexUtils.inversePermutation(projects,
-                tbl.getRowType(typeFactory, requiredColumns), true);
+        //noinspection DataFlowIssue: TableScan always has table
+        IgniteDataSource dataSource = 
getTable().unwrap(IgniteDataSource.class);
+
+        //noinspection DataFlowIssue: this class supports only tables which 
are derived from IgniteDataSource
+        Mappings.TargetMapping mapping = RexUtils.inversePermutation(
+                projects,
+                dataSource.getRowType(typeFactory, requiredColumns),
+                true
+        );
 
         RexShuttle shuttle = new RexShuttle() {
             @Override
diff --git 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/RexUtils.java
 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/RexUtils.java
index 38ec6fa6666..4823bd4eb51 100644
--- 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/RexUtils.java
+++ 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/RexUtils.java
@@ -1013,18 +1013,13 @@ public class RexUtils {
         return InputRefReplacer.INSTANCE.apply(node);
     }
 
-    /**
-     * ReplaceLocalRefs.
-     * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
-     */
-    public static RexNode replaceLocalRefs(RexNode node) {
+    /** Replaces all occurrences of {@link RexLocalRef} within given list of 
nodes with {@link RexInputRef}. */
+    public static RexNode replaceLocalRefs(@Nullable RexNode node) {
+        //noinspection DataFlowIssue: RexShuttle expects null as input.
         return LocalRefReplacer.INSTANCE.apply(node);
     }
 
-    /**
-     * ReplaceLocalRefs.
-     * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
-     */
+    /** Replaces all occurrences of {@link RexLocalRef} within given rex node 
with {@link RexInputRef}. */
     public static List<RexNode> replaceLocalRefs(List<RexNode> nodes) {
         return LocalRefReplacer.INSTANCE.apply(nodes);
     }

Reply via email to