[ASTERIXDB-2439][COMP] SELECT v.* should not fail if v is not an object
- user model changes: yes
- storage format changes: no
- interface changes: no
Details:
- SELECT v.* should return an empty object if v is not an object
- If other projections are present in the SELECT clause
then v.* should be ignored if v is not an object
- Remove trailing whitespace in push-limit-to-primary-lookup-select.5.adm
Change-Id: I925ff19d8ee226c5db59172b4d1952be27265130
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2859
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
index c9ab86e..42b38c6 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
@@ -20,6 +20,7 @@
import java.util.ArrayDeque;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
@@ -44,7 +45,9 @@
import org.apache.asterix.lang.common.expression.QuantifiedExpression;
import org.apache.asterix.lang.common.expression.RecordConstructor;
import org.apache.asterix.lang.common.expression.VariableExpr;
+import org.apache.asterix.lang.common.literal.MissingLiteral;
import org.apache.asterix.lang.common.literal.StringLiteral;
+import org.apache.asterix.lang.common.literal.TrueLiteral;
import org.apache.asterix.lang.common.statement.Query;
import org.apache.asterix.lang.common.struct.OperatorType;
import org.apache.asterix.lang.common.struct.QuantifiedPair;
@@ -69,6 +72,7 @@
import org.apache.asterix.lang.sqlpp.optype.SetOpType;
import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
+import org.apache.asterix.lang.sqlpp.util.SqlppRewriteUtil;
import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor;
import org.apache.asterix.metadata.declared.MetadataProvider;
@@ -731,18 +735,27 @@
}
// Generates the return expression for a regular select clause.
- private Expression generateReturnExpr(SelectRegular selectRegular, SelectBlock selectBlock) {
+ private Expression generateReturnExpr(SelectRegular selectRegular, SelectBlock selectBlock)
+ throws CompilationException {
List<Expression> recordExprs = new ArrayList<>();
List<FieldBinding> fieldBindings = new ArrayList<>();
for (Projection projection : selectRegular.getProjections()) {
if (projection.varStar()) {
+ SourceLocation sourceLoc = projection.getSourceLocation();
if (!fieldBindings.isEmpty()) {
RecordConstructor recordConstr = new RecordConstructor(new ArrayList<>(fieldBindings));
- recordConstr.setSourceLocation(projection.getSourceLocation());
+ recordConstr.setSourceLocation(sourceLoc);
recordExprs.add(recordConstr);
fieldBindings.clear();
}
- recordExprs.add(projection.getExpression());
+ Expression projectionExpr = projection.getExpression();
+ CallExpr toObjectExpr = new CallExpr(new FunctionSignature(BuiltinFunctions.TO_OBJECT),
+ Collections.singletonList(projectionExpr));
+ toObjectExpr.setSourceLocation(sourceLoc);
+ CallExpr ifMissingOrNullExpr = new CallExpr(new FunctionSignature(BuiltinFunctions.IF_MISSING_OR_NULL),
+ Arrays.asList(toObjectExpr, new RecordConstructor(Collections.emptyList())));
+ ifMissingOrNullExpr.setSourceLocation(sourceLoc);
+ recordExprs.add(ifMissingOrNullExpr);
} else if (projection.star()) {
if (selectBlock.hasGroupbyClause()) {
getGroupBindings(selectBlock.getGroupbyClause(), fieldBindings);
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/select-star/var_star_2/var_star_2.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/select-star/var_star_2/var_star_2.1.query.sqlpp
index 3598c13..fcee460 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/select-star/var_star_2/var_star_2.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/select-star/var_star_2/var_star_2.1.query.sqlpp
@@ -19,8 +19,9 @@
/*
* Description : Invalid data type in select var.*
- * Expected Res : Failure
+ * Expected Res : Success
*/
SELECT t, t.*
FROM [1, 2, 3] t
+ ORDER BY t
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/select-star/var_star_2/var_star_2.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/select-star/var_star_2/var_star_2.2.query.sqlpp
new file mode 100644
index 0000000..a2a6dd3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/select-star/var_star_2/var_star_2.2.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.
+ */
+
+/*
+ * Description : Invalid data type in select var.*
+ * Expected Res : Success
+ */
+
+ SELECT t.*
+ FROM [1, 2, 3] t
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/push-limit-to-primary-lookup-select/push-limit-to-primary-lookup-select.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/push-limit-to-primary-lookup-select/push-limit-to-primary-lookup-select.5.adm
index 6f265b3..7d9ef47 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/push-limit-to-primary-lookup-select/push-limit-to-primary-lookup-select.5.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/push-limit-to-primary-lookup-select/push-limit-to-primary-lookup-select.5.adm
@@ -22,7 +22,7 @@
-- BTREE_SEARCH |PARTITIONED|
exchange
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
- order (ASC, $$24) (ASC, $$25)
+ order (ASC, $$24) (ASC, $$25)
-- STABLE_SORT [$$24(ASC), $$25(ASC)] |PARTITIONED|
exchange
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/select-star/var_star_2/var_star_2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/select-star/var_star_2/var_star_2.1.adm
new file mode 100644
index 0000000..310bc8e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/select-star/var_star_2/var_star_2.1.adm
@@ -0,0 +1,3 @@
+{ "t": 1 }
+{ "t": 2 }
+{ "t": 3 }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/select-star/var_star_2/var_star_2.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/select-star/var_star_2/var_star_2.2.adm
new file mode 100644
index 0000000..fe22dac
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/select-star/var_star_2/var_star_2.2.adm
@@ -0,0 +1,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 fc777d5..faa621c 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -5943,8 +5943,7 @@
</test-case>
<test-case FilePath="select-star">
<compilation-unit name="var_star_2">
- <output-dir compare="Text">var_star</output-dir>
- <expected-error>ASX0002: Type mismatch</expected-error>
+ <output-dir compare="Text">var_star_2</output-dir>
</compilation-unit>
</test-case>
</test-group>
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/2_string_common.md b/asterixdb/asterix-doc/src/main/markdown/builtins/2_string_common.md
index c9145fd..1c2fd7e 100644
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/2_string_common.md
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/2_string_common.md
@@ -340,7 +340,7 @@
* `string_replacement` : a pattern `string` to be used as the replacement,
* `string_flag` : (Optional) a `string` with flags to be used during replace.
* The following modes are enabled with these flags: dotall (s), multiline (m), case_insensitive (i), and comments and whitespace (x).
- * `replacement_limit`: (Optional) an `integer` specifying the maximum number of replacements to make
+ * `replacement_limit`: (Optional) an `integer` specifying the maximum number of replacements to make
(if negative then all occurrences will be replaced)
* Return Value:
* Returns a `string` that is obtained after the replacements,