asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Till Westmann (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: WIP - DO NOT REVIEW YET
Date Sat, 05 Mar 2016 00:35:23 GMT
Till Westmann has uploaded a new change for review.

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

Change subject: WIP - DO NOT REVIEW YET
......................................................................

WIP - DO NOT REVIEW YET

add NonTaggedFormatUtil.getNonOptionalType

Change-Id: If76d261f7b5526269ad3ecda5e172bff58f2b4bc
---
M asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/CheckFilterExpressionTypeRule.java
M asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
M asterix-om/src/main/java/org/apache/asterix/om/pointables/ARecordVisitablePointable.java
M asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/Substring2TypeComputer.java
M asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java
5 files changed, 17 insertions(+), 53 deletions(-)


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

diff --git a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/CheckFilterExpressionTypeRule.java
b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/CheckFilterExpressionTypeRule.java
index 3eadba3..5bd40c8 100644
--- a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/CheckFilterExpressionTypeRule.java
+++ b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/CheckFilterExpressionTypeRule.java
@@ -19,12 +19,11 @@
 
 package org.apache.asterix.optimizer.rules;
 
-import org.apache.commons.lang3.mutable.Mutable;
-
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.AUnionType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.om.util.NonTaggedFormatUtil;
+import org.apache.commons.lang3.mutable.Mutable;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
@@ -45,7 +44,8 @@
 public class CheckFilterExpressionTypeRule implements IAlgebraicRewriteRule {
 
     @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext
context) throws AlgebricksException {
+    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext
context)
+            throws AlgebricksException {
         return false;
     }
 
@@ -60,28 +60,11 @@
         ILogicalExpression condition = select.getCondition().getValue();
         IVariableTypeEnvironment env = select.computeOutputTypeEnvironment(context);
         IAType condType = (IAType) env.getType(condition);
-        if (condType.getTypeTag() != ATypeTag.BOOLEAN && condType.getTypeTag() !=
ATypeTag.ANY
-                && !isPossibleBoolean(condType)) {
-            throw new AlgebricksException("The select condition " + condition.toString()
-                    + " should be of the boolean type.");
+        ATypeTag confTypeTag = NonTaggedFormatUtil.getNonOptionalType(condType).getTypeTag();
+        if (confTypeTag != ATypeTag.BOOLEAN && confTypeTag != ATypeTag.ANY) {
+            throw new AlgebricksException(
+                    "The select condition " + condition.toString() + " should be of the boolean
type.");
         }
         return false;
     }
-
-    /**
-     * Check if the type is optional boolean or not
-     *
-     * @param type
-     * @return true if it is; false otherwise.
-     */
-    private boolean isPossibleBoolean(IAType type) {
-        while (NonTaggedFormatUtil.isOptional(type)) {
-            type = ((AUnionType) type).getNullableType();
-            if (type.getTypeTag() == ATypeTag.BOOLEAN || type.getTypeTag() == ATypeTag.ANY)
{
-                return true;
-            }
-        }
-        return false;
-    }
-
 }
diff --git a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
index de6eebf..14f0f3b 100644
--- a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
+++ b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
@@ -272,10 +272,7 @@
             if (!reqFieldNames[i].equals(inputFieldNames[i])) {
                 return false;
             }
-            IAType reqTypeInside = reqTypes[i];
-            if (NonTaggedFormatUtil.isOptional(reqTypes[i])) {
-                reqTypeInside = ((AUnionType) reqTypes[i]).getNullableType();
-            }
+            IAType reqTypeInside = NonTaggedFormatUtil.getNonOptionalType(reqTypes[i]);
             IAType inputTypeInside = inputTypes[i];
             if (NonTaggedFormatUtil.isOptional(inputTypes[i])) {
                 if (!NonTaggedFormatUtil.isOptional(reqTypes[i])) {
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/ARecordVisitablePointable.java
b/asterix-om/src/main/java/org/apache/asterix/om/pointables/ARecordVisitablePointable.java
index 67b62d6..944b2a6 100644
--- a/asterix-om/src/main/java/org/apache/asterix/om/pointables/ARecordVisitablePointable.java
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/ARecordVisitablePointable.java
@@ -99,11 +99,7 @@
         typeBos.reset();
         try {
             for (int i = 0; i < numberOfSchemaFields; i++) {
-                ATypeTag ftypeTag = fieldTypes[i].getTypeTag();
-
-                if (NonTaggedFormatUtil.isOptional(fieldTypes[i]))
-                    // optional field: add the embedded non-null type tag
-                    ftypeTag = ((AUnionType) fieldTypes[i]).getNullableType().getTypeTag();
+                ATypeTag ftypeTag = NonTaggedFormatUtil.getNonOptionalType(fieldTypes[i]).getTypeTag();
 
                 // add type tag Reference
                 int tagStart = typeBos.size();
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/Substring2TypeComputer.java
b/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/Substring2TypeComputer.java
index 6cc2f6d..e139253 100644
--- a/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/Substring2TypeComputer.java
+++ b/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/Substring2TypeComputer.java
@@ -20,7 +20,6 @@
 
 import org.apache.asterix.om.typecomputer.base.IResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.AUnionType;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.om.util.NonTaggedFormatUtil;
@@ -42,26 +41,11 @@
         }
         ILogicalExpression arg0 = fce.getArguments().get(0).getValue();
         ILogicalExpression arg1 = fce.getArguments().get(1).getValue();
-        IAType t0, t1;
-        try {
-            t0 = (IAType) env.getType(arg0);
-            t1 = (IAType) env.getType(arg1);
-        } catch (AlgebricksException e) {
-            throw new AlgebricksException(e);
-        }
+        IAType t0 = (IAType) env.getType(arg0);
+        IAType t1 = (IAType) env.getType(arg1);
 
-        ATypeTag tag0, tag1;
-        if (NonTaggedFormatUtil.isOptional(t0)) {
-            tag0 = ((AUnionType) t0).getNullableType().getTypeTag();
-        } else {
-            tag0 = t0.getTypeTag();
-        }
-
-        if (NonTaggedFormatUtil.isOptional(t1)) {
-            tag1 = ((AUnionType) t1).getNullableType().getTypeTag();
-        } else {
-            tag1 = t1.getTypeTag();
-        }
+        ATypeTag tag0 = NonTaggedFormatUtil.getNonOptionalType(t0).getTypeTag();
+        ATypeTag tag1 = NonTaggedFormatUtil.getNonOptionalType(t1).getTypeTag();
 
         // Allow substring to work with ANY types, i.e., types that are unknown at compile
time.
         if (tag0 == ATypeTag.ANY || tag1 == ATypeTag.ANY) {
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java
b/asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java
index c24ce45..6651375 100644
--- a/asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java
+++ b/asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java
@@ -105,6 +105,10 @@
         return type.getTypeTag() == ATypeTag.UNION && ((AUnionType) type).isNullableType();
     }
 
+    public static IAType getNonOptionalType(IAType type) {
+        return isOptional(type) ? ((AUnionType) type).getNullableType() : type;
+    }
+
     public static int getFieldValueLength(byte[] serNonTaggedAObject, int offset, ATypeTag
typeTag, boolean tagged)
             throws AsterixException {
         switch (typeTag) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If76d261f7b5526269ad3ecda5e172bff58f2b4bc
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <tillw@apache.org>

Mime
View raw message