You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by im...@apache.org on 2026/10/02 18:03:40 UTC

(asterixdb) branch master updated: [ASTERIXDB-3820][FUN] Make dimension a non-optional argument of isvector

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

parshimers 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 69e1554d0f [ASTERIXDB-3820][FUN] Make dimension a non-optional argument of isvector
69e1554d0f is described below

commit 69e1554d0f311fd693175d1ea095779ee9c78acc
Author: Le0shy <le...@gmail.com>
AuthorDate: Wed Sep 30 23:39:35 2026 -0700

    [ASTERIXDB-3820][FUN] Make dimension a non-optional argument of isvector
    
    - user model changes: yes
    - storage format changes: no
    - interface changes: no
    
    Details:
    isvector(v) without the optional dimension is no longer a user-facing
    function. The one-argument form stays registered privately for internal
    use. A dimension that is not a positive integer gives null and a
    warning, as isbitset does.
    
    Generated-by: Claude Opus 5.5 <no...@anthropic.com>
    Change-Id: I9c430dceeda94efc9ec57883f6ac91739a4f4993
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21957
    Reviewed-by: Ian Maxon <im...@apache.org>
    Integration-Tests: Ian Maxon <im...@apache.org>
    Reviewed-by: Hongyu Shi <le...@gmail.com>
    Tested-by: Ian Maxon <im...@apache.org>
---
 .../types/isvector/isvector.1.query.sqlpp          | 12 ++++-----
 .../types/isvector/isvector.2.query.sqlpp          | 21 +++++++++++++++
 ...vector.1.query.sqlpp => isvector.3.query.sqlpp} | 24 ++++++-----------
 .../results/types/isvector/isvector.1.adm          |  2 +-
 .../results/types/isvector/isvector.3.adm          |  1 +
 .../src/test/resources/runtimets/sqlpp_queries.xml |  7 ++++-
 .../asterix/om/functions/BuiltinFunctions.java     |  2 +-
 .../evaluators/functions/IsVectorDescriptor.java   | 31 +++++++++++++++++-----
 8 files changed, 68 insertions(+), 32 deletions(-)

diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.1.query.sqlpp
index 6450c2c96f..6f20b55eac 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.1.query.sqlpp
@@ -17,10 +17,9 @@
  * under the License.
  */
 
-// isvector(v) and isvector(v, dimension). Null and missing propagate as for the rest of the
-// is_* family, so "k" is null and "l" is absent rather than both being false.
+// isvector(v, dimension). Null and missing propagate as for the rest of the is_* family, so "k" is
+// null and "l" is absent rather than both being false.
 {
-  "a_ok":          isvector([0.2, 0.1, 0.4, 0.3]),
   "b_ok_dim":      isvector([0.2, 0.1, 0.4, 0.3], 4),
   "c_mixed":       isvector([0.2, 0.1, "s", 0.3], 4),
   "d_all_string":  isvector(["a", "b", "c", "d"], 4),
@@ -28,10 +27,9 @@
   "f_nested":      isvector([0.2, 0.1, [1], 0.3], 4),
   "g_short":       isvector([0.2, 0.1, 0.3], 4),
   "h_empty_dim":   isvector([], 4),
-  "i_empty_nodim": isvector([]),
-  "j_not_list":    isvector("x"),
-  "k_null":        isvector(null),
-  "l_missing":     isvector(missing),
+  "j_not_list":    isvector("x", 4),
+  "k_null":        isvector(null, 4),
+  "l_missing":     isvector(missing, 4),
   "m_integers":    isvector([1, 2, 3], 3),
   "n_underscore":  is_vector([1, 2, 3], 3)
 };
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.2.query.sqlpp
new file mode 100644
index 0000000000..1df8262f06
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.2.query.sqlpp
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+// The dimension is required: the one-argument form is not a user-facing function.
+isvector([0.2, 0.1, 0.4, 0.3]);
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.3.query.sqlpp
similarity index 50%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.1.query.sqlpp
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.3.query.sqlpp
index 6450c2c96f..25a06e3770 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/types/isvector/isvector.3.query.sqlpp
@@ -17,21 +17,13 @@
  * under the License.
  */
 
-// isvector(v) and isvector(v, dimension). Null and missing propagate as for the rest of the
-// is_* family, so "k" is null and "l" is absent rather than both being false.
+// A dimension that is not a positive integer gives null and a warning rather than an answer.
+// requesttype=application/json
+// param max-warnings:json=10
+
 {
-  "a_ok":          isvector([0.2, 0.1, 0.4, 0.3]),
-  "b_ok_dim":      isvector([0.2, 0.1, 0.4, 0.3], 4),
-  "c_mixed":       isvector([0.2, 0.1, "s", 0.3], 4),
-  "d_all_string":  isvector(["a", "b", "c", "d"], 4),
-  "e_null_elem":   isvector([0.2, 0.1, null, 0.3], 4),
-  "f_nested":      isvector([0.2, 0.1, [1], 0.3], 4),
-  "g_short":       isvector([0.2, 0.1, 0.3], 4),
-  "h_empty_dim":   isvector([], 4),
-  "i_empty_nodim": isvector([]),
-  "j_not_list":    isvector("x"),
-  "k_null":        isvector(null),
-  "l_missing":     isvector(missing),
-  "m_integers":    isvector([1, 2, 3], 3),
-  "n_underscore":  is_vector([1, 2, 3], 3)
+  "a_zero_dim":     isvector([1, 2, 3], 0),
+  "b_negative_dim": isvector([1, 2, 3], -1),
+  "c_fraction_dim": isvector([1, 2, 3], 2.5),
+  "d_string_dim":   isvector([1, 2, 3], "3")
 };
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isvector/isvector.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isvector/isvector.1.adm
index c9edfb0afc..5d617d8967 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isvector/isvector.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isvector/isvector.1.adm
@@ -1 +1 @@
-{ "a_ok": true, "b_ok_dim": true, "c_mixed": false, "d_all_string": false, "e_null_elem": false, "f_nested": false, "g_short": false, "h_empty_dim": false, "i_empty_nodim": false, "j_not_list": false, "k_null": null, "m_integers": true, "n_underscore": true }
+{ "b_ok_dim": true, "c_mixed": false, "d_all_string": false, "e_null_elem": false, "f_nested": false, "g_short": false, "h_empty_dim": false, "j_not_list": false, "k_null": null, "m_integers": true, "n_underscore": true }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isvector/isvector.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isvector/isvector.3.adm
new file mode 100644
index 0000000000..235739a8c1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/types/isvector/isvector.3.adm
@@ -0,0 +1 @@
+{ "a_zero_dim": null, "b_negative_dim": null, "c_fraction_dim": null, "d_string_dim": null }
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 55db4c0f46..666be3a4ae 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
@@ -15024,9 +15024,14 @@
         <output-dir compare="Text">isarray</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="types">
+    <test-case FilePath="types" check-warnings="true">
       <compilation-unit name="isvector">
         <output-dir compare="Text">isvector</output-dir>
+        <expected-error>ASX1081: Cannot find function with signature isvector(1)</expected-error>
+        <expected-warn>ASX0043: Value out of range, function asterix:is-vector#2 expects its 2nd input parameter value to be between 1 and 2147483647, received 0 (in line 25, at column 21)</expected-warn>
+        <expected-warn>ASX0043: Value out of range, function asterix:is-vector#2 expects its 2nd input parameter value to be between 1 and 2147483647, received -1 (in line 26, at column 21)</expected-warn>
+        <expected-warn>ASX0002: Type mismatch: function is-vector expects its 2nd input parameter to be of type bigint, but the actual input type is double (in line 27, at column 21)</expected-warn>
+        <expected-warn>ASX0002: Type mismatch: function is-vector expects its 2nd input parameter to be of type bigint, but the actual input type is string (in line 28, at column 21)</expected-warn>
       </compilation-unit>
     </test-case>
     <test-case FilePath="types">
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index 5ebf2a2c6c..9102c411ee 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -1431,7 +1431,7 @@ public class BuiltinFunctions {
         addFunction(IS_NUMBER, ABooleanTypeComputer.INSTANCE, true);
         addFunction(IS_STRING, ABooleanTypeComputer.INSTANCE, true);
         addFunction(IS_ARRAY, ABooleanTypeComputer.INSTANCE, true);
-        addFunction(IS_VECTOR, ABooleanTypeComputer.INSTANCE, true);
+        addPrivateFunction(IS_VECTOR, ABooleanTypeComputer.INSTANCE, true);
         addFunction(IS_VECTOR_WITH_DIMENSION, ABooleanTypeComputer.INSTANCE, true);
         addFunction(IS_OBJECT, ABooleanTypeComputer.INSTANCE, true);
         addFunction(IS_MULTISET, ABooleanTypeComputer.INSTANCE, true);
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsVectorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsVectorDescriptor.java
index 61b7a8bc8c..992dc8fd0b 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsVectorDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsVectorDescriptor.java
@@ -23,8 +23,10 @@ import java.io.DataOutput;
 import org.apache.asterix.common.annotations.MissingNullInOutFunction;
 import org.apache.asterix.dataflow.data.nontagged.serde.AObjectSerializerDeserializer;
 import org.apache.asterix.om.base.ABoolean;
+import org.apache.asterix.om.exceptions.ExceptionUtil;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.common.VectorValidator;
@@ -50,7 +52,7 @@ import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
  * </pre>
  * <p>
  * Null and missing propagate as for {@code is_array} and the rest of the {@code is_*} family, so
- * {@code isvector(null)} is {@code null} rather than {@code false}. Negating the call alone would
+ * {@code isvector(null, 4)} is {@code null} rather than {@code false}. Negating the call alone would
  * therefore leave out the rows whose field is null or absent, which the index skips too.
  * <p>
  * The function is <b>total</b> since {@link VectorValidator} never throws, which CLUSTER BY's usable-vector
@@ -94,7 +96,7 @@ public class IsVectorDescriptor extends AbstractScalarFunctionDynamicDescriptor
         }
     }
 
-    private static final class IsVectorEvaluator implements IScalarEvaluator {
+    private final class IsVectorEvaluator implements IScalarEvaluator {
 
         private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
         private final DataOutput out = resultStorage.getDataOutput();
@@ -103,8 +105,10 @@ public class IsVectorDescriptor extends AbstractScalarFunctionDynamicDescriptor
         private final IScalarEvaluator valueEval;
         private final IScalarEvaluator dimensionEval;
         private final VectorValidator validator = new VectorValidator();
+        private final IEvaluatorContext ctx;
 
         private IsVectorEvaluator(IScalarEvaluatorFactory[] args, IEvaluatorContext ctx) throws HyracksDataException {
+            this.ctx = ctx;
             valueEval = args[0].createScalarEvaluator(ctx);
             dimensionEval = args.length > 1 ? args[1].createScalarEvaluator(ctx) : null;
         }
@@ -122,10 +126,25 @@ public class IsVectorDescriptor extends AbstractScalarFunctionDynamicDescriptor
                     return;
                 }
             }
-            // Any dimension when none was given; getIntegerValue rejects a non-numeric second argument.
-            int dimension = dimensionEval == null ? -1
-                    : ATypeHierarchy.getIntegerValue(BuiltinFunctions.IS_VECTOR.getName(), 1,
-                            dimensionPtr.getByteArray(), dimensionPtr.getStartOffset());
+            // -1 means any length; only the internal one-argument form uses it.
+            int dimension = -1;
+            if (dimensionEval != null) {
+                byte[] bytes = dimensionPtr.getByteArray();
+                int offset = dimensionPtr.getStartOffset();
+                if (!PointableHelper.isValidLongValue(bytes, offset, true)) {
+                    PointableHelper.setNull(result);
+                    ExceptionUtil.warnTypeMismatch(ctx, sourceLoc, getIdentifier(), bytes[offset], 1, ATypeTag.BIGINT);
+                    return;
+                }
+                dimension = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 1, bytes, offset);
+                // The validator would read 0 or a negative dimension as "any length".
+                if (dimension < 1) {
+                    PointableHelper.setNull(result);
+                    ExceptionUtil.warnValueOutOfRange(ctx, sourceLoc, getIdentifier(), 1, 1, Integer.MAX_VALUE,
+                            dimension);
+                    return;
+                }
+            }
             boolean isVector = validator.isVector(valuePtr.getByteArray(), valuePtr.getStartOffset(),
                     valuePtr.getLength(), dimension);
             resultStorage.reset();