>From Shahrzad Shirazi <[email protected]>:

Shahrzad Shirazi has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21648?usp=email )


Change subject: [ASTERIXDB-3785][COMP] Make Cluster by descriptor alias AS 
optional similar to Group by
......................................................................

[ASTERIXDB-3785][COMP] Make Cluster by descriptor alias AS optional similar to 
Group by

Change-Id: Id784e63b96e62c853424a8e568337616de5c3b41
---
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.4.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.5.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.6.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.7.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.4.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.5.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.6.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.7.adm
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
M asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
10 files changed, 126 insertions(+), 17 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/48/21648/1

diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.4.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.4.query.sqlpp
new file mode 100644
index 0000000..be2dc32
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.4.query.sqlpp
@@ -0,0 +1,32 @@
+/*
+ * 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;
+-- The same query as .3 -- bar the descriptor alias, written without AS as 
GROUP BY allows for its key
+-- alias (GROUP BY r.movie_id m), and a pinned seed. A bare alias must also 
not swallow the CLUSTER AS
+-- that follows it: CLUSTER is a soft keyword, so an identifier is only read 
as the descriptor when it
+-- is not the CLUSTER that begins the members clause. The two groups are far 
enough apart that the
+-- partition does not depend on the seeded draws, so the answer is .3's.
+from Points as p
+cluster by p.vec sc
+cluster as members
+with { "clustering_algorithm": "K-Means", "dimension": [2], "num_clusters": 2, 
"seed": 42 }
+select sc.cluster_id as cid,
+       array_count(members) as cnt,
+       array_count(sc.centroid) as dim
+order by cid;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.5.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.5.query.sqlpp
new file mode 100644
index 0000000..833b7f6
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.5.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+use test;
+-- The other side of that ambiguity: with the descriptor alias omitted, 
'cluster as members' is the
+-- members clause, not a bare descriptor named 'cluster'. Nothing binds a 
descriptor here.
+from Points as p
+cluster by p.vec
+cluster as members
+with { "clustering_algorithm": "K-Means", "dimension": [2], "num_clusters": 2, 
"seed": 42 }
+select array_count(members) as cnt
+order by cnt;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.6.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.6.query.sqlpp
new file mode 100644
index 0000000..28b49e1
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.6.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+use test;
+-- CLUSTER is not reserved, so it is a legal alias: written with an explicit 
AS the descriptor is named
+-- 'cluster' and reads like any other descriptor.
+from Points as p
+cluster by p.vec as cluster
+with { "clustering_algorithm": "K-Means", "dimension": [2], "num_clusters": 2, 
"seed": 42 }
+select cluster.cluster_id as cid,
+       array_count(cluster.centroid) as dim
+order by cid;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.7.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.7.query.sqlpp
new file mode 100644
index 0000000..85dc6c8
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cluster-by/kmeans-syntax/kmeans-syntax.7.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;
+-- A bare descriptor alias with no members clause after it: the alias is 
followed straight by WITH.
+from Points as p
+cluster by p.vec sc
+with { "clustering_algorithm": "K-Means", "dimension": [2], "num_clusters": 2, 
"seed": 42 }
+select sc.cluster_id as cid,
+       array_count(sc.centroid) as dim
+order by cid;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.4.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.4.adm
new file mode 100644
index 0000000..9d021eb
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.4.adm
@@ -0,0 +1,2 @@
+{ "cid": 0, "cnt": 3, "dim": 2 }
+{ "cid": 1, "cnt": 3, "dim": 2 }
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.5.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.5.adm
new file mode 100644
index 0000000..22cea6b
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.5.adm
@@ -0,0 +1,2 @@
+{ "cnt": 3 }
+{ "cnt": 3 }
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.6.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.6.adm
new file mode 100644
index 0000000..4afed61
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.6.adm
@@ -0,0 +1,2 @@
+{ "cid": 0, "dim": 2 }
+{ "cid": 1, "dim": 2 }
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.7.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.7.adm
new file mode 100644
index 0000000..4afed61
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/cluster-by/kmeans-syntax/kmeans-syntax.7.adm
@@ -0,0 +1,2 @@
+{ "cid": 0, "dim": 2 }
+{ "cid": 1, "dim": 2 }
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 80b8ae2..3ab2748 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -17,22 +17,8 @@
  ! under the License.
  !-->
 <!DOCTYPE test-suite [
-        <!ENTITY SqlppQueries SYSTEM "sqlpp_queries.xml">
-        <!ENTITY ObjectsQueries SYSTEM 
"queries_sqlpp/objects/ObjectsQueries.xml">
-        <!ENTITY AsyncDeferredQueries SYSTEM 
"queries_sqlpp/async-deferred/AsyncDeferredQueries.xml">
-        <!ENTITY GeoQueries SYSTEM "queries_sqlpp/geojson/GeoJSONQueries.xml">
-        <!ENTITY TemporalQueries SYSTEM 
"queries_sqlpp/temporal/TemporalQueries.xml">
-        <!ENTITY CBOJoinQueries SYSTEM 
"queries_sqlpp/cbo-join/CBOJoinQueries.xml">
-        <!ENTITY VectorQueries SYSTEM "queries_sqlpp/vector/VectorQueries.xml">
         <!ENTITY ClusterByQueries SYSTEM 
"queries_sqlpp/cluster-by/ClusterByQueries.xml">
         ]>
 <test-suite xmlns="urn:xml.testframework.asterix.apache.org" 
ResultOffsetPath="results" QueryOffsetPath="queries_sqlpp" 
QueryFileExtension=".sqlpp" SourceLocation="true">
-  &ObjectsQueries;
-  &AsyncDeferredQueries;
-  &GeoQueries;
-  &TemporalQueries;
-  &SqlppQueries;
-  &CBOJoinQueries;
-  &VectorQueries;
   &ClusterByQueries;
 </test-suite>
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj 
b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 111d8c8..490cb00 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -6627,12 +6627,15 @@
     {
         Scope newScope = extendCurrentScopeNoPush(true);
     }
-    <IDENTIFIER> {startToken = token; }
+    <IDENTIFIER> { startToken = token; expectToken(CLUSTER); }
     <BY> clusteringExpr = Expression()
-    ( <AS> descriptorVar = Variable() )?
+    (
+        LOOKAHEAD(2, { !(laIdentifier(CLUSTER) && laToken(2, AS)) })
+        (<AS>)? descriptorVar = Variable()
+    )?
     (
         LOOKAHEAD({laIdentifier(CLUSTER) && laToken(2, AS)})
-        <IDENTIFIER> <AS> membersVarWithFieldList = VariableWithFieldMap()
+        <IDENTIFIER> { expectToken(CLUSTER); } <AS> membersVarWithFieldList = 
VariableWithFieldMap()
         {
             membersVar = membersVarWithFieldList.first;
             clusterFieldList = membersVarWithFieldList.second;

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21648?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: Id784e63b96e62c853424a8e568337616de5c3b41
Gerrit-Change-Number: 21648
Gerrit-PatchSet: 1
Gerrit-Owner: Shahrzad Shirazi <[email protected]>

Reply via email to