You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ra...@apache.org on 2016/12/12 06:31:12 UTC
[1/2] incubator-carbondata git commit: branch was rebased
Repository: incubator-carbondata
Updated Branches:
refs/heads/master 311a7d31b -> b1f4acad3
branch was rebased
extra line removed
BAtchResultTest and ByteArrayWrapper Test classes were formatted
test files were corrected
deleted unnecessary files
Project: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/commit/a1fdd5ed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/tree/a1fdd5ed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/diff/a1fdd5ed
Branch: refs/heads/master
Commit: a1fdd5eda390b32b5782ee52aa7b82457f1de8f3
Parents: 311a7d3
Author: deepakmehra10 <de...@gmail.com>
Authored: Fri Dec 9 17:09:38 2016 +0530
Committer: ravipesala <ra...@gmail.com>
Committed: Mon Dec 12 11:59:49 2016 +0530
----------------------------------------------------------------------
.../scan/complextypes/ArrayQueryTypeTest.java | 57 +++
.../complextypes/PrimitiveQueryTypeTest.java | 132 +++++
.../scan/complextypes/StructQueryTypeTest.java | 74 +++
.../scan/executor/util/QueryUtilTest.java | 51 ++
.../scan/expression/ColumnExpressionTest.java | 71 +++
.../scan/expression/ExpressionResultTest.java | 479 +++++++++++++++++++
.../scan/expression/LiteralExpressionTest.java | 59 +++
.../expression/logical/AndExpressionTest.java | 81 ++++
.../expression/logical/FalseExpressionTest.java | 48 ++
.../expression/logical/OrExpressionTest.java | 79 +++
.../carbondata/scan/result/BatchResultTest.java | 95 ++++
.../scan/wrappers/ByteArrayWrapperTest.java | 107 +++++
12 files changed, 1333 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/complextypes/ArrayQueryTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/complextypes/ArrayQueryTypeTest.java b/core/src/test/java/org/apache/carbondata/scan/complextypes/ArrayQueryTypeTest.java
new file mode 100644
index 0000000..8fc5484
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/complextypes/ArrayQueryTypeTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.complextypes;
+
+import java.nio.ByteBuffer;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.pentaho.di.core.util.Assert.assertNotNull;
+import static org.pentaho.di.core.util.Assert.assertNull;
+
+public class ArrayQueryTypeTest {
+
+ private static ArrayQueryType arrayQueryType;
+
+ @BeforeClass public static void setUp() {
+ String name = "test";
+ String parentName = "testParent";
+ int blockIndex = 1;
+ arrayQueryType = new ArrayQueryType(name, parentName, blockIndex);
+ }
+
+ @Test public void testGetDataBasedOnDataTypeFromSurrogatesForNull() {
+ ByteBuffer surrogateData = ByteBuffer.allocate(10);
+ surrogateData.put(0, (byte) 0xFF);
+ surrogateData.put(1, (byte) 0xFF);
+ surrogateData.put(2, (byte) 0xFF);
+ surrogateData.put(3, (byte) 0xFF);
+ assertNull(arrayQueryType.getDataBasedOnDataTypeFromSurrogates(surrogateData));
+ }
+
+ @Test public void testGetDataBasedOnDataTypeFromSurrogates() {
+ ByteBuffer surrogateData = ByteBuffer.allocate(10);
+ surrogateData.put(3, (byte) 1);
+ arrayQueryType.setName("testName");
+ arrayQueryType.setParentname("testName");
+ arrayQueryType.addChildren(arrayQueryType);
+ assertNotNull(arrayQueryType.getDataBasedOnDataTypeFromSurrogates(surrogateData));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/complextypes/PrimitiveQueryTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/complextypes/PrimitiveQueryTypeTest.java b/core/src/test/java/org/apache/carbondata/scan/complextypes/PrimitiveQueryTypeTest.java
new file mode 100644
index 0000000..2ab0fc3
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/complextypes/PrimitiveQueryTypeTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.complextypes;
+
+import java.nio.ByteBuffer;
+
+import org.apache.carbondata.core.cache.dictionary.ColumnDictionaryInfo;
+import org.apache.carbondata.core.cache.dictionary.Dictionary;
+import org.apache.carbondata.core.cache.dictionary.ForwardDictionary;
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+import org.apache.carbondata.core.keygenerator.mdkey.Bits;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.spark.sql.types.BooleanType$;
+import org.apache.spark.sql.types.DoubleType$;
+import org.apache.spark.sql.types.IntegerType$;
+import org.apache.spark.sql.types.LongType$;
+import org.apache.spark.sql.types.TimestampType$;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class PrimitiveQueryTypeTest {
+ private static PrimitiveQueryType primitiveQueryType, primitiveQueryTypeForInt,
+ primitiveQueryTypeForLong, primitiveQueryTypeForDouble, primitiveQueryTypeForBoolean,
+ primitiveQueryTypeForTimeStamp, primitiveQueryTypeForTimeStampForIsDictionaryFalse;
+ private static Dictionary dictionary;
+
+ @BeforeClass public static void setUp() {
+ String name = "test";
+ String parentName = "testParent";
+ int blockIndex = 1;
+ int keySize = 1;
+ boolean isDirectDictionary = true;
+ primitiveQueryType =
+ new PrimitiveQueryType(name, parentName, blockIndex, DataType.STRING, keySize, dictionary,
+ isDirectDictionary);
+ primitiveQueryTypeForInt =
+ new PrimitiveQueryType(name, parentName, blockIndex, DataType.INT, keySize, dictionary,
+ isDirectDictionary);
+ primitiveQueryTypeForDouble =
+ new PrimitiveQueryType(name, parentName, blockIndex, DataType.DOUBLE, keySize, dictionary,
+ isDirectDictionary);
+ primitiveQueryTypeForLong =
+ new PrimitiveQueryType(name, parentName, blockIndex, DataType.LONG, keySize, dictionary,
+ isDirectDictionary);
+ primitiveQueryTypeForBoolean =
+ new PrimitiveQueryType(name, parentName, blockIndex, DataType.BOOLEAN, keySize, dictionary,
+ isDirectDictionary);
+ primitiveQueryTypeForTimeStamp =
+ new PrimitiveQueryType(name, parentName, blockIndex, DataType.TIMESTAMP, keySize,
+ dictionary, isDirectDictionary);
+ ColumnDictionaryInfo columnDictionaryInfo = new ColumnDictionaryInfo(DataType.STRING);
+ ForwardDictionary forwardDictionary = new ForwardDictionary(columnDictionaryInfo);
+ primitiveQueryTypeForTimeStampForIsDictionaryFalse =
+ new PrimitiveQueryType(name, parentName, blockIndex, DataType.TIMESTAMP, keySize,
+ forwardDictionary, false);
+
+ }
+
+ @Test public void testGetDataTypeForDefault() {
+ assertEquals(IntegerType$.MODULE$, primitiveQueryType.getSchemaType());
+ }
+
+ @Test public void testGetDataTypeForInt() {
+ assertEquals(IntegerType$.MODULE$, primitiveQueryTypeForInt.getSchemaType());
+ }
+
+ @Test public void testGetDataTypeForDouble() {
+ assertEquals(DoubleType$.MODULE$, primitiveQueryTypeForDouble.getSchemaType());
+ }
+
+ @Test public void testGetDataTypeForBoolean() {
+ assertEquals(BooleanType$.MODULE$, primitiveQueryTypeForBoolean.getSchemaType());
+ }
+
+ @Test public void testGetDataTypeForTimeStamp() {
+ assertEquals(TimestampType$.MODULE$, primitiveQueryTypeForTimeStamp.getSchemaType());
+ }
+
+ @Test public void testGetDataTypeForLong() {
+ assertEquals(LongType$.MODULE$, primitiveQueryTypeForLong.getSchemaType());
+ }
+
+ @Test public void testGetDataBasedOnDataTypeFromSurrogates() {
+ ByteBuffer surrogateData = ByteBuffer.allocate(10);
+ surrogateData.put(3, (byte) 1);
+ new MockUp<Bits>() {
+ @Mock public long[] getKeyArray(byte[] key, int offset) {
+ return new long[] { 1313045L };
+ }
+ };
+ Object expectedValue = 1313043000000L;
+
+ Object actualValue =
+ primitiveQueryTypeForTimeStamp.getDataBasedOnDataTypeFromSurrogates(surrogateData);
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetDataBasedOnDataTypeFromSurrogatesWhenIsDictionaryFalse() {
+ ByteBuffer surrogateData = ByteBuffer.allocate(10);
+ surrogateData.put(3, (byte) 1);
+ new MockUp<ForwardDictionary>() {
+ @Mock public String getDictionaryValueForKey(int surrogateKey) {
+ return "2015-10-20 12:30:01";
+ }
+ };
+
+ Object expectedValue = 1445324401000000L;
+ Object actualValue = primitiveQueryTypeForTimeStampForIsDictionaryFalse
+ .getDataBasedOnDataTypeFromSurrogates(surrogateData);
+ assertEquals(expectedValue, actualValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/complextypes/StructQueryTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/complextypes/StructQueryTypeTest.java b/core/src/test/java/org/apache/carbondata/scan/complextypes/StructQueryTypeTest.java
new file mode 100644
index 0000000..c029495
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/complextypes/StructQueryTypeTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.complextypes;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class StructQueryTypeTest {
+ private static StructQueryType structQueryType;
+ private static ArrayQueryType arrayQueryType;
+
+ @BeforeClass public static void setUp() {
+ String name = "testName";
+ String parentName = "testName";
+ int blockIndex = 5;
+ structQueryType = new StructQueryType(name, parentName, blockIndex);
+ arrayQueryType = new ArrayQueryType(name, parentName, blockIndex);
+ }
+
+ @Test public void testGetDataBasedOnDataTypeFromSurrogates() {
+ ByteBuffer surrogateData = ByteBuffer.allocate(10);
+ surrogateData.put(3, (byte) 1);
+ structQueryType.addChildren(arrayQueryType);
+ List children = new ArrayList();
+ children.add(arrayQueryType);
+ assertNotNull(structQueryType.getDataBasedOnDataTypeFromSurrogates(surrogateData));
+ }
+
+ @Test public void testGetColsCount() {
+ structQueryType.setName("testName");
+ structQueryType.setParentname("testName");
+ structQueryType.addChildren(arrayQueryType);
+ new MockUp<ArrayQueryType>() {
+ @Mock int getColsCount() {
+ return 1;
+ }
+ };
+ int actualValue = structQueryType.getColsCount();
+ int expectedValue = 2;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetSchemaType() {
+ List children = new ArrayList();
+ children.add(null);
+ assertNotNull(structQueryType.getSchemaType());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/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 3fcbffa..1b9fcb7 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
@@ -34,6 +34,8 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import static org.junit.Assert.assertArrayEquals;
+
public class QueryUtilTest extends TestCase {
private SegmentProperties segmentProperties;
@@ -184,6 +186,55 @@ public class QueryUtilTest extends TestCase {
assertEquals(expectedValue, actualValue);
}
+ @Test public void testGetMaskedKey() {
+ byte[] data = { 1, 2, 3, 4, 5, 5 };
+ byte[] maxKey = { 15, 20, 25, 30, 35, 35 };
+ int[] maskByteRanges = { 1, 2, 3, 4, 5 };
+ int byteCount = 5;
+ byte[] actualValue = QueryUtil.getMaskedKey(data, maxKey, maskByteRanges, byteCount);
+ byte[] expectedValue = { 0, 1, 4, 1, 1 };
+ assertArrayEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetMaxKeyBasedOnOrinal() throws Exception {
+ List<Integer> dummyList = new ArrayList<>();
+ dummyList.add(0, 1);
+ dummyList.add(1, 2);
+ byte[] actualValue =
+ QueryUtil.getMaxKeyBasedOnOrinal(dummyList, segmentProperties.getDimensionKeyGenerator());
+ byte[] expectedValue = { 0, -1, -1, 0, 0, 0 };
+ assertArrayEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetSortDimensionIndexes() {
+ List<QueryDimension> sortedDimensions = 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));
+ sortedDimensions.add(dimension);
+ }
+ List<QueryDimension> queryDimensions = 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));
+ queryDimensions.add(dimension);
+ }
+ byte[] actualValue = QueryUtil.getSortDimensionIndexes(sortedDimensions, queryDimensions);
+ byte[] expectedValue = { 0, 0 };
+ assertArrayEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetActualTypeIndex() {
+ List<String> dummyList = new ArrayList<>();
+ dummyList.add("test1");
+ dummyList.add("test2");
+ int[] actualValue = QueryUtil.getActualTypeIndex(dummyList);
+ int[] expectedValue = { 0, 1 };
+ assertArrayEquals(expectedValue, actualValue);
+ }
+
@AfterClass public void tearDown() {
segmentProperties = null;
}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/expression/ColumnExpressionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/ColumnExpressionTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/ColumnExpressionTest.java
new file mode 100644
index 0000000..eda9e54
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/expression/ColumnExpressionTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.expression;
+
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+import org.apache.carbondata.scan.filter.intf.RowImpl;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ColumnExpressionTest {
+
+ private ColumnExpression columnExpression;
+
+ @Before public void setUp() {
+ String columnName = "IMEI";
+ DataType dataType = DataType.STRING;
+ columnExpression = new ColumnExpression(columnName, dataType);
+ }
+
+ @Test public void testEvaluate() {
+ RowImpl rowImpl = new RowImpl();
+ rowImpl.setValues(new Integer[] { 1 });
+ new MockUp<RowImpl>() {
+ @Mock public Object getVal(int index) {
+ return 1;
+ }
+ };
+ ExpressionResult expectedValue = new ExpressionResult(DataType.INT, 1);
+ assertEquals(expectedValue, columnExpression.evaluate(rowImpl));
+ }
+
+ @Test public void testEvaluateForNullValue() {
+ RowImpl rowImpl = new RowImpl();
+ rowImpl.setValues(null);
+ new MockUp<RowImpl>() {
+ @Mock public Object getVal(int index) {
+ return null;
+ }
+ };
+ ExpressionResult expectedValue = new ExpressionResult(null);
+ assertEquals(expectedValue, columnExpression.evaluate(rowImpl));
+ }
+
+ @Test public void testGetString() {
+ String actualValue = columnExpression.getString();
+ String expectedValue = "ColumnExpression(IMEI)";
+ assertEquals(expectedValue, actualValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/expression/ExpressionResultTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/ExpressionResultTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/ExpressionResultTest.java
new file mode 100644
index 0000000..df3df0a
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/expression/ExpressionResultTest.java
@@ -0,0 +1,479 @@
+/*
+ * 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.expression;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.pentaho.di.core.util.Assert.assertFalse;
+import static org.pentaho.di.core.util.Assert.assertNull;
+
+public class ExpressionResultTest {
+ private static final double DELTA = 1e-15;
+ private static ExpressionResult expressionResult;
+
+ @BeforeClass public static void setUp() {
+ expressionResult = new ExpressionResult(DataType.INT, null);
+ }
+
+ @Test public void testGetIntForNull() throws FilterIllegalMemberException {
+ assertNull(expressionResult.getInt());
+ }
+
+ @Test public void testGetIntForString() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "5");
+ int actualValue = expressionResultForString.getInt();
+ int expectedValue = 5;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetIntForNumberFormatException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "FOOBAR");
+ expressionResultForString.getInt();
+ }
+
+ @Test public void testGetIntForDouble() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForDouble = new ExpressionResult(DataType.DOUBLE, 5.0);
+ int actualValue = expressionResultForDouble.getInt();
+ int expectedValue = 5;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetIntForInt() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForInt = new ExpressionResult(DataType.INT, 5);
+ int actualValue = expressionResultForInt.getInt();
+ int expectedValue = 5;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetIntForIllegalMemberException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForInt = new ExpressionResult(DataType.FLOAT, 25.36);
+ expressionResultForInt.getInt();
+ }
+
+ @Test(expected = FilterIllegalMemberException.class) public void testGetIntForClassCastException()
+ throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForInt = new ExpressionResult(DataType.INT, "STRING");
+ expressionResultForInt.getInt();
+ }
+
+ @Test public void testGetShortForNull() throws FilterIllegalMemberException {
+ assertNull(expressionResult.getShort());
+ }
+
+ @Test public void testGetShortForString() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "5");
+ short actualValue = expressionResultForString.getShort();
+ short expectedValue = 5;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetShortForNumberFormatException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "FOOBAR");
+ expressionResultForString.getShort();
+ }
+
+ @Test public void testGetShortForDouble() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForDouble = new ExpressionResult(DataType.DOUBLE, 5.0);
+ short actualValue = expressionResultForDouble.getShort();
+ short expectedValue = 5;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetShortForInt() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForInt = new ExpressionResult(DataType.INT, 5);
+ short actualValue = expressionResultForInt.getShort();
+ short expectedValue = 5;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetShortForIllegalMemberException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForInt = new ExpressionResult(DataType.FLOAT, 25.36);
+ expressionResultForInt.getShort();
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetShortForClassCastException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForInt = new ExpressionResult(DataType.INT, "STRING");
+ expressionResultForInt.getShort();
+ }
+
+ @Test public void testGetStringForNull() throws FilterIllegalMemberException {
+ assertNull(expressionResult.getString());
+ }
+
+ @Test public void testGetStringForString() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "5");
+ String actualValue = expressionResultForString.getString();
+ String expectedValue = "5";
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetStringForException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.INT, "5");
+ String actualValue = expressionResultForString.getString();
+ String expectedValue = "5";
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetDoubleForNull() throws FilterIllegalMemberException {
+ assertNull(expressionResult.getDouble());
+ }
+
+ @Test public void testGetDoubleForString() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "5");
+ double actualValue = expressionResultForString.getDouble();
+ double expectedValue = 5;
+ assertEquals(expectedValue, actualValue, DELTA);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetDoubleForNumberFormatException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "FOOBAR");
+ expressionResultForString.getDouble();
+ }
+
+ @Test public void testGetDoubleForInt() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForDouble = new ExpressionResult(DataType.INT, 5);
+ double actualValue = expressionResultForDouble.getDouble();
+ double expectedValue = 5.0;
+ assertEquals(expectedValue, actualValue, DELTA);
+ }
+
+ @Test public void testGetDoubleForDouble() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForDouble = new ExpressionResult(DataType.DOUBLE, 5.0);
+ double actualValue = expressionResultForDouble.getDouble();
+ double expectedValue = 5;
+ assertEquals(expectedValue, actualValue, DELTA);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetDoubleForIllegalMemberException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForDouble = new ExpressionResult(DataType.FLOAT, 25.36);
+ expressionResultForDouble.getDouble();
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetDoubleForClassCastException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForDouble = new ExpressionResult(DataType.DOUBLE, "STRING");
+ expressionResultForDouble.getDouble();
+ }
+
+ @Test public void testGetLongForNull() throws FilterIllegalMemberException {
+ assertNull(expressionResult.getLong());
+ }
+
+ @Test public void testGetLongForString() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "5");
+ long actualValue = expressionResultForString.getLong();
+ long expectedValue = 5;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetLongForNumberFormatException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "FOOBAR");
+ expressionResultForString.getLong();
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetLongForIllegalMemberException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForLong = new ExpressionResult(DataType.FLOAT, 25.36);
+ expressionResultForLong.getLong();
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetLongForClassCastException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForLong = new ExpressionResult(DataType.LONG, "STRING");
+ expressionResultForLong.getLong();
+ }
+
+ @Test public void testGetDecimalForNull() throws FilterIllegalMemberException {
+ assertNull(expressionResult.getDecimal());
+ }
+
+ @Test public void testGetDecimalForString() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "5");
+ BigDecimal actualValue = expressionResultForString.getDecimal();
+ BigDecimal expectedValue = new BigDecimal(5.00);
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetDecimalForNumberFormatException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "FOOBAR");
+ expressionResultForString.getDecimal();
+ }
+
+ @Test public void testGetDecimalForInt() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForInt = new ExpressionResult(DataType.INT, 5);
+ BigDecimal actualValue = expressionResultForInt.getDecimal();
+ BigDecimal expectedValue = new BigDecimal(5);
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetDecimalForDouble() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForDouble = new ExpressionResult(DataType.DOUBLE, 5);
+ BigDecimal actualValue = expressionResultForDouble.getDecimal();
+ BigDecimal expectedValue = new BigDecimal(5);
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetDecimalForDecimal() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForDecimal = new ExpressionResult(DataType.DECIMAL, 5);
+ BigDecimal actualValue = expressionResultForDecimal.getDecimal();
+ BigDecimal expectedValue = new BigDecimal(5);
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetDecimalForIllegalMemberException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForFloat = new ExpressionResult(DataType.FLOAT, 25.36);
+ expressionResultForFloat.getDecimal();
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetDecimalForClassCastException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForException = new ExpressionResult(DataType.LONG, "STRING");
+ expressionResultForException.getDecimal();
+ }
+
+ @Test public void testGetTimeForNull() throws FilterIllegalMemberException {
+ assertNull(expressionResult.getTime());
+ }
+
+ @Test public void testGetTimeForString() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString =
+ new ExpressionResult(DataType.STRING, "2016-11-07 10:15:09");
+ long actualValue = expressionResultForString.getTime();
+ long expectedValue = (1478493909000000L);
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class) public void testGetTimeForParseException()
+ throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForParseException =
+ new ExpressionResult(DataType.STRING, "FOOBAR");
+ expressionResultForParseException.getTime();
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetTimeForIllegalMemberException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForFloat = new ExpressionResult(DataType.FLOAT, 25.36);
+ expressionResultForFloat.getTime();
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetTimeForClassCastException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForException = new ExpressionResult(DataType.LONG, "STRING");
+ expressionResultForException.getTime();
+ }
+
+ @Test public void testGetBooleanForNull() throws FilterIllegalMemberException {
+ assertNull(expressionResult.getBoolean());
+ }
+
+ @Test public void testGetBooleanForString() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.STRING, "true");
+ boolean actualValue = expressionResultForString.getBoolean();
+ boolean expectedValue = true;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetBooleanForBoolean() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForString = new ExpressionResult(DataType.BOOLEAN, "true");
+ boolean actualValue = expressionResultForString.getBoolean();
+ boolean expectedValue = true;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test(expected = FilterIllegalMemberException.class)
+ public void testGetBooleanForIllegalMemberException() throws FilterIllegalMemberException {
+ ExpressionResult expressionResultForFloat = new ExpressionResult(DataType.FLOAT, 25.36);
+ expressionResultForFloat.getBoolean();
+ }
+
+ @Test public void testGetList() {
+ ExpressionResult obj = new ExpressionResult(DataType.STRING, "test");
+ List<ExpressionResult> actualValue = obj.getList();
+ List<ExpressionResult> expected = new ArrayList<>();
+ expected.add(0, obj);
+ assertEquals(expected, actualValue);
+ }
+
+ @Test public void testHashCode() {
+ ExpressionResult obj = new ExpressionResult(DataType.INT, 1);
+ int actualValue = obj.hashCode();
+ int expectedValue = 80;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testHashCodeForNull() {
+ ExpressionResult obj = new ExpressionResult(null);
+ int actualValue = obj.hashCode();
+ int expectedValue = 31;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testHashCodeForNul() {
+ ExpressionResult obj = new ExpressionResult(DataType.DOUBLE, null);
+ int actualValue = obj.hashCode();
+ int expectedValue = 31;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testEqualsForObjNOtInstanceOfExpressionResult() {
+ ExpressionResult expressionResult = new ExpressionResult(DataType.INT, 5);
+ List obj = new ArrayList();
+ obj.add(0, 0);
+ obj.add(1, 1);
+ boolean result = expressionResult.equals(obj);
+ assertFalse(result);
+ }
+
+ @Test public void testEqualsForString() {
+ ExpressionResult expressionResult = new ExpressionResult(DataType.STRING, "5");
+ ExpressionResult objToCompare = new ExpressionResult(DataType.STRING, "6");
+ boolean result = expressionResult.equals(objToCompare);
+ assertFalse(result);
+ }
+
+ @Test public void testEqualsForShort() {
+ ExpressionResult expressionResult = new ExpressionResult(DataType.SHORT, 5);
+ ExpressionResult objToCompare = new ExpressionResult(DataType.SHORT, 6);
+ boolean result = expressionResult.equals(objToCompare);
+ assertFalse(result);
+ }
+
+ @Test public void testEqualsForInt() {
+ ExpressionResult expressionResult = new ExpressionResult(DataType.INT, 5);
+ ExpressionResult objToCompare = new ExpressionResult(DataType.INT, 6);
+ boolean result = expressionResult.equals(objToCompare);
+ assertFalse(result);
+ }
+
+ @Test public void testEqualsForDecimal() {
+ ExpressionResult expressionResult = new ExpressionResult(DataType.DECIMAL, 5);
+ ExpressionResult objToCompare = new ExpressionResult(DataType.DECIMAL, 6);
+ boolean result = expressionResult.equals(objToCompare);
+ assertFalse(result);
+ }
+
+ @Test public void testEqualsForDouble() {
+ ExpressionResult expressionResult = new ExpressionResult(DataType.DOUBLE, 5.89);
+ ExpressionResult objToCompare = new ExpressionResult(DataType.DOUBLE, 6.90);
+ boolean result = expressionResult.equals(objToCompare);
+ assertFalse(result);
+ }
+
+ @Test public void testEqualsForException() {
+ ExpressionResult expressionResult =
+ new ExpressionResult(DataType.TIMESTAMP, "2016-11-07 10:15:09");
+ ExpressionResult objToCompare = new ExpressionResult(DataType.DOUBLE, "2016-11-06 10:15:09");
+ boolean result = expressionResult.equals(objToCompare);
+ assertFalse(result);
+ }
+
+ @Test public void testEqualsForLongAndTimeStamp() {
+ ExpressionResult expressionResult =
+ new ExpressionResult(DataType.TIMESTAMP, new Long(11111111111111111L));
+ ExpressionResult objToCompare =
+ new ExpressionResult(DataType.LONG, new Long(11111111111111111L));
+ boolean result = expressionResult.equals(objToCompare);
+ assertTrue(result);
+ }
+
+ @Test public void compareToForInt() {
+ ExpressionResult obj = new ExpressionResult(DataType.INT, 5);
+ ExpressionResult expressionResult = new ExpressionResult(DataType.INT, 6);
+ int actualValue = expressionResult.compareTo(obj);
+ int expectedValue = 1;
+ assertEquals(expectedValue, actualValue);
+
+ }
+
+ @Test public void compareToForDecimal() {
+ ExpressionResult obj = new ExpressionResult(DataType.DECIMAL, 5);
+ ExpressionResult expressionResult = new ExpressionResult(DataType.DECIMAL, 6);
+ int actualValue = expressionResult.compareTo(obj);
+ int expectedValue = 1;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void compareToForException() {
+ ExpressionResult obj = new ExpressionResult(DataType.INT, 5);
+ ExpressionResult expressionResult = new ExpressionResult(DataType.DECIMAL, 6);
+ int actualValue = expressionResult.compareTo(obj);
+ int expectedValue = -1;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void compareToForTimestamp() {
+ ExpressionResult obj = new ExpressionResult(DataType.TIMESTAMP, "2016-11-07 10:15:09");
+ ExpressionResult expressionResult =
+ new ExpressionResult(DataType.TIMESTAMP, "2016-11-07 10:15:09");
+ int actualValue = expressionResult.compareTo(obj);
+ int expectedValue = -1;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testGetListAsString() throws FilterIllegalMemberException {
+ ExpressionResult obj = new ExpressionResult(DataType.INT, 6);
+ List<String> actualValue = obj.getListAsString();
+ List<String> expectedValue = new ArrayList<>();
+ expectedValue.add("6");
+ assertThat(actualValue, is(equalTo(expectedValue)));
+ }
+
+ @Test public void compareToForString() {
+ ExpressionResult obj = new ExpressionResult(DataType.STRING, "2016");
+ ExpressionResult expressionResult = new ExpressionResult(DataType.STRING, "2016");
+ int actualValue = expressionResult.compareTo(obj);
+ int expectedValue = 0;
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testIsNullForNull() {
+ ExpressionResult obj = new ExpressionResult(DataType.STRING, null);
+ boolean actualValue = obj.isNull();
+ assertTrue(actualValue);
+ }
+
+ @Test public void testIsNullForNotNull() {
+ ExpressionResult obj = new ExpressionResult(DataType.STRING, "test");
+ boolean actualValue = obj.isNull();
+ assertFalse(actualValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/expression/LiteralExpressionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/LiteralExpressionTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/LiteralExpressionTest.java
new file mode 100644
index 0000000..f32a0c1
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/expression/LiteralExpressionTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.expression;
+
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+import org.apache.carbondata.scan.filter.intf.RowImpl;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class LiteralExpressionTest {
+
+ private LiteralExpression literalExpression;
+
+ @Before public void setUp() {
+ String value = "testing";
+ literalExpression = new LiteralExpression(value, DataType.STRING);
+ }
+
+ @Test public void testEvaluate() {
+ RowImpl rowImpl = new RowImpl();
+ rowImpl.setValues(new String[] { "testing" });
+ ExpressionResult expectedResult = new ExpressionResult(DataType.STRING, "testing");
+ assertEquals(expectedResult, literalExpression.evaluate(rowImpl));
+ }
+
+ @Test public void testGetExpressionResult() {
+ RowImpl rowImpl = new RowImpl();
+ rowImpl.setValues(new String[] { "testing" });
+ literalExpression.evaluate(rowImpl);
+ ExpressionResult expectedResult = new ExpressionResult(DataType.STRING, "testing");
+ assertEquals(expectedResult, literalExpression.evaluate(rowImpl));
+ }
+
+ @Test public void testGetString() {
+ String actualValue = literalExpression.getString();
+ String expectedValue = "LiteralExpression(testing)";
+ assertEquals(expectedValue, actualValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/expression/logical/AndExpressionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/logical/AndExpressionTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/logical/AndExpressionTest.java
new file mode 100644
index 0000000..5635dd7
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/expression/logical/AndExpressionTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.expression.logical;
+
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+import org.apache.carbondata.scan.expression.ColumnExpression;
+import org.apache.carbondata.scan.expression.ExpressionResult;
+import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException;
+import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException;
+import org.apache.carbondata.scan.filter.intf.RowImpl;
+import org.apache.carbondata.scan.filter.intf.RowIntf;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+public class AndExpressionTest {
+
+ private AndExpression andExpression;
+
+ @Before public void setUp() {
+ ColumnExpression leftExpression = new ColumnExpression("IMEI", DataType.BOOLEAN);
+ ColumnExpression rightExpression = new ColumnExpression("IMEI", DataType.BOOLEAN);
+ andExpression = new AndExpression(leftExpression, rightExpression);
+ }
+
+ @Test(expected = Exception.class) public void testEvaluateForDefault()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ RowImpl rowImpl = new RowImpl();
+ rowImpl.setValues(new Boolean[] { true });
+ final ExpressionResult expressionResult = new ExpressionResult(DataType.STRING, "test");
+ new MockUp<ColumnExpression>() {
+ @Mock public ExpressionResult evaluate(RowIntf value)
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ return expressionResult;
+ }
+ };
+ andExpression.evaluate(rowImpl);
+ }
+
+ @Test public void testEvaluate() throws FilterUnsupportedException, FilterIllegalMemberException {
+ RowImpl rowImpl = new RowImpl();
+ rowImpl.setValues(new Boolean[] { false });
+ final ExpressionResult expressionResult = new ExpressionResult(DataType.BOOLEAN, "test");
+ new MockUp<ColumnExpression>() {
+ @Mock public ExpressionResult evaluate(RowIntf value)
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ return expressionResult;
+ }
+ };
+ ExpressionResult actualValue = andExpression.evaluate(rowImpl);
+ assertTrue(actualValue instanceof ExpressionResult);
+ }
+
+ @Test public void testGetString() {
+ String actualValue = andExpression.getString();
+ String expectedValue = "And(ColumnExpression(IMEI),ColumnExpression(IMEI))";
+ assertEquals(expectedValue, actualValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/expression/logical/FalseExpressionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/logical/FalseExpressionTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/logical/FalseExpressionTest.java
new file mode 100644
index 0000000..0b07503
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/expression/logical/FalseExpressionTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.expression.logical;
+
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+import org.apache.carbondata.scan.expression.ColumnExpression;
+import org.apache.carbondata.scan.expression.ExpressionResult;
+import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException;
+import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException;
+import org.apache.carbondata.scan.filter.intf.RowImpl;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class FalseExpressionTest {
+ private FalseExpression falseExpression;
+
+ @Before public void setUp() {
+ ColumnExpression columnExpression = new ColumnExpression("IMEI", DataType.BOOLEAN);
+ falseExpression = new FalseExpression(columnExpression);
+ }
+
+ @Test public void testEvaluate() throws FilterUnsupportedException, FilterIllegalMemberException {
+ RowImpl rowImpl = new RowImpl();
+ rowImpl.setValues(new Boolean[] { true });
+ ExpressionResult actualValue = falseExpression.evaluate(rowImpl);
+ assertEquals(new ExpressionResult(DataType.BOOLEAN, false), actualValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/expression/logical/OrExpressionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/logical/OrExpressionTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/logical/OrExpressionTest.java
new file mode 100644
index 0000000..1a07a9c
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/expression/logical/OrExpressionTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.expression.logical;
+
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+import org.apache.carbondata.scan.expression.ColumnExpression;
+import org.apache.carbondata.scan.expression.ExpressionResult;
+import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException;
+import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException;
+import org.apache.carbondata.scan.filter.intf.RowImpl;
+import org.apache.carbondata.scan.filter.intf.RowIntf;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+public class OrExpressionTest {
+ private OrExpression orExpression;
+
+ @Before public void setUp() {
+ ColumnExpression leftExpression = new ColumnExpression("IMEI", DataType.BOOLEAN);
+ ColumnExpression rightExpression = new ColumnExpression("IMEI", DataType.BOOLEAN);
+ orExpression = new OrExpression(leftExpression, rightExpression);
+ }
+
+ @Test public void testGetString() {
+ String actualValue = orExpression.getString();
+ String expectedValue = "Or(ColumnExpression(IMEI),ColumnExpression(IMEI))";
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test public void testEvaluate() throws FilterIllegalMemberException, FilterUnsupportedException {
+ RowImpl rowImpl = new RowImpl();
+ rowImpl.setValues(new Boolean[] { false });
+ final ExpressionResult expressionResult = new ExpressionResult(DataType.BOOLEAN, "test");
+ new MockUp<ColumnExpression>() {
+ @Mock public ExpressionResult evaluate(RowIntf value) {
+ return expressionResult;
+ }
+ };
+
+ assertTrue(orExpression.evaluate(rowImpl) instanceof ExpressionResult);
+ }
+
+ @Test(expected = Exception.class) public void testEvaluateForDefault()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ RowImpl rowImpl = new RowImpl();
+ rowImpl.setValues(new Boolean[] { true });
+ final ExpressionResult expressionResult = new ExpressionResult(DataType.STRING, "test");
+ new MockUp<ColumnExpression>() {
+ @Mock public ExpressionResult evaluate(RowIntf value)
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ return expressionResult;
+ }
+ };
+ orExpression.evaluate(rowImpl);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/result/BatchResultTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/result/BatchResultTest.java b/core/src/test/java/org/apache/carbondata/scan/result/BatchResultTest.java
new file mode 100644
index 0000000..5a6225e
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/result/BatchResultTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.result;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class BatchResultTest {
+ private static BatchResult batchResult;
+ private static List<Object[]> rowsList = new ArrayList(2);
+
+ @BeforeClass public static void setUp() {
+ batchResult = new BatchResult();
+ rowsList.add(0, new Integer[] { 1, 2 });
+ rowsList.add(1, new Integer[] { 3 });
+ }
+
+ @Test public void testNext() throws NoSuchElementException {
+ BatchResult rows = new BatchResult();
+ rows.setRows(rowsList);
+ Object[] result = rows.next();
+ assert (result.equals(rowsList.get(0)));
+ }
+
+ @Test(expected = NoSuchElementException.class) public void testNextWithNoSuchElementException() {
+ BatchResult rows = new BatchResult();
+ List emptyList = new ArrayList(2);
+ rows.setRows(emptyList);
+ rows.next();
+ }
+
+ @Test public void testGetRows() {
+ new MockUp<BatchResult>() {
+ @Mock public void $init() {
+ //to be left blank
+ }
+ };
+ BatchResult batchResult = new BatchResult();
+ List<Object[]> list = batchResult.getRows();
+ assertNull("Number of rows is null", list);
+ }
+
+ @Test public void testHasNext() {
+ List<Object[]> list = new ArrayList<>();
+ list.add(0, new Integer[] { 1, 2 });
+ list.add(1, new Integer[] { 1, 2 });
+ batchResult.setRows(list);
+ boolean result = batchResult.hasNext();
+ assert (result);
+ }
+
+ @Test public void testGetRawRow() {
+ List<Object[]> list = new ArrayList<>();
+ list.add(0, new Integer[] { 1, 2 });
+ batchResult.setRows(list);
+ Object[] actualValue = batchResult.getRawRow(0);
+ assert (list.get(0) == actualValue);
+ }
+
+ @Test public void testGetSize() {
+ List<Object[]> list = new ArrayList<>();
+ list.add(0, new Integer[] { 1, 2 });
+ list.add(1, new Integer[] { 1, 2 });
+ batchResult.setRows(list);
+ int actualValue = batchResult.getSize();
+ int expectedValue = 2;
+ assertEquals(expectedValue, actualValue);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a1fdd5ed/core/src/test/java/org/apache/carbondata/scan/wrappers/ByteArrayWrapperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/scan/wrappers/ByteArrayWrapperTest.java b/core/src/test/java/org/apache/carbondata/scan/wrappers/ByteArrayWrapperTest.java
new file mode 100644
index 0000000..dfeb63d
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/scan/wrappers/ByteArrayWrapperTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.wrappers;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertFalse;
+import static junit.framework.TestCase.assertTrue;
+
+public class ByteArrayWrapperTest {
+ private static ByteArrayWrapper byteArrayWrapper;
+ byte[] dictionaryKey = new byte[] { 1 };
+ byte[][] complexTypesKeys = { { 1 }, { 1 } };
+ byte[][] noDictionaryKeys = new byte[][] { { 1 }, { 1 } };
+
+ @BeforeClass
+
+ public static void setUp() {
+ byteArrayWrapper = new ByteArrayWrapper();
+ }
+
+ @AfterClass public static void tearDown() {
+ byteArrayWrapper = null;
+ }
+
+ @Test public void testHashCodeValue() {
+ byteArrayWrapper.setDictionaryKey(dictionaryKey);
+ byteArrayWrapper.setComplexTypesKeys(complexTypesKeys);
+ byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys);
+
+ int result = byteArrayWrapper.hashCode();
+ assert (29583456 == result);
+ }
+
+ @Test public void testEqualsWithOtherAsInstanceOfByteArrayWrapper() {
+ ByteArrayWrapper other;
+ other = null;
+ boolean result = byteArrayWrapper.equals(other);
+ assertFalse(result);
+ }
+
+ @Test public void testEqualsWithNoDictionaryKeysOtherNotEqualNoDictionaryKeys() {
+ byte[][] noDictionaryKeysOther = { { 1 } };
+ byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys);
+ ByteArrayWrapper other = new ByteArrayWrapper();
+ other.setNoDictionaryKeys(noDictionaryKeysOther);
+ boolean result = byteArrayWrapper.equals(other);
+ assertFalse(result);
+ }
+
+ @Test public void testEqualsWithComplexTypesKeysOtherNotEqualComplexTypesKeys() {
+ byte[][] complexTypesKeysOther = { { 1 } };
+ byteArrayWrapper.setComplexTypesKeys(complexTypesKeys);
+ byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys);
+ ByteArrayWrapper other = new ByteArrayWrapper();
+ other.setComplexTypesKeys(complexTypesKeysOther);
+ other.setNoDictionaryKeys(noDictionaryKeys);
+ boolean result = byteArrayWrapper.equals(other);
+ assertFalse(result);
+ }
+
+ @Test
+
+ public void testEqualsForFirstElementComplexTypesKeysAndOther() {
+ ByteArrayWrapper other = new ByteArrayWrapper();
+ other.setComplexTypesKeys(complexTypesKeys);
+ other.setDictionaryKey(dictionaryKey);
+ other.setNoDictionaryKeys(noDictionaryKeys);
+ byteArrayWrapper.setComplexTypesKeys(complexTypesKeys);
+ byteArrayWrapper.setDictionaryKey(dictionaryKey);
+ byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys);
+ boolean result = byteArrayWrapper.equals(other);
+ assertTrue(result);
+ }
+
+ @Test public void testCompareTo() {
+ byteArrayWrapper.setDictionaryKey(dictionaryKey);
+ ByteArrayWrapper other = new ByteArrayWrapper();
+ other.setDictionaryKey(dictionaryKey);
+ other.setNoDictionaryKeys(noDictionaryKeys);
+ other.setComplexTypesKeys(complexTypesKeys);
+ byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys);
+ byteArrayWrapper.setComplexTypesKeys(complexTypesKeys);
+ int actualResult = byteArrayWrapper.compareTo(other);
+ int expectedResult = 0;
+ assertEquals(expectedResult, actualResult);
+ }
+}
[2/2] incubator-carbondata git commit: [CARBONDATA-395] Test cases
added for Scan Package. This closes #343
Posted by ra...@apache.org.
[CARBONDATA-395] Test cases added for Scan Package. This closes #343
Project: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/commit/b1f4acad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/tree/b1f4acad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/diff/b1f4acad
Branch: refs/heads/master
Commit: b1f4acad312d13fa614ec1d6b3a727b99c46223c
Parents: 311a7d3 a1fdd5e
Author: ravipesala <ra...@gmail.com>
Authored: Mon Dec 12 12:00:44 2016 +0530
Committer: ravipesala <ra...@gmail.com>
Committed: Mon Dec 12 12:00:44 2016 +0530
----------------------------------------------------------------------
.../scan/complextypes/ArrayQueryTypeTest.java | 57 +++
.../complextypes/PrimitiveQueryTypeTest.java | 132 +++++
.../scan/complextypes/StructQueryTypeTest.java | 74 +++
.../scan/executor/util/QueryUtilTest.java | 51 ++
.../scan/expression/ColumnExpressionTest.java | 71 +++
.../scan/expression/ExpressionResultTest.java | 479 +++++++++++++++++++
.../scan/expression/LiteralExpressionTest.java | 59 +++
.../expression/logical/AndExpressionTest.java | 81 ++++
.../expression/logical/FalseExpressionTest.java | 48 ++
.../expression/logical/OrExpressionTest.java | 79 +++
.../carbondata/scan/result/BatchResultTest.java | 95 ++++
.../scan/wrappers/ByteArrayWrapperTest.java | 107 +++++
12 files changed, 1333 insertions(+)
----------------------------------------------------------------------