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 2021/07/13 21:02:39 UTC
Change in asterixdb[master]: [ASTERIXDB-2927][SQL++] EACH AND EVERY quantified expressions
From Glenn Galvizo <gg...@uci.edu>:
Glenn Galvizo has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/12323 )
Change subject: [ASTERIXDB-2927][SQL++] EACH AND EVERY quantified expressions
......................................................................
[ASTERIXDB-2927][SQL++] EACH AND EVERY quantified expressions
- user mode changes: yes
- storage format changes: no
- interface changes: no
User now has the option to use "EACH AND EVERY" in addition to ANY/SOME
and EVERY for quantified expressions. "EACH AND EVERY" is similar to
"EVERY", except we require that at least one item exists in the
quantified array / multiset (i.e. no empty sets in the result).
Change-Id: I66315f69eb1579a4c450cc3d0e97b39a03fe5194
---
M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
A asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-1.sqlpp
A asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-2.sqlpp
A asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-3.sqlpp
A asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-1.plan
A asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-2.plan
A asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-3.plan
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.2.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.3.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.1.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.2.adm
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
M asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
16 files changed, 334 insertions(+), 3 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/23/12323/1
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
index c053ab9..4af8b80 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
@@ -1329,7 +1329,7 @@
fAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.NON_EMPTY_STREAM,
new ArrayList<>());
fAgg.setSourceLocation(sourceLoc);
- } else { // EVERY
+ } else { // EVERY or EACH_AND_EVERY
// look for input items that do not satisfy the condition, if none found then return true
// when inverting the condition account for NULL/MISSING by replacing them with FALSE
// condition() -> not(if-missing-or-null(condition(), false))
@@ -1636,6 +1636,39 @@
s.setRootOp(planRoot);
VariableReferenceExpression varRef = new VariableReferenceExpression(p.second);
varRef.setSourceLocation(sourceLoc);
+
+ // For EACH AND EVERY quantification, we must add a non-emptiness SELECT below the SUBPLAN.
+ if (expr instanceof QuantifiedExpression
+ && ((QuantifiedExpression) expr).getQuantifier().equals(Quantifier.EACH_AND_EVERY)) {
+ QuantifiedExpression qe = (QuantifiedExpression) expr;
+ for (QuantifiedPair qt : qe.getQuantifiedList()) {
+ // Get the length of the array / multiset.
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 =
+ langExprToAlgExpression(qt.getExpr(), topOpRef);
+ AbstractFunctionCallExpression lenExpr = new ScalarFunctionCallExpression(
+ BuiltinFunctions.getBuiltinFunctionInfo(BuiltinFunctions.LEN));
+ lenExpr.getArguments().add(new MutableObject<>(eo1.first));
+ lenExpr.setSourceLocation(sourceLoc);
+
+ // This length must be greater than 0.
+ ConstantExpression eZero =
+ new ConstantExpression(new AsterixConstantValue(new AInt64(0L)));
+ eZero.setSourceLocation(sourceLoc);
+ AbstractFunctionCallExpression nonEmptinessExpr = new ScalarFunctionCallExpression(
+ BuiltinFunctions.getBuiltinFunctionInfo(BuiltinFunctions.GT));
+ nonEmptinessExpr.getArguments().add(new MutableObject<>(lenExpr));
+ nonEmptinessExpr.getArguments().add(new MutableObject<>(eZero));
+ nonEmptinessExpr.setSourceLocation(sourceLoc);
+
+ // Filter based on this condition, and place this SELECT below our SUBPLAN.
+ SelectOperator es =
+ new SelectOperator(new MutableObject<>(nonEmptinessExpr), false, null);
+ es.setSourceLocation(sourceLoc);
+ es.getInputs().addAll(s.getInputs());
+ s.getInputs().clear();
+ s.getInputs().add(new MutableObject<>(es));
+ }
+ }
return new Pair<>(varRef, new MutableObject<>(s));
}
}
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-1.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-1.sqlpp
new file mode 100644
index 0000000..1df6c7d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-1.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.
+ */
+
+DROP DATAVERSE TestDataverse IF EXISTS;
+CREATE DATAVERSE TestDataverse;
+USE TestDataverse;
+
+CREATE TYPE TestType AS {
+ _id: uuid
+};
+CREATE DATASET Dataset1 (TestType)
+PRIMARY KEY _id AUTOGENERATED;
+
+-- Quantifying on items in an array.
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items
+ SATISFIES I = 1
+SELECT *;
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-2.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-2.sqlpp
new file mode 100644
index 0000000..94de0e5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-2.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * 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 TestDataverse IF EXISTS;
+CREATE DATAVERSE TestDataverse;
+USE TestDataverse;
+
+CREATE TYPE TestType AS {
+ _id: uuid
+};
+CREATE DATASET Dataset1 (TestType)
+PRIMARY KEY _id AUTOGENERATED;
+
+-- Quantifying on items in an array, that are within an array.
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items
+ SATISFIES (
+ EACH AND EVERY J IN I.items
+ SATISFIES J = 1
+ )
+SELECT *;
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-3.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-3.sqlpp
new file mode 100644
index 0000000..30b103c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-3.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.
+ */
+
+DROP DATAVERSE TestDataverse IF EXISTS;
+CREATE DATAVERSE TestDataverse;
+USE TestDataverse;
+
+CREATE TYPE TestType AS {
+ _id: uuid
+};
+CREATE DATASET Dataset1 (TestType)
+PRIMARY KEY _id AUTOGENERATED;
+
+-- Quantifying on items in two arrays.
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items, J IN D.other_items
+ SATISFIES I = 1 AND J = 2
+SELECT *;
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-1.plan
new file mode 100644
index 0000000..b90dc62
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-1.plan
@@ -0,0 +1,21 @@
+-- DISTRIBUTE_RESULT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- STREAM_SELECT |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- SUBPLAN |PARTITIONED|
+ {
+ -- AGGREGATE |LOCAL|
+ -- STREAM_SELECT |LOCAL|
+ -- UNNEST |LOCAL|
+ -- NESTED_TUPLE_SOURCE |LOCAL|
+ }
+ -- STREAM_SELECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- DATASOURCE_SCAN (TestDataverse.Dataset1) |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- EMPTY_TUPLE_SOURCE |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-2.plan
new file mode 100644
index 0000000..f3dd136
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-2.plan
@@ -0,0 +1,30 @@
+-- DISTRIBUTE_RESULT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- STREAM_SELECT |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- SUBPLAN |PARTITIONED|
+ {
+ -- AGGREGATE |LOCAL|
+ -- STREAM_SELECT |LOCAL|
+ -- SUBPLAN |LOCAL|
+ {
+ -- AGGREGATE |LOCAL|
+ -- STREAM_SELECT |LOCAL|
+ -- UNNEST |LOCAL|
+ -- NESTED_TUPLE_SOURCE |LOCAL|
+ }
+ -- STREAM_SELECT |LOCAL|
+ -- ASSIGN |LOCAL|
+ -- UNNEST |LOCAL|
+ -- NESTED_TUPLE_SOURCE |LOCAL|
+ }
+ -- STREAM_SELECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- DATASOURCE_SCAN (TestDataverse.Dataset1) |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- EMPTY_TUPLE_SOURCE |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-3.plan
new file mode 100644
index 0000000..88cc156
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-3.plan
@@ -0,0 +1,22 @@
+-- DISTRIBUTE_RESULT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- STREAM_SELECT |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- SUBPLAN |PARTITIONED|
+ {
+ -- AGGREGATE |LOCAL|
+ -- STREAM_SELECT |LOCAL|
+ -- UNNEST |LOCAL|
+ -- UNNEST |LOCAL|
+ -- NESTED_TUPLE_SOURCE |LOCAL|
+ }
+ -- STREAM_SELECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- DATASOURCE_SCAN (TestDataverse.Dataset1) |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- EMPTY_TUPLE_SOURCE |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.1.ddl.sqlpp
new file mode 100644
index 0000000..fb19ba8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.1.ddl.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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 TestDataverse IF EXISTS;
+CREATE DATAVERSE TestDataverse;
+USE TestDataverse;
+
+CREATE TYPE TestType AS {
+ _id: uuid
+};
+
+CREATE DATASET Dataset1 (TestType)
+PRIMARY KEY _id AUTOGENERATED;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.2.update.sqlpp
new file mode 100644
index 0000000..97cda55
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.2.update.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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 TestDataverse;
+
+INSERT INTO Dataset1 [
+ { "items": [], "other_items": [1, 2, 3] },
+ { "items": null, "other_items": [1, 2, 3] },
+ { "other_items": [1, 2, 3] },
+ { "items": [1, 2, 3], "other_items": [1, 2, 3 ] },
+ { "items": [1, 2], "other_items": [1, 2, 3] },
+ { "items": [1, 2, 3, 4], "other_items": [1, 2, 3] }
+];
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.3.query.sqlpp
new file mode 100644
index 0000000..74e2043
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.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 TestDataverse;
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items
+ SATISFIES I BETWEEN 1 AND 3
+SELECT D.items
+ORDER BY D.items;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.4.query.sqlpp
new file mode 100644
index 0000000..2dace8f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.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 TestDataverse;
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items, J IN D.other_items
+ SATISFIES I BETWEEN 1 AND 3 AND J BETWEEN 1 AND 3
+SELECT D.items, D.other_items
+ORDER BY D.items, D.other_items;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.1.adm
new file mode 100644
index 0000000..4746c44
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.1.adm
@@ -0,0 +1,2 @@
+{ "items": [ 1, 2 ] }
+{ "items": [ 1, 2, 3 ] }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.2.adm
new file mode 100644
index 0000000..01c0fff
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.2.adm
@@ -0,0 +1,2 @@
+{ "items": [ 1, 2 ], "other_items": [ 1, 2, 3 ] }
+{ "items": [ 1, 2, 3 ], "other_items": [ 1, 2, 3 ] }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 02b5721..cfcf01c 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -9338,6 +9338,11 @@
</test-group>
<test-group name="quantifiers">
<test-case FilePath="quantifiers">
+ <compilation-unit name="each_and_every_01">
+ <output-dir compare="Text">each_and_every_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="quantifiers">
<compilation-unit name="anysat_01">
<output-dir compare="Text">somesat_01</output-dir>
</compilation-unit>
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
index a35d975..4d9749d 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
@@ -78,6 +78,7 @@
}
public enum Quantifier {
+ EACH_AND_EVERY,
EVERY,
SOME
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index c4c86f4..ac80e66 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -4781,8 +4781,9 @@
createNewScope();
}
- ( ((<ANY>|<SOME>) { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
- | (<EVERY> { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
+ ( (<ANY>|<SOME>) { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }
+ | <EACH><AND><EVERY> { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.EACH_AND_EVERY); }
+ | <EVERY> { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); } )
var = Variable() <IN> inExpr = Expression()
{
pair = new QuantifiedPair(var, inExpr);
@@ -4902,6 +4903,7 @@
| <DROP : "drop">
| <ELEMENT : "element">
| <EXPLAIN : "explain">
+ | <EACH: "each">
| <ELSE : "else">
| <ENFORCED : "enforced">
| <END : "end">
--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/12323
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I66315f69eb1579a4c450cc3d0e97b39a03fe5194
Gerrit-Change-Number: 12323
Gerrit-PatchSet: 1
Gerrit-Owner: Glenn Galvizo <gg...@uci.edu>
Gerrit-MessageType: newchange
Change in asterixdb[master]: [ASTERIXDB-2927][SQL++] EACH AND EVERY quantified expressions
Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
Anon. E. Moose #1000171 has posted comments on this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/12323 )
Change subject: [ASTERIXDB-2927][SQL++] EACH AND EVERY quantified expressions
......................................................................
Patch Set 2: Contrib-2
Analytics Compatibility Tests Failed
https://cbjenkins.page.link/Y19EazKA9MvVWwfr8 : UNSTABLE
--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/12323
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I66315f69eb1579a4c450cc3d0e97b39a03fe5194
Gerrit-Change-Number: 12323
Gerrit-PatchSet: 2
Gerrit-Owner: Glenn Galvizo <gg...@uci.edu>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-CC: Dmitry Lychagin <dm...@couchbase.com>
Gerrit-Comment-Date: Wed, 14 Jul 2021 23:02:52 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Change in asterixdb[master]: [ASTERIXDB-2927][SQL++] EACH AND EVERY quantified expressions
Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
From Glenn Galvizo <gg...@uci.edu>:
Glenn Galvizo has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/12323 )
Change subject: [ASTERIXDB-2927][SQL++] EACH AND EVERY quantified expressions
......................................................................
[ASTERIXDB-2927][SQL++] EACH AND EVERY quantified expressions
- user mode changes: yes
- storage format changes: no
- interface changes: no
User now has the option to use "EACH AND EVERY" in addition to ANY/SOME
and EVERY for quantified expressions. "EACH AND EVERY" is similar to
"EVERY", except we require that at least one item exists in the
quantified array / multiset (i.e. no empty sets in the result).
Change-Id: I66315f69eb1579a4c450cc3d0e97b39a03fe5194
---
M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
A asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-1.sqlpp
A asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-2.sqlpp
A asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-3.sqlpp
A asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-1.plan
A asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-2.plan
A asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-3.plan
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.1.ddl.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.2.update.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.3.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.1.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.2.adm
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
M asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
16 files changed, 334 insertions(+), 3 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/23/12323/1
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
index c053ab9..4af8b80 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
@@ -1329,7 +1329,7 @@
fAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.NON_EMPTY_STREAM,
new ArrayList<>());
fAgg.setSourceLocation(sourceLoc);
- } else { // EVERY
+ } else { // EVERY or EACH_AND_EVERY
// look for input items that do not satisfy the condition, if none found then return true
// when inverting the condition account for NULL/MISSING by replacing them with FALSE
// condition() -> not(if-missing-or-null(condition(), false))
@@ -1636,6 +1636,39 @@
s.setRootOp(planRoot);
VariableReferenceExpression varRef = new VariableReferenceExpression(p.second);
varRef.setSourceLocation(sourceLoc);
+
+ // For EACH AND EVERY quantification, we must add a non-emptiness SELECT below the SUBPLAN.
+ if (expr instanceof QuantifiedExpression
+ && ((QuantifiedExpression) expr).getQuantifier().equals(Quantifier.EACH_AND_EVERY)) {
+ QuantifiedExpression qe = (QuantifiedExpression) expr;
+ for (QuantifiedPair qt : qe.getQuantifiedList()) {
+ // Get the length of the array / multiset.
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 =
+ langExprToAlgExpression(qt.getExpr(), topOpRef);
+ AbstractFunctionCallExpression lenExpr = new ScalarFunctionCallExpression(
+ BuiltinFunctions.getBuiltinFunctionInfo(BuiltinFunctions.LEN));
+ lenExpr.getArguments().add(new MutableObject<>(eo1.first));
+ lenExpr.setSourceLocation(sourceLoc);
+
+ // This length must be greater than 0.
+ ConstantExpression eZero =
+ new ConstantExpression(new AsterixConstantValue(new AInt64(0L)));
+ eZero.setSourceLocation(sourceLoc);
+ AbstractFunctionCallExpression nonEmptinessExpr = new ScalarFunctionCallExpression(
+ BuiltinFunctions.getBuiltinFunctionInfo(BuiltinFunctions.GT));
+ nonEmptinessExpr.getArguments().add(new MutableObject<>(lenExpr));
+ nonEmptinessExpr.getArguments().add(new MutableObject<>(eZero));
+ nonEmptinessExpr.setSourceLocation(sourceLoc);
+
+ // Filter based on this condition, and place this SELECT below our SUBPLAN.
+ SelectOperator es =
+ new SelectOperator(new MutableObject<>(nonEmptinessExpr), false, null);
+ es.setSourceLocation(sourceLoc);
+ es.getInputs().addAll(s.getInputs());
+ s.getInputs().clear();
+ s.getInputs().add(new MutableObject<>(es));
+ }
+ }
return new Pair<>(varRef, new MutableObject<>(s));
}
}
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-1.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-1.sqlpp
new file mode 100644
index 0000000..1df6c7d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-1.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.
+ */
+
+DROP DATAVERSE TestDataverse IF EXISTS;
+CREATE DATAVERSE TestDataverse;
+USE TestDataverse;
+
+CREATE TYPE TestType AS {
+ _id: uuid
+};
+CREATE DATASET Dataset1 (TestType)
+PRIMARY KEY _id AUTOGENERATED;
+
+-- Quantifying on items in an array.
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items
+ SATISFIES I = 1
+SELECT *;
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-2.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-2.sqlpp
new file mode 100644
index 0000000..94de0e5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-2.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * 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 TestDataverse IF EXISTS;
+CREATE DATAVERSE TestDataverse;
+USE TestDataverse;
+
+CREATE TYPE TestType AS {
+ _id: uuid
+};
+CREATE DATASET Dataset1 (TestType)
+PRIMARY KEY _id AUTOGENERATED;
+
+-- Quantifying on items in an array, that are within an array.
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items
+ SATISFIES (
+ EACH AND EVERY J IN I.items
+ SATISFIES J = 1
+ )
+SELECT *;
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-3.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-3.sqlpp
new file mode 100644
index 0000000..30b103c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/each-and-every-3.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.
+ */
+
+DROP DATAVERSE TestDataverse IF EXISTS;
+CREATE DATAVERSE TestDataverse;
+USE TestDataverse;
+
+CREATE TYPE TestType AS {
+ _id: uuid
+};
+CREATE DATASET Dataset1 (TestType)
+PRIMARY KEY _id AUTOGENERATED;
+
+-- Quantifying on items in two arrays.
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items, J IN D.other_items
+ SATISFIES I = 1 AND J = 2
+SELECT *;
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-1.plan
new file mode 100644
index 0000000..b90dc62
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-1.plan
@@ -0,0 +1,21 @@
+-- DISTRIBUTE_RESULT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- STREAM_SELECT |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- SUBPLAN |PARTITIONED|
+ {
+ -- AGGREGATE |LOCAL|
+ -- STREAM_SELECT |LOCAL|
+ -- UNNEST |LOCAL|
+ -- NESTED_TUPLE_SOURCE |LOCAL|
+ }
+ -- STREAM_SELECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- DATASOURCE_SCAN (TestDataverse.Dataset1) |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- EMPTY_TUPLE_SOURCE |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-2.plan
new file mode 100644
index 0000000..f3dd136
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-2.plan
@@ -0,0 +1,30 @@
+-- DISTRIBUTE_RESULT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- STREAM_SELECT |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- SUBPLAN |PARTITIONED|
+ {
+ -- AGGREGATE |LOCAL|
+ -- STREAM_SELECT |LOCAL|
+ -- SUBPLAN |LOCAL|
+ {
+ -- AGGREGATE |LOCAL|
+ -- STREAM_SELECT |LOCAL|
+ -- UNNEST |LOCAL|
+ -- NESTED_TUPLE_SOURCE |LOCAL|
+ }
+ -- STREAM_SELECT |LOCAL|
+ -- ASSIGN |LOCAL|
+ -- UNNEST |LOCAL|
+ -- NESTED_TUPLE_SOURCE |LOCAL|
+ }
+ -- STREAM_SELECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- DATASOURCE_SCAN (TestDataverse.Dataset1) |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- EMPTY_TUPLE_SOURCE |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-3.plan
new file mode 100644
index 0000000..88cc156
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/each-and-every-3.plan
@@ -0,0 +1,22 @@
+-- DISTRIBUTE_RESULT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- STREAM_SELECT |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- SUBPLAN |PARTITIONED|
+ {
+ -- AGGREGATE |LOCAL|
+ -- STREAM_SELECT |LOCAL|
+ -- UNNEST |LOCAL|
+ -- UNNEST |LOCAL|
+ -- NESTED_TUPLE_SOURCE |LOCAL|
+ }
+ -- STREAM_SELECT |PARTITIONED|
+ -- ASSIGN |PARTITIONED|
+ -- STREAM_PROJECT |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- DATASOURCE_SCAN (TestDataverse.Dataset1) |PARTITIONED|
+ -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- EMPTY_TUPLE_SOURCE |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.1.ddl.sqlpp
new file mode 100644
index 0000000..fb19ba8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.1.ddl.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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 TestDataverse IF EXISTS;
+CREATE DATAVERSE TestDataverse;
+USE TestDataverse;
+
+CREATE TYPE TestType AS {
+ _id: uuid
+};
+
+CREATE DATASET Dataset1 (TestType)
+PRIMARY KEY _id AUTOGENERATED;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.2.update.sqlpp
new file mode 100644
index 0000000..97cda55
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.2.update.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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 TestDataverse;
+
+INSERT INTO Dataset1 [
+ { "items": [], "other_items": [1, 2, 3] },
+ { "items": null, "other_items": [1, 2, 3] },
+ { "other_items": [1, 2, 3] },
+ { "items": [1, 2, 3], "other_items": [1, 2, 3 ] },
+ { "items": [1, 2], "other_items": [1, 2, 3] },
+ { "items": [1, 2, 3, 4], "other_items": [1, 2, 3] }
+];
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.3.query.sqlpp
new file mode 100644
index 0000000..74e2043
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.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 TestDataverse;
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items
+ SATISFIES I BETWEEN 1 AND 3
+SELECT D.items
+ORDER BY D.items;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.4.query.sqlpp
new file mode 100644
index 0000000..2dace8f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/quantifiers/each_and_every_01/each_and_every_01.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 TestDataverse;
+FROM Dataset1 D
+WHERE EACH AND EVERY I IN D.items, J IN D.other_items
+ SATISFIES I BETWEEN 1 AND 3 AND J BETWEEN 1 AND 3
+SELECT D.items, D.other_items
+ORDER BY D.items, D.other_items;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.1.adm
new file mode 100644
index 0000000..4746c44
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.1.adm
@@ -0,0 +1,2 @@
+{ "items": [ 1, 2 ] }
+{ "items": [ 1, 2, 3 ] }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.2.adm
new file mode 100644
index 0000000..01c0fff
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/quantifiers/each_and_every_01/each_and_every_01.2.adm
@@ -0,0 +1,2 @@
+{ "items": [ 1, 2 ], "other_items": [ 1, 2, 3 ] }
+{ "items": [ 1, 2, 3 ], "other_items": [ 1, 2, 3 ] }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 02b5721..cfcf01c 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -9338,6 +9338,11 @@
</test-group>
<test-group name="quantifiers">
<test-case FilePath="quantifiers">
+ <compilation-unit name="each_and_every_01">
+ <output-dir compare="Text">each_and_every_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="quantifiers">
<compilation-unit name="anysat_01">
<output-dir compare="Text">somesat_01</output-dir>
</compilation-unit>
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
index a35d975..4d9749d 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
@@ -78,6 +78,7 @@
}
public enum Quantifier {
+ EACH_AND_EVERY,
EVERY,
SOME
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index c4c86f4..ac80e66 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -4781,8 +4781,9 @@
createNewScope();
}
- ( ((<ANY>|<SOME>) { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
- | (<EVERY> { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
+ ( (<ANY>|<SOME>) { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }
+ | <EACH><AND><EVERY> { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.EACH_AND_EVERY); }
+ | <EVERY> { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); } )
var = Variable() <IN> inExpr = Expression()
{
pair = new QuantifiedPair(var, inExpr);
@@ -4902,6 +4903,7 @@
| <DROP : "drop">
| <ELEMENT : "element">
| <EXPLAIN : "explain">
+ | <EACH: "each">
| <ELSE : "else">
| <ENFORCED : "enforced">
| <END : "end">
--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/12323
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I66315f69eb1579a4c450cc3d0e97b39a03fe5194
Gerrit-Change-Number: 12323
Gerrit-PatchSet: 1
Gerrit-Owner: Glenn Galvizo <gg...@uci.edu>
Gerrit-MessageType: newchange