You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mh...@apache.org on 2026/07/03 11:52:26 UTC

(asterixdb) branch master updated: [ASTERIXDB-3787][STO] Fix infinite loop reading array-nested union-typed columns

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

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 79bdb52312 [ASTERIXDB-3787][STO] Fix infinite loop reading array-nested union-typed columns
79bdb52312 is described below

commit 79bdb5231220fa3b2056d5dbbca6103e765f8007
Author: rithwik.koul <ri...@couchbase.com>
AuthorDate: Thu Jul 2 16:18:11 2026 +0530

    [ASTERIXDB-3787][STO] Fix infinite loop reading array-nested union-typed columns
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    PathExtractorVisitor.getReversedDelimiters() reversed the shared
    delimiters field in place via Collections.reverse instead of returning a
    reversed copy. The reader requires delimiter levels in descending order
    (largest nesting level first).
    
    For a union-typed leaf, getOrCreateReaders loops over the union's flat
    children, calling createReader -> getReversedDelimiters once per child.
    Each call re-reversed the same field, so odd-numbered children got the
    correct descending order and even-numbered children got it flipped back
    to ascending. With a single delimiter the flip is a no-op, so the bug
    only surfaced when the leaf sat under two or more nested arrays.
    
    An ascending delimiter array corrupts
    RepeatedPrimitiveColumnValuesReader: levelToDelimiterMap is built wrong
    and setDelimiterIndex uses the wrong threshold, so
    isDelimiter()/getDelimiterIndex() never reach the value
    EndOfRepeatedGroupAssembler waits for. The group-end condition never
    fires, the assembler keeps jumping back to the group's first value, and
    the query spins forever on the same tuple.
    
    Ex-ref: MB-72388
    Change-Id: Ib4c961272a6eea730efeb7d75c95cd9ea72e9aaa
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21392
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Ritik Raj <ri...@couchbase.com>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Rithwik Koul <ri...@couchbase.com>
---
 .../nested-array-mixed-type-empty.001.ddl.sqlpp    | 38 ++++++++++++++++++++++
 .../nested-array-mixed-type-empty.002.update.sqlpp | 34 +++++++++++++++++++
 .../nested-array-mixed-type-empty.003.query.sqlpp  | 27 +++++++++++++++
 .../nested-array-mixed-type-empty.003.adm          |  0
 .../src/test/resources/runtimets/sqlpp_queries.xml |  5 +++
 .../schema/visitor/PathExtractorVisitor.java       | 11 +++++--
 6 files changed, 113 insertions(+), 2 deletions(-)

diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.001.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.001.ddl.sqlpp
new file mode 100644
index 0000000000..522a8047d8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.001.ddl.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description  : Minimal reproduction of the column-filter hang: a filter on a field reached through two
+ *                nested array unnests, where the compared leaf holds mixed numeric types (int and double)
+ *                and is therefore a UNION column, and the predicate matches no row. This used to hang
+ *                forever while building the repeated column readers.
+ * Expected Res : Success (empty result)
+ */
+
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+
+USE test;
+
+CREATE DATASET test PRIMARY KEY (id: string)
+WITH {
+    "storage-format": {
+        "format": "column"
+    }
+};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.002.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.002.update.sqlpp
new file mode 100644
index 0000000000..8c3d0d2489
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.002.update.sqlpp
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE test;
+
+UPSERT INTO test ({
+    "id": "1",
+    "payload": {
+        "array_field": [
+            {
+                "nested_array": [
+                    { "field_1": "val1", "field_2": { "field3": 25 } },
+                    { "field_1": "val2", "field_2": { "field3": 25.6 } }
+                ]
+            }
+        ]
+    }
+});
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.003.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.003.query.sqlpp
new file mode 100644
index 0000000000..0d1d5ba87c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.003.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+USE test;
+
+SELECT *
+FROM test t
+UNNEST t.payload.array_field n1
+UNNEST n1.nested_array n2
+WHERE n2.field_1 = "val1"
+  AND n2.field_2.field3 > 100;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.003.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/column/filter/nested-array-mixed-type-empty/nested-array-mixed-type-empty.003.adm
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
index d4437c01af..a1acc30442 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
@@ -16760,6 +16760,11 @@
         <output-dir compare="Text">filter/ASTERIXDB-3582-2</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="column">
+      <compilation-unit name="filter/nested-array-mixed-type-empty">
+        <output-dir compare="Text">filter/nested-array-mixed-type-empty</output-dir>
+      </compilation-unit>
+    </test-case>
     <test-case FilePath="column">
       <compilation-unit name="filter/double">
         <output-dir compare="Text">filter/double</output-dir>
diff --git a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/metadata/schema/visitor/PathExtractorVisitor.java b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/metadata/schema/visitor/PathExtractorVisitor.java
index 1b63361b94..d2ef16576f 100644
--- a/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/metadata/schema/visitor/PathExtractorVisitor.java
+++ b/asterixdb/asterix-column/src/main/java/org/apache/asterix/column/metadata/schema/visitor/PathExtractorVisitor.java
@@ -138,7 +138,14 @@ public class PathExtractorVisitor implements ISchemaNodeVisitor<AbstractSchemaNo
     }
 
     private int[] getReversedDelimiters() {
-        Collections.reverse(delimiters);
-        return delimiters.toIntArray();
+        // toIntArray() returns a fresh copy; reverse the copy so the shared delimiters list is left intact for the
+        // next reader built from the same path (e.g., each branch of a union-typed leaf).
+        int[] reversed = delimiters.toIntArray();
+        for (int i = 0, j = reversed.length - 1; i < j; i++, j--) {
+            int tmp = reversed[i];
+            reversed[i] = reversed[j];
+            reversed[j] = tmp;
+        }
+        return reversed;
     }
 }