asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject asterixdb git commit: introduce ConstantExpressionUtil
Date Fri, 12 Aug 2016 18:08:56 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 9d63f9f24 -> de5746e6b


introduce ConstantExpressionUtil

Change-Id: Ic0034bd6ba7f449a03eda48070a8de614608c2dd
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1069
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/de5746e6
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/de5746e6
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/de5746e6

Branch: refs/heads/master
Commit: de5746e6b6e2c6f6cc49c30c3dd62511a3ccf9a0
Parents: 9d63f9f
Author: Till Westmann <tillw@apache.org>
Authored: Fri Aug 12 09:31:05 2016 -0700
Committer: Till Westmann <tillw@apache.org>
Committed: Fri Aug 12 11:08:02 2016 -0700

----------------------------------------------------------------------
 .../algebra/util/ConstantExpressionUtil.java    | 66 ++++++++++++++++++++
 .../optimizer/rules/UnnestToDataScanRule.java   | 21 +------
 .../LangExpressionToPlanTranslator.java         |  1 -
 3 files changed, 68 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/de5746e6/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/util/ConstantExpressionUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/util/ConstantExpressionUtil.java
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/util/ConstantExpressionUtil.java
new file mode 100644
index 0000000..300ef9d
--- /dev/null
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/util/ConstantExpressionUtil.java
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+package org.apache.asterix.algebra.util;
+
+import org.apache.asterix.om.base.AInt32;
+import org.apache.asterix.om.base.AString;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.constants.AsterixConstantValue;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
+import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.IAlgebricksConstantValue;
+
+public class ConstantExpressionUtil {
+
+    private static IAObject getAsterixConstantValue(AbstractFunctionCallExpression f, int
index, ATypeTag typeTag) {
+        final ILogicalExpression expr = f.getArguments().get(index).getValue();
+        if (expr.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
+            return null;
+        }
+        final IAlgebricksConstantValue acv = ((ConstantExpression) expr).getValue();
+        if (!(acv instanceof AsterixConstantValue)) {
+            return null;
+        }
+        final IAObject iaObject = ((AsterixConstantValue) acv).getObject();
+        return iaObject.getType().getTypeTag() == typeTag ? iaObject : null;
+    }
+
+    public static Integer getIntArgument(AbstractFunctionCallExpression f, int index) {
+        final IAObject iaObject = getAsterixConstantValue(f, index, ATypeTag.INT32);
+        return iaObject != null ? ((AInt32) iaObject).getIntegerValue() : null;
+    }
+
+    public static String getStringArgument(AbstractFunctionCallExpression f, int index) {
+        final IAObject iaObject = getAsterixConstantValue(f, index, ATypeTag.STRING);
+        return iaObject != null ? ((AString) iaObject).getStringValue() : null;
+    }
+
+    public static Integer getIntArgument(ILogicalExpression expr, int index) {
+        return expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL
+                ? getIntArgument((AbstractFunctionCallExpression) expr, index) : null;
+    }
+
+    public static String getStringArgument(ILogicalExpression expr, int index) {
+        return expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL
+                ? getStringArgument((AbstractFunctionCallExpression) expr, index) : null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/de5746e6/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/UnnestToDataScanRule.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/UnnestToDataScanRule.java
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/UnnestToDataScanRule.java
index d623830..69c9f7d 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/UnnestToDataScanRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/UnnestToDataScanRule.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.optimizer.rules;
 
+import static org.apache.asterix.algebra.util.ConstantExpressionUtil.getStringArgument;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -297,23 +299,4 @@ public class UnnestToDataScanRule implements IAlgebraicRewriteRule {
         }
         return new Pair<String, String>(dataverseName, datasetName);
     }
-
-    private String getStringArgument(AbstractFunctionCallExpression f, int index) {
-
-        ILogicalExpression expr = f.getArguments().get(index).getValue();
-        if (expr.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
-            return null;
-        }
-        ConstantExpression ce = (ConstantExpression) expr;
-        IAlgebricksConstantValue acv = ce.getValue();
-        if (!(acv instanceof AsterixConstantValue)) {
-            return null;
-        }
-        AsterixConstantValue acv2 = (AsterixConstantValue) acv;
-        if (acv2.getObject().getType().getTypeTag() != ATypeTag.STRING) {
-            return null;
-        }
-        String argument = ((AString) acv2.getObject()).getStringValue();
-        return argument;
-    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/de5746e6/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
index 5081587..d85419e 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
@@ -40,7 +40,6 @@ import org.apache.asterix.lang.aql.util.RangeMapBuilder;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Expression.Kind;
 import org.apache.asterix.lang.common.base.ILangExpression;
-import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;


Mime
View raw message