carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipes...@apache.org
Subject [1/2] incubator-carbondata git commit: filterutil test cases and Queryutil test cases added
Date Mon, 28 Nov 2016 03:19:02 GMT
Repository: incubator-carbondata
Updated Branches:
  refs/heads/master 739afbd71 -> c7c87e940


filterutil test cases and Queryutil test cases added


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

Branch: refs/heads/master
Commit: a9d608beacaf001cb13372bbc44601ba96e1f4df
Parents: 739afbd
Author: deepakmehra10 <deeps.deeps1991@gmail.com>
Authored: Wed Nov 23 16:58:42 2016 +0530
Committer: ravipesala <ravi.pesala@gmail.com>
Committed: Mon Nov 28 08:47:34 2016 +0530

----------------------------------------------------------------------
 .../scan/executor/util/QueryUtilTest.java       |  95 +++-
 .../carbondata/scan/filter/FilterUtilTest.java  | 473 +++++++++++++++++++
 2 files changed, 549 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a9d608be/core/src/test/java/org/apache/carbondata/scan/executor/util/QueryUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/executor/util/QueryUtilTest.java
b/core/src/test/java/org/apache/carbondata/scan/executor/util/QueryUtilTest.java
index 295a1f0..3fcbffa 100644
--- a/core/src/test/java/org/apache/carbondata/scan/executor/util/QueryUtilTest.java
+++ b/core/src/test/java/org/apache/carbondata/scan/executor/util/QueryUtilTest.java
@@ -22,12 +22,14 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.apache.carbondata.core.carbon.datastore.block.SegmentProperties;
 import org.apache.carbondata.core.carbon.datastore.block.SegmentPropertiesTestUtil;
 import org.apache.carbondata.core.keygenerator.KeyGenException;
 import org.apache.carbondata.scan.model.QueryDimension;
+
+import junit.framework.TestCase;
+import mockit.Mock;
+import mockit.MockUp;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -41,12 +43,12 @@ public class QueryUtilTest extends TestCase {
   }
 
   @Test public void testGetMaskedByteRangeGivingProperMaksedByteRange() {
-	  
-	QueryDimension dimension = new QueryDimension(segmentProperties.getDimensions().get(0).getColName());
-	dimension.setDimension(segmentProperties.getDimensions().get(0));  
+
+    QueryDimension dimension =
+        new QueryDimension(segmentProperties.getDimensions().get(0).getColName());
+    dimension.setDimension(segmentProperties.getDimensions().get(0));
     int[] maskedByteRange = QueryUtil
-        .getMaskedByteRange(Arrays.asList(dimension),
-            segmentProperties.getDimensionKeyGenerator());
+        .getMaskedByteRange(Arrays.asList(dimension), segmentProperties.getDimensionKeyGenerator());
     int[] expectedMaskedByteRange = { 0 };
     for (int i = 0; i < maskedByteRange.length; i++) {
       assertEquals(expectedMaskedByteRange[i], maskedByteRange[i]);
@@ -56,7 +58,8 @@ public class QueryUtilTest extends TestCase {
   @Test public void testGetMaskedByteRangeGivingProperMaksedByteRangeOnlyForDictionaryKey()
{
     List<QueryDimension> dimensions = new ArrayList<QueryDimension>();
     for (int i = 0; i < 2; i++) {
-      QueryDimension dimension = new QueryDimension(segmentProperties.getDimensions().get(i).getColName());
+      QueryDimension dimension =
+          new QueryDimension(segmentProperties.getDimensions().get(i).getColName());
       dimension.setDimension(segmentProperties.getDimensions().get(i));
       dimensions.add(dimension);
     }
@@ -80,12 +83,13 @@ public class QueryUtilTest extends TestCase {
   }
 
   @Test public void testGetMaxKeyBasedOnDimensions() {
-	  List<QueryDimension> dimensions = new ArrayList<QueryDimension>();
-	    for (int i = 0; i < 2; i++) {
-	      QueryDimension dimension = new QueryDimension(segmentProperties.getDimensions().get(i).getColName());
-	      dimension.setDimension(segmentProperties.getDimensions().get(i));
-	      dimensions.add(dimension);
-	    }
+    List<QueryDimension> dimensions = new ArrayList<QueryDimension>();
+    for (int i = 0; i < 2; i++) {
+      QueryDimension dimension =
+          new QueryDimension(segmentProperties.getDimensions().get(i).getColName());
+      dimension.setDimension(segmentProperties.getDimensions().get(i));
+      dimensions.add(dimension);
+    }
     byte[] maxKeyBasedOnDimensions = null;
     try {
       maxKeyBasedOnDimensions = QueryUtil
@@ -110,12 +114,12 @@ public class QueryUtilTest extends TestCase {
   }
 
   @Test public void testGetMaksedByte() {
-	  QueryDimension dimension = new QueryDimension(segmentProperties.getDimensions().get(0).getColName());
-		dimension.setDimension(segmentProperties.getDimensions().get(0)); 
-		dimension.setDimension(segmentProperties.getDimensions().get(0));
+    QueryDimension dimension =
+        new QueryDimension(segmentProperties.getDimensions().get(0).getColName());
+    dimension.setDimension(segmentProperties.getDimensions().get(0));
+    dimension.setDimension(segmentProperties.getDimensions().get(0));
     int[] maskedByteRange = QueryUtil
-        .getMaskedByteRange(Arrays.asList(dimension),
-            segmentProperties.getDimensionKeyGenerator());
+        .getMaskedByteRange(Arrays.asList(dimension), segmentProperties.getDimensionKeyGenerator());
     int[] maskedByte = QueryUtil
         .getMaskedByte(segmentProperties.getDimensionKeyGenerator().getDimCount(), maskedByteRange);
     int[] expectedMaskedByte = { 0, -1, -1, -1, -1, -1 };
@@ -127,6 +131,59 @@ public class QueryUtilTest extends TestCase {
     }
   }
 
+  @Test public void testSearchInArrayWithSearchInputNotPresentInArray() {
+    int[] dummyArray = { 1, 2, 3, 4, 5 };
+    int searchInput = 6;
+    boolean result = QueryUtil.searchInArray(dummyArray, searchInput);
+    assert (!result);
+  }
+
+  @Test public void testSearchInArrayWithSearchInputPresentInArray() {
+    int[] dummyArray = { 1, 2, 3, 4, 5 };
+    int searchInput = 1;
+    boolean result = QueryUtil.searchInArray(dummyArray, searchInput);
+    assert (result);
+  }
+
+  @Test public void testGetColumnGroupIdWhenOrdinalValueNotPresentInArrayIndex() {
+    int ordinal = 0;
+    new MockUp<SegmentProperties>() {
+      @Mock public int[][] getColumnGroups() {
+        int columnGroups[][] = { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 } };
+        return columnGroups;
+      }
+    };
+    int actualValue = QueryUtil.getColumnGroupId(segmentProperties, ordinal);
+    int expectedValue = 4; //expectedValue will always be arrayLength - 1
+    assertEquals(expectedValue, actualValue);
+  }
+
+  @Test public void testGetColumnGroupIdWhenOrdinalValuePresentInArrayIndex() {
+    int ordinal = 1;
+    new MockUp<SegmentProperties>() {
+      @Mock public int[][] getColumnGroups() {
+        int columnGroups[][] = { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 } };
+        return columnGroups;
+      }
+    };
+    int actualValue = QueryUtil.getColumnGroupId(segmentProperties, ordinal);
+    int expectedValue = 0;
+    assertEquals(expectedValue, actualValue);
+  }
+
+  @Test public void testGetColumnGroupIdWhenColumnGroupsIndexValueLengthLessThanOne() {
+    int ordinal = 1;
+    new MockUp<SegmentProperties>() {
+      @Mock public int[][] getColumnGroups() {
+        int columnGroups[][] = { { 1 } };
+        return columnGroups;
+      }
+    };
+    int actualValue = QueryUtil.getColumnGroupId(segmentProperties, ordinal);
+    int expectedValue = -1;
+    assertEquals(expectedValue, actualValue);
+  }
+
   @AfterClass public void tearDown() {
     segmentProperties = null;
   }

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a9d608be/core/src/test/java/org/apache/carbondata/scan/filter/FilterUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/filter/FilterUtilTest.java b/core/src/test/java/org/apache/carbondata/scan/filter/FilterUtilTest.java
new file mode 100644
index 0000000..ba4c46a
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/filter/FilterUtilTest.java
@@ -0,0 +1,473 @@
+/*
+ * 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.carbondata.scan.filter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest;
+import org.apache.carbondata.core.carbon.AbsoluteTableIdentifier;
+import org.apache.carbondata.core.carbon.CarbonTableIdentifier;
+import org.apache.carbondata.core.carbon.ColumnIdentifier;
+import org.apache.carbondata.core.carbon.datastore.IndexKey;
+import org.apache.carbondata.core.carbon.datastore.block.SegmentProperties;
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+import org.apache.carbondata.core.carbon.metadata.encoder.Encoding;
+import org.apache.carbondata.core.carbon.metadata.schema.table.column.CarbonColumn;
+import org.apache.carbondata.core.carbon.metadata.schema.table.column.CarbonDimension;
+import org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.keygenerator.KeyGenException;
+import org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator;
+import org.apache.carbondata.scan.executor.exception.QueryExecutionException;
+import org.apache.carbondata.scan.expression.ColumnExpression;
+import org.apache.carbondata.scan.expression.Expression;
+import org.apache.carbondata.scan.expression.LiteralExpression;
+import org.apache.carbondata.scan.expression.conditional.ListExpression;
+import org.apache.carbondata.scan.filter.intf.RowImpl;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertFalse;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+public class FilterUtilTest extends AbstractDictionaryCacheTest {
+
+  private ColumnSchema columnSchema;
+
+  @Before public void setUp() throws Exception {
+    init();
+    this.databaseName = props.getProperty("database", "testSchema");
+    this.tableName = props.getProperty("tableName", "carbon");
+    this.carbonStorePath = props.getProperty("storePath", "carbonStore");
+    carbonTableIdentifier =
+        new CarbonTableIdentifier(databaseName, tableName, UUID.randomUUID().toString());
+    this.carbonStorePath = props.getProperty("storePath", "carbonStore");
+    columnSchema = new ColumnSchema();
+    columnSchema.setColumnar(true);
+    columnSchema.setColumnName("IMEI");
+    columnSchema.setColumnUniqueId(UUID.randomUUID().toString());
+    columnSchema.setDataType(DataType.STRING);
+    columnSchema.setDimensionColumn(true);
+  }
+
+  @Test public void testCheckIfLeftExpressionRequireEvaluation() {
+    List<Expression> children = new ArrayList<>();
+    ListExpression expression = new ListExpression(children);
+    boolean result = FilterUtil.checkIfLeftExpressionRequireEvaluation(expression);
+    assertTrue(result);
+  }
+
+  @Test
+  public void testCheckIfLeftExpressionRequireEvaluationWithExpressionNotInstanceOfColumnExpression()
{
+    ColumnExpression expression = new ColumnExpression("test", DataType.STRING);
+    boolean result = FilterUtil.checkIfLeftExpressionRequireEvaluation(expression);
+    assertFalse(result);
+  }
+
+  @Test public void testNanSafeEqualsDoublesWithUnEqualValues() {
+    Double d1 = new Double(60.67);
+    Double d2 = new Double(60.69);
+    boolean result = FilterUtil.nanSafeEqualsDoubles(d1, d2);
+    assertFalse(result);
+  }
+
+  @Test public void testNanSafeEqualsDoublesWithEqualValues() {
+    Double d1 = new Double(60.67);
+    Double d2 = new Double(60.67);
+    boolean result = FilterUtil.nanSafeEqualsDoubles(d1, d2);
+    assertTrue(result);
+  }
+
+  @Test public void testCompareFilterKeyBasedOnDataTypeForShortValue() {
+    String dictionaryVal = "1";
+    String memberVal = "1";
+    int actualResult =
+        FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.SHORT);
+    int expectedResult = 0;
+    assertEquals(expectedResult, actualResult);
+  }
+
+  @Test public void testCompareFilterKeyBasedOnDataTypeForIntValue() {
+    String dictionaryVal = "1000";
+    String memberVal = "1001";
+    int actualResult =
+        FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.INT);
+    int expectedResult = -1;
+    assertEquals(expectedResult, actualResult);
+  }
+
+  @Test public void testCompareFilterKeyBasedOnDataTypeForDoubleValue() {
+    String dictionaryVal = "1.90";
+    String memberVal = "1.89";
+    int actualResult =
+        FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.DOUBLE);
+    int expectedResult = 1;
+    assertEquals(expectedResult, actualResult);
+  }
+
+  @Test public void testCompareFilterKeyBasedOnDataTypeForLongValue() {
+    String dictionaryVal = "111111111111111";
+    String memberVal = "1111111111111111";
+    int actualResult =
+        FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.LONG);
+    int expectedResult = -1;
+    assertEquals(expectedResult, actualResult);
+  }
+
+  @Test public void testCompareFilterKeyBasedOnDataTypeForBooleanValue() {
+    String dictionaryVal = "true";
+    String memberVal = "false";
+    int actualResult =
+        FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.BOOLEAN);
+    int expectedResult = 1;
+    assertEquals(expectedResult, actualResult);
+  }
+
+  @Test public void testCompareFilterKeyBasedOnDataTypeForDecimalValue() {
+    String dictionaryVal = "1111111";
+    String memberVal = "1111";
+    int actualResult =
+        FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.DECIMAL);
+    int expectedResult = 1;
+    assertEquals(expectedResult, actualResult);
+  }
+
+  @Test public void testCompareFilterKeyBasedOnDataTypeForDefaultValue() {
+    String dictionaryVal = "11.78";
+    String memberVal = "1111.90";
+    int actualResult =
+        FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.FLOAT);
+    int expectedResult = -1;
+    assertEquals(expectedResult, actualResult);
+  }
+
+  @Test public void testCompareFilterKeyBasedOnDataTypeForTimestamp() {
+    String dictionaryVal = "2008-01-01 00:00:01";
+    String memberVal = "2008-01-01 00:00:01";
+    int actualValue =
+        FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.TIMESTAMP);
+    int expectedValue = 0;
+    assertEquals(expectedValue, actualValue);
+  }
+
+  @Test public void testCompareFilterKeyBasedOnDataTypeForException() throws Exception {
+    String dictionaryVal = "test";
+    String memberVal = "1";
+    int actualValue =
+        FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.INT);
+    int expectedValue = -1;
+    assertEquals(expectedValue, actualValue);
+  }
+
+  @Test public void testCreateIndexKeyFromResolvedFilterVal() throws Exception {
+    long[] startOrEndKey = new long[] { 0, 10 };
+    byte[] startOrEndKeyForNoDictDimension = { 1, 2 };
+    int[] keys = new int[] { 1, 2 };
+    MultiDimKeyVarLengthGenerator multiDimKeyVarLengthGenerator =
+        new MultiDimKeyVarLengthGenerator(keys);
+    assertTrue(FilterUtil
+        .createIndexKeyFromResolvedFilterVal(startOrEndKey, multiDimKeyVarLengthGenerator,
+            startOrEndKeyForNoDictDimension) != null);
+
+  }
+
+  @Test public void testCheckIfExpressionContainsColumn() {
+    String columnName = "IMEI";
+    Expression expression = new ColumnExpression(columnName, DataType.STRING);
+    boolean result = FilterUtil.checkIfExpressionContainsColumn(expression);
+    assertTrue(result);
+  }
+
+  @Test
+  public void testCheckIfExpressionContainsColumnWithExpressionNotInstanceOfColumnExpression()
{
+    String columnName = "IMEI";
+    Expression expression = new LiteralExpression(columnName, DataType.STRING);
+    boolean result = FilterUtil.checkIfExpressionContainsColumn(expression);
+    assertFalse(result);
+  }
+
+  @Test public void testIsExpressionNeedsToResolved() {
+    boolean isIncludeFilter = true;
+    Object obj = "test";
+    LiteralExpression literalExpression = new LiteralExpression(obj, DataType.STRING);
+    boolean result = FilterUtil.isExpressionNeedsToResolved(literalExpression, isIncludeFilter);
+    assertFalse(result);
+  }
+
+  @Test public void testIsExpressionNeedsToResolvedWithDataTypeNullAndIsIncludeFilterFalse()
{
+    boolean isIncludeFilter = false;
+    Object obj = "test";
+    LiteralExpression literalExpression = new LiteralExpression(obj, DataType.NULL);
+    boolean result = FilterUtil.isExpressionNeedsToResolved(literalExpression, isIncludeFilter);
+    assertTrue(result);
+  }
+
+  @Test public void testGetMaskKey() {
+    int surrogate = 1;
+    int[] keys = new int[] { 1, 2 };
+    MultiDimKeyVarLengthGenerator multiDimKeyVarLengthGenerator =
+        new MultiDimKeyVarLengthGenerator(keys);
+    int ordinal = 1;
+    int keyOrdinal = 1;
+    int columnGroupOrdinal = 1;
+    int complexTypeOrdinal = 1;
+    ColumnSchema columnSchema = new ColumnSchema();
+    columnSchema.setColumnar(true);
+    columnSchema.setColumnName("IMEI");
+    columnSchema.setColumnUniqueId(UUID.randomUUID().toString());
+    columnSchema.setDataType(DataType.STRING);
+    columnSchema.setDimensionColumn(true);
+    CarbonDimension carbonDimension =
+        new CarbonDimension(columnSchema, ordinal, keyOrdinal, columnGroupOrdinal,
+            complexTypeOrdinal);
+    byte[] expectedResult = new byte[] { 1 };
+    byte[] actualResult =
+        FilterUtil.getMaskKey(surrogate, carbonDimension, multiDimKeyVarLengthGenerator);
+    assertArrayEquals(expectedResult, actualResult);
+  }
+
+  @Test public void testGetFilterListForAllMembersRS() throws Exception {
+    Expression expression = new ColumnExpression("IMEI", DataType.STRING);
+    ColumnExpression columnExpression = new ColumnExpression("IMEI", DataType.STRING);
+    String defaultValues = "test";
+    int defaultSurrogate = 1;
+    boolean isIncludeFilter = true;
+    int ordinal = 1;
+    ColumnSchema dimColumn = new ColumnSchema();
+    dimColumn.setColumnar(true);
+    dimColumn.setColumnName("IMEI");
+    dimColumn.setColumnUniqueId(UUID.randomUUID().toString());
+    dimColumn.setDataType(DataType.STRING);
+    dimColumn.setDimensionColumn(true);
+    final CarbonColumn carbonColumn = new CarbonColumn(dimColumn, ordinal);
+    new MockUp<ColumnExpression>() {
+      @Mock public CarbonColumn getCarbonColumn() {
+        return carbonColumn;
+      }
+    };
+
+    new MockUp<RowImpl>() {
+      @Mock public Object getVal(int index) {
+        return "test";
+      }
+    };
+    assertTrue(FilterUtil
+        .getFilterListForAllMembersRS(expression, columnExpression, defaultValues, defaultSurrogate,
+            isIncludeFilter) instanceof DimColumnFilterInfo);
+  }
+
+  @Test public void testGetFilterListForAllMembersRSWithDefaultValuesEqualsToNull()
+      throws Exception {
+    Expression expression = new ColumnExpression("IMEI", DataType.STRING);
+    ColumnExpression columnExpression = new ColumnExpression("IMEI", DataType.STRING);
+    String defaultValues = CarbonCommonConstants.MEMBER_DEFAULT_VAL;
+    int defaultSurrogate = 1;
+    boolean isIncludeFilter = true;
+    int ordinal = 1;
+    ColumnSchema dimColumn = new ColumnSchema();
+    dimColumn.setColumnar(true);
+    dimColumn.setColumnName("IMEI");
+    dimColumn.setColumnUniqueId(UUID.randomUUID().toString());
+    dimColumn.setDataType(DataType.STRING);
+    dimColumn.setDimensionColumn(true);
+    final CarbonColumn carbonColumn = new CarbonColumn(dimColumn, ordinal);
+    new MockUp<ColumnExpression>() {
+      @Mock public CarbonColumn getCarbonColumn() {
+        return carbonColumn;
+      }
+    };
+
+    new MockUp<RowImpl>() {
+      @Mock public Object getVal(int index) {
+        return "test";
+      }
+    };
+    assertTrue(FilterUtil
+        .getFilterListForAllMembersRS(expression, columnExpression, defaultValues, defaultSurrogate,
+            isIncludeFilter) instanceof DimColumnFilterInfo);
+  }
+
+  @Test public void testgetFilterListForRS() throws Exception {
+    Expression expression = new ColumnExpression("IMEI", DataType.STRING);
+    ColumnExpression columnExpression = new ColumnExpression("IMEI", DataType.STRING);
+    String defaultValues = CarbonCommonConstants.MEMBER_DEFAULT_VAL;
+    int defaultSurrogate = 1;
+    int ordinal = 1;
+    final CarbonColumn carbonColumn = new CarbonColumn(columnSchema, ordinal);
+    new MockUp<ColumnExpression>() {
+      @Mock public CarbonColumn getCarbonColumn() {
+        return carbonColumn;
+      }
+    };
+
+    new MockUp<RowImpl>() {
+      @Mock public Object getVal(int index) {
+        return "test";
+      }
+    };
+    assertTrue(FilterUtil.getFilterListForRS(expression, columnExpression, defaultValues,
+        defaultSurrogate) instanceof DimColumnFilterInfo);
+  }
+
+  @Test public void testGetFilterList() throws Exception {
+    Expression expression = new ColumnExpression("IMEI", DataType.STRING);
+    ColumnExpression columnExpression = new ColumnExpression("IMEI", DataType.STRING);
+    int ordinal = 1;
+    boolean isIncludeFilter = true;
+    CarbonTableIdentifier carbonTableIdentifier =
+        new CarbonTableIdentifier("databaseName", "tableName", "tableID");
+    AbsoluteTableIdentifier absoluteTableIdentifier =
+        new AbsoluteTableIdentifier(this.carbonStorePath, carbonTableIdentifier);
+    final Map<String, String> columnProperties = new HashMap<>();
+    columnProperties.put("1", "column1");
+    columnProperties.put("2", "column2");
+    final CarbonTableIdentifier carbonTableIdentifier1 =
+        new CarbonTableIdentifier(databaseName, tableName, UUID.randomUUID().toString());
+    int keyOrdinal = 1;
+    int columnGroupOrdinal = 1;
+    int complexTypeOrdinal = 1;
+    final CarbonDimension carbonDimension =
+        new CarbonDimension(columnSchema, ordinal, keyOrdinal, columnGroupOrdinal,
+            complexTypeOrdinal);
+
+    new MockUp<AbsoluteTableIdentifier>() {
+      @Mock public CarbonTableIdentifier getCarbonTableIdentifier() {
+        return carbonTableIdentifier1;
+      }
+    };
+
+    final Map<String, String> columnProperties1 = new HashMap<>();
+    columnProperties1.put("1", "column1");
+    columnProperties1.put("2", "column2");
+
+    new MockUp<CarbonColumn>() {
+      @Mock public ColumnIdentifier getColumnIdentifier() {
+        ColumnIdentifier columnIdentifier =
+            new ColumnIdentifier("1", columnProperties, DataType.STRING);
+        return columnIdentifier;
+      }
+    };
+
+    new MockUp<CarbonColumn>() {
+      @Mock public DataType getDataType() {
+        return DataType.STRING;
+      }
+    };
+
+    new MockUp<ColumnExpression>() {
+      @Mock public CarbonDimension getDimension() {
+        return carbonDimension;
+      }
+    };
+
+    final CarbonColumn carbonColumn = new CarbonColumn(columnSchema, ordinal);
+    new MockUp<ColumnExpression>() {
+      @Mock public CarbonColumn getCarbonColumn() {
+        return carbonColumn;
+      }
+    };
+    assertTrue(FilterUtil.getFilterList(absoluteTableIdentifier, expression, columnExpression,
+        isIncludeFilter) instanceof DimColumnFilterInfo);
+  }
+
+  @Test public void testCheckIfDataTypeNotTimeStamp() {
+    Expression expression = new ColumnExpression("test", DataType.STRING);
+    boolean result = FilterUtil.checkIfDataTypeNotTimeStamp(expression);
+    assertFalse(result);
+  }
+
+  @Test public void testPrepareDefaultEndIndexKey() throws Exception {
+    List<ColumnSchema> columnsInTable = new ArrayList<>();
+    columnsInTable.add(columnSchema);
+    int[] columnCardinality = new int[] { 1, 2 };
+    new MockUp<ColumnSchema>() {
+      @Mock public List<Encoding> getEncodingList() {
+        List<Encoding> encodingList = new ArrayList<>();
+        encodingList.add(Encoding.DICTIONARY);
+        return encodingList;
+      }
+    };
+    SegmentProperties segmentProperties = new SegmentProperties(columnsInTable, columnCardinality);
+    assertTrue(FilterUtil.prepareDefaultEndIndexKey(segmentProperties) instanceof IndexKey);
+  }
+
+  @Test(expected = QueryExecutionException.class)
+  public void testGetForwardDictionaryCacheWithException() throws Exception {
+
+    AbsoluteTableIdentifier absoluteTableIdentifier =
+        new AbsoluteTableIdentifier(this.carbonStorePath, carbonTableIdentifier);
+    int ordinal = 1;
+    int keyOrdinal = 1;
+    int columnGroupOrdinal = 1;
+    int complexTypeOrdinal = 1;
+    CarbonDimension carbonDimension =
+        new CarbonDimension(columnSchema, ordinal, keyOrdinal, columnGroupOrdinal,
+            complexTypeOrdinal);
+    FilterUtil.getForwardDictionaryCache(absoluteTableIdentifier, carbonDimension);
+  }
+
+  @Test public void testCheckIfRightExpressionRequireEvaluation() {
+    Expression expression = new ColumnExpression("test", DataType.STRING);
+    boolean result = FilterUtil.checkIfRightExpressionRequireEvaluation(expression);
+    assertTrue(result);
+  }
+
+  @Test
+  public void testCheckIfRightExpressionRequireEvaluationWithExpressionIsInstanceOfLiteralExpression()
{
+    Expression expression = new LiteralExpression("test", DataType.STRING);
+    boolean result = FilterUtil.checkIfRightExpressionRequireEvaluation(expression);
+    assertFalse(result);
+  }
+
+  @Test public void testGetNoDictionaryValKeyMemberForFilter() {
+    boolean isIncludeFilter = true;
+    AbsoluteTableIdentifier absoluteTableIdentifier =
+        new AbsoluteTableIdentifier(this.carbonStorePath, carbonTableIdentifier);
+    ColumnExpression expression = new ColumnExpression("test", DataType.STRING);
+    List<String> evaluateResultListFinal = new ArrayList<>();
+    evaluateResultListFinal.add("test1");
+    evaluateResultListFinal.add("test2");
+    assertTrue(FilterUtil.getNoDictionaryValKeyMemberForFilter(absoluteTableIdentifier, expression,
+        evaluateResultListFinal, isIncludeFilter) instanceof DimColumnFilterInfo);
+  }
+
+  @Test public void testPrepareDefaultStartIndexKey() throws KeyGenException {
+    List<ColumnSchema> columnsInTable = new ArrayList<>();
+    columnsInTable.add(columnSchema);
+    int[] columnCardinality = new int[] { 1, 2 };
+    new MockUp<ColumnSchema>() {
+      @Mock public List<Encoding> getEncodingList() {
+        List<Encoding> encodingList = new ArrayList<>();
+        encodingList.add(Encoding.DICTIONARY);
+        return encodingList;
+      }
+    };
+    SegmentProperties segmentProperties = new SegmentProperties(columnsInTable, columnCardinality);
+    assertTrue(FilterUtil.prepareDefaultStartIndexKey(segmentProperties) instanceof IndexKey);
+  }
+}


Mime
View raw message