You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ch...@apache.org on 2017/01/16 14:52:40 UTC
[03/52] [partial] incubator-carbondata git commit: move core package
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/collector/impl/RawBasedResultCollectorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/collector/impl/RawBasedResultCollectorTest.java b/core/src/test/java/org/apache/carbondata/core/scan/collector/impl/RawBasedResultCollectorTest.java
new file mode 100644
index 0000000..a87e272
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/scan/collector/impl/RawBasedResultCollectorTest.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.core.scan.collector.impl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class RawBasedResultCollectorTest {
+//
+// private static RawBasedResultCollector rawBasedResultCollector;
+// private static BlockExecutionInfo blockExecutionInfo;
+// private static KeyGenerator keyGenerator;
+//
+// @BeforeClass public static void setUp() {
+// keyGenerator = new MockUp<KeyGenerator>() {
+// @SuppressWarnings("unused") @Mock long[] getKeyArray(byte[] key, int[] maskedByteRanges) {
+// return new long[] { 1, 2 };
+// }
+//
+// @SuppressWarnings("unused") @Mock byte[] generateKey(long[] keys) throws KeyGenException {
+// return new byte[] { 1, 2 };
+// }
+//
+// }.getMockInstance();
+//
+// blockExecutionInfo = new BlockExecutionInfo();
+// KeyStructureInfo keyStructureInfo = new KeyStructureInfo();
+// keyStructureInfo.setKeyGenerator(keyGenerator);
+// keyStructureInfo.setMaxKey(new byte[] { 1, 2 });
+// keyStructureInfo.setMaskedBytes(new int[] { 1, 2 });
+// keyStructureInfo.setMaskByteRanges(new int[] { 1, 2 });
+// blockExecutionInfo.setKeyStructureInfo(keyStructureInfo);
+// AggregatorInfo aggregatorInfo = new AggregatorInfo();
+// aggregatorInfo.setMeasureOrdinals(new int[] { 10, 20, 30, 40 });
+// aggregatorInfo.setMeasureExists(new boolean[] { true, false, false, false });
+// aggregatorInfo.setDefaultValues(new Object[] { 1, 2, 3, 4 });
+// aggregatorInfo.setMeasureDataTypes(
+// new DataType[] { DataType.INT, DataType.TIMESTAMP, DataType.INT, DataType.INT });
+// QueryMeasure queryMeasure1 = new QueryMeasure("QMCol1");
+// queryMeasure1.setQueryOrder(1);
+// QueryMeasure queryMeasure2 = new QueryMeasure("QMCol2");
+// queryMeasure1.setQueryOrder(2);
+// QueryMeasure queryMeasure3 = new QueryMeasure("QMCol3");
+// queryMeasure1.setQueryOrder(3);
+// QueryMeasure queryMeasure4 = new QueryMeasure("QMCol4");
+// queryMeasure1.setQueryOrder(4);
+// QueryDimension queryDimension1 = new QueryDimension("QDCol1");
+// queryDimension1.setQueryOrder(1);
+// ColumnSchema columnSchema = new ColumnSchema();
+// queryDimension1.setDimension(new CarbonDimension(columnSchema, 0, 0, 0, 0));
+// QueryDimension queryDimension2 = new QueryDimension("QDCol2");
+// queryDimension2.setQueryOrder(2);
+// queryDimension2.setDimension(new CarbonDimension(columnSchema, 1, 1, 1, 1));
+// QueryDimension queryDimension3 = new QueryDimension("QDCol3");
+// queryDimension3.setQueryOrder(3);
+// queryDimension3.setDimension(new CarbonDimension(columnSchema, 2, 0, 0, 0));
+// QueryDimension queryDimension4 = new QueryDimension("QDCol4");
+// queryDimension4.setQueryOrder(4);
+// queryDimension4.setDimension(new CarbonDimension(columnSchema, 3, 0, 0, 0));
+// blockExecutionInfo.setQueryDimensions(
+// new QueryDimension[] { queryDimension1, queryDimension2, queryDimension3,
+// queryDimension4 });
+// blockExecutionInfo.setQueryMeasures(
+// new QueryMeasure[] { queryMeasure1, queryMeasure2, queryMeasure3, queryMeasure4 });
+// blockExecutionInfo.setFixedKeyUpdateRequired(true);
+// blockExecutionInfo.setAggregatorInfo(aggregatorInfo);
+// blockExecutionInfo.setMaskedByteForBlock(new int[] { 1, 2 });
+// blockExecutionInfo.setBlockKeyGenerator(keyGenerator);
+// rawBasedResultCollector = new RawBasedResultCollector(blockExecutionInfo);
+// }
+//
+// @Test public void testToCollectData() {
+//
+// new MockUp<NonFilterQueryScannedResult>() {
+// @SuppressWarnings("unused") @Mock byte[] getDictionaryKeyArray() {
+// this.getMockInstance().incrementCounter();
+// return new byte[] { 1, 2 };
+// }
+//
+// @SuppressWarnings("unused") @Mock byte[][] getNoDictionaryKeyArray() {
+// return new byte[][] { { 1, 2 } };
+// }
+//
+// @SuppressWarnings("unused") @Mock byte[][] getComplexTypeKeyArray() {
+// return new byte[][] { { 1, 2 }, { 1, 2 } };
+// }
+//
+// @SuppressWarnings("unused") @Mock public MeasureColumnDataChunk getMeasureChunk(int ordinal) {
+// MeasureColumnDataChunk measureColumnDataChunk = new MeasureColumnDataChunk();
+// PresenceMeta presenceMeta = new PresenceMeta();
+// BitSet bitSet = new BitSet();
+// bitSet.set(1);
+// presenceMeta.setBitSet(bitSet);
+// measureColumnDataChunk.setNullValueIndexHolder(presenceMeta);
+// CarbonReadDataHolder carbonReadDataHolder = new CarbonReadDataHolder();
+// carbonReadDataHolder.setReadableLongValues(new long[] { 1 });
+// measureColumnDataChunk.setMeasureDataHolder(carbonReadDataHolder);
+// return measureColumnDataChunk;
+// }
+// };
+//
+// new MockUp<QueryUtil>() {
+// @SuppressWarnings("unused") @Mock byte[] getMaskedKey(byte[] data, byte[] maxKey,
+// int[] maskByteRanges, int byteCount) {
+// return new byte[] { 1, 2 };
+// }
+// };
+//
+// AbstractScannedResult abstractScannedResult =
+// new NonFilterQueryScannedResult(blockExecutionInfo);
+// abstractScannedResult.setNumberOfRows(2);
+// List<Object[]> result = rawBasedResultCollector.collectData(abstractScannedResult, 2);
+// int expectedResult = 2;
+// assertThat(result.size(), is(equalTo(expectedResult)));
+// }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/complextypes/ArrayQueryTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/complextypes/ArrayQueryTypeTest.java b/core/src/test/java/org/apache/carbondata/core/scan/complextypes/ArrayQueryTypeTest.java
new file mode 100644
index 0000000..a7b31e3
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/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.core.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/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/complextypes/PrimitiveQueryTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/complextypes/PrimitiveQueryTypeTest.java b/core/src/test/java/org/apache/carbondata/core/scan/complextypes/PrimitiveQueryTypeTest.java
new file mode 100644
index 0000000..6c5abb2
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/scan/complextypes/PrimitiveQueryTypeTest.java
@@ -0,0 +1,156 @@
+/*
+ * 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.core.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.metadata.datatype.DataType;
+import org.apache.carbondata.core.keygenerator.directdictionary.DirectDictionaryGenerator;
+import org.apache.carbondata.core.keygenerator.directdictionary.DirectDictionaryKeyGeneratorFactory;
+import org.apache.carbondata.core.keygenerator.mdkey.Bits;
+import org.apache.carbondata.core.util.DataTypeUtil;
+
+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;
+ private boolean isDirectDictionary = false;
+
+ @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 = primitiveQueryTypeForTimeStampForIsDictionaryFalse
+ .getDataBasedOnDataTypeFromSurrogates(surrogateData);
+ Object actualValue = primitiveQueryTypeForTimeStampForIsDictionaryFalse
+ .getDataBasedOnDataTypeFromSurrogates(surrogateData);
+ assertEquals(expectedValue, actualValue);
+ }
+
+ public Object getDataBasedOnDataTypeFromSurrogates(ByteBuffer surrogateData) {
+ int keySize = 2;
+ byte[] data = new byte[keySize];
+ surrogateData.get(data);
+ Bits bit = new Bits(new int[] { keySize * 8 });
+ int surrgateValue = (int) bit.getKeyArray(data, 0)[0];
+ Object actualData = null;
+ if (isDirectDictionary) {
+ DirectDictionaryGenerator directDictionaryGenerator =
+ DirectDictionaryKeyGeneratorFactory.getDirectDictionaryGenerator(DataType.TIMESTAMP);
+ actualData = directDictionaryGenerator.getValueFromSurrogate(surrgateValue);
+ } else {
+ String dictionaryValueForKey = dictionary.getDictionaryValueForKey(surrgateValue);
+ actualData = DataTypeUtil.getDataBasedOnDataType(dictionaryValueForKey, DataType.TIMESTAMP);
+ }
+ return actualData;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/complextypes/StructQueryTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/complextypes/StructQueryTypeTest.java b/core/src/test/java/org/apache/carbondata/core/scan/complextypes/StructQueryTypeTest.java
new file mode 100644
index 0000000..1fc62d1
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/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.core.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/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/executor/util/QueryUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/executor/util/QueryUtilTest.java b/core/src/test/java/org/apache/carbondata/core/scan/executor/util/QueryUtilTest.java
new file mode 100644
index 0000000..00f05f4
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/scan/executor/util/QueryUtilTest.java
@@ -0,0 +1,241 @@
+/*
+ * 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.core.scan.executor.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.carbondata.core.datastore.block.SegmentProperties;
+import org.apache.carbondata.core.datastore.block.SegmentPropertiesTestUtil;
+import org.apache.carbondata.core.keygenerator.KeyGenException;
+import org.apache.carbondata.core.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;
+
+import static org.junit.Assert.assertArrayEquals;
+
+public class QueryUtilTest extends TestCase {
+
+ private SegmentProperties segmentProperties;
+
+ @BeforeClass public void setUp() {
+ segmentProperties = SegmentPropertiesTestUtil.getSegmentProperties();
+ }
+
+ @Test public void testGetMaskedByteRangeGivingProperMaksedByteRange() {
+
+ QueryDimension dimension =
+ new QueryDimension(segmentProperties.getDimensions().get(0).getColName());
+ dimension.setDimension(segmentProperties.getDimensions().get(0));
+ int[] maskedByteRange = QueryUtil
+ .getMaskedByteRange(Arrays.asList(dimension), segmentProperties.getDimensionKeyGenerator());
+ int[] expectedMaskedByteRange = { 0 };
+ for (int i = 0; i < maskedByteRange.length; i++) {
+ assertEquals(expectedMaskedByteRange[i], maskedByteRange[i]);
+ }
+ }
+
+ @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());
+ dimension.setDimension(segmentProperties.getDimensions().get(i));
+ dimensions.add(dimension);
+ }
+ int[] maskedByteRange =
+ QueryUtil.getMaskedByteRange(dimensions, segmentProperties.getDimensionKeyGenerator());
+ int[] expectedMaskedByteRange = { 0 };
+ for (int i = 0; i < maskedByteRange.length; i++) {
+ assertEquals(expectedMaskedByteRange[i], maskedByteRange[i]);
+ }
+ }
+
+ @Test public void testGetMaskedByteRangeBasedOrdinalGivingProperMaskedByte() {
+ List<Integer> dimensionOrdinal = new ArrayList<Integer>();
+ dimensionOrdinal.add(0);
+ int[] maskedByteRange = QueryUtil.getMaskedByteRangeBasedOrdinal(dimensionOrdinal,
+ segmentProperties.getDimensionKeyGenerator());
+ int[] expectedMaskedByteRange = { 0 };
+ for (int i = 0; i < maskedByteRange.length; i++) {
+ assertEquals(expectedMaskedByteRange[i], maskedByteRange[i]);
+ }
+ }
+
+ @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);
+ }
+ byte[] maxKeyBasedOnDimensions = null;
+ try {
+ maxKeyBasedOnDimensions = QueryUtil
+ .getMaxKeyBasedOnDimensions(dimensions, segmentProperties.getDimensionKeyGenerator());
+ } catch (KeyGenException e) {
+ assertTrue(false);
+ }
+ byte[] expectedMaxKeyBasedOnDimensions = { -1, 0, 0, 0, 0, 0 };
+ for (int i = 0; i < expectedMaxKeyBasedOnDimensions.length; i++) {
+ if (expectedMaxKeyBasedOnDimensions[i] != maxKeyBasedOnDimensions[i]) {
+ assertTrue(false);
+ }
+ }
+ long[] expectedKeyArray = { 255, 0, 0, 0, 0, 0 };
+ long[] keyArray =
+ segmentProperties.getDimensionKeyGenerator().getKeyArray(maxKeyBasedOnDimensions);
+ for (int i = 0; i < keyArray.length; i++) {
+ if (expectedKeyArray[i] != keyArray[i]) {
+ assertTrue(false);
+ }
+ }
+ }
+
+ @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));
+ int[] maskedByteRange = QueryUtil
+ .getMaskedByteRange(Arrays.asList(dimension), segmentProperties.getDimensionKeyGenerator());
+ int[] maskedByte = QueryUtil
+ .getMaskedByte(segmentProperties.getDimensionKeyGenerator().getDimCount(), maskedByteRange);
+ int[] expectedMaskedByte = { 0, -1, -1, -1, -1, -1 };
+
+ for (int i = 0; i < expectedMaskedByte.length; i++) {
+ if (expectedMaskedByte[i] != maskedByte[i]) {
+ assertTrue(false);
+ }
+ }
+ }
+
+ @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);
+ }
+
+ @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/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/executor/util/RestructureUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/executor/util/RestructureUtilTest.java b/core/src/test/java/org/apache/carbondata/core/scan/executor/util/RestructureUtilTest.java
new file mode 100644
index 0000000..65ca2ca
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/scan/executor/util/RestructureUtilTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.core.scan.executor.util;
+
+import org.apache.carbondata.core.metadata.encoder.Encoding;
+import org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension;
+import org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure;
+import org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema;
+import org.apache.carbondata.core.scan.executor.infos.AggregatorInfo;
+import org.apache.carbondata.core.scan.model.QueryDimension;
+import org.apache.carbondata.core.scan.model.QueryMeasure;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class RestructureUtilTest {
+
+ @Test public void testToGetUpdatedQueryDimension() {
+ List<Encoding> encodingList = new ArrayList<Encoding>();
+ encodingList.add(Encoding.DICTIONARY);
+ ColumnSchema columnSchema1 = new ColumnSchema();
+ columnSchema1.setColumnName("Id");
+ columnSchema1.setEncodingList(encodingList);
+ ColumnSchema columnSchema2 = new ColumnSchema();
+ columnSchema2.setColumnName("Name");
+ columnSchema2.setEncodingList(encodingList);
+ ColumnSchema columnSchema3 = new ColumnSchema();
+ columnSchema3.setColumnName("Age");
+ columnSchema3.setEncodingList(encodingList);
+ ColumnSchema columnSchema4 = new ColumnSchema();
+ columnSchema4.setColumnName("Salary");
+ columnSchema4.setEncodingList(encodingList);
+ ColumnSchema columnSchema5 = new ColumnSchema();
+ columnSchema5.setColumnName("Address");
+ columnSchema5.setEncodingList(encodingList);
+
+ CarbonDimension tableBlockDimension1 = new CarbonDimension(columnSchema1, 1, 1, 1, 1);
+ CarbonDimension tableBlockDimension2 = new CarbonDimension(columnSchema2, 5, 5, 5, 5);
+ List<CarbonDimension> tableBlockDimensions =
+ Arrays.asList(tableBlockDimension1, tableBlockDimension2);
+
+ CarbonDimension tableComplexDimension1 = new CarbonDimension(columnSchema3, 4, 4, 4, 4);
+ CarbonDimension tableComplexDimension2 = new CarbonDimension(columnSchema4, 2, 2, 2, 2);
+ List<CarbonDimension> tableComplexDimensions =
+ Arrays.asList(tableComplexDimension1, tableComplexDimension2);
+
+ QueryDimension queryDimension1 = new QueryDimension("Id");
+ queryDimension1.setDimension(tableBlockDimension1);
+ QueryDimension queryDimension2 = new QueryDimension("Name");
+ queryDimension2.setDimension(tableComplexDimension2);
+ QueryDimension queryDimension3 = new QueryDimension("Address");
+ queryDimension3.setDimension(new CarbonDimension(columnSchema5, 3, 3, 3, 3));
+
+ List<QueryDimension> queryDimensions =
+ Arrays.asList(queryDimension1, queryDimension2, queryDimension3);
+
+ List<QueryDimension> result = RestructureUtil
+ .getUpdatedQueryDimension(queryDimensions, tableBlockDimensions, tableComplexDimensions);
+
+ assertThat(result, is(equalTo(Arrays.asList(queryDimension1, queryDimension2))));
+ }
+
+ @Test public void testToGetAggregatorInfos() {
+ ColumnSchema columnSchema1 = new ColumnSchema();
+ columnSchema1.setColumnName("Id");
+ ColumnSchema columnSchema2 = new ColumnSchema();
+ columnSchema2.setColumnName("Name");
+ ColumnSchema columnSchema3 = new ColumnSchema();
+ columnSchema3.setColumnName("Age");
+
+ CarbonMeasure carbonMeasure1 = new CarbonMeasure(columnSchema1, 1);
+ CarbonMeasure carbonMeasure2 = new CarbonMeasure(columnSchema2, 2);
+ CarbonMeasure carbonMeasure3 = new CarbonMeasure(columnSchema3, 3);
+ carbonMeasure3.setDefaultValue("3".getBytes());
+ List<CarbonMeasure> currentBlockMeasures = Arrays.asList(carbonMeasure1, carbonMeasure2);
+
+ QueryMeasure queryMeasure1 = new QueryMeasure("Id");
+ queryMeasure1.setMeasure(carbonMeasure1);
+ QueryMeasure queryMeasure2 = new QueryMeasure("Name");
+ queryMeasure2.setMeasure(carbonMeasure2);
+ QueryMeasure queryMeasure3 = new QueryMeasure("Age");
+ queryMeasure3.setMeasure(carbonMeasure3);
+ List<QueryMeasure> queryMeasures = Arrays.asList(queryMeasure1, queryMeasure2, queryMeasure3);
+
+ AggregatorInfo aggregatorInfo =
+ RestructureUtil.getAggregatorInfos(queryMeasures, currentBlockMeasures);
+ boolean[] measuresExist = { true, true, false };
+ assertThat(aggregatorInfo.getMeasureExists(), is(equalTo(measuresExist)));
+ Object[] defaultValues = { null, null, "3".getBytes() };
+ assertThat(aggregatorInfo.getDefaultValues(), is(equalTo(defaultValues)));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/expression/ColumnExpressionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/expression/ColumnExpressionTest.java b/core/src/test/java/org/apache/carbondata/core/scan/expression/ColumnExpressionTest.java
new file mode 100644
index 0000000..fdc0dbe
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/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.core.scan.expression;
+
+import org.apache.carbondata.core.metadata.datatype.DataType;
+import org.apache.carbondata.core.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/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/expression/ExpressionResultTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/expression/ExpressionResultTest.java b/core/src/test/java/org/apache/carbondata/core/scan/expression/ExpressionResultTest.java
new file mode 100644
index 0000000..15e3848
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/scan/expression/ExpressionResultTest.java
@@ -0,0 +1,498 @@
+/*
+ * 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.core.scan.expression;
+
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.carbondata.core.metadata.datatype.DataType;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.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 = getTime("2016-11-07 10:15:09");
+ assertEquals(expectedValue, actualValue);
+ }
+
+ public Long getTime(String value) throws FilterIllegalMemberException {
+ if (value == null) {
+ return null;
+ }
+ SimpleDateFormat parser =
+ new SimpleDateFormat(CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT);
+ Date dateToStr;
+ try {
+ dateToStr = parser.parse(value.toString());
+ return dateToStr.getTime();
+ } catch (ParseException e) {
+ throw new FilterIllegalMemberException("Cannot convert value to Time/Long type value");
+ }
+ }
+
+ @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 = 0;
+ 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/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/expression/LiteralExpressionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/expression/LiteralExpressionTest.java b/core/src/test/java/org/apache/carbondata/core/scan/expression/LiteralExpressionTest.java
new file mode 100644
index 0000000..945153b
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/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.core.scan.expression;
+
+import org.apache.carbondata.core.metadata.datatype.DataType;
+import org.apache.carbondata.core.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/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/expression/conditional/EqualToExpressionUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/expression/conditional/EqualToExpressionUnitTest.java b/core/src/test/java/org/apache/carbondata/core/scan/expression/conditional/EqualToExpressionUnitTest.java
new file mode 100644
index 0000000..9fa5307
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/scan/expression/conditional/EqualToExpressionUnitTest.java
@@ -0,0 +1,315 @@
+/*
+ * 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.core.scan.expression.conditional;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.carbondata.core.metadata.datatype.DataType;
+import org.apache.carbondata.core.scan.expression.ColumnExpression;
+import org.apache.carbondata.core.scan.expression.ExpressionResult;
+import org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException;
+import org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException;
+import org.apache.carbondata.core.scan.filter.intf.RowImpl;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.spark.sql.types.Decimal;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class EqualToExpressionUnitTest {
+
+ static EqualToExpression equalToExpression;
+
+ @Test public void testForEqualToExpressionWithGetString() throws Exception {
+ ColumnExpression right = new ColumnExpression("name", DataType.STRING);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ String expected_result = "EqualTo(ColumnExpression(name),ColumnExpression(name))";
+ String result = equalToExpression.getString();
+ assertEquals(expected_result, result);
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithShortDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ RowImpl value = new RowImpl();
+ Short[] row = { 15 };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Short getShort() {
+ return 15;
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithStringDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("name", DataType.STRING);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ RowImpl value = new RowImpl();
+ String[] row = { "String1" };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public String getString() {
+ return "String1";
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithIntDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("number", DataType.INT);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ RowImpl value = new RowImpl();
+ Integer[] row = { 14 };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Integer getInt() {
+ return 14;
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithDoubleDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("contact", DataType.DOUBLE);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ RowImpl value = new RowImpl();
+ Double[] row = { 44D };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Double getDouble() {
+ return 44D;
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithLongDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("contact", DataType.LONG);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ RowImpl value = new RowImpl();
+ Long[] row = { 1234567654321L };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Long getLong() {
+ return 1234567654321L;
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithTimestampDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ try {
+ ColumnExpression right = new ColumnExpression("timestamp", DataType.TIMESTAMP);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ RowImpl value = new RowImpl();
+ DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateFormat.parse("23/09/2007");
+ long time = date.getTime();
+ Timestamp[] row = { new Timestamp(time) };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Long getTime() {
+ return 18465213000000L;
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ } catch (ParseException e) {
+ System.out.println("Error while parsing " + e.getMessage());
+ }
+ }
+
+ @Test(expected = FilterUnsupportedException.class) public void testForEqualToExpressionForDefaultCase()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ RowImpl value = new RowImpl();
+ Boolean[] row = { true };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+ ExpressionResult result = equalToExpression.evaluate(value);
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithBooleanParameter()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right, true);
+ RowImpl value = new RowImpl();
+ Short[] row = { 15 };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Short getShort() {
+ return 15;
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithLeftAndRightDifferentDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression left = new ColumnExpression("name", DataType.STRING);
+ left.setColIndex(0);
+ ColumnExpression right = new ColumnExpression("number", DataType.INT);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ String[] row1 = { "String1" };
+ Integer[] row = { 14 };
+ Object objectRow[] = { row, row1 };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Integer getInt() {
+ return 14;
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithIsNullReturnFalse()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ RowImpl value = new RowImpl();
+ Short[] row = { 15 };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public boolean isNull() {
+ return true;
+ }
+ };
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Short getShort() {
+ return 15;
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertFalse(result.getBoolean());
+
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithNullWhileCreatingObject()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right, true);
+ RowImpl value = new RowImpl();
+ Short[] row = { 15 };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public boolean isNull() {
+ return true;
+ }
+ };
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Short getShort() {
+ return 15;
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertEquals(DataType.BOOLEAN, result.getDataType());
+
+ }
+
+ @Test public void testEvaluateForEqualToExpressionWithDecimalDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("contact", DataType.DECIMAL);
+ right.setColIndex(0);
+ equalToExpression = new EqualToExpression(right, right);
+ RowImpl value = new RowImpl();
+ Decimal[] row = new Decimal[] { Decimal.apply(12345.0) };
+ Object objectRow[] = { row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public BigDecimal getDecimal() {
+ return new BigDecimal(12345.0);
+ }
+ };
+
+ ExpressionResult result = equalToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/scan/expression/conditional/GreaterThanEqualToExpressionUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/scan/expression/conditional/GreaterThanEqualToExpressionUnitTest.java b/core/src/test/java/org/apache/carbondata/core/scan/expression/conditional/GreaterThanEqualToExpressionUnitTest.java
new file mode 100644
index 0000000..eae809c
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/scan/expression/conditional/GreaterThanEqualToExpressionUnitTest.java
@@ -0,0 +1,293 @@
+/*
+ * 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.core.scan.expression.conditional;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.carbondata.core.metadata.datatype.DataType;
+import org.apache.carbondata.core.scan.expression.ColumnExpression;
+import org.apache.carbondata.core.scan.expression.ExpressionResult;
+import org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException;
+import org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException;
+import org.apache.carbondata.core.scan.filter.intf.RowImpl;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.spark.sql.types.Decimal;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class GreaterThanEqualToExpressionUnitTest {
+
+ static GreaterThanEqualToExpression greaterThanEqualToExpression;
+
+ @Test public void testEvaluateForGreaterThanEqualToExpressionWithBothStringISSame()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression left = new ColumnExpression("left_name", DataType.STRING);
+ left.setColIndex(0);
+ ColumnExpression right = new ColumnExpression("right_name", DataType.STRING);
+ right.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ String[] row = { "string1" };
+ String[] row1 = { "string1" };
+ Object objectRow[] = { row, row1 };
+
+ new MockUp<ExpressionResult>() {
+ @Mock public String getString() {
+ return "string1";
+ }
+ };
+ value.setValues(objectRow);
+ ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testEvaluateForGreaterThanEqualToExpressionWithShortDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
+ right.setColIndex(0);
+ ColumnExpression left = new ColumnExpression("id", DataType.SHORT);
+ left.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ Short[] row = { 15 };
+ Short[] row1 = { 16 };
+ Object objectRow[] = { row1, row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Short getShort() {
+ return 16;
+ }
+ };
+
+ ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+
+ }
+
+ @Test public void testEvaluateForGreaterThanEqualToExpressionWithIntDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("right_number", DataType.INT);
+ right.setColIndex(0);
+ ColumnExpression left = new ColumnExpression("left_number", DataType.INT);
+ left.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ Integer[] row = { 140 };
+ Integer[] row1 = { 145 };
+ Object objectRow[] = { row1, row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Integer getInt() {
+ return 145;
+ }
+ };
+
+ ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testEvaluateForGreaterThanEqualToExpressionWithDoubleDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("right_contact", DataType.DOUBLE);
+ right.setColIndex(0);
+ ColumnExpression left = new ColumnExpression("left_contact", DataType.DOUBLE);
+ left.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ Double[] row = { 44D };
+ Double[] row1 = { 45D };
+ Object objectRow[] = { row1, row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Double getDouble() {
+ return 45D;
+ }
+ };
+
+ ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testEvaluateForGreaterThanEqualToExpressionWithLongDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("contact", DataType.LONG);
+ right.setColIndex(0);
+ ColumnExpression left = new ColumnExpression("contact", DataType.LONG);
+ left.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ Long[] row = { 1234567654321L };
+ Long[] row1 = { 1234567654321L };
+ Object objectRow[] = { row1, row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Long getLong() {
+ return 1234567654321L;
+ }
+ };
+
+ ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testEvaluateForGreaterThanEqualToExpressionWithTimestampDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ try {
+ ColumnExpression left = new ColumnExpression("timestamp", DataType.TIMESTAMP);
+ left.setColIndex(0);
+ ColumnExpression right = new ColumnExpression("timestamp", DataType.TIMESTAMP);
+ right.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateFormat.parse("23/09/2007");
+ long time = date.getTime();
+ Timestamp[] row = { new Timestamp(time) };
+ Timestamp[] row1 = { new Timestamp(time) };
+ Object objectRow[] = { row, row1 };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Long getTime() {
+ return 18465213000000L;
+ }
+ };
+
+ ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ } catch (ParseException e) {
+ System.out.println("Error while parsing " + e.getMessage());
+ }
+ }
+
+ @Test(expected = FilterUnsupportedException.class) public void testForGreaterThanEqualToExpressionWithDefaultCase()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN);
+ right.setColIndex(0);
+ ColumnExpression left = new ColumnExpression("contact", DataType.BOOLEAN);
+ left.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ Boolean[] row = { true };
+ Object objectRow[] = { row, row };
+ value.setValues(objectRow);
+ greaterThanEqualToExpression.evaluate(value);
+ }
+
+ @Test public void testEvaluateForGreaterThanEqualToExpressionWithDecimalDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression right = new ColumnExpression("contact", DataType.DECIMAL);
+ right.setColIndex(0);
+ ColumnExpression left = new ColumnExpression("contact", DataType.DECIMAL);
+ left.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ Decimal[] row = new Decimal[] { Decimal.apply(12345.0) };
+ Object objectRow[] = { row, row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public BigDecimal getDecimal() {
+ return new BigDecimal(12345.0);
+ }
+ };
+
+ ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testEvaluateForGreaterThanEqualToExpressionWithIsNullReturnTrue()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression left = new ColumnExpression("id", DataType.SHORT);
+ left.setColIndex(0);
+ ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
+ right.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ Short[] row = { 15 };
+ Object objectRow[] = { row, row };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public boolean isNull() {
+ return true;
+ }
+ };
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Short getShort() {
+ return 15;
+ }
+ };
+
+ ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
+ assertFalse(result.getBoolean());
+
+ }
+
+ @Test public void testEvaluateForGreaterThanEqualToExpressionWithLeftAndRightDifferentDataType()
+ throws FilterUnsupportedException, FilterIllegalMemberException {
+ ColumnExpression left = new ColumnExpression("name", DataType.STRING);
+ left.setColIndex(1);
+ ColumnExpression right = new ColumnExpression("number", DataType.INT);
+ right.setColIndex(0);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ RowImpl value = new RowImpl();
+ String[] row1 = { "String1" };
+ Integer[] row = { 14 };
+ Object objectRow[] = { row, row1 };
+ value.setValues(objectRow);
+
+ new MockUp<ExpressionResult>() {
+ @Mock public Integer getInt() {
+ return 14;
+ }
+ };
+
+ ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
+ assertTrue(result.getBoolean());
+ }
+
+ @Test public void testForGreaterThanEqualToExpressionWithGetString() throws Exception {
+ ColumnExpression left = new ColumnExpression("left_name", DataType.STRING);
+ left.setColIndex(0);
+ ColumnExpression right = new ColumnExpression("right_name", DataType.STRING);
+ right.setColIndex(1);
+ greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
+ String expected_result = "GreaterThanEqualTo(ColumnExpression(left_name),ColumnExpression(right_name))";
+ String result = greaterThanEqualToExpression.getString();
+ assertEquals(expected_result, result);
+ }
+
+}
+