[ASTERIXDB-2952][COMP] Support CROSS JOIN
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Add support for CROSS JOIN
- Add testcases and update documentation
Change-Id: Ib9f7350576592ca2858e46878e0b428855e3f2d2
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/12904
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.1.ddl.sqlpp
new file mode 100644
index 0000000..dd75e79
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.1.ddl.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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.Schema as
+ closed {
+ unique1 : bigint,
+ unique2 : bigint,
+ two : bigint,
+ four : bigint,
+ ten : bigint,
+ twenty : bigint,
+ onePercent : bigint,
+ tenPercent : bigint,
+ twentyPercent : bigint,
+ fiftyPercent : bigint,
+ unique3 : bigint,
+ evenOnePercent : bigint,
+ oddOnePercent : bigint,
+ stringu1 : string,
+ stringu2 : string,
+ string4 : string
+};
+
+create dataset onektup(Schema) primary key unique2;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.2.update.sqlpp
new file mode 100644
index 0000000..e5d85fe
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.2.update.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;
+
+load dataset onektup using localfs ((`path`=`asterix_nc1://data/wisc/onektup.adm`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.3.query.sqlpp
new file mode 100644
index 0000000..6e29bdd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.3.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Cross join: 100 * 100 -> 10,000 tuples
+ */
+
+use test;
+
+select count(*) as cnt
+from onektup cross join onektup as onektup2;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.4.query.sqlpp
new file mode 100644
index 0000000..d0be10b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.4.query.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.
+ */
+
+/*
+ * Cross join: 5 * 5 -> 25 tuples
+ */
+
+use test;
+
+select t1.unique1 x, t2.unique1 y
+from onektup t1 cross join onektup t2
+where t1.twenty = 0 and t2.twenty = 1
+order by x, y;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.5.query.sqlpp
new file mode 100644
index 0000000..2c542f7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-01/cross-join-01.5.query.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+/*
+ * Cross join: 2 * 2 -> 4 tuples
+ */
+
+use test;
+
+select x, y
+from [1,2] x cross join [3, 4] y
+order by x, y;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-02-negative/cross-join-02-negative.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-02-negative/cross-join-02-negative.1.query.sqlpp
new file mode 100644
index 0000000..92d4678
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/join/cross-join-02-negative/cross-join-02-negative.1.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.
+ */
+
+/*
+ * Negative: left branch variable is not in scope
+ * for the right branch of the cross join
+ */
+
+select count(*) as cnt
+from [ [1,2], [3,4] ] as x cross join x as y;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/join/cross-join-01/cross-join-01.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/join/cross-join-01/cross-join-01.3.adm
new file mode 100644
index 0000000..4f947fd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/join/cross-join-01/cross-join-01.3.adm
@@ -0,0 +1 @@
+{ "cnt": 10000 }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/join/cross-join-01/cross-join-01.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/join/cross-join-01/cross-join-01.4.adm
new file mode 100644
index 0000000..d6aa101
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/join/cross-join-01/cross-join-01.4.adm
@@ -0,0 +1,25 @@
+{ "x": 0, "y": 1 }
+{ "x": 0, "y": 21 }
+{ "x": 0, "y": 41 }
+{ "x": 0, "y": 61 }
+{ "x": 0, "y": 81 }
+{ "x": 20, "y": 1 }
+{ "x": 20, "y": 21 }
+{ "x": 20, "y": 41 }
+{ "x": 20, "y": 61 }
+{ "x": 20, "y": 81 }
+{ "x": 40, "y": 1 }
+{ "x": 40, "y": 21 }
+{ "x": 40, "y": 41 }
+{ "x": 40, "y": 61 }
+{ "x": 40, "y": 81 }
+{ "x": 60, "y": 1 }
+{ "x": 60, "y": 21 }
+{ "x": 60, "y": 41 }
+{ "x": 60, "y": 61 }
+{ "x": 60, "y": 81 }
+{ "x": 80, "y": 1 }
+{ "x": 80, "y": 21 }
+{ "x": 80, "y": 41 }
+{ "x": 80, "y": 61 }
+{ "x": 80, "y": 81 }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/join/cross-join-01/cross-join-01.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/join/cross-join-01/cross-join-01.5.adm
new file mode 100644
index 0000000..ffd1e6c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/join/cross-join-01/cross-join-01.5.adm
@@ -0,0 +1,4 @@
+{ "x": 1, "y": 3 }
+{ "x": 1, "y": 4 }
+{ "x": 2, "y": 3 }
+{ "x": 2, "y": 4 }
\ 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 cb4c5ad..bdc2603 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -6561,6 +6561,17 @@
</test-group>
<test-group name="join">
<test-case FilePath="join">
+ <compilation-unit name="cross-join-01">
+ <output-dir compare="Text">cross-join-01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="join">
+ <compilation-unit name="cross-join-02-negative">
+ <output-dir compare="Text">none</output-dir>
+ <expected-error>ASX1077: Cannot find dataset x in dataverse Default nor an alias with name x (in line 26, at column 39)</expected-error>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="join">
<compilation-unit name="hash_join_array">
<output-dir compare="Text">hash_join_array</output-dir>
</compilation-unit>
diff --git a/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf b/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf
index c9cabe9..805ac0a 100644
--- a/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf
+++ b/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf
@@ -69,7 +69,8 @@
NamedExpr ::= Expr ("AS"? Variable)?
-JoinStep ::= ("INNER" | ( ( "LEFT" | "RIGHT" ) "OUTER"?))? "JOIN" NamedExpr "ON" Expr
+JoinStep ::= ( ("INNER" | ( ( "LEFT" | "RIGHT" ) "OUTER"?))? "JOIN" NamedExpr "ON" Expr ) |
+ ( "CROSS" "JOIN" NamedExpr )
UnnestStep ::= ("INNER" | ( "LEFT" "OUTER"?))? "UNNEST" NamedExpr
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index ca4d903..3a29260 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -4570,6 +4570,7 @@
| ( <INNER> correlateClause = JoinOrUnnestClause(JoinType.INNER, UnnestType.INNER) )
| ( <LEFT> ( <OUTER> )? correlateClause = JoinOrUnnestClause(JoinType.LEFTOUTER, UnnestType.LEFTOUTER) )
| ( <RIGHT> ( <OUTER> )? correlateClause = JoinClause(JoinType.RIGHTOUTER) )
+ | ( <CROSS> correlateClause = CrossJoinClause() )
)
{
correlateClauses.add(correlateClause);
@@ -4599,19 +4600,46 @@
JoinClause JoinClause(JoinType joinType) throws ParseException :
{
Token startToken = null;
- Expression rightExpr = null;
- VariableExpr rightVar = null;
- VariableExpr posVar = null;
+ Triple<Expression, VariableExpr, VariableExpr> rightInput = null;
Expression conditionExpr = null;
}
{
- <JOIN> { startToken = token; } rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
+ <JOIN> { startToken = token; } rightInput = JoinClauseRightInput() <ON> conditionExpr = Expression()
+ {
+ JoinClause joinClause = new JoinClause(joinType, rightInput.first, rightInput.second, rightInput.third,
+ conditionExpr);
+ return addSourceLocation(joinClause, startToken);
+ }
+}
+
+JoinClause CrossJoinClause() throws ParseException :
+{
+ Token startToken = null;
+ Triple<Expression, VariableExpr, VariableExpr> rightInput = null;
+ Expression conditionExpr = null;
+}
+{
+ <JOIN> { startToken = token; } rightInput = JoinClauseRightInput()
+ {
+ JoinClause joinClause = new JoinClause(JoinType.INNER, rightInput.first, rightInput.second, rightInput.third,
+ new LiteralExpr(TrueLiteral.INSTANCE));
+ return addSourceLocation(joinClause, startToken);
+ }
+}
+
+Triple<Expression, VariableExpr, VariableExpr> JoinClauseRightInput() throws ParseException :
+{
+ Expression rightExpr = null;
+ VariableExpr rightVar = null;
+ VariableExpr posVar = null;
+}
+{
+ rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())?
{
if (rightVar == null) {
rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true);
}
- JoinClause joinClause = new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
- return addSourceLocation(joinClause, startToken);
+ return new Triple<Expression, VariableExpr, VariableExpr>(rightExpr, rightVar, posVar);
}
}
@@ -5068,6 +5096,7 @@
| <CASE : "case">
| <CLOSED : "closed">
| <CREATE : "create">
+ | <CROSS : "cross">
| <COMPACTION : "compaction"> // no longer used
| <COMPACT : "compact">
| <CONNECT : "connect">