This is an automated email from the ASF dual-hosted git repository.
alsuliman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push:
new 40fdcd2a5d [ASTERIXDB-3489][COMP] Allow start index to be optional for
array slicing
40fdcd2a5d is described below
commit 40fdcd2a5d609bfd41189d7abf07473511dad5be
Author: brianyen <[email protected]>
AuthorDate: Wed Aug 21 16:22:58 2024 -0700
[ASTERIXDB-3489][COMP] Allow start index to be optional for array slicing
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
Change the grammar to allow the start index to be optional
for array slicing. For example:
arr[:]
arr[]
arr[:5]
The new syntax is:
PathExpression ::= PrimaryExpression ( Field | Index )*
Index ::= "[" (Expression)? (":" ( Expression )? )? "]"
Ext-ref: MB-41418
Change-Id: Ibb45daccf047243034e0f85e9467f6a7f520a5be
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18706
Integration-Tests: Jenkins <[email protected]>
Tested-by: Jenkins <[email protected]>
Reviewed-by: Ali Alsuliman <[email protected]>
---
.../array_slice_bracket_notation.1.ddl.sqlpp | 21 ++++++++++
.../array_slice_bracket_notation.2.update.sqlpp | 20 ++++++++++
.../array_slice_bracket_notation.3.query.sqlpp | 45 ++++++++++++++++++++++
.../array_slice_bracket_notation.4.ddl.sqlpp | 21 ++++++++++
.../array_slice_bracket_notation.3.adm | 1 +
.../src/test/resources/runtimets/sqlpp_queries.xml | 5 +++
.../asterix-lang-sqlpp/src/main/javacc/SQLPP.jj | 12 ++++--
7 files changed, 121 insertions(+), 4 deletions(-)
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.1.ddl.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.1.ddl.sqlpp
new file mode 100755
index 0000000000..8103562527
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.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.
+ */
+
+CREATE TYPE openType AS {id: int};
+CREATE DATASET ds(openType) primary key id;
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.2.update.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.2.update.sqlpp
new file mode 100755
index 0000000000..a9171ce01a
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.2.update.sqlpp
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+UPSERT INTO ds {"id": 1, "arr": [0, 1, 2, 3, 4, 5]};
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.3.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.3.query.sqlpp
new file mode 100755
index 0000000000..91a479a97a
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.3.query.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+with arr as [0, 1, 2, 3, 4, 5] select value
+{
+ "t1": (arr[2]),
+ "t2": (arr[2:4]),
+ "t3": (arr[2:10]),
+ "t4": (arr[-7:4]),
+ "t5": (arr[-7:10]),
+ "t6": (arr[-3:4]),
+ "t7": (arr[2:-1]),
+ "t8": (arr[2:]),
+ "t9": (arr[10:]),
+ "t10": (arr[-7:]),
+ "t11": (arr[:]),
+ "t12": (arr[0]),
+ "t13": (arr[:4]),
+ "t14": (arr[:10]),
+ "t15": (arr[:-7]),
+ "t16": ([][0:]),
+ "t17": ([][:0]),
+ "t18": (select value ds.arr[1:3] from ds),
+ "t19": (select value ds.arr[1:] from ds),
+ "t20": (select value ds.arr[:3] from ds),
+ "t21": (select value ds.arr[] from ds),
+ "t22": (select value ds.arr[:] from ds),
+ "t20": (select value ds.arr[:10] from ds)
+};
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.4.ddl.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.4.ddl.sqlpp
new file mode 100755
index 0000000000..43604c69f6
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.4.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 DATASET ds;
+DROP TYPE openType;
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/results/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.3.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.3.adm
new file mode 100644
index 0000000000..0e8c7abb50
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/results/array_fun/array_slice/array_slice_bracket_notation/array_slice_bracket_notation.3.adm
@@ -0,0 +1 @@
+{ "t1": 2, "t2": [ 2, 3 ], "t3": null, "t4": null, "t5": null, "t6": [ 3 ],
"t7": [ 2, 3, 4 ], "t8": [ 2, 3, 4, 5 ], "t9": null, "t10": null, "t11": [ 0,
1, 2, 3, 4, 5 ], "t12": 0, "t13": [ 0, 1, 2, 3 ], "t14": null, "t15": null,
"t16": null, "t17": null, "t18": [ [ 1, 2 ] ], "t19": [ [ 1, 2, 3, 4, 5 ] ],
"t20": [ [ 0, 1, 2 ] ], "t21": [ [ 0, 1, 2, 3, 4, 5 ] ], "t22": [ [ 0, 1, 2, 3,
4, 5 ] ] }
\ No newline at end of file
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 3ad9438d78..338cd8df1a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
@@ -3120,6 +3120,11 @@
<output-dir compare="Text">array_union</output-dir>
</compilation-unit>
</test-case>
+ <test-case FilePath="array_fun">
+ <compilation-unit name="array_slice/array_slice_bracket_notation">
+ <output-dir
compare="Text">array_slice/array_slice_bracket_notation</output-dir>
+ </compilation-unit>
+ </test-case>
<test-case FilePath="array_fun">
<compilation-unit name="array_slice/array_slice_double_argument">
<output-dir
compare="Text">array_slice/array_slice_double_argument</output-dir>
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index da5f0ab9b8..4276a14981 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -4407,7 +4407,7 @@ AbstractAccessor IndexAccessor(Expression inputExpr)
throws ParseException:
(
<MUL> { star = true; }
|
- ( expr1 = Expression() ( <COLON> { slice = true; } ( expr2 = Expression()
)? )? )
+ ( (expr1 = Expression()) ? ( <COLON> { slice = true; } ( expr2 =
Expression() )? )? )
)
<RIGHTBRACKET>
{
@@ -4418,10 +4418,14 @@ AbstractAccessor IndexAccessor(Expression inputExpr)
throws ParseException:
ensureIntegerLiteral( (LiteralExpr) expr2, "Index");
}
AbstractAccessor resultAccessor;
- if (slice) {
+
+ if (star) {
+ resultAccessor = new IndexAccessor(inputExpr,
IndexAccessor.IndexKind.STAR, null);
+ } else if (slice || expr1 == null) {
+ if (expr1 == null) {
+ expr1 = new LiteralExpr(new LongIntegerLiteral(0L));
+ }
resultAccessor = new ListSliceExpression(inputExpr, expr1, expr2);
- } else if (star) {
- resultAccessor = new IndexAccessor(inputExpr,
IndexAccessor.IndexKind.STAR, null);
} else {
resultAccessor = new IndexAccessor(inputExpr,
IndexAccessor.IndexKind.ELEMENT, expr1);
}