asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [1/3] asterixdb git commit: Add EXISTS/NOT EXISTS.
Date Sat, 16 Jul 2016 03:57:02 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master c1407ced9 -> 196db5d8a


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/196db5d8/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 06b067e..99b875a 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -77,7 +77,6 @@ import org.apache.asterix.lang.common.expression.RecordTypeDefinition;
 import org.apache.asterix.lang.common.expression.TypeExpression;
 import org.apache.asterix.lang.common.expression.TypeReferenceExpression;
 import org.apache.asterix.lang.common.expression.UnaryExpr;
-import org.apache.asterix.lang.common.expression.UnaryExpr.Sign;
 import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition;
 import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.literal.DoubleLiteral;
@@ -1618,7 +1617,11 @@ Expression OperatorExpr()throws ParseException:
           op.addOperand(operand);
         op.setCurrentop(true);
         }
-      op.addOperator(token.image.toLowerCase());
+        try{
+            op.addOperator(token.image.toLowerCase());
+        } catch (Exception e){
+            throw new ParseException(e.getMessage());
+        }
     }
 
     operand = AndExpr()
@@ -1639,7 +1642,7 @@ Expression AndExpr()throws ParseException:
   Expression operand = null;
 }
 {
-    operand = RelExpr()
+    operand = NotExpr()
     (
 
       <AND>
@@ -1647,12 +1650,16 @@ Expression AndExpr()throws ParseException:
         if (op == null) {
           op = new OperatorExpr();
           op.addOperand(operand);
-        op.setCurrentop(true);
+          op.setCurrentop(true);
+        }
+        try{
+           op.addOperator(token.image.toLowerCase());
+        } catch (AsterixException e){
+           throw new ParseException(e.getMessage());
         }
-      op.addOperator(token.image.toLowerCase());
     }
 
-    operand = RelExpr()
+    operand = NotExpr()
     {
       op.addOperand(operand);
     }
@@ -1664,7 +1671,22 @@ Expression AndExpr()throws ParseException:
     }
 }
 
-
+Expression NotExpr()throws ParseException:
+{
+   Expression inputExpr;
+   boolean not = false;
+}
+{
+  (<NOT> { not = true; } )? inputExpr = RelExpr()
+  {
+    if(not){
+        FunctionSignature signature = new FunctionSignature(null, "not", 1);
+        return new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(inputExpr)));
+    } else {
+        return inputExpr;
+    }
+  }
+}
 
 Expression RelExpr()throws ParseException:
 {
@@ -1706,7 +1728,11 @@ Expression RelExpr()throws ParseException:
             op.setCurrentop(true);
             broadcast = false;
           }
-          op.addOperator(operator);
+          try{
+            op.addOperator(operator);
+          } catch (AsterixException e){
+            throw new ParseException(e.getMessage());
+          }
         }
 
        operand = IsExpr()
@@ -1771,7 +1797,11 @@ Expression AddExpr()throws ParseException:
         op.addOperand(operand);
         op.setCurrentop(true);
         }
-      ((OperatorExpr)op).addOperator(token.image);
+        try{
+            ((OperatorExpr)op).addOperator(token.image);
+        } catch (Exception e){
+            throw new ParseException(e.getMessage());
+        }
     }
 
     operand = MultExpr()
@@ -1800,7 +1830,11 @@ Expression MultExpr()throws ParseException:
         op.addOperand(operand);
         op.setCurrentop(true);
         }
-      op.addOperator(token.image);
+        try{
+            op.addOperator(token.image);
+        } catch (Exception e){
+            throw new ParseException(e.getMessage());
+        }
     }
     operand = UnaryExpr()
     {
@@ -1815,39 +1849,33 @@ Expression MultExpr()throws ParseException:
 
 Expression UnaryExpr() throws ParseException:
 {
-    Expression uexpr = null;
+    boolean not = false;
+    UnaryExpr uexpr = null;
     Expression expr = null;
-    FunctionSignature signature = null;
-}
-{
-    ( (<PLUS> | <MINUS> | <NOT>)
-    {
-        switch(token.image){
-            case "+":
-                uexpr = new UnaryExpr();
-                ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
-                break;
-            case "-":
-                uexpr = new UnaryExpr();
-                ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
-                break;
-            default:
-                signature = new FunctionSignature(null, "not", 1);
-                break;
+}
+{
+    ( (<PLUS> | <MINUS> | (<NOT> { not = true; } )? <EXISTS> )
+    {
+        String exprType = token.image.toLowerCase();
+        if(not){
+           exprType = "not_" + exprType;
+        }
+        uexpr = new UnaryExpr();
+        try{
+            uexpr.setExprType(exprType);
+        } catch (AsterixException e){
+            throw new ParseException(e.getMessage());
         }
     }
     )?
 
     expr = ValueExpr()
     {
-        if(uexpr!=null){
-            ((UnaryExpr)uexpr).setExpr(expr);
-            return uexpr;
-        } else if (signature!=null){
-            return new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(expr)));
-        } else{
+       if(uexpr==null){
             return expr;
-        }
+       }
+       uexpr.setExpr(expr);
+       return uexpr;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/196db5d8/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/ConstantExpression.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/ConstantExpression.java
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/ConstantExpression.java
index 33da4f9..8f55632 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/ConstantExpression.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/ConstantExpression.java
@@ -22,6 +22,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.commons.lang3.mutable.Mutable;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -33,7 +34,7 @@ import org.apache.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionVis
 public final class ConstantExpression extends AbstractLogicalExpression {
     private IAlgebricksConstantValue value;
 
-    public final static ConstantExpression TRUE = new ConstantExpression(new IAlgebricksConstantValue()
{
+    public static final ConstantExpression TRUE = new ConstantExpression(new IAlgebricksConstantValue()
{
 
         @Override
         public boolean isTrue() {
@@ -60,7 +61,7 @@ public final class ConstantExpression extends AbstractLogicalExpression
{
             return "TRUE";
         }
     });
-    public final static ConstantExpression FALSE = new ConstantExpression(new IAlgebricksConstantValue()
{
+    public static final ConstantExpression FALSE = new ConstantExpression(new IAlgebricksConstantValue()
{
 
         @Override
         public boolean isTrue() {
@@ -87,7 +88,7 @@ public final class ConstantExpression extends AbstractLogicalExpression
{
             return "FALSE";
         }
     });
-    public final static ConstantExpression MISSING = new ConstantExpression(new IAlgebricksConstantValue()
{
+    public static final ConstantExpression MISSING = new ConstantExpression(new IAlgebricksConstantValue()
{
 
         @Override
         public boolean isTrue() {
@@ -115,7 +116,7 @@ public final class ConstantExpression extends AbstractLogicalExpression
{
         }
     });
 
-    private Map<Object, IExpressionAnnotation> annotationMap = new HashMap<Object,
IExpressionAnnotation>();
+    private Map<Object, IExpressionAnnotation> annotationMap = new HashMap<>();
 
     public ConstantExpression(IAlgebricksConstantValue value) {
         this.value = value;
@@ -170,10 +171,10 @@ public final class ConstantExpression extends AbstractLogicalExpression
{
 
     @Override
     public AbstractLogicalExpression cloneExpression() {
-        Map<Object, IExpressionAnnotation> m = new HashMap<Object, IExpressionAnnotation>();
-        for (Object k : annotationMap.keySet()) {
-            IExpressionAnnotation annot2 = annotationMap.get(k).copy();
-            m.put(k, annot2);
+        Map<Object, IExpressionAnnotation> m = new HashMap<>();
+        for (Entry<Object, IExpressionAnnotation> entry : annotationMap.entrySet())
{
+            IExpressionAnnotation annot2 = entry.getValue().copy();
+            m.put(entry.getKey(), annot2);
         }
         ConstantExpression c = new ConstantExpression(value);
         c.annotationMap = m;


Mime
View raw message