kylin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liy...@apache.org
Subject [26/30] incubator-kylin git commit: KYLIN-993 Code review, minor formattings
Date Wed, 18 Nov 2015 02:39:20 GMT
KYLIN-993 Code review, minor formattings


Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/3285a42a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/3285a42a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/3285a42a

Branch: refs/heads/1.x-HBase1.1.3
Commit: 3285a42ab4d376cda314b06237f5f78de54016b7
Parents: bed15ab
Author: Li, Yang <yangli9@ebay.com>
Authored: Tue Nov 17 17:47:13 2015 +0800
Committer: Li, Yang <yangli9@ebay.com>
Committed: Tue Nov 17 17:47:13 2015 +0800

----------------------------------------------------------------------
 .../metadata/filter/CompareTupleFilter.java     | 22 +++--
 .../metadata/filter/FunctionTupleFilter.java    | 13 ++-
 .../metadata/filter/util/BuiltInMethod.java     |  8 +-
 .../kylin/storage/hbase/CubeStorageEngine.java  |  3 +-
 .../storage/hbase/FuzzyValueCombination.java    |  2 -
 .../CoprocessorTupleFilterTranslator.java       | 93 +++++++++-----------
 6 files changed, 67 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3285a42a/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
index 6754ff7..73fd0fb 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
@@ -19,9 +19,12 @@
 package org.apache.kylin.metadata.filter;
 
 import java.nio.ByteBuffer;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
 
-import org.apache.calcite.sql.SqlFunction;
 import org.apache.kylin.common.util.BytesUtil;
 import org.apache.kylin.metadata.model.TblColRef;
 import org.apache.kylin.metadata.tuple.ITuple;
@@ -31,12 +34,15 @@ import org.apache.kylin.metadata.tuple.ITuple;
  */
 public class CompareTupleFilter extends TupleFilter {
 
+    // operand 1 is either a column or a function
     private TblColRef column;
+    private FunctionTupleFilter function;
+    
+    // operand 2 is constants
     private Collection<String> conditionValues;
     private String firstCondValue;
     private Map<String, String> dynamicVariables;
     private String nullString;
-    private FunctionTupleFilter functionTupleFilter;
 
     public CompareTupleFilter(FilterOperatorEnum op) {
         super(new ArrayList<TupleFilter>(2), op);
@@ -80,7 +86,7 @@ public class CompareTupleFilter extends TupleFilter {
             DynamicTupleFilter dynamicFilter = (DynamicTupleFilter) child;
             this.dynamicVariables.put(dynamicFilter.getVariableName(), null);
         } else if (child instanceof FunctionTupleFilter) {
-            this.functionTupleFilter = (FunctionTupleFilter)child;
+            this.function = (FunctionTupleFilter)child;
         }
         //TODO
         //        else if (child instanceof ExtractTupleFilter) {
@@ -105,8 +111,8 @@ public class CompareTupleFilter extends TupleFilter {
         return column;
     }
 
-    public FunctionTupleFilter getFunctionTupleFilter() {
-        return functionTupleFilter;
+    public FunctionTupleFilter getFunction() {
+        return function;
     }
 
     public Map<String, String> getVariables() {
@@ -141,7 +147,7 @@ public class CompareTupleFilter extends TupleFilter {
 
     @Override
     public String toString() {
-        return "CompareFilter [" + (functionTupleFilter == null ? column : functionTupleFilter)
+ " " + operator + " " + conditionValues + ", children=" + children + "]";
+        return "CompareFilter [" + (function == null ? column : function) + " " + operator
+ " " + conditionValues + ", children=" + children + "]";
     }
 
     // TODO requires generalize, currently only evaluates COLUMN {op} CONST
@@ -213,7 +219,7 @@ public class CompareTupleFilter extends TupleFilter {
 
     @Override
     public boolean isEvaluable() {
-        return (functionTupleFilter != null || column != null) && !conditionValues.isEmpty();
+        return (function != null || column != null) && !conditionValues.isEmpty();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3285a42a/metadata/src/main/java/org/apache/kylin/metadata/filter/FunctionTupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/FunctionTupleFilter.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/FunctionTupleFilter.java
index 62ab42f..731e5ab 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/FunctionTupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/FunctionTupleFilter.java
@@ -47,7 +47,7 @@ public class FunctionTupleFilter extends TupleFilter {
     private boolean isValid = false;
 
     public FunctionTupleFilter(SqlOperator sqlOperator) {
-        super(Lists.<TupleFilter>newArrayList(), FilterOperatorEnum.FUNCTION);
+        super(Lists.<TupleFilter> newArrayList(), FilterOperatorEnum.FUNCTION);
         this.methodParams = Lists.newArrayList();
         this.sqlOperator = sqlOperator;
 
@@ -67,9 +67,9 @@ public class FunctionTupleFilter extends TupleFilter {
             return null;
 
         if (columnContainerFilter instanceof ColumnTupleFilter)
-            return ((ColumnTupleFilter)columnContainerFilter).getColumn();
+            return ((ColumnTupleFilter) columnContainerFilter).getColumn();
         else if (columnContainerFilter instanceof FunctionTupleFilter)
-            return ((FunctionTupleFilter)columnContainerFilter).getColumn();
+            return ((FunctionTupleFilter) columnContainerFilter).getColumn();
 
         throw new UnsupportedOperationException("Wrong type TupleFilter in FunctionTupleFilter.");
     }
@@ -79,7 +79,7 @@ public class FunctionTupleFilter extends TupleFilter {
             methodParams.set(colPosition, input);
         else if (columnContainerFilter instanceof FunctionTupleFilter)
             methodParams.set(colPosition, ((FunctionTupleFilter) columnContainerFilter).invokeFunction(input));
-        return method.invoke(null, (Object[])(methodParams.toArray()));
+        return method.invoke(null, (Object[]) (methodParams.toArray()));
     }
 
     public boolean isValid() {
@@ -87,7 +87,6 @@ public class FunctionTupleFilter extends TupleFilter {
     }
 
     @Override
-    @SuppressWarnings("unchecked")
     public void addChild(TupleFilter child) {
         if (child instanceof ColumnTupleFilter || child instanceof FunctionTupleFilter) {
             columnContainerFilter = child;
@@ -96,7 +95,7 @@ public class FunctionTupleFilter extends TupleFilter {
         } else if (child instanceof ConstantTupleFilter) {
             String constVal = child.getValues().iterator().next();
             try {
-                Class clazz = Primitives.wrap(method.getParameterTypes()[methodParams.size()]);
+                Class<?> clazz = Primitives.wrap(method.getParameterTypes()[methodParams.size()]);
                 if (!Primitives.isWrapperType(clazz))
                     methodParams.add(constVal);
                 else
@@ -125,7 +124,7 @@ public class FunctionTupleFilter extends TupleFilter {
     }
 
     @Override
-    public String toString(){
+    public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append(sqlOperator.getName());
         sb.append("(");

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3285a42a/metadata/src/main/java/org/apache/kylin/metadata/filter/util/BuiltInMethod.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/util/BuiltInMethod.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/util/BuiltInMethod.java
index 1f15c9c..3a36385 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/util/BuiltInMethod.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/util/BuiltInMethod.java
@@ -18,12 +18,12 @@
 
 package org.apache.kylin.metadata.filter.util;
 
-import com.google.common.collect.ImmutableMap;
-import org.apache.calcite.avatica.util.DateTimeUtils;
+import java.lang.reflect.Method;
+
 import org.apache.calcite.linq4j.tree.Types;
 import org.apache.calcite.runtime.SqlFunctions;
 
-import java.lang.reflect.Method;
+import com.google.common.collect.ImmutableMap;
 
 /**
  * Created by dongli on 11/13/15.
@@ -50,7 +50,7 @@ public enum BuiltInMethod {
         MAP = builder.build();
     }
 
-    BuiltInMethod(Class clazz, String methodName, Class... argumentTypes) {
+    BuiltInMethod(Class<?> clazz, String methodName, Class<?>... argumentTypes)
{
         this.method = Types.lookupMethod(clazz, methodName, argumentTypes);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3285a42a/storage/src/main/java/org/apache/kylin/storage/hbase/CubeStorageEngine.java
----------------------------------------------------------------------
diff --git a/storage/src/main/java/org/apache/kylin/storage/hbase/CubeStorageEngine.java b/storage/src/main/java/org/apache/kylin/storage/hbase/CubeStorageEngine.java
index fdb8986..ed12781 100644
--- a/storage/src/main/java/org/apache/kylin/storage/hbase/CubeStorageEngine.java
+++ b/storage/src/main/java/org/apache/kylin/storage/hbase/CubeStorageEngine.java
@@ -267,7 +267,8 @@ public class CubeStorageEngine implements IStorageEngine {
     }
 
     private void collectColumnsRecursively(TupleFilter filter, Set<TblColRef> collector)
{
-        if (filter == null) return;
+        if (filter == null)
+            return;
 
         if (filter instanceof ColumnTupleFilter) {
             collectColumns(((ColumnTupleFilter) filter).getColumn(), collector);

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3285a42a/storage/src/main/java/org/apache/kylin/storage/hbase/FuzzyValueCombination.java
----------------------------------------------------------------------
diff --git a/storage/src/main/java/org/apache/kylin/storage/hbase/FuzzyValueCombination.java
b/storage/src/main/java/org/apache/kylin/storage/hbase/FuzzyValueCombination.java
index 616a232..ce14b2b 100644
--- a/storage/src/main/java/org/apache/kylin/storage/hbase/FuzzyValueCombination.java
+++ b/storage/src/main/java/org/apache/kylin/storage/hbase/FuzzyValueCombination.java
@@ -18,9 +18,7 @@
 
 package org.apache.kylin.storage.hbase;
 
-import java.util.Arrays;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3285a42a/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorTupleFilterTranslator.java
----------------------------------------------------------------------
diff --git a/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorTupleFilterTranslator.java
b/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorTupleFilterTranslator.java
index aae945d..6affc18 100644
--- a/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorTupleFilterTranslator.java
+++ b/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorTupleFilterTranslator.java
@@ -18,16 +18,20 @@
 
 package org.apache.kylin.storage.hbase.coprocessor;
 
-import com.google.common.primitives.Primitives;
 import org.apache.kylin.cube.kv.RowKeyColumnIO;
 import org.apache.kylin.dict.Dictionary;
-import org.apache.kylin.metadata.filter.*;
+import org.apache.kylin.metadata.filter.ColumnTupleFilter;
+import org.apache.kylin.metadata.filter.CompareTupleFilter;
+import org.apache.kylin.metadata.filter.ConstantTupleFilter;
+import org.apache.kylin.metadata.filter.FunctionTupleFilter;
+import org.apache.kylin.metadata.filter.ITupleFilterTranslator;
+import org.apache.kylin.metadata.filter.TupleFilter;
 import org.apache.kylin.metadata.filter.TupleFilter.FilterOperatorEnum;
 import org.apache.kylin.metadata.model.TblColRef;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.reflect.InvocationTargetException;
+import com.google.common.primitives.Primitives;
 
 /**
  * Created by dongli on 11/11/15.
@@ -71,17 +75,11 @@ public class CoprocessorTupleFilterTranslator implements ITupleFilterTranslator
         try {
             for (int i = dict.getMinId(); i <= dict.getMaxId(); i++) {
                 String dictVal = dict.getValueFromId(i);
-                if ((Boolean)functionTupleFilter.invokeFunction(dictVal)) {
+                if ((Boolean) functionTupleFilter.invokeFunction(dictVal)) {
                     translated.addChild(new ConstantTupleFilter(dictVal));
                 }
             }
-        } catch (IllegalAccessException e) {
-            logger.debug(e.getMessage());
-            return null;
-        } catch (InvocationTargetException e) {
-            logger.debug(e.getMessage());
-            return null;
-        } catch (IllegalArgumentException e) {
+        } catch (Exception e) {
             logger.debug(e.getMessage());
             return null;
         }
@@ -89,11 +87,11 @@ public class CoprocessorTupleFilterTranslator implements ITupleFilterTranslator
     }
 
     @SuppressWarnings("unchecked")
-    private TupleFilter translateCompareTupleFilter(CompareTupleFilter compTupleFilter){
-        if (compTupleFilter.getFunctionTupleFilter() == null)
+    private TupleFilter translateCompareTupleFilter(CompareTupleFilter compTupleFilter) {
+        if (compTupleFilter.getFunction() == null)
             return null;
 
-        FunctionTupleFilter functionTupleFilter = compTupleFilter.getFunctionTupleFilter();
+        FunctionTupleFilter functionTupleFilter = compTupleFilter.getFunction();
         if (!functionTupleFilter.isValid())
             return null;
 
@@ -109,55 +107,46 @@ public class CoprocessorTupleFilterTranslator implements ITupleFilterTranslator
             for (int i = dict.getMinId(); i <= dict.getMaxId(); i++) {
                 String dictVal = dict.getValueFromId(i);
                 Object computedVal = functionTupleFilter.invokeFunction(dictVal);
-                Class clazz = Primitives.wrap(computedVal.getClass());
+                Class<?> clazz = Primitives.wrap(computedVal.getClass());
                 Object targetVal = compTupleFilter.getFirstValue();
                 if (Primitives.isWrapperType(clazz))
                     targetVal = clazz.cast(clazz.getDeclaredMethod("valueOf", String.class).invoke(null,
compTupleFilter.getFirstValue()));
 
-                int comp = ((Comparable)computedVal).compareTo(targetVal);
+                int comp = ((Comparable<Object>) computedVal).compareTo(targetVal);
                 boolean compResult = false;
                 switch (compTupleFilter.getOperator()) {
-                    case EQ:
-                        compResult = comp == 0;
-                        break;
-                    case NEQ:
-                        compResult = comp != 0;
-                        break;
-                    case LT:
-                        compResult = comp < 0;
-                        break;
-                    case LTE:
-                        compResult = comp <= 0;
-                        break;
-                    case GT:
-                        compResult = comp > 0;
-                        break;
-                    case GTE:
-                        compResult = comp >= 0;
-                        break;
-                    case IN:
-                        compResult = compTupleFilter.getValues().contains(computedVal.toString());
-                        break;
-                    case NOTIN:
-                        compResult = !compTupleFilter.getValues().contains(computedVal.toString());
-                        break;
-                    default:
-                        break;
+                case EQ:
+                    compResult = comp == 0;
+                    break;
+                case NEQ:
+                    compResult = comp != 0;
+                    break;
+                case LT:
+                    compResult = comp < 0;
+                    break;
+                case LTE:
+                    compResult = comp <= 0;
+                    break;
+                case GT:
+                    compResult = comp > 0;
+                    break;
+                case GTE:
+                    compResult = comp >= 0;
+                    break;
+                case IN:
+                    compResult = compTupleFilter.getValues().contains(computedVal.toString());
+                    break;
+                case NOTIN:
+                    compResult = !compTupleFilter.getValues().contains(computedVal.toString());
+                    break;
+                default:
+                    break;
                 }
                 if (compResult) {
                     translated.addChild(new ConstantTupleFilter(dictVal));
                 }
             }
-        } catch (IllegalAccessException e) {
-            logger.debug(e.getMessage());
-            return null;
-        } catch (InvocationTargetException e) {
-            logger.debug(e.getMessage());
-            return null;
-        } catch (IllegalArgumentException e) {
-            logger.debug(e.getMessage());
-            return null;
-        } catch (NoSuchMethodException e) {
+        } catch (Exception e) {
             logger.debug(e.getMessage());
             return null;
         }


Mime
View raw message