You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2026/05/21 20:32:54 UTC
[XL] Change in asterixdb[master]: Add sparse-vector-dot-product function
From Savyasach Reddy <es...@gmail.com>:
Savyasach Reddy has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21274?usp=email )
Change subject: Add sparse-vector-dot-product function
......................................................................
Add sparse-vector-dot-product function
Change-Id: I57de625366800bf4f64ad9d0705211ac29db8336
---
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.2.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.3.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.5.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.6.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.2.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.3.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.2.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.3.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.2.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.3.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.5.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.3.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.4.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.5.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.6.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.3.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.3.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.4.adm
M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ATypeTag.java
A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/sparsevector/SparseVectorDotProductDescriptor.java
A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/sparsevector/SparseVectorDotProductEvaluator.java
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
31 files changed, 1,057 insertions(+), 0 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/74/21274/1
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.1.ddl.sqlpp
new file mode 100644
index 0000000..13f3613
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.1.ddl.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type test.DocType as open { id: int32 };
+create dataset test.Docs(DocType) primary key id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.2.update.sqlpp
new file mode 100644
index 0000000..98aac80
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.2.update.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+insert into Docs select element {"id": 1, "vec": {"indices": [1, 2, 3], "values": [1.0f, 2.0f, 3.0f]}};
+insert into Docs select element {"id": 2, "vec": {"indices": [1, 4], "values": [5.0f, 2.0f]}};
+insert into Docs select element {"id": 3, "vec": {"indices": [2, 3, 4], "values": [3.0f, 4.0f, 1.0f]}};
+insert into Docs select element {"id": 4, "vec": {"indices": [5, 6], "values": [7.0f, 8.0f]}};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.3.query.sqlpp
new file mode 100644
index 0000000..168641a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.3.query.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+with
+ q32 as {"indices": [1, 3, 5], "values": [1.0f, 2.0f, 3.0f]},
+ doc1 as {"indices": [1, 2, 3], "values": [4.0f, 5.0f, 6.0f]},
+ doc2 as {"indices": [2, 4, 6], "values": [1.0f, 1.0f, 1.0f]},
+ doc3 as {"indices": [1, 3, 5], "values": [2.0f, 2.0f, 2.0f]},
+ doc4 as {"indices": [5], "values": [10.0f]},
+ q64 as {"indices": [bigint("100"), bigint("200"), bigint("300")], "values": [1.0, 0.5, 2.0]},
+ d64_1 as {"indices": [bigint("100"), bigint("200")], "values": [3.0, 4.0]},
+ d64_2 as {"indices": [bigint("300"), bigint("400")], "values": [1.5, 9.9]},
+ d64_3 as {"indices": [bigint("400"), bigint("500")], "values": [1.0, 1.0]},
+ qmix as {"indices": [1, 2], "values": [1.0, 2.0]},
+ dmix as {"indices": [1, 3], "values": [3.0, 4.0]},
+ empty as {"indices": [], "values": []},
+ a as {"indices": [1, 2], "values": [2.0f, 3.0f]},
+ b as {"indices": [2, 3], "values": [5.0f, 7.0f]},
+ noIdx as {"values": [1.0f]},
+ noVal as {"indices": [1]}
+select
+ test.`sparse-vector-dot-product`(q32, doc1) as p_partial,
+ test.`sparse-vector-dot-product`(q32, doc2) as p_nolap,
+ test.`sparse-vector-dot-product`(q32, doc3) as p_full,
+ test.`sparse-vector-dot-product`(q32, doc4) as p_single,
+ test.`sparse-vector-dot-product`(q64, d64_1) as p_i64_partial,
+ test.`sparse-vector-dot-product`(q64, d64_2) as p_i64_single,
+ test.`sparse-vector-dot-product`(q64, d64_3) as p_i64_nolap,
+ test.`sparse-vector-dot-product`(qmix, dmix) as p_mixed,
+ test.`sparse-vector-dot-product`(empty, doc1) as p_empty_q,
+ test.`sparse-vector-dot-product`(doc1, empty) as p_empty_d,
+ test.`sparse-vector-dot-product`(empty, empty) as p_empty_both,
+ test.`sparse-vector-dot-product`(a, b) as p_comm_ab,
+ test.`sparse-vector-dot-product`(b, a) as p_comm_ba,
+ test.`sparse-vector-dot-product`(null, doc1) as p_null_q,
+ test.`sparse-vector-dot-product`(doc1, null) as p_null_d,
+ test.`sparse-vector-dot-product`(null, null) as p_null_both,
+ test.`sparse-vector-dot-product`(missing, doc1) as p_miss_q,
+ test.`sparse-vector-dot-product`(doc1, missing) as p_miss_d,
+ test.`sparse-vector-dot-product`(q32, noIdx) as p_no_idx,
+ test.`sparse-vector-dot-product`(q32, noVal) as p_no_val;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.4.query.sqlpp
new file mode 100644
index 0000000..2b16d31
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.4.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+with query_vec as {"indices": [1, 2, 3], "values": [1.0f, 1.0f, 1.0f]}
+select d.id, test.`sparse-vector-dot-product`(query_vec, d.vec) as score
+from Docs d
+order by score desc, d.id asc;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.5.query.sqlpp
new file mode 100644
index 0000000..4abebbb
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.5.query.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+with
+ null_idx as {"indices": null, "values": [1.0f, 2.0f]},
+ null_val as {"indices": [1, 2], "values": null},
+ ca as {"indices": [1, 2], "values": [1.0f, 2.0f]},
+ cb as {"indices": [2, 3], "values": [3.0f, 4.0f]},
+ dup as {"indices": [1, 1], "values": [2.0f, 3.0f]},
+ one_doc as {"indices": [1], "values": [4.0f]},
+ neg_q as {"indices": [-1, 2], "values": [1.0f, 2.0f]},
+ neg_d as {"indices": [-1, 3], "values": [3.0f, 4.0f]},
+ mix_v_q as {"indices": [1, 2], "values": [1.0f, 2.0]},
+ mix_v_d as {"indices": [1, 2], "values": [3.0f, 4.0]},
+ mix_i_q as {"indices": [1, bigint("2")], "values": [1.0f, 2.0f]},
+ mix_i_d as {"indices": [1, bigint("2")], "values": [3.0f, 4.0f]}
+select
+ test.`sparse-vector-dot-product`(null_idx, ca) as p_null_idx,
+ test.`sparse-vector-dot-product`(null_val, ca) as p_null_val,
+ test.`sparse-vector-dot-product`(ca, cb) as p_both_stable,
+ test.`sparse-vector-dot-product`(dup, one_doc) as p_dup_idx,
+ test.`sparse-vector-dot-product`(neg_q, neg_d) as p_neg_idx,
+ test.`sparse-vector-dot-product`(mix_v_q, mix_v_d) as p_mixed_vals,
+ test.`sparse-vector-dot-product`(mix_i_q, mix_i_d) as p_mixed_idxs;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.6.query.sqlpp
new file mode 100644
index 0000000..1bb8ec7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.6.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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 d.id as did, e.id as eid,
+ test.`sparse-vector-dot-product`(d.vec, e.vec) as score
+from Docs d, Docs e
+where d.id <= 2 and e.id <= 2
+order by d.id, e.id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.1.ddl.sqlpp
new file mode 100644
index 0000000..13f3613
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.1.ddl.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type test.DocType as open { id: int32 };
+create dataset test.Docs(DocType) primary key id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.2.update.sqlpp
new file mode 100644
index 0000000..98aac80
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.2.update.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+insert into Docs select element {"id": 1, "vec": {"indices": [1, 2, 3], "values": [1.0f, 2.0f, 3.0f]}};
+insert into Docs select element {"id": 2, "vec": {"indices": [1, 4], "values": [5.0f, 2.0f]}};
+insert into Docs select element {"id": 3, "vec": {"indices": [2, 3, 4], "values": [3.0f, 4.0f, 1.0f]}};
+insert into Docs select element {"id": 4, "vec": {"indices": [5, 6], "values": [7.0f, 8.0f]}};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.3.query.sqlpp
new file mode 100644
index 0000000..2907206
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.3.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+with query_vec as {"indices": [1, 2, 3], "values": [1.0f, 1.0f, 1.0f]}
+select d.id, test.`sparse-vector-dot-product`(d.vec, query_vec) as score
+from Docs d
+order by score desc, d.id asc;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.1.ddl.sqlpp
new file mode 100644
index 0000000..7557e8a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.1.ddl.sqlpp
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type test.SparseVecType as closed {
+ indices: [int32],
+ values: [float]
+};
+
+create type test.DocType as closed {
+ id: int32,
+ vec: SparseVecType
+};
+
+create dataset test.Docs(DocType) primary key id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.2.update.sqlpp
new file mode 100644
index 0000000..98aac80
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.2.update.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+insert into Docs select element {"id": 1, "vec": {"indices": [1, 2, 3], "values": [1.0f, 2.0f, 3.0f]}};
+insert into Docs select element {"id": 2, "vec": {"indices": [1, 4], "values": [5.0f, 2.0f]}};
+insert into Docs select element {"id": 3, "vec": {"indices": [2, 3, 4], "values": [3.0f, 4.0f, 1.0f]}};
+insert into Docs select element {"id": 4, "vec": {"indices": [5, 6], "values": [7.0f, 8.0f]}};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.3.query.sqlpp
new file mode 100644
index 0000000..2b16d31
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.3.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+with query_vec as {"indices": [1, 2, 3], "values": [1.0f, 1.0f, 1.0f]}
+select d.id, test.`sparse-vector-dot-product`(query_vec, d.vec) as score
+from Docs d
+order by score desc, d.id asc;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.4.query.sqlpp
new file mode 100644
index 0000000..2907206
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.4.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+with query_vec as {"indices": [1, 2, 3], "values": [1.0f, 1.0f, 1.0f]}
+select d.id, test.`sparse-vector-dot-product`(d.vec, query_vec) as score
+from Docs d
+order by score desc, d.id asc;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.1.ddl.sqlpp
new file mode 100644
index 0000000..132ea6d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.1.ddl.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.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.2.query.sqlpp
new file mode 100644
index 0000000..cb7b8f0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.2.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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 element test.`sparse-vector-dot-product`(42, {"indices": [1], "values": [1.0f]});
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.3.query.sqlpp
new file mode 100644
index 0000000..cf1b676
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.3.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+/*
+ * Passing a non-record as the second argument must raise ASX0002 TypeMismatch.
+ */
+
+use test;
+
+select element test.`sparse-vector-dot-product`({"indices": [1], "values": [1.0f]}, 42);
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.4.query.sqlpp
new file mode 100644
index 0000000..51137e2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.4.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * 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 element test.`sparse-vector-dot-product`(
+ {"indices": [1, 2], "values": [1.0f]},
+ {"indices": [1], "values": [1.0f]});
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.5.query.sqlpp
new file mode 100644
index 0000000..6a1e27a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sparse-vector/sparse-vector-dot-product_errors/sparse-vector-dot-product_errors.5.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * 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 element test.`sparse-vector-dot-product`(
+ {"indices": ["a"], "values": [1.0f]},
+ {"indices": [1], "values": [1.0f]});
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.3.adm
new file mode 100644
index 0000000..573f663
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.3.adm
@@ -0,0 +1 @@
+{ "p_partial": 16.0, "p_nolap": 0.0, "p_full": 12.0, "p_single": 30.0, "p_i64_partial": 5.0, "p_i64_single": 3.0, "p_i64_nolap": 0.0, "p_mixed": 3.0, "p_empty_q": 0.0, "p_empty_d": 0.0, "p_empty_both": 0.0, "p_comm_ab": 15.0, "p_comm_ba": 15.0, "p_null_q": null, "p_null_d": null, "p_null_both": null, "p_no_idx": 0.0, "p_no_val": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.4.adm
new file mode 100644
index 0000000..95b4503
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.4.adm
@@ -0,0 +1,4 @@
+{ "id": 3, "score": 7.0 }
+{ "id": 1, "score": 6.0 }
+{ "id": 2, "score": 5.0 }
+{ "id": 4, "score": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.5.adm
new file mode 100644
index 0000000..fe5abcf
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.5.adm
@@ -0,0 +1 @@
+{ "p_null_idx": null, "p_null_val": null, "p_both_stable": 6.0, "p_dup_idx": 12.0, "p_neg_idx": 3.0, "p_mixed_vals": 11.0, "p_mixed_idxs": 11.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.6.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.6.adm
new file mode 100644
index 0000000..8c6ec71
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product/sparse-vector-dot-product.6.adm
@@ -0,0 +1,4 @@
+{ "did": 1, "eid": 1, "score": 14.0 }
+{ "did": 1, "eid": 2, "score": 5.0 }
+{ "did": 2, "eid": 1, "score": 5.0 }
+{ "did": 2, "eid": 2, "score": 29.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.3.adm
new file mode 100644
index 0000000..95b4503
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_arg1-query/sparse-vector-dot-product_arg1-query.3.adm
@@ -0,0 +1,4 @@
+{ "id": 3, "score": 7.0 }
+{ "id": 1, "score": 6.0 }
+{ "id": 2, "score": 5.0 }
+{ "id": 4, "score": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.3.adm
new file mode 100644
index 0000000..95b4503
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.3.adm
@@ -0,0 +1,4 @@
+{ "id": 3, "score": 7.0 }
+{ "id": 1, "score": 6.0 }
+{ "id": 2, "score": 5.0 }
+{ "id": 4, "score": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.4.adm
new file mode 100644
index 0000000..95b4503
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sparse-vector/sparse-vector-dot-product_closed/sparse-vector-dot-product_closed.4.adm
@@ -0,0 +1,4 @@
+{ "id": 3, "score": 7.0 }
+{ "id": 1, "score": 6.0 }
+{ "id": 2, "score": 5.0 }
+{ "id": 4, "score": 0.0 }
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 b4672e1..227edc7 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
@@ -10554,6 +10554,32 @@
</compilation-unit>
</test-case>
</test-group>
+ <test-group name="sparse-vector">
+ <test-case FilePath="sparse-vector">
+ <compilation-unit name="sparse-vector-dot-product">
+ <output-dir compare="Text">sparse-vector-dot-product</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="sparse-vector">
+ <compilation-unit name="sparse-vector-dot-product_closed">
+ <output-dir compare="Text">sparse-vector-dot-product_closed</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="sparse-vector">
+ <compilation-unit name="sparse-vector-dot-product_arg1-query">
+ <output-dir compare="Text">sparse-vector-dot-product_arg1-query</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="sparse-vector">
+ <compilation-unit name="sparse-vector-dot-product_errors">
+ <output-dir compare="Text">none</output-dir>
+ <expected-error>ASX0002: Type mismatch: function sparse-vector-dot-product expects its 1st input parameter to be of type object, but the actual input type is bigint</expected-error>
+ <expected-error>ASX0002: Type mismatch: function sparse-vector-dot-product expects its 2nd input parameter to be of type object, but the actual input type is bigint</expected-error>
+ <expected-error>ASX0006: Invalid format for sparse vector: indices and values arrays must have equal length in sparse-vector-dot-product</expected-error>
+ <expected-error>ASX0002: Type mismatch: function sparse-vector-dot-product expects its 1st input parameter to be of type integer or bigint, but the actual input type is string</expected-error>
+ </compilation-unit>
+ </test-case>
+ </test-group>
<test-group name="spatial">
<test-case FilePath="spatial">
<compilation-unit name="cell-aggregation-with-filtering">
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 4ca36d3..f98e20a 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
@@ -855,6 +855,9 @@
public static final FunctionIdentifier PREFIX_LEN_JACCARD = FunctionConstants.newAsterix("prefix-len-jaccard", 2);
+ public static final FunctionIdentifier SPARSE_VECTOR_DOT_PRODUCT =
+ FunctionConstants.newAsterix("sparse-vector-dot-product", 2);
+
public static final FunctionIdentifier SIMILARITY_JACCARD = FunctionConstants.newAsterix("similarity-jaccard", 2);
public static final FunctionIdentifier SIMILARITY_JACCARD_CHECK =
FunctionConstants.newAsterix("similarity-jaccard-check", 3);
@@ -1926,6 +1929,7 @@
// Similarity functions
addFunction(EDIT_DISTANCE_CONTAINS, OrderedListOfAnyTypeComputer.INSTANCE, true);
+ addFunction(SPARSE_VECTOR_DOT_PRODUCT, ADoubleTypeComputer.INSTANCE, true);
addFunction(SIMILARITY_JACCARD, AFloatTypeComputer.INSTANCE, true);
addFunction(SIMILARITY_JACCARD_CHECK, OrderedListOfAnyTypeComputer.INSTANCE, true);
addPrivateFunction(SIMILARITY_JACCARD_SORTED, AFloatTypeComputer.INSTANCE, true);
@@ -3253,6 +3257,7 @@
similarityFunctions.add(EDIT_DISTANCE);
similarityFunctions.add(EDIT_DISTANCE_CHECK);
similarityFunctions.add(EDIT_DISTANCE_CONTAINS);
+ similarityFunctions.add(SPARSE_VECTOR_DOT_PRODUCT);
}
public static boolean isSimilarityFunction(FunctionIdentifier fi) {
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ATypeTag.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ATypeTag.java
index 53ae805..7559fa4 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ATypeTag.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ATypeTag.java
@@ -102,6 +102,7 @@
public static final byte SERIALIZED_BINARY_TYPE_TAG = BINARY.serialize();
public static final byte SERIALIZED_UUID_TYPE_TAG = UUID.serialize();
public static final byte SERIALIZED_GEOMETRY_TYPE_TAG = GEOMETRY.serialize();
+ public static final byte SERIALIZED_ANY_TYPE_TAG = ANY.serialize();
/*
* Serialized Tags end
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/sparsevector/SparseVectorDotProductDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/sparsevector/SparseVectorDotProductDescriptor.java
new file mode 100644
index 0000000..de9fce9
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/sparsevector/SparseVectorDotProductDescriptor.java
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+package org.apache.asterix.runtime.evaluators.functions.sparsevector;
+
+import java.io.Serial;
+
+import org.apache.asterix.common.annotations.MissingNullInOutFunction;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.om.functions.IFunctionTypeInferer;
+import org.apache.asterix.om.typecomputer.impl.TypeComputeUtils;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.asterix.om.utils.RecordUtil;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.functions.FunctionTypeInferers;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IEvaluatorContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+@MissingNullInOutFunction
+public class SparseVectorDotProductDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+ @Serial
+ private static final long serialVersionUID = 1L;
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new SparseVectorDotProductDescriptor();
+ }
+
+ @Override
+ public IFunctionTypeInferer createFunctionTypeInferer() {
+ return FunctionTypeInferers.SET_ARGUMENTS_TYPE;
+ }
+ };
+
+ private ARecordType arg0RecType = RecordUtil.FULLY_OPEN_RECORD_TYPE;
+ private ARecordType arg1RecType = RecordUtil.FULLY_OPEN_RECORD_TYPE;
+
+ @Override
+ public void setImmutableStates(Object... states) {
+ if (states.length < 2) {
+ return;
+ }
+ ARecordType t0 = TypeComputeUtils.extractRecordType((IAType) states[0]);
+ ARecordType t1 = TypeComputeUtils.extractRecordType((IAType) states[1]);
+ arg0RecType = t0 != null ? t0 : RecordUtil.FULLY_OPEN_RECORD_TYPE;
+ arg1RecType = t1 != null ? t1 : RecordUtil.FULLY_OPEN_RECORD_TYPE;
+ }
+
+ @Override
+ public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+ final ARecordType capturedArg0RecType = arg0RecType;
+ final ARecordType capturedArg1RecType = arg1RecType;
+ return new IScalarEvaluatorFactory() {
+ @Serial
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public IScalarEvaluator createScalarEvaluator(IEvaluatorContext ctx) throws HyracksDataException {
+ return new SparseVectorDotProductEvaluator(args, ctx, capturedArg0RecType, capturedArg1RecType);
+ }
+ };
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.SPARSE_VECTOR_DOT_PRODUCT;
+ }
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/sparsevector/SparseVectorDotProductEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/sparsevector/SparseVectorDotProductEvaluator.java
new file mode 100644
index 0000000..479d3cc
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/sparsevector/SparseVectorDotProductEvaluator.java
@@ -0,0 +1,399 @@
+/*
+ * 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.
+ */
+package org.apache.asterix.runtime.evaluators.functions.sparsevector;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
+import org.apache.asterix.om.base.ADouble;
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.base.AMutableString;
+import org.apache.asterix.om.base.AString;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.pointables.ARecordVisitablePointable;
+import org.apache.asterix.om.pointables.base.IVisitablePointable;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.runtime.evaluators.common.OrderedListIterator;
+import org.apache.asterix.runtime.evaluators.functions.PointableHelper;
+import org.apache.asterix.runtime.exceptions.InvalidDataFormatException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IEvaluatorContext;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+/**
+ * Computes the dot product of two sparse vectors, each represented as a record
+ * with fields {@code indices} (int32 or int64 array) and {@code values} (float or double array).
+ * <p>
+ * The evaluator detects which argument is stable across tuple evaluations and caches
+ * its index-to-value map accordingly. Each argument's content is compared against its
+ * own previous bytes: if arg1 is stable and arg0 is not, arg1 is used as the query side;
+ * otherwise arg0 is.
+ */
+public class SparseVectorDotProductEvaluator implements IScalarEvaluator {
+
+ private static final byte[] INDICES_FIELD_NAME;
+ private static final byte[] VALUES_FIELD_NAME;
+
+ static {
+ try {
+ INDICES_FIELD_NAME = serializeFieldName("indices");
+ VALUES_FIELD_NAME = serializeFieldName("values");
+ } catch (HyracksDataException e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static byte[] serializeFieldName(String name) throws HyracksDataException {
+ ArrayBackedValueStorage storage = new ArrayBackedValueStorage();
+ ISerializerDeserializer<AString> strSerde =
+ SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
+ strSerde.serialize(new AMutableString(name), storage.getDataOutput());
+ byte[] bytes = new byte[storage.getLength()];
+ System.arraycopy(storage.getByteArray(), storage.getStartOffset(), bytes, 0, storage.getLength());
+ return bytes;
+ }
+
+ private final IScalarEvaluator arg0VecEval;
+ private final IScalarEvaluator arg1VecEval;
+
+ private final IPointable arg0Ptr = new VoidPointable();
+ private final IPointable arg1Ptr = new VoidPointable();
+
+ private final ARecordVisitablePointable arg0Recordable;
+ private final ARecordVisitablePointable arg1Recordable;
+
+ private final OrderedListIterator queryIndicesIter = new OrderedListIterator();
+ private final OrderedListIterator queryValuesIter = new OrderedListIterator();
+ private final OrderedListIterator docIndicesIter = new OrderedListIterator();
+ private final OrderedListIterator docValuesIter = new OrderedListIterator();
+
+ private final Map<Long, Double> queryMap = new HashMap<>();
+
+ private byte[] cachedArg0Bytes = new byte[0];
+ private int cachedArg0Len = 0;
+ private byte[] cachedArg1Bytes = new byte[0];
+ private int cachedArg1Len = 0;
+
+ // Content snapshot of the last query-side vector, used to skip rebuilding queryMap
+ private byte[] cachedQueryBytes = new byte[0];
+ private int cachedQueryBytesLen = 0;
+
+ private boolean resultIsNull = false;
+
+ private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+ private final DataOutput out = resultStorage.getDataOutput();
+ private final AMutableDouble aDouble = new AMutableDouble(0);
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ADouble> doubleSerde =
+ SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
+
+ public SparseVectorDotProductEvaluator(IScalarEvaluatorFactory[] args, IEvaluatorContext ctx,
+ ARecordType arg0RecType, ARecordType arg1RecType) throws HyracksDataException {
+ arg0VecEval = args[0].createScalarEvaluator(ctx);
+ arg1VecEval = args[1].createScalarEvaluator(ctx);
+ arg0Recordable = new ARecordVisitablePointable(arg0RecType);
+ arg1Recordable = new ARecordVisitablePointable(arg1RecType);
+ }
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
+ resultStorage.reset();
+ resultIsNull = false;
+
+ arg0VecEval.evaluate(tuple, arg0Ptr);
+ arg1VecEval.evaluate(tuple, arg1Ptr);
+
+ if (PointableHelper.checkAndSetMissingOrNull(result, arg0Ptr, arg1Ptr)) {
+ return;
+ }
+
+ checkRecordTypeTag(arg0Ptr, 0);
+ checkRecordTypeTag(arg1Ptr, 1);
+
+ boolean arg0Stable = sameBytes(arg0Ptr, cachedArg0Bytes, cachedArg0Len);
+ boolean arg1Stable = sameBytes(arg1Ptr, cachedArg1Bytes, cachedArg1Len);
+
+ if (!arg0Stable) {
+ cachedArg0Bytes = copySnapshot(cachedArg0Bytes, arg0Ptr);
+ cachedArg0Len = arg0Ptr.getLength();
+ }
+ if (!arg1Stable) {
+ cachedArg1Bytes = copySnapshot(cachedArg1Bytes, arg1Ptr);
+ cachedArg1Len = arg1Ptr.getLength();
+ }
+
+ // Use arg1 as the query side only when it is stable and arg0 is not.
+ // On the first call both appear unstable (no prior bytes); arg0 is the default.
+ boolean queryIsArg1 = arg1Stable && !arg0Stable;
+ IPointable queryPtr = queryIsArg1 ? arg1Ptr : arg0Ptr;
+ ARecordVisitablePointable queryRec = queryIsArg1 ? arg1Recordable : arg0Recordable;
+ IPointable docPtr = queryIsArg1 ? arg0Ptr : arg1Ptr;
+ ARecordVisitablePointable docRec = queryIsArg1 ? arg0Recordable : arg1Recordable;
+ int queryOrdinal = queryIsArg1 ? 1 : 0;
+ int docOrdinal = queryIsArg1 ? 0 : 1;
+
+ refreshQueryMap(queryPtr, queryRec, queryOrdinal);
+ if (resultIsNull) {
+ try {
+ out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ result.set(resultStorage);
+ return;
+ }
+
+ double dotProduct = probeDocVector(docPtr, docRec, docOrdinal);
+ if (resultIsNull) {
+ try {
+ out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ result.set(resultStorage);
+ return;
+ }
+
+ try {
+ aDouble.setValue(dotProduct);
+ doubleSerde.serialize(aDouble, out);
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ result.set(resultStorage);
+ }
+
+ private void checkRecordTypeTag(IPointable ptr, int argOrdinal) throws HyracksDataException {
+ if (ptr.getByteArray()[ptr.getStartOffset()] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
+ throw new TypeMismatchException(BuiltinFunctions.SPARSE_VECTOR_DOT_PRODUCT, argOrdinal,
+ ptr.getByteArray()[ptr.getStartOffset()], ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
+ }
+ }
+
+ /**
+ * Rebuilds the query hashmap if the query vector bytes have changed since the last call.
+ * In the common case (fixed query, scanning documents) this only fires once.
+ */
+ private void refreshQueryMap(IPointable queryPtr, ARecordVisitablePointable queryRec, int argOrdinal)
+ throws HyracksDataException {
+ byte[] buf = queryPtr.getByteArray();
+ int off = queryPtr.getStartOffset();
+ int len = queryPtr.getLength();
+
+ if (cachedQueryBytesLen == len && Arrays.equals(cachedQueryBytes, 0, len, buf, off, off + len)) {
+ return;
+ }
+
+ queryMap.clear();
+ queryRec.set(buf, off, len);
+
+ IVisitablePointable indicesFv = findField(queryRec, INDICES_FIELD_NAME);
+ IVisitablePointable valuesFv = findField(queryRec, VALUES_FIELD_NAME);
+
+ if (isNullOrMissingValue(indicesFv) || isNullOrMissingValue(valuesFv)) {
+ // Invalidate cache so a later valid query forces a full rebuild
+ cachedQueryBytesLen = 0;
+ resultIsNull = true;
+ return;
+ }
+
+ if (isInvalidListField(indicesFv) || isInvalidListField(valuesFv)) {
+ cachedQueryBytes = copySnapshot(cachedQueryBytes, queryPtr);
+ cachedQueryBytesLen = len;
+ return;
+ }
+
+ queryIndicesIter.reset(indicesFv.getByteArray(), indicesFv.getStartOffset());
+ queryValuesIter.reset(valuesFv.getByteArray(), valuesFv.getStartOffset());
+ validateEqualLength(queryIndicesIter.size(), queryValuesIter.size());
+
+ while (queryIndicesIter.hasNext() && queryValuesIter.hasNext()) {
+ queryMap.put(
+ readIndex(indicesFv.getByteArray(), indicesFv.getStartOffset(), queryIndicesIter.getPos(),
+ argOrdinal),
+ readValue(valuesFv.getByteArray(), valuesFv.getStartOffset(), queryValuesIter.getPos(),
+ argOrdinal));
+ queryIndicesIter.next();
+ queryValuesIter.next();
+ }
+
+ cachedQueryBytes = copySnapshot(cachedQueryBytes, queryPtr);
+ cachedQueryBytesLen = len;
+ }
+
+ /**
+ * Iterates the document vector's indices and looks each one up in the cached query hashmap.
+ */
+ private double probeDocVector(IPointable docPtr, ARecordVisitablePointable docRec, int argOrdinal)
+ throws HyracksDataException {
+ docRec.set(docPtr.getByteArray(), docPtr.getStartOffset(), docPtr.getLength());
+
+ IVisitablePointable indicesFv = findField(docRec, INDICES_FIELD_NAME);
+ IVisitablePointable valuesFv = findField(docRec, VALUES_FIELD_NAME);
+
+ if (isNullOrMissingValue(indicesFv) || isNullOrMissingValue(valuesFv)) {
+ resultIsNull = true;
+ return 0.0;
+ }
+
+ if (isInvalidListField(indicesFv) || isInvalidListField(valuesFv)) {
+ return 0.0;
+ }
+
+ docIndicesIter.reset(indicesFv.getByteArray(), indicesFv.getStartOffset());
+ docValuesIter.reset(valuesFv.getByteArray(), valuesFv.getStartOffset());
+
+ validateEqualLength(docIndicesIter.size(), docValuesIter.size());
+
+ if (queryMap.isEmpty()) {
+ return 0.0;
+ }
+
+ double sum = 0.0;
+ while (docIndicesIter.hasNext() && docValuesIter.hasNext()) {
+ Double qVal = queryMap.get(readIndex(indicesFv.getByteArray(), indicesFv.getStartOffset(),
+ docIndicesIter.getPos(), argOrdinal));
+ if (qVal != null) {
+ sum += qVal * readValue(valuesFv.getByteArray(), valuesFv.getStartOffset(), docValuesIter.getPos(),
+ argOrdinal);
+ }
+ docIndicesIter.next();
+ docValuesIter.next();
+ }
+ return sum;
+ }
+
+ private static void validateEqualLength(int indicesSize, int valuesSize) throws HyracksDataException {
+ if (indicesSize != valuesSize) {
+ throw new InvalidDataFormatException(null, BuiltinFunctions.SPARSE_VECTOR_DOT_PRODUCT,
+ "sparse vector: indices and values arrays must have equal length");
+ }
+ }
+
+ private static boolean sameBytes(IPointable ptr, byte[] snap, int snapLen) {
+ if (snapLen == 0) {
+ return false;
+ }
+ byte[] buf = ptr.getByteArray();
+ int off = ptr.getStartOffset();
+ int len = ptr.getLength();
+ return snapLen == len && Arrays.equals(snap, 0, len, buf, off, off + len);
+ }
+
+ private static byte[] copySnapshot(byte[] snap, IPointable ptr) {
+ int len = ptr.getLength();
+ if (snap.length < len) {
+ snap = new byte[len];
+ }
+ System.arraycopy(ptr.getByteArray(), ptr.getStartOffset(), snap, 0, len);
+ return snap;
+ }
+
+ private static IVisitablePointable findField(ARecordVisitablePointable rec, byte[] targetFieldName) {
+ List<IVisitablePointable> fieldNames = rec.getFieldNames();
+ List<IVisitablePointable> fieldValues = rec.getFieldValues();
+ for (int i = 0, n = fieldNames.size(); i < n; i++) {
+ IVisitablePointable fn = fieldNames.get(i);
+ if (fn.getLength() == targetFieldName.length && Arrays.equals(fn.getByteArray(), fn.getStartOffset(),
+ fn.getStartOffset() + fn.getLength(), targetFieldName, 0, targetFieldName.length)) {
+ return fieldValues.get(i);
+ }
+ }
+ return null;
+ }
+
+ private static boolean isNullOrMissingValue(IVisitablePointable fv) {
+ if (fv == null) {
+ return false;
+ }
+ byte tag = fv.getByteArray()[fv.getStartOffset()];
+ return tag == ATypeTag.SERIALIZED_NULL_TYPE_TAG || tag == ATypeTag.SERIALIZED_MISSING_TYPE_TAG;
+ }
+
+ private static boolean isInvalidListField(IVisitablePointable fv) {
+ return fv == null || fv.getByteArray()[fv.getStartOffset()] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG;
+ }
+
+ private static long readIndex(byte[] listData, int listOff, int itemPos, int argOrdinal)
+ throws HyracksDataException {
+ byte elemTag = listData[listOff + 1];
+ if (elemTag == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
+ return AInt32SerializerDeserializer.getInt(listData, itemPos);
+ }
+ if (elemTag == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
+ return AInt64SerializerDeserializer.getLong(listData, itemPos);
+ }
+ if (elemTag != ATypeTag.SERIALIZED_ANY_TYPE_TAG) {
+ throw new TypeMismatchException(BuiltinFunctions.SPARSE_VECTOR_DOT_PRODUCT, argOrdinal, elemTag,
+ ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG);
+ }
+ byte itemTag = listData[itemPos];
+ if (itemTag == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
+ return AInt32SerializerDeserializer.getInt(listData, itemPos + 1);
+ }
+ if (itemTag == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
+ return AInt64SerializerDeserializer.getLong(listData, itemPos + 1);
+ }
+ throw new TypeMismatchException(BuiltinFunctions.SPARSE_VECTOR_DOT_PRODUCT, argOrdinal, itemTag,
+ ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG);
+ }
+
+ private static double readValue(byte[] listData, int listOff, int itemPos, int argOrdinal)
+ throws HyracksDataException {
+ byte elemTag = listData[listOff + 1];
+ if (elemTag == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
+ return AFloatSerializerDeserializer.getFloat(listData, itemPos);
+ }
+ if (elemTag == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
+ return ADoubleSerializerDeserializer.getDouble(listData, itemPos);
+ }
+ if (elemTag != ATypeTag.SERIALIZED_ANY_TYPE_TAG) {
+ throw new TypeMismatchException(BuiltinFunctions.SPARSE_VECTOR_DOT_PRODUCT, argOrdinal, elemTag,
+ ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG);
+ }
+ byte itemTag = listData[itemPos];
+ if (itemTag == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
+ return ADoubleSerializerDeserializer.getDouble(listData, itemPos + 1);
+ }
+ if (itemTag == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
+ return AFloatSerializerDeserializer.getFloat(listData, itemPos + 1);
+ }
+ throw new TypeMismatchException(BuiltinFunctions.SPARSE_VECTOR_DOT_PRODUCT, argOrdinal, itemTag,
+ ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG);
+ }
+}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
index 106b165..6f20370 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
@@ -580,6 +580,7 @@
import org.apache.asterix.runtime.evaluators.functions.records.RecordTransformDescriptor;
import org.apache.asterix.runtime.evaluators.functions.records.RecordUnwrapDescriptor;
import org.apache.asterix.runtime.evaluators.functions.records.RecordValuesDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.sparsevector.SparseVectorDotProductDescriptor;
import org.apache.asterix.runtime.evaluators.functions.temporal.AdjustDateTimeForTimeZoneDescriptor;
import org.apache.asterix.runtime.evaluators.functions.temporal.AdjustTimeForTimeZoneDescriptor;
import org.apache.asterix.runtime.evaluators.functions.temporal.CalendarDurationFromDateDescriptor;
@@ -1071,6 +1072,9 @@
fc.add(NumericATan2Descriptor.FACTORY);
fc.add(FromBaseDescriptor.FACTORY);
+ // Similarity Functions
+ fc.add(SparseVectorDotProductDescriptor.FACTORY);
+
// Comparisons.
fc.add(EqualsDescriptor.FACTORY);
fc.add(GreaterThanDescriptor.FACTORY);
--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21274?usp=email
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I57de625366800bf4f64ad9d0705211ac29db8336
Gerrit-Change-Number: 21274
Gerrit-PatchSet: 1
Gerrit-Owner: Savyasach Reddy <es...@gmail.com>