Repository: incubator-carbondata
Updated Branches:
refs/heads/master e051d8f0a -> 06f181b55
made changes in the test cases
add test cases with different dim split,dimension and exception handling
Project: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/commit/5ef67ac8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/tree/5ef67ac8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/diff/5ef67ac8
Branch: refs/heads/master
Commit: 5ef67ac88d2c967129e5c5dd98055efcd1d1f1e9
Parents: e051d8f
Author: Anurag <anurag@knoldus.com>
Authored: Tue Nov 8 13:35:28 2016 +0530
Committer: ravipesala <ravi.pesala@gmail.com>
Committed: Fri Dec 9 10:47:04 2016 +0530
----------------------------------------------------------------------
.../keygenerator/mdkey/NumberCompressor.java | 4 +-
...mKeyVarLengthEquiSplitGeneratorUnitTest.java | 199 +++++++++++++++++++
...VarLengthVariableSplitGeneratorUnitTest.java | 152 ++++++++++++++
...ctDictionaryKeyGeneratorFactoryUnitTest.java | 45 +++++
.../factory/KeyGeneratorFactoryUnitTest.java | 63 ++++++
.../core/keygenerator/mdkey/BitsUnitTest.java | 112 +++++++++++
.../MultiDimKeyVarLengthGeneratorUnitTest.java | 91 +++++++++
.../mdkey/NumberCompressorUnitTest.java | 119 +++++++++++
8 files changed, 783 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/5ef67ac8/core/src/main/java/org/apache/carbondata/core/keygenerator/mdkey/NumberCompressor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/carbondata/core/keygenerator/mdkey/NumberCompressor.java
b/core/src/main/java/org/apache/carbondata/core/keygenerator/mdkey/NumberCompressor.java
index b83cf71..fa61f38 100644
--- a/core/src/main/java/org/apache/carbondata/core/keygenerator/mdkey/NumberCompressor.java
+++ b/core/src/main/java/org/apache/carbondata/core/keygenerator/mdkey/NumberCompressor.java
@@ -40,8 +40,8 @@ public class NumberCompressor {
private byte bitsLength;
- public NumberCompressor(int cardinaity) {
- bitsLength = (byte) Long.toBinaryString(cardinaity).length();
+ public NumberCompressor(int cardinality) {
+ bitsLength = (byte) Long.toBinaryString(cardinality).length();
}
public byte[] compress(int[] keys) {
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/5ef67ac8/core/src/test/java/org/apache/carbondata/core/keygenerator/columnar/impl/MultiDimKeyVarLengthEquiSplitGeneratorUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/keygenerator/columnar/impl/MultiDimKeyVarLengthEquiSplitGeneratorUnitTest.java
b/core/src/test/java/org/apache/carbondata/core/keygenerator/columnar/impl/MultiDimKeyVarLengthEquiSplitGeneratorUnitTest.java
new file mode 100644
index 0000000..a9ea7c5
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/keygenerator/columnar/impl/MultiDimKeyVarLengthEquiSplitGeneratorUnitTest.java
@@ -0,0 +1,199 @@
+/*
+ * 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.keygenerator.columnar.impl;
+
+import org.junit.*;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static junit.framework.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.core.Is.is;
+
+import java.util.Arrays;
+
+import org.apache.carbondata.core.keygenerator.KeyGenException;
+
+public class MultiDimKeyVarLengthEquiSplitGeneratorUnitTest {
+
+ static MultiDimKeyVarLengthEquiSplitGenerator multiDimKeyVarLengthEquiSplitGenerator;
+
+ @BeforeClass public static void setup() {
+ int[] lens = new int[] { 32, 8, 16, 16, 16 };
+ byte dimensionsToSplit = 1;
+ multiDimKeyVarLengthEquiSplitGenerator =
+ new MultiDimKeyVarLengthEquiSplitGenerator(lens, dimensionsToSplit);
+ }
+
+ @Test public void testSplitKeyWithNewDimensionToSplit() {
+ int[] lens = new int[] { 24, 8, 16, 16, 16 };
+ byte dimensionsToSplit = 3;
+ MultiDimKeyVarLengthEquiSplitGenerator multiDimKeyVarLengthEquiSplitGeneratorNew =
+ new MultiDimKeyVarLengthEquiSplitGenerator(lens, dimensionsToSplit);
+ byte[][] result_value = new byte[][] { { 16, 8, 24, 46, 76, 64 }, { 80, 36, 72, 48 }
};
+ byte[] key = new byte[] { 16, 8, 24, 46, 76, 64, 80, 36, 72, 48 };
+ byte[][] result = multiDimKeyVarLengthEquiSplitGeneratorNew.splitKey(key);
+ assert (Arrays.deepEquals(result, result_value));
+ }
+
+ @Test public void testSplitKeyWithNewDimensionToSplitValue16() {
+ int[] lens = new int[] { 24, 8, 16, 16, 16 };
+ byte dimensionsToSplit = 16;
+ MultiDimKeyVarLengthEquiSplitGenerator multiDimKeyVarLengthEquiSplitGeneratorNew =
+ new MultiDimKeyVarLengthEquiSplitGenerator(lens, dimensionsToSplit);
+ byte[][] result_value = new byte[][] { { 16, 8, 24, 46, 76, 64, 80, 36, 72, 48 } };
+ byte[] key = new byte[] { 16, 8, 24, 46, 76, 64, 80, 36, 72, 48 };
+ byte[][] result = multiDimKeyVarLengthEquiSplitGeneratorNew.splitKey(key);
+ assert (Arrays.deepEquals(result, result_value));
+ }
+
+ @Test public void testGenerateAndSplitKeyAndGetKeyArrayWithActualLogic() throws KeyGenException
{
+ long[] keys = new long[] { 12253L, 48254L, 451245L, 52245L, 36458L, 48123L, 264L, 5852L,
42L };
+ long[] expected_result = { 12253, 126, 58029, 52245, 36458 };
+ byte[][] result_GenerateAndSplitKey =
+ multiDimKeyVarLengthEquiSplitGenerator.generateAndSplitKey(keys);
+ long[] result_GetKeyArray =
+ multiDimKeyVarLengthEquiSplitGenerator.getKeyArray(result_GenerateAndSplitKey);
+ assertThat(result_GetKeyArray, is(equalTo(expected_result)));
+ }
+
+ @Test public void testSplitKey() throws Exception {
+ byte[][] result_value =
+ new byte[][] { { 1, 102, 20, 56 }, { 64 }, { 36, 18 }, { 16, 28 }, { 98, 93 } };
+ byte[] key = new byte[] { 1, 102, 20, 56, 64, 36, 18, 16, 28, 98, 93 };
+ byte[][] result = multiDimKeyVarLengthEquiSplitGenerator.splitKey(key);
+ assert (Arrays.deepEquals(result, result_value));
+ }
+
+ @Test public void testGetKeyArray() throws Exception {
+ long[] result_value = new long[] { 23467064L, 64L, 9234L, 4124L, 25181L };
+ byte[][] key = new byte[][] { { 1, 102, 20, 56, 64, 36, 18, 16, 28, 98, 93 } };
+ long[] result = multiDimKeyVarLengthEquiSplitGenerator.getKeyArray(key);
+ assertThat(result, is(equalTo(result_value)));
+ }
+
+ @Test public void testKeyByteArray() throws Exception {
+ byte[] result_value = new byte[] { 1, 102, 20, 56, 64, 36, 18, 16, 28, 98, 93 };
+ byte[][] key = new byte[][] { { 1, 102, 20, 56, 64, 36, 18, 16, 28, 98, 93 } };
+ byte[] result = multiDimKeyVarLengthEquiSplitGenerator.getKeyByteArray(key);
+ assert (Arrays.equals(result, result_value));
+ }
+
+ /*
+ * In this test scenario We will send blockIndexes { 0 }.
+ * Where value of blockKeySize is {4,1,2,2,2}
+ * It will add value 0f {0} indexes and will return the size which is 4.
+ *
+ * @throws Exception
+ */
+
+ @Test public void testGetKeySizeByBlockWithBlockIndexesLengthIsZero() throws Exception
{
+ int result_value = 4;
+ int[] blockIndexes = new int[] { 0 };
+ int result = multiDimKeyVarLengthEquiSplitGenerator.getKeySizeByBlock(blockIndexes);
+ assertEquals(result_value, result);
+ }
+
+ /*
+ * In this test scenario We will send blockIndexes { 0, 1, 2 }.
+ * Where value of blockKeySize is {4,1,2,2,2}
+ * It will add value 0f {0, 1, 2} indexes and will return the size which is 7.
+ *
+ * @throws Exception
+ */
+
+ @Test public void testGetKeySizeByBlockWithBlockIndexesLengthIsGreaterThanZero()
+ throws Exception {
+ int result_value = 7;
+ int[] blockIndexes = new int[] { 0, 1, 2 };
+ int result = multiDimKeyVarLengthEquiSplitGenerator.getKeySizeByBlock(blockIndexes);
+ assertEquals(result_value, result);
+ }
+
+ /*
+ * In this test scenario We will send blockIndexes {1, 2, 7} where {7} > blockKeySize.length
which is 5.
+ * Where value of blockKeySize is {4,1,2,2,2}
+ * It will add value 0f {1, 2, 7} indexes and will return the size which is 3.
+ *
+ * @throws Exception
+ */
+
+ @Test public void testGetKeySizeByBlockWithBlockIndexesLengthIsBlockKeySizeLength()
+ throws Exception {
+ int result_value = 3;
+ int[] blockIndexes = new int[] { 1, 2, 7 };
+ int result = multiDimKeyVarLengthEquiSplitGenerator.getKeySizeByBlock(blockIndexes);
+ assertEquals(result_value, result);
+ }
+
+ /*
+ * In this test scenario We will send blockIndexes {10} where {10} > blockKeySize.length
which is 5.
+ * Where value of blockKeySize is {4,1,2,2,2}
+ * It will return default value 0.
+ *
+ * @throws Exception
+ */
+
+ @Test public void testGetKeySizeByBlockWith() throws Exception {
+ int result_value = 0;
+ int[] key = new int[] { 10 };
+ int result = multiDimKeyVarLengthEquiSplitGenerator.getKeySizeByBlock(key);
+ assertEquals(result_value, result);
+ }
+
+ @Test public void testEqualsWithAnyObject() throws Exception {
+ Object obj = new Object();
+ boolean result = multiDimKeyVarLengthEquiSplitGenerator.equals(obj);
+ assert (!result);
+ }
+
+ @Test public void testEqualsWithDifferentValueMultiDimKeyVarLengthEquiSplitGeneratorObject()
+ throws Exception {
+ int[] lens = new int[] { 32, 8, 16, 16, 16 };
+ byte dimensionsToSplit = 2;
+ boolean result = multiDimKeyVarLengthEquiSplitGenerator
+ .equals(new MultiDimKeyVarLengthEquiSplitGenerator(lens, dimensionsToSplit));
+ assert (!result);
+ }
+
+ @Test public void testEqualsWithSameValueMultiDimKeyVarLengthEquiSplitGeneratorObject()
+ throws Exception {
+ int[] lens = new int[] { 32, 8, 16, 16, 16 };
+ byte dimensionsToSplit = 1;
+ boolean result = multiDimKeyVarLengthEquiSplitGenerator
+ .equals(new MultiDimKeyVarLengthEquiSplitGenerator(lens, dimensionsToSplit));
+ assert (result);
+ }
+
+ /**
+ * Test case for exception when Key size is less than byte key size
+ */
+
+ @Test(expected = ArrayIndexOutOfBoundsException.class) public void testSplitKeyWithException()
{
+ int[] lens = new int[] { 24, 8, 16, 16, 16 };
+ byte dimensionsToSplit = 3;
+ MultiDimKeyVarLengthEquiSplitGenerator multiDimKeyVarLengthEquiSplitGeneratorNew =
+ new MultiDimKeyVarLengthEquiSplitGenerator(lens, dimensionsToSplit);
+ byte[][] result_value = new byte[][] { { 16, 8, 24, 46, 76, 64 }, { 80, 36, 72, 48 }
};
+ byte[] key = new byte[] { 16, 8, 24, 46, 76 };
+ byte[][] result = multiDimKeyVarLengthEquiSplitGeneratorNew.splitKey(key);
+ assert (Arrays.deepEquals(result, result_value));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/5ef67ac8/core/src/test/java/org/apache/carbondata/core/keygenerator/columnar/impl/MultiDimKeyVarLengthVariableSplitGeneratorUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/keygenerator/columnar/impl/MultiDimKeyVarLengthVariableSplitGeneratorUnitTest.java
b/core/src/test/java/org/apache/carbondata/core/keygenerator/columnar/impl/MultiDimKeyVarLengthVariableSplitGeneratorUnitTest.java
new file mode 100644
index 0000000..60d6e2c
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/keygenerator/columnar/impl/MultiDimKeyVarLengthVariableSplitGeneratorUnitTest.java
@@ -0,0 +1,152 @@
+/*
+ * 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.keygenerator.columnar.impl;
+
+import org.apache.carbondata.core.keygenerator.KeyGenException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static junit.framework.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.core.Is.is;
+
+public class MultiDimKeyVarLengthVariableSplitGeneratorUnitTest {
+
+ private static MultiDimKeyVarLengthVariableSplitGenerator
+ multiDimKeyVarLengthVariableSplitGenerator;
+
+ @BeforeClass public static void setup() {
+ int[] lens = new int[] { 32, 8, 16, 16, 16 };
+ int[] dimSplit = new int[] { 1, 1, 1, 1, 1 };
+ multiDimKeyVarLengthVariableSplitGenerator =
+ new MultiDimKeyVarLengthVariableSplitGenerator(lens, dimSplit);
+ }
+
+ @Test public void testWithDifferentValueInDimSplit() throws Exception {
+
+ int[] lens = new int[] { 32, 8, 32, 32, 16 };
+ int[] dimSplit = new int[] { 12, 8, 1, 8, 16 };
+ MultiDimKeyVarLengthVariableSplitGenerator multiDimKeyVarLengthVariableSplitGeneratorNew
=
+ new MultiDimKeyVarLengthVariableSplitGenerator(lens, dimSplit);
+
+ byte[][] result_value =
+ new byte[][] { { 24, 56, 72, 48, 56, 36, 18, 24, 40, 24, 64, 24, 56, 72, 48 } };
+ byte[] key = new byte[] { 24, 56, 72, 48, 56, 36, 18, 24, 40, 24, 64, 24, 56, 72, 48
};
+ byte[][] result = multiDimKeyVarLengthVariableSplitGeneratorNew.splitKey(key);
+ assertThat(result, is(equalTo(result_value)));
+ }
+
+ @Test public void testGenerateAndSplitKeyAndGetKeyArrayWithActualLogic() throws KeyGenException
{
+ long[] keys = new long[] { 12253L, 48254L, 451245L, 52245L, 36458L, 48123L, 264L, 5852L,
42L };
+ long[] expected_result = { 12253, 126, 58029, 52245, 36458 };
+ byte[][] result_GenerateAndSplitKey =
+ multiDimKeyVarLengthVariableSplitGenerator.generateAndSplitKey(keys);
+ long[] result_GetKeyArray =
+ multiDimKeyVarLengthVariableSplitGenerator.getKeyArray(result_GenerateAndSplitKey);
+ assertThat(result_GetKeyArray, is(equalTo(expected_result)));
+ }
+
+ @Test public void testGenerateAndSplitKeyAndGetKeyArrayWithActualLogicWithInt()
+ throws KeyGenException {
+ int[] keys = new int[] { 122, 254, 4512, 52, 36, 481, 264, 58, 42 };
+ long[] expected_result = { 122L, 254L, 4512L, 52L, 36L };
+ byte[][] result_GenerateAndSplitKey =
+ multiDimKeyVarLengthVariableSplitGenerator.generateAndSplitKey(keys);
+ long[] result_GetKeyArray =
+ multiDimKeyVarLengthVariableSplitGenerator.getKeyArray(result_GenerateAndSplitKey);
+ assertThat(result_GetKeyArray, is(equalTo(expected_result)));
+ }
+
+ @Test public void testGenerateAndSplitKeyAndGetKeyByteArrayWithActualLogicWithInt()
+ throws KeyGenException {
+ int[] keys = new int[] { 1220, 2554, 452, 520, 360, 48, 24, 56, 42 };
+ byte[] expected_result = new byte[] { 0, 0, 4, -60, -6, 1, -60, 2, 8, 1, 104 };
+ byte[][] result_GenerateAndSplitKey =
+ multiDimKeyVarLengthVariableSplitGenerator.generateAndSplitKey(keys);
+ byte[] result_GetKeyByteArray =
+ multiDimKeyVarLengthVariableSplitGenerator.getKeyByteArray(result_GenerateAndSplitKey);
+ assertThat(result_GetKeyByteArray, is(equalTo(expected_result)));
+ }
+
+ @Test public void testSplitKey() throws Exception {
+ byte[][] result_value =
+ new byte[][] { { 1, 102, 20, 56 }, { 64 }, { 36, 18 }, { 16, 28 }, { 98, 93 } };
+ byte[] key = new byte[] { 1, 102, 20, 56, 64, 36, 18, 16, 28, 98, 93 };
+ byte[][] result = multiDimKeyVarLengthVariableSplitGenerator.splitKey(key);
+ assertThat(result, is(equalTo(result_value)));
+ }
+
+ @Test public void testGetKeyArray() throws Exception {
+ long[] result_value = new long[] { 23467064, 64, 9234, 4124, 25181 };
+ byte[][] key = new byte[][] { { 1, 102, 20, 56, 64, 36, 18, 16, 28, 98, 93 } };
+ long[] result = multiDimKeyVarLengthVariableSplitGenerator.getKeyArray(key);
+ assertThat(result, is(equalTo(result_value)));
+ }
+
+ @Test public void testKeyByteArray() throws Exception {
+ byte[] result_value = new byte[] { 1, 102, 20, 56, 64, 36, 18, 16, 28, 98, 93 };
+ byte[][] key = new byte[][] { { 1, 102, 20, 56, 64, 36, 18, 16, 28, 98, 93 } };
+ byte[] result = multiDimKeyVarLengthVariableSplitGenerator.getKeyByteArray(key);
+ assertThat(result, is(equalTo(result_value)));
+ }
+
+ @Test public void testGetKeySizeByBlockWithBlockIndexesInRange() throws Exception {
+ int result_value = 3;
+ int[] blockIndexes = new int[] { 1, 4 };
+ int result = multiDimKeyVarLengthVariableSplitGenerator.getKeySizeByBlock(blockIndexes);
+ assertEquals(result_value, result);
+ }
+
+ @Test public void testGetKeySizeByBlockWithBlockIndexes() throws Exception {
+ int result_value = 9;
+ int[] blockIndexes = new int[] { 1, 4, 2, 0 };
+ int result = multiDimKeyVarLengthVariableSplitGenerator.getKeySizeByBlock(blockIndexes);
+ assertEquals(result_value, result);
+ }
+
+ @Test public void equalsWithError() throws Exception {
+ Object obj = new Object();
+ boolean result = multiDimKeyVarLengthVariableSplitGenerator.equals(obj);
+ assertEquals(false, result);
+ }
+
+ @Test public void equalsWithTrue() throws Exception {
+ boolean result = multiDimKeyVarLengthVariableSplitGenerator
+ .equals(multiDimKeyVarLengthVariableSplitGenerator);
+ assertEquals(true, result);
+ }
+
+ /**
+ * Test case for exception when Key size is less than byte key size
+ */
+
+ @Test(expected = ArrayIndexOutOfBoundsException.class) public void testSplitKeyWithException()
{
+
+ int[] lens = new int[] { 32, 8, 32, 32, 16 };
+ int[] dimSplit = new int[] { 12, 8, 1, 8, 16 };
+ MultiDimKeyVarLengthVariableSplitGenerator multiDimKeyVarLengthVariableSplitGeneratorNew
=
+ new MultiDimKeyVarLengthVariableSplitGenerator(lens, dimSplit);
+
+ byte[] key = new byte[] { 24, 56, 72, 48, 56, 36, 18 };
+ multiDimKeyVarLengthVariableSplitGeneratorNew.splitKey(key);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/5ef67ac8/core/src/test/java/org/apache/carbondata/core/keygenerator/directdictionary/DirectDictionaryKeyGeneratorFactoryUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/keygenerator/directdictionary/DirectDictionaryKeyGeneratorFactoryUnitTest.java
b/core/src/test/java/org/apache/carbondata/core/keygenerator/directdictionary/DirectDictionaryKeyGeneratorFactoryUnitTest.java
new file mode 100644
index 0000000..022ec6a
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/keygenerator/directdictionary/DirectDictionaryKeyGeneratorFactoryUnitTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.keygenerator.directdictionary;
+
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+import org.apache.carbondata.core.keygenerator.directdictionary.timestamp.TimeStampDirectDictionaryGenerator;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+public class DirectDictionaryKeyGeneratorFactoryUnitTest {
+
+ @Test public void testGetDirectDictionaryGenerator() throws Exception {
+
+ int expectedResult = 1;
+ DirectDictionaryGenerator result =
+ DirectDictionaryKeyGeneratorFactory.getDirectDictionaryGenerator(DataType.TIMESTAMP);
+ assertEquals (expectedResult,result.generateDirectSurrogateKey("TimeStamp"));
+ }
+
+ @Test public void testGetDirectDictionaryGeneratorReturnNull() throws Exception {
+ DirectDictionaryGenerator result =
+ DirectDictionaryKeyGeneratorFactory.getDirectDictionaryGenerator(DataType.ARRAY);
+ Assert.assertNull(result);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/5ef67ac8/core/src/test/java/org/apache/carbondata/core/keygenerator/factory/KeyGeneratorFactoryUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/keygenerator/factory/KeyGeneratorFactoryUnitTest.java
b/core/src/test/java/org/apache/carbondata/core/keygenerator/factory/KeyGeneratorFactoryUnitTest.java
new file mode 100644
index 0000000..feba4f1
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/keygenerator/factory/KeyGeneratorFactoryUnitTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.keygenerator.factory;
+
+import org.apache.carbondata.core.keygenerator.KeyGenerator;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+import static org.apache.carbondata.core.keygenerator.factory.KeyGeneratorFactory.getKeyGenerator;
+
+public class KeyGeneratorFactoryUnitTest {
+
+ @Test public void testGetKeyGenerator() throws Exception {
+
+ int expected = 3;
+ int[] dimension = new int[] { 1, 2, 3 };
+ KeyGenerator result = getKeyGenerator(dimension);
+ assertEquals(expected, result.getDimCount());
+ }
+
+ /**
+ * Return 0 when we provide empty int[] in method.
+ *
+ * @throws Exception
+ */
+
+ @Test public void testGetKeyGeneratorNegative() throws Exception {
+
+ int expected = 0;
+ int[] dimension = new int[] {};
+ KeyGenerator result = getKeyGenerator(dimension);
+ assertEquals(expected, result.getDimCount());
+ }
+
+ @Test public void testGetKeyGenerato() throws Exception {
+
+ int expected = 9;
+ int[] dimCardinality = new int[] { 10, 20, 30, 11, 26, 52, 85, 65, 12 };
+ int[] columnSplits = new int[] { 2 };
+ KeyGenerator result = getKeyGenerator(dimCardinality, columnSplits);
+ assertEquals(expected, result.getDimCount());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/5ef67ac8/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/BitsUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/BitsUnitTest.java
b/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/BitsUnitTest.java
new file mode 100644
index 0000000..bb6b428
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/BitsUnitTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.keygenerator.mdkey;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+
+public class BitsUnitTest {
+ static Bits bits;
+
+ @BeforeClass public static void setup() {
+ int[] lens = new int[] { 32, 8, 24, 64, 64 };
+ bits = new Bits(lens);
+ }
+
+ @Test public void testGetWithIntKeys() throws Exception {
+ long[] expected = new long[] { 0L, 0L, 86570434576L};
+ int[] keys = new int[] { 20, 40, 16, 24, 80 };
+ long[] result = bits.get(keys);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testGetWithLongKeys() throws Exception {
+ long[] expected = new long[] { 0L, 0L, 103616086028L};
+ long[] keys = new long[] { 24L, 32L, 12L, 64L, 40L };
+ long[] result = bits.get(keys);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testGetKeyByteOffsets() throws Exception {
+ int[] lens = new int[] { 64, 64, 64, 64, 64 };
+ Bits bits1 = new Bits(lens);
+ int index = 2;
+ int[] expected = new int[] { 16, 23 };
+ int[] result = bits1.getKeyByteOffsets(index);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testGetKeyArray() throws Exception {
+ int[] lens = new int[] { 8, 32, 24 };
+ Bits bit1 = new Bits(lens);
+ int[] maskByteRanges = new int[] { 1, 3, 5, 6, 4, 8, 9, 2 };
+ byte[] key = new byte[] { 8, 24, 32, 24, 40, 127, 64, 16, 24, 16 };
+ long[] expected = new long[] { 24L, 410992680L, 1576992L };
+ long[] result = bit1.getKeyArray(key, maskByteRanges);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testGetKeyArrayWithKeyContainsNegativeValueOFByte() throws Exception
{
+ int[] lens = new int[] { 8, 32, 24 };
+ Bits bit1 = new Bits(lens);
+ int[] maskByteRanges = new int[] { 1, 3, 5, 6, 4, 8, 9, 2 };
+ byte[] key = new byte[] { -8, 24, 32, -24, 40, -127, 64, 16, -24, 16 };
+ long[] expected = new long[] { 24L, 3900784680L, 15208480L };
+ long[] result = bit1.getKeyArray(key, maskByteRanges);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testGetKeyArrayWithByteBoundaryValue() throws Exception {
+ int[] lens = new int[] { 127, 127, 127 };
+ Bits bits1= new Bits(lens);
+ int[] maskByteRanges =
+ new int[] { 1, 3, 5, 6, 4, 8, 9, 2, 1, 3, 5, 6, 4, 8, 9, 2, 1, 3, 5, 6, 4, 8, 9,
2, 1, 3, 5,
+ 6, 4, 8, 9, 2, 1, 3, 5, 6, 4, 8, 9, 2, 1, 3, 5, 6, 4, 8, 9, 2 };
+ byte[] key = new byte[] { 127, 24, 32, 127, 40, 127, 64, 16, 24, 16 };
+ long[] expected =
+ new long[] { 7061077969919295616L, 3530538984959647808L, 1765269492479823904L };
+ long[] result = bits1.getKeyArray(key, maskByteRanges);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testGetKeyArrayWithNullValue() throws Exception {
+ int[] lens = new int[] { 20, 35, 10 };
+ Bits bit1 = new Bits(lens);
+ byte[] key = new byte[] { 10, 20, 30, 10, 15, 10, 20, 30, 10, 15 };
+ long[] expected = new long[] { 41200, 10800497927L, 522 };
+ long[] result = bit1.getKeyArray(key, null);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testEqualsWithBitsObject() throws Exception {
+ boolean result = bits.equals(bits);
+ assertEquals(true, result);
+ }
+
+ @Test public void testEqualsWithOtherObject() throws Exception {
+ boolean result = bits.equals(new Object());
+ assertEquals(false, result);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/5ef67ac8/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/MultiDimKeyVarLengthGeneratorUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/MultiDimKeyVarLengthGeneratorUnitTest.java
b/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/MultiDimKeyVarLengthGeneratorUnitTest.java
new file mode 100644
index 0000000..a5c5eff
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/MultiDimKeyVarLengthGeneratorUnitTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.keygenerator.mdkey;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class MultiDimKeyVarLengthGeneratorUnitTest {
+ private MultiDimKeyVarLengthGenerator multiDimKeyVarLengthGenerator;
+
+ @Before public void setup() {
+ int[] lens = new int[] { 1, 2, 3 };
+ multiDimKeyVarLengthGenerator = new MultiDimKeyVarLengthGenerator(lens);
+ }
+
+ @Test public void testGetSubKeyArray() throws Exception {
+ byte[] key = new byte[] { 1, 102, 20 };
+ int index = 1;
+ int size = 2;
+ long[] expected = new long[] { 0, 1 };
+ long[] result = multiDimKeyVarLengthGenerator.getSubKeyArray(key, index, size);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testGetSubKeyArrayWithIndexIsLessThanZeroAndSizeIsZero() throws Exception
{
+ byte[] key = new byte[] { 1, 102, 20 };
+ int index = -1;
+ int size = 0;
+ long[] result = multiDimKeyVarLengthGenerator.getSubKeyArray(key, index, size);
+ assertNull(result);
+ }
+
+ @Test public void testEqualsWithSameInstance() throws Exception {
+ int[] lens = new int[] { 1, 2, 3 };
+ MultiDimKeyVarLengthGenerator multiDimKeyVarLengthGenerator1 =
+ new MultiDimKeyVarLengthGenerator(lens);
+ boolean result = multiDimKeyVarLengthGenerator.equals(multiDimKeyVarLengthGenerator1);
+ assertEquals(true, result);
+ }
+
+ @Test public void testEqualsWithDifferenceInstance() throws Exception {
+ boolean result = multiDimKeyVarLengthGenerator.equals(new Object());
+ assertEquals(false, result);
+ }
+
+ @Test public void testCompareWithSameByteArray() throws Exception {
+ byte[] keys = new byte[] { 10, 2, 10, 2, 10, 2, 10, 2, 10, 2 };
+ int expected = 0;
+ int result = multiDimKeyVarLengthGenerator.compare(keys, keys);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testCompareWithByteArray1IsGreaterThanByteArray2() throws Exception {
+ byte[] byteArray1 = new byte[] { 10, 2, 10 };
+ byte[] byteArray2 = new byte[] { 10, 1 };
+ int expected = 1;
+ int result = multiDimKeyVarLengthGenerator.compare(byteArray1, byteArray2);
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test public void testCompareWithByteArray1IsLessThanByteArray2() throws Exception {
+ byte[] byteArray1 = new byte[] { 10, 2 };
+ byte[] byteArray2 = new byte[] { 10, 1, 30 };
+ int expected = 1;
+ int result = multiDimKeyVarLengthGenerator.compare(byteArray1, byteArray2);
+ assertThat(result, is(equalTo(expected)));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/5ef67ac8/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/NumberCompressorUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/NumberCompressorUnitTest.java
b/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/NumberCompressorUnitTest.java
new file mode 100644
index 0000000..e6cd599
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/keygenerator/mdkey/NumberCompressorUnitTest.java
@@ -0,0 +1,119 @@
+/*
+ * 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.keygenerator.mdkey;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class NumberCompressorUnitTest {
+
+ private NumberCompressor numberCompressor;
+
+ @Test public void testCompress() throws Exception {
+ int cardinality = 10;
+ numberCompressor = new NumberCompressor(cardinality);
+ byte[] expected_result = new byte[] { 2, 86, 115 };
+ int[] keys = new int[] { 2, 5, 6, 7, 3 };
+ byte[] result = numberCompressor.compress(keys);
+ assertThat(result, is(equalTo(expected_result)));
+ }
+
+ @Test public void testGetWithIntKeysAndSameIndexes() throws Exception {
+ int cardinality = 10;
+ numberCompressor = new NumberCompressor(cardinality);
+ long[] expected_result = new long[] { 153203, 0 };
+ int[] keys = new int[] { 2, 5, 6, 7, 3 };
+ int size = 2;
+ long[] result = numberCompressor.get(keys, size);
+ assertThat(result, is(equalTo(expected_result)));
+ }
+
+ @Test public void testGetWithIntKeysAndDifferentIndexes() throws Exception {
+ int cardinality = 10;
+ numberCompressor = new NumberCompressor(cardinality);
+ long[] expected_result = new long[] { 2695178248884938548L, 0 };
+ int[] keys = new int[] { 2, 5, 6, 7, 3, 2, 5, 6, 7, 3, 2, 5, 6, 7, 3, 4 };
+ int size = 2;
+ long[] result = numberCompressor.get(keys, size);
+ assertThat(result, is(equalTo(expected_result)));
+ }
+
+ @Test public void testGetWithIntKeysAndDifferentIndexesAndConsideredBitsLessThanBitsLength()
+ throws Exception {
+ int cardinality = 1000;
+ numberCompressor = new NumberCompressor(cardinality);
+ long[] expected_result = new long[] { 2311479113337014277L, 0 };
+ int[] keys = new int[] { 2, 5, 6, 7, 3, 2, 5 };
+ int size = 2;
+ long[] result = numberCompressor.get(keys, size);
+ assertThat(result, is(equalTo(expected_result)));
+ }
+
+ @Test public void testUnCompress() throws Exception {
+ int cardinality = 10;
+ numberCompressor = new NumberCompressor(cardinality);
+ int[] expected_result = new int[] { 6, 4, 0, 2 };
+ byte[] keys = new byte[] { 100, 2 };
+ int[] result = numberCompressor.unCompress(keys);
+ assertThat(result, is(equalTo(expected_result)));
+ }
+
+ @Test public void testUnCompressWithTenKeys() throws Exception {
+ int cardinality = 10;
+ numberCompressor = new NumberCompressor(cardinality);
+ int[] expected_result =
+ new int[] { 0, 10, 0, 2, 0, 10, 0, 2, 0, 10, 0, 2, 0, 10, 0, 2, 0, 10, 0, 2 };
+ byte[] keys = new byte[] { 10, 2, 10, 2, 10, 2, 10, 2, 10, 2 };
+ int[] result = numberCompressor.unCompress(keys);
+ System.out.println(result);
+ assertThat(result, is(equalTo(expected_result)));
+ }
+
+ @Test public void testUnCompressWithPOSGreaterThanZero() throws Exception {
+ int cardinality = 100;
+ numberCompressor = new NumberCompressor(cardinality);
+ int[] expected_result = new int[] { 16, 4, 10, 1, 2, 64, 32, 80, 8, 20, 11 };
+ byte[] keys = new byte[] { 100, 2, 10, 2, 10, 2, 10, 2, 10, 11 };
+ int[] result = numberCompressor.unCompress(keys);
+ assertThat(result, is(equalTo(expected_result)));
+ }
+
+ @Test public void testCompressWithWordsSizeFromBytesSize() throws Exception {
+ int cardinality = 10;
+ numberCompressor = new NumberCompressor(cardinality);
+ byte[] expected_result = new byte[] { 2, 86, 115, 37, 103, 50, 86, 115, 86 };
+ int[] keys = new int[] { 2, 5, 6, 7, 3, 2, 5, 6, 7, 3, 2, 5, 6, 7, 3, 5, 6 };
+ byte[] result = numberCompressor.compress(keys);
+ assertThat(result, is(equalTo(expected_result)));
+ }
+
+ @Test public void testCompressWithIntMaxValue() throws Exception {
+ int cardinality = 10;
+ numberCompressor = new NumberCompressor(cardinality);
+ byte[] expected_result = new byte[] { -35, -52, -52 };
+ int[] keys = new int[] { 214748364, 5456, 214748364, 214748364, 214748364 };
+ byte[] result = numberCompressor.compress(keys);
+ assertThat(result, is(equalTo(expected_result)));
+ }
+}
|