Dmitry Lychagin has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/2859

Change subject: [ASTERIXDB-2439][COMP] SELECT v.* should not fail if v is not 
an object
......................................................................

[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
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
M 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/select-star/var_star_2/var_star_2.1.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/select-star/var_star_2/var_star_2.2.query.sqlpp
M 
asterixdb/asterix-app/src/test/resources/runtimets/results/limit/push-limit-to-primary-lookup-select/push-limit-to-primary-lookup-select.5.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/select-star/var_star_2/var_star_2.1.adm
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/select-star/var_star_2/var_star_2.2.adm
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
7 files changed, 52 insertions(+), 7 deletions(-)


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

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 033c92f..b6fd0c6 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;
@@ -41,7 +42,9 @@
 import org.apache.asterix.lang.common.expression.LiteralExpr;
 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.VarIdentifier;
 import org.apache.asterix.lang.common.util.FunctionUtil;
@@ -64,6 +67,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;
@@ -710,18 +714,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 dedabbe..48fcb99 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>

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2859
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I925ff19d8ee226c5db59172b4d1952be27265130
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Dmitry Lychagin <[email protected]>

Reply via email to