http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentPropertiesTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentPropertiesTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentPropertiesTest.java deleted file mode 100644 index 72d47df..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentPropertiesTest.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * 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.carbon.datastore.block; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; - -import org.apache.carbondata.core.carbon.metadata.datatype.DataType; -import org.apache.carbondata.core.carbon.metadata.encoder.Encoding; -import org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema; -import org.apache.carbondata.core.constants.CarbonCommonConstants; - -import junit.framework.TestCase; -import org.junit.BeforeClass; -import org.junit.Test; - -public class SegmentPropertiesTest extends TestCase { - - private SegmentProperties blockMetadataInfos; - - @BeforeClass public void setUp() { - List<ColumnSchema> columnSchema = new ArrayList<ColumnSchema>(); - columnSchema.add(getDimensionColumn1()); - columnSchema.add(getDimensionColumn2()); - columnSchema.add(getDimensionColumn3()); - columnSchema.add(getDimensionColumn4()); - columnSchema.add(getDimensionColumn5()); - columnSchema.add(getDimensionColumn9()); - columnSchema.add(getDimensionColumn10()); - columnSchema.add(getDimensionColumn11()); - columnSchema.add(getDimensionColumn6()); - columnSchema.add(getDimensionColumn7()); - columnSchema.add(getMeasureColumn()); - columnSchema.add(getMeasureColumn1()); - int[] cardinality = new int[columnSchema.size()]; - int x = 100; - for (int i = 0; i < columnSchema.size(); i++) { - cardinality[i] = x; - x++; - } - blockMetadataInfos = new SegmentProperties(columnSchema, cardinality); - } - - @Test public void testBlockMetadataHasProperDimensionCardinality() { - int[] cardinality = { 100, 102, 103, 105, 106, 107 }; - boolean isProper = true; - for (int i = 0; i < cardinality.length; i++) { - isProper = cardinality[i] == blockMetadataInfos.getDimColumnsCardinality()[i]; - if (!isProper) { - assertTrue(false); - } - } - assertTrue(true); - } - - @Test public void testBlockMetadataHasProperComplesDimensionCardinality() { - int[] cardinality = { 108, 109 }; - boolean isProper = true; - for (int i = 0; i < cardinality.length; i++) { - isProper = cardinality[i] == blockMetadataInfos.getComplexDimColumnCardinality()[i]; - if (!isProper) { - assertTrue(false); - } - } - assertTrue(true); - } - - @Test public void testBlockMetadataHasProperDimensionBlockMapping() { - Map<Integer, Integer> dimensionOrdinalToBlockMapping = new HashMap<Integer, Integer>(); - dimensionOrdinalToBlockMapping.put(0, 0); - dimensionOrdinalToBlockMapping.put(1, 1); - dimensionOrdinalToBlockMapping.put(2, 2); - dimensionOrdinalToBlockMapping.put(3, 2); - dimensionOrdinalToBlockMapping.put(4, 3); - dimensionOrdinalToBlockMapping.put(5, 4); - dimensionOrdinalToBlockMapping.put(6, 4); - dimensionOrdinalToBlockMapping.put(7, 4); - dimensionOrdinalToBlockMapping.put(8, 5); - dimensionOrdinalToBlockMapping.put(9, 6); - Map<Integer, Integer> dimensionOrdinalToBlockMappingActual = - blockMetadataInfos.getDimensionOrdinalToBlockMapping(); - assertEquals(dimensionOrdinalToBlockMapping.size(), - dimensionOrdinalToBlockMappingActual.size()); - Iterator<Entry<Integer, Integer>> iterator = - dimensionOrdinalToBlockMapping.entrySet().iterator(); - while (iterator.hasNext()) { - Entry<Integer, Integer> next = iterator.next(); - Integer integer = dimensionOrdinalToBlockMappingActual.get(next.getKey()); - if (integer != next.getValue()) { - assertTrue(false); - } - } - assertTrue(true); - } - - @Test public void testBlockMetadataHasProperMeasureBlockMapping() { - Map<Integer, Integer> measureOrdinalToBlockMapping = new HashMap<Integer, Integer>(); - measureOrdinalToBlockMapping.put(0, 0); - measureOrdinalToBlockMapping.put(1, 1); - Map<Integer, Integer> measureOrdinalToBlockMappingActual = - blockMetadataInfos.getMeasuresOrdinalToBlockMapping(); - assertEquals(measureOrdinalToBlockMapping.size(), measureOrdinalToBlockMappingActual.size()); - Iterator<Entry<Integer, Integer>> iterator = measureOrdinalToBlockMapping.entrySet().iterator(); - while (iterator.hasNext()) { - Entry<Integer, Integer> next = iterator.next(); - Integer integer = measureOrdinalToBlockMappingActual.get(next.getKey()); - if (integer != next.getValue()) { - assertTrue(false); - } - } - assertTrue(true); - } - - @Test public void testNumberOfDimensionsIsCorrect() { - assertEquals(8, blockMetadataInfos.getDimensions().size()); - } - - @Test public void testNumberOfMeasuesIsCorrect() { - assertEquals(2, blockMetadataInfos.getMeasures().size()); - } - - @Test public void testNumberOfComplexDimensionIsCorrect() { - assertEquals(1, blockMetadataInfos.getComplexDimensions().size()); - } - - @Test public void testEachColumnValueSizeHasProperValue() { - int[] size = { 1, -1, 2, -1, 3 }; - int[] eachDimColumnValueSize = blockMetadataInfos.getEachDimColumnValueSize(); - boolean isEqual = false; - for (int i = 0; i < size.length; i++) { - isEqual = size[i] == eachDimColumnValueSize[i]; - if (!isEqual) { - assertTrue(false); - } - } - assertTrue(true); - } - - @Test public void testEachComplexColumnValueSizeHasProperValue() { - int[] size = { 1, 1 }; - int[] eachDimColumnValueSize = blockMetadataInfos.getEachComplexDimColumnValueSize(); - boolean isEqual = false; - for (int i = 0; i < size.length; i++) { - isEqual = size[i] == eachDimColumnValueSize[i]; - if (!isEqual) { - assertTrue(false); - } - } - assertTrue(true); - } - - private ColumnSchema getDimensionColumn1() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - private ColumnSchema getDimensionColumn2() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI1"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - private ColumnSchema getDimensionColumn3() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI2"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setColumnGroup(0); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - private ColumnSchema getDimensionColumn4() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI3"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - dimColumn.setColumnGroup(0); - return dimColumn; - } - - private ColumnSchema getDimensionColumn5() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI4"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - private ColumnSchema getDimensionColumn9() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI9"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setColumnGroup(1); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - private ColumnSchema getDimensionColumn10() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI10"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - dimColumn.setColumnGroup(1); - return dimColumn; - } - - private ColumnSchema getDimensionColumn11() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI11"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - dimColumn.setColumnGroup(1); - return dimColumn; - } - - private ColumnSchema getDimensionColumn6() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI5"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.ARRAY); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(1); - return dimColumn; - } - - private ColumnSchema getDimensionColumn7() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI6"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - private ColumnSchema getMeasureColumn() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnName("IMEI_COUNT"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DELTA); - dimColumn.setEncodingList(encodeList); - return dimColumn; - } - - private ColumnSchema getMeasureColumn1() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnName("IMEI_COUNT1"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DELTA); - dimColumn.setEncodingList(encodeList); - return dimColumn; - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentPropertiesTestUtil.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentPropertiesTestUtil.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentPropertiesTestUtil.java deleted file mode 100644 index ed1068a..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentPropertiesTestUtil.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * 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.carbon.datastore.block; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import org.apache.carbondata.core.carbon.metadata.datatype.DataType; -import org.apache.carbondata.core.carbon.metadata.encoder.Encoding; -import org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema; -import org.apache.carbondata.core.constants.CarbonCommonConstants; - -public class SegmentPropertiesTestUtil { - - public static SegmentProperties getSegmentProperties() { - List<ColumnSchema> columnSchema = new ArrayList<ColumnSchema>(); - columnSchema.add(getDimensionColumn1()); - columnSchema.add(getDimensionColumn2()); - columnSchema.add(getDimensionColumn3()); - columnSchema.add(getDimensionColumn4()); - columnSchema.add(getDimensionColumn5()); - columnSchema.add(getDimensionColumn9()); - columnSchema.add(getDimensionColumn10()); - columnSchema.add(getDimensionColumn11()); - columnSchema.add(getDimensionColumn6()); - columnSchema.add(getDimensionColumn7()); - columnSchema.add(getMeasureColumn()); - columnSchema.add(getMeasureColumn1()); - int[] cardinality = new int[columnSchema.size()]; - int x = 100; - for (int i = 0; i < columnSchema.size(); i++) { - cardinality[i] = x; - x++; - } - SegmentProperties segmentProperties = new SegmentProperties(columnSchema, cardinality); - return segmentProperties; - } - - public static ColumnSchema getDimensionColumn1() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - public static ColumnSchema getDimensionColumn2() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI1"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - public static ColumnSchema getDimensionColumn3() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI2"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setColumnGroup(0); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - public static ColumnSchema getDimensionColumn4() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI3"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - dimColumn.setColumnGroup(0); - return dimColumn; - } - - public static ColumnSchema getDimensionColumn5() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI4"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - public static ColumnSchema getDimensionColumn9() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI9"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setColumnGroup(1); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - public static ColumnSchema getDimensionColumn10() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI10"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - dimColumn.setColumnGroup(1); - return dimColumn; - } - - public static ColumnSchema getDimensionColumn11() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(false); - dimColumn.setColumnName("IMEI11"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - dimColumn.setColumnGroup(1); - return dimColumn; - } - - public static ColumnSchema getDimensionColumn6() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI5"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.ARRAY); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(1); - return dimColumn; - } - - public static ColumnSchema getDimensionColumn7() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI6"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - public static ColumnSchema getMeasureColumn() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnName("IMEI_COUNT"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DELTA); - dimColumn.setEncodingList(encodeList); - return dimColumn; - } - - public static ColumnSchema getMeasureColumn1() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnName("IMEI_COUNT1"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DELTA); - dimColumn.setEncodingList(encodeList); - return dimColumn; - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentTaskIndexTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentTaskIndexTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentTaskIndexTest.java deleted file mode 100644 index 8a08fc4..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentTaskIndexTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.carbon.datastore.block; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.carbondata.core.carbon.datastore.BTreeBuilderInfo; -import org.apache.carbondata.core.carbon.datastore.impl.btree.BlockBTreeBuilder; -import org.apache.carbondata.core.carbon.metadata.blocklet.BlockletInfo; -import org.apache.carbondata.core.carbon.metadata.blocklet.DataFileFooter; -import org.apache.carbondata.core.carbon.metadata.blocklet.SegmentInfo; -import org.apache.carbondata.core.carbon.metadata.blocklet.index.BlockletIndex; -import org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema; - -import mockit.Mock; -import mockit.MockUp; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import static junit.framework.TestCase.assertEquals; - -public class SegmentTaskIndexTest { - - private static SegmentInfo segmentInfo; - private static DataFileFooter footer; - private static ColumnSchema columnSchema; - private static BlockletInfo blockletInfo; - private static BlockletIndex blockletIndex; - private static List<DataFileFooter> footerList = new ArrayList<DataFileFooter>(); - private static List<ColumnSchema> columnSchemaList = new ArrayList<ColumnSchema>(); - - @BeforeClass public static void setUp() { - segmentInfo = new SegmentInfo(); - footer = new DataFileFooter(); - columnSchema = new ColumnSchema(); - blockletInfo = new BlockletInfo(); - blockletIndex = new BlockletIndex(); - } - - @Test public void testBuild() { - new MockUp<BlockBTreeBuilder>() { - @Mock public void build(BTreeBuilderInfo segmentBuilderInfos) {} - }; - long numberOfRows = 100; - SegmentTaskIndex segmentTaskIndex = new SegmentTaskIndex(); - columnSchema.setColumnName("employeeName"); - columnSchemaList.add(new ColumnSchema()); - - footer.setSegmentInfo(segmentInfo); - footer.setColumnInTable(columnSchemaList); - footer.setBlockletList(Arrays.asList(blockletInfo)); - footer.setNumberOfRows(numberOfRows); - footerList.add(footer); - - segmentTaskIndex.buildIndex(footerList); - assertEquals(footerList.get(0).getNumberOfRows(), numberOfRows); - - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/TableBlockInfoTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/TableBlockInfoTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/TableBlockInfoTest.java deleted file mode 100644 index b6669ed..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/TableBlockInfoTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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.carbon.datastore.block; - -import mockit.Mock; -import mockit.MockUp; - -import org.apache.carbondata.core.carbon.ColumnarFormatVersion; -import org.apache.carbondata.core.carbon.path.CarbonTablePath; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static junit.framework.TestCase.assertEquals; - -public class TableBlockInfoTest { - - static TableBlockInfo tableBlockInfo; - static TableBlockInfo tableBlockInfos; - - @BeforeClass public static void setup() { - tableBlockInfo = new TableBlockInfo("filePath", 4, "segmentId", null, 6, ColumnarFormatVersion.V1); - tableBlockInfos = new TableBlockInfo("filepath", 6, "5", null, 6, new BlockletInfos(6, 2, 2), ColumnarFormatVersion.V1); - } - - @Test public void equalTestWithSameObject() { - Boolean res = tableBlockInfo.equals(tableBlockInfo); - assert (res); - } - - @Test public void equalTestWithSimilarObject() { - TableBlockInfo tableBlockInfoTest = new TableBlockInfo("filePath", 4, "segmentId", null, 6, ColumnarFormatVersion.V1); - Boolean res = tableBlockInfo.equals(tableBlockInfoTest); - assert (res); - } - - @Test public void equalTestWithNullObject() { - Boolean res = tableBlockInfo.equals(null); - assert (!res); - } - - @Test public void equalTestWithStringObject() { - Boolean res = tableBlockInfo.equals("dummyObject"); - assert (!res); - } - - @Test public void equlsTestWithDiffSegmentId() { - TableBlockInfo tableBlockInfoTest = new TableBlockInfo("filePath", 4, "diffsegmentId", null, 6, ColumnarFormatVersion.V1); - Boolean res = tableBlockInfo.equals(tableBlockInfoTest); - assert (!res); - } - - @Test public void equlsTestWithDiffBlockOffset() { - TableBlockInfo tableBlockInfoTest = new TableBlockInfo("filePath", 6, "segmentId", null, 6, ColumnarFormatVersion.V1); - Boolean res = tableBlockInfo.equals(tableBlockInfoTest); - assert (!res); - } - - @Test public void equalsTestWithDiffBlockLength() { - TableBlockInfo tableBlockInfoTest = new TableBlockInfo("filePath", 4, "segmentId", null, 4, ColumnarFormatVersion.V1); - Boolean res = tableBlockInfo.equals(tableBlockInfoTest); - assert (!res); - } - - @Test public void equalsTestWithDiffBlockletNumber() { - TableBlockInfo tableBlockInfoTest = - new TableBlockInfo("filepath", 6, "segmentId", null, 6, new BlockletInfos(6, 3, 2), ColumnarFormatVersion.V1); - Boolean res = tableBlockInfos.equals(tableBlockInfoTest); - assert (!res); - } - - @Test public void equalsTestWithDiffFilePath() { - TableBlockInfo tableBlockInfoTest = - new TableBlockInfo("difffilepath", 6, "segmentId", null, 6, new BlockletInfos(6, 3, 2), ColumnarFormatVersion.V1); - Boolean res = tableBlockInfos.equals(tableBlockInfoTest); - assert (!res); - } - - @Test public void compareToTestForSegmentId() { - TableBlockInfo tableBlockInfo = - new TableBlockInfo("difffilepath", 6, "5", null, 6, new BlockletInfos(6, 3, 2), ColumnarFormatVersion.V1); - int res = tableBlockInfos.compareTo(tableBlockInfo); - int expectedResult = 2; - assertEquals(res, expectedResult); - - TableBlockInfo tableBlockInfo1 = - new TableBlockInfo("difffilepath", 6, "6", null, 6, new BlockletInfos(6, 3, 2), ColumnarFormatVersion.V1); - int res1 = tableBlockInfos.compareTo(tableBlockInfo1); - int expectedResult1 = -1; - assertEquals(res1, expectedResult1); - - TableBlockInfo tableBlockInfo2 = - new TableBlockInfo("difffilepath", 6, "4", null, 6, new BlockletInfos(6, 3, 2), ColumnarFormatVersion.V1); - int res2 = tableBlockInfos.compareTo(tableBlockInfo2); - int expectedresult2 = 1; - assertEquals(res2, expectedresult2); - } - - @Test public void compareToTestForOffsetAndLength() { - new MockUp<CarbonTablePath>() { - @Mock boolean isCarbonDataFile(String fileNameWithPath) { - return true; - } - - }; - - new MockUp<CarbonTablePath.DataFileUtil>() { - @Mock String getTaskNo(String carbonDataFileName) { - return carbonDataFileName.length() + ""; - } - - @Mock String getPartNo(String carbonDataFileName) { - return "5"; - } - - }; - - TableBlockInfo tableBlockInfo = new TableBlockInfo("difffilepaths", 6, "5", null, 3, ColumnarFormatVersion.V1); - int res = tableBlockInfos.compareTo(tableBlockInfo); - int expectedResult = -5; - assertEquals(res, expectedResult); - - TableBlockInfo tableBlockInfo1 = new TableBlockInfo("filepath", 6, "5", null, 3, ColumnarFormatVersion.V1); - int res1 = tableBlockInfos.compareTo(tableBlockInfo1); - int expectedResult1 = 1; - assertEquals(res1, expectedResult1); - - TableBlockInfo tableBlockInfoTest = - new TableBlockInfo("filePath", 6, "5", null, 7, new BlockletInfos(6, 2, 2), ColumnarFormatVersion.V1); - int res2 = tableBlockInfos.compareTo(tableBlockInfoTest); - int expectedResult2 = -1; - assertEquals(res2, expectedResult2); - } - - @Test public void compareToTestWithStartBlockletNo() { - TableBlockInfo tableBlockInfo = - new TableBlockInfo("filepath", 6, "5", null, 6, new BlockletInfos(6, 3, 2), ColumnarFormatVersion.V1); - int res = tableBlockInfos.compareTo(tableBlockInfo); - int expectedresult =-1; - assertEquals(res, expectedresult); - - TableBlockInfo tableBlockInfo1 = - new TableBlockInfo("filepath", 6, "5", null, 6, new BlockletInfos(6, 1, 2), ColumnarFormatVersion.V1); - int res1 = tableBlockInfos.compareTo(tableBlockInfo1); - int expectedresult1 = 1; - assertEquals(res1, expectedresult1); - } - - @Test public void compareToTest() { - int res = tableBlockInfos.compareTo(tableBlockInfos); - int expectedResult = 0; - assertEquals(res, expectedResult); - } - - @Test public void hashCodeTest() { - int res = tableBlockInfo.hashCode(); - int expectedResult = 1041505621; - assertEquals(res, expectedResult); - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/TableTaskInfoTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/TableTaskInfoTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/TableTaskInfoTest.java deleted file mode 100644 index e9d09b8..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/TableTaskInfoTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.carbon.datastore.block; - -import org.apache.carbondata.core.carbon.ColumnarFormatVersion; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class TableTaskInfoTest { - - static TableTaskInfo tableTaskInfo; - static List<TableBlockInfo> tableBlockInfoList; - - @BeforeClass public static void setup() { - tableBlockInfoList = new ArrayList<>(5); - - String[] locations = { "loc1", "loc2", "loc3" }; - tableBlockInfoList.add(0, new TableBlockInfo("filePath", 2, "segmentID", locations, 6, ColumnarFormatVersion.V1)); - - String[] locs = { "loc4", "loc5" }; - tableBlockInfoList.add(1, new TableBlockInfo("filepath", 2, "segmentId", locs, 6, ColumnarFormatVersion.V1)); - - tableTaskInfo = new TableTaskInfo("taskId", tableBlockInfoList); - } - - @Test public void getLocationsTest() { - String locations[] = { "loc1", "loc2", "loc3", "loc4", "loc5" }; - String res[] = tableTaskInfo.getLocations(); - assert (Arrays.equals(locations, res)); - } - - @Test public void maxNoNodesTest() { - List<String> locs = new ArrayList<String>(); - locs.add("loc1"); - locs.add("loc2"); - locs.add("loc3"); - locs.add("loc4"); - locs.add("loc5"); - - List<String> res = TableTaskInfo.maxNoNodes(tableBlockInfoList); - assert (res.equals(locs)); - } - - @Test public void maxNoNodesTestForElse() { - List<String> locs = new ArrayList<String>(); - locs.add("loc1"); - locs.add("loc2"); - locs.add("loc3"); - List<TableBlockInfo> tableBlockInfoListTest = new ArrayList<>(); - - String[] locations = { "loc1", "loc2", "loc3" }; - tableBlockInfoListTest.add(0, new TableBlockInfo("filePath", 2, "segmentID", locations, 6, ColumnarFormatVersion.V1)); - - String[] locations1 = { "loc1", "loc2", "loc3" }; - tableBlockInfoListTest.add(1, new TableBlockInfo("filePath", 2, "segmentID", locations1, 6, ColumnarFormatVersion.V1)); - - List<String> res = TableTaskInfo.maxNoNodes(tableBlockInfoListTest); - assert (res.equals(locs)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/impl/ColumnGroupDimensionDataChunkTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/impl/ColumnGroupDimensionDataChunkTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/impl/ColumnGroupDimensionDataChunkTest.java deleted file mode 100644 index 0266e83..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/impl/ColumnGroupDimensionDataChunkTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.carbon.datastore.chunk.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.carbondata.core.keygenerator.KeyGenException; -import org.apache.carbondata.core.keygenerator.KeyGenerator; -import org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator; -import org.apache.carbondata.core.util.CarbonUtil; -import org.apache.carbondata.scan.executor.infos.KeyStructureInfo; -import org.apache.carbondata.scan.executor.util.QueryUtil; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ColumnGroupDimensionDataChunkTest { - - static ColumnGroupDimensionDataChunk columnGroupDimensionDataChunk; - static KeyGenerator keyGenerator; - - @BeforeClass public static void setup() { - int[] bitLength = CarbonUtil.getDimensionBitLength(new int[] { 10, 10, 10 }, new int[] { 3 }); - // create a key generator - keyGenerator = new MultiDimKeyVarLengthGenerator(bitLength); - byte[] data = new byte[keyGenerator.getKeySizeInBytes() * 3]; - int position = 0; - for (int i = 1; i <= 3; i++) { - try { - System.arraycopy(keyGenerator.generateKey(new int[] { i, i, i }), 0, data, position, - keyGenerator.getKeySizeInBytes()); - } catch (KeyGenException e) { - assertTrue(false); - } - position += keyGenerator.getKeySizeInBytes(); - } - columnGroupDimensionDataChunk = - new ColumnGroupDimensionDataChunk(data, keyGenerator.getKeySizeInBytes(), 3); - } - - @Test public void fillChunkDataTest() { - List<Integer> ordinals = new ArrayList<Integer>(); - ordinals.add(1); - KeyStructureInfo keyStructureInfo = getKeyStructureInfo(ordinals, keyGenerator); - byte[] buffer = new byte[1]; - columnGroupDimensionDataChunk.fillChunkData(buffer, 0, 1, keyStructureInfo); - assertEquals(buffer[0], 2); - } - - @Test public void getChunkDataTest() { - byte[] b = { 34, 2 }; - byte res[] = columnGroupDimensionDataChunk.getChunkData(1); - assert (Arrays.equals(res, b)); - } - - @Test public void fillConvertedChunkDataTest() { - int[] row = new int[3]; - int[] expected = { 0, 0, 3 }; - List<Integer> ordinals = new ArrayList<Integer>(); - ordinals.add(2); - KeyStructureInfo keyStructureInfo = getKeyStructureInfo(ordinals, keyGenerator); - keyStructureInfo.setMdkeyQueryDimensionOrdinal(new int[] { 2 }); - int res = columnGroupDimensionDataChunk.fillConvertedChunkData(2, 2, row, keyStructureInfo); - assert (Arrays.equals(row, expected)); - } - - /** - * Below method will be used to get the key structure info for the query - * - * @param queryModel query model - * @param keyGenerator - * @return key structure info - */ - private KeyStructureInfo getKeyStructureInfo(List<Integer> ordinals, KeyGenerator keyGenerator) { - // getting the masked byte range for dictionary column - int[] maskByteRanges = QueryUtil.getMaskedByteRangeBasedOrdinal(ordinals, keyGenerator); - - // getting the masked bytes for query dimension dictionary column - int[] maskedBytes = QueryUtil.getMaskedByte(keyGenerator.getKeySizeInBytes(), maskByteRanges); - - // max key for the dictionary dimension present in the query - byte[] maxKey = null; - try { - // getting the max key which will be used to masked and get the - // masked key - maxKey = QueryUtil.getMaxKeyBasedOnOrinal(ordinals, keyGenerator); - } catch (KeyGenException e) { - } - - KeyStructureInfo restructureInfos = new KeyStructureInfo(); - restructureInfos.setKeyGenerator(keyGenerator); - restructureInfos.setMaskByteRanges(maskByteRanges); - restructureInfos.setMaxKey(maxKey); - return restructureInfos; - } -} - http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/impl/FixedLengthDimensionDataChunkTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/impl/FixedLengthDimensionDataChunkTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/impl/FixedLengthDimensionDataChunkTest.java deleted file mode 100644 index c1dd83e..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/impl/FixedLengthDimensionDataChunkTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.carbon.datastore.chunk.impl; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; - -import org.apache.carbondata.scan.executor.infos.KeyStructureInfo; -import org.junit.BeforeClass; -import org.junit.Test; - - -public class FixedLengthDimensionDataChunkTest { - - static FixedLengthDimensionDataChunk fixedLengthDimensionDataChunk; - static byte[] data; - - @BeforeClass public static void setup() { - data = "dummy string".getBytes(); - - int invertedIndex[] = { 1, 3, 5, 7, 8 }; - - int invertedIndexReverse[] = { 1, 0, 5, 7, 8 }; - fixedLengthDimensionDataChunk = - new FixedLengthDimensionDataChunk(data, invertedIndex, invertedIndexReverse, 5, 4); - } - - @Test public void fillChunkDataTest() { - KeyStructureInfo keyStructureInfo = new KeyStructureInfo(); - int[] maskByteRanges = { 1, 2, 4, 6, 5 }; - keyStructureInfo.setMaskByteRanges(maskByteRanges); - keyStructureInfo.setMaxKey("1234567".getBytes()); - int res = fixedLengthDimensionDataChunk.fillChunkData(data, 0, 0, keyStructureInfo); - int expectedResult = 4 ; - assertEquals(res, expectedResult); - } - - @Test public void getChunkDataTest() { - byte expected[] = { 121, 32, 115, 116 }; - byte res[] = fixedLengthDimensionDataChunk.getChunkData(0); - assert (Arrays.equals(res, expected)); - } - - @Test public void fillConvertedChunkDataTest() { - int[] row = { 1, 2, 4, 6 }; - KeyStructureInfo keyStructureInfo = new KeyStructureInfo(); - int res = fixedLengthDimensionDataChunk.fillConvertedChunkData(1, 0, row, keyStructureInfo); - int expectedResult = 1; - assertEquals(res, expectedResult); - } -} - - http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/reader/dimension/CompressedDimensionChunkFileBasedReaderTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/reader/dimension/CompressedDimensionChunkFileBasedReaderTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/reader/dimension/CompressedDimensionChunkFileBasedReaderTest.java deleted file mode 100644 index 2815b93..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/reader/dimension/CompressedDimensionChunkFileBasedReaderTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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.carbon.datastore.chunk.reader.dimension; - - -public class CompressedDimensionChunkFileBasedReaderTest { - -// static CompressedDimensionChunkFileBasedReaderV1 compressedDimensionChunkFileBasedReader; -// static List<DataChunk> dataChunkList; -// -// @BeforeClass public static void setup() { -// int eachColumnBlockSize[] = { 1, 2, 4, 5 }; -// dataChunkList = new ArrayList<>(); -// -// DataChunk dataChunk = new DataChunk(); -// dataChunkList.add(dataChunk); -// BlockletInfo info = new BlockletInfo(); -// info.setDimensionColumnChunk(dataChunkList); -// compressedDimensionChunkFileBasedReader = -// new CompressedDimensionChunkFileBasedReaderV1(info, eachColumnBlockSize, "filePath"); -// } -// -// @Test public void readDimensionChunksTest() { -// FileHolder fileHolder = new MockUp<FileHolder>() { -// @Mock public byte[] readByteArray(String filePath, long offset, int length) { -// byte mockedValue[] = { 1, 5, 4, 8, 7 }; -// return mockedValue; -// } -// }.getMockInstance(); -// -// new MockUp<CarbonUtil>() { -// @Mock public boolean hasEncoding(List<Encoding> encodings, Encoding encoding) { -// return true; -// } -// -// @Mock public int[] getUnCompressColumnIndex(int totalLength, byte[] columnIndexData, -// NumberCompressor numberCompressor,int offset) { -// int mockedValue[] = { 1, 1 }; -// return mockedValue; -// } -// }; -// -// new MockUp<SnappyCompressor>() { -// @Mock public byte[] unCompressByte(byte[] compInput) { -// byte mockedValue[] = { 1 }; -// return mockedValue; -// } -// }; -// -// new MockUp<UnBlockIndexer>() { -// @Mock public byte[] uncompressData(byte[] data, int[] index, int keyLen) { -// byte mockedValue[] = { 1, 5, 4, 8, 7 }; -// return mockedValue; -// } -// }; -// -// int[][] blockIndexes = {{0,0}}; -// DimensionColumnDataChunk dimensionColumnDataChunk[] = -// compressedDimensionChunkFileBasedReader.readDimensionChunks(fileHolder, blockIndexes); -// byte expectedResult[] = { 1 }; -// assertEquals(dimensionColumnDataChunk[0].getColumnValueSize(), 1); -// for (int i = 0; i < dimensionColumnDataChunk[0].getChunkData(0).length; i++) { -// assertEquals(dimensionColumnDataChunk[0].getChunkData(0)[i], expectedResult[i]); -// } -// } -// -// @Test public void readDimensionChunksTestForIfStatement() { -// FileHolder fileHolder = new MockUp<FileHolder>() { -// @Mock public byte[] readByteArray(String filePath, long offset, int length) { -// byte mockedValue[] = { 1, 5, 4, 8, 7 }; -// return mockedValue; -// } -// }.getMockInstance(); -// -// new MockUp<CarbonUtil>() { -// @Mock public boolean hasEncoding(List<Encoding> encodings, Encoding encoding) { -// return true; -// } -// -// @Mock public int[] getUnCompressColumnIndex(int totalLength, byte[] columnIndexData, -// NumberCompressor numberCompressor, int offset) { -// int mockedValue[] = { 1, 1 }; -// return mockedValue; -// } -// }; -// -// new MockUp<SnappyCompressor>() { -// @Mock public byte[] unCompressByte(byte[] compInput) { -// byte mockedValue[] = { 1 }; -// return mockedValue; -// } -// }; -// -// new MockUp<UnBlockIndexer>() { -// @Mock public byte[] uncompressData(byte[] data, int[] index, int keyLen) { -// byte mockedValue[] = { 1, 5, 4, 8, 7 }; -// return mockedValue; -// } -// }; -// -// new MockUp<DataChunk>() { -// @Mock public boolean isRowMajor() { -// return true; -// } -// }; -// int[][] blockIndexes = {{0,0}}; -// DimensionColumnDataChunk dimensionColumnDataChunk[] = -// compressedDimensionChunkFileBasedReader.readDimensionChunks(fileHolder, blockIndexes); -// -// byte expectedResult[] = { 1 }; -// assertEquals(dimensionColumnDataChunk[0].getColumnValueSize(), 1); -// -// for (int i = 0; i < dimensionColumnDataChunk[0].getChunkData(0).length; i++) { -// assertEquals(dimensionColumnDataChunk[0].getChunkData(0)[i], expectedResult[i]); -// } -// } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/reader/measure/CompressedMeasureChunkFileBasedReaderTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/reader/measure/CompressedMeasureChunkFileBasedReaderTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/reader/measure/CompressedMeasureChunkFileBasedReaderTest.java deleted file mode 100644 index 1e88671..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/chunk/reader/measure/CompressedMeasureChunkFileBasedReaderTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.apache.carbondata.core.carbon.datastore.chunk.reader.measure; - -import static junit.framework.TestCase.assertEquals; - -import java.io.IOException; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; - -import mockit.Mock; -import mockit.MockUp; - -import org.apache.carbondata.core.carbon.datastore.chunk.MeasureColumnDataChunk; -import org.apache.carbondata.core.carbon.datastore.chunk.reader.measure.v1.CompressedMeasureChunkFileBasedReaderV1; -import org.apache.carbondata.core.carbon.metadata.blocklet.BlockletInfo; -import org.apache.carbondata.core.carbon.metadata.blocklet.datachunk.DataChunk; -import org.apache.carbondata.core.datastorage.store.FileHolder; -import org.apache.carbondata.core.datastorage.store.compression.MeasureMetaDataModel; -import org.apache.carbondata.core.datastorage.store.compression.WriterCompressModel; -import org.apache.carbondata.core.datastorage.store.dataholder.CarbonWriteDataHolder; -import org.apache.carbondata.core.datastorage.util.StoreFactory; -import org.apache.carbondata.core.metadata.ValueEncoderMeta; -import org.apache.carbondata.core.util.ValueCompressionUtil; -import org.junit.BeforeClass; -import org.junit.Test; - -public class CompressedMeasureChunkFileBasedReaderTest { - - static CompressedMeasureChunkFileBasedReaderV1 compressedMeasureChunkFileBasedReader; - static CarbonWriteDataHolder[] dataHolder = new CarbonWriteDataHolder[1]; - - static WriterCompressModel writerCompressModel; - @BeforeClass public static void setup() { - List<DataChunk> dataChunkList = new ArrayList<>(); - DataChunk dataChunk = new DataChunk(); - dataChunkList.add(dataChunk); - dataChunk.setDataPageLength(10); - writerCompressModel = new WriterCompressModel(); - Object maxValue[] = new Object[]{new Long[]{8L, 0L}}; - Object minValue[] = new Object[]{new Long[]{1L,0L}}; - byte[] dataTypeSelected = new byte[1]; - char[] aggType = new char[]{'b'}; - MeasureMetaDataModel measureMDMdl = - new MeasureMetaDataModel(minValue, maxValue, new int[]{1}, maxValue.length, null, - aggType, dataTypeSelected); - writerCompressModel = ValueCompressionUtil.getWriterCompressModel(measureMDMdl); - - - ValueEncoderMeta meta = new ValueEncoderMeta(); - meta.setMaxValue(new Long[]{8L,0L}); - meta.setMinValue(new Long[]{1L,0L}); - meta.setMantissa(1); - meta.setType('b'); - List<ValueEncoderMeta> valueEncoderMetaList = new ArrayList<>(); - valueEncoderMetaList.add(meta); - dataChunkList.get(0).setValueEncoderMeta(valueEncoderMetaList); - BlockletInfo info = new BlockletInfo(); - info.setMeasureColumnChunk(dataChunkList); - compressedMeasureChunkFileBasedReader = - new CompressedMeasureChunkFileBasedReaderV1(info, "filePath"); - } - - @Test public void readMeasureChunkTest() throws IOException { - FileHolder fileHolder = new MockUp<FileHolder>() { - @Mock public byte[] readByteArray(String filePath, long offset, int length) { - dataHolder[0] = new CarbonWriteDataHolder(); - dataHolder[0].initialiseBigDecimalValues(1); - dataHolder[0].setWritableBigDecimalValueByIndex(0, new long[]{2L,1L}); - byte[][] writableMeasureDataArray = - StoreFactory.createDataStore(writerCompressModel).getWritableMeasureDataArray(dataHolder) - .clone(); - return writableMeasureDataArray[0]; - } - }.getMockInstance(); - - MeasureColumnDataChunk measureColumnDataChunks = - compressedMeasureChunkFileBasedReader.readMeasureChunk(fileHolder, 0); - - BigDecimal bigD = new BigDecimal("2.1"); - assertEquals(bigD, - measureColumnDataChunks.getMeasureDataHolder().getReadableBigDecimalValueByIndex(0)); - - } - - @Test public void readMeasureChunksTest() throws IOException { - FileHolder fileHolder = new MockUp<FileHolder>() { - @Mock public byte[] readByteArray(String filePath, long offset, int length) { - dataHolder[0] = new CarbonWriteDataHolder(); - dataHolder[0].initialiseBigDecimalValues(1); - dataHolder[0].setWritableBigDecimalValueByIndex(0, new long[]{2L,1L}); - byte[][] writableMeasureDataArray = - StoreFactory.createDataStore(writerCompressModel).getWritableMeasureDataArray(dataHolder) - .clone(); - return writableMeasureDataArray[0]; - } - }.getMockInstance(); - - int[][] blockIndexes = {{0,0}}; - MeasureColumnDataChunk measureColumnDataChunks[] = - compressedMeasureChunkFileBasedReader.readMeasureChunks(fileHolder, blockIndexes); - - BigDecimal bigD = new BigDecimal("2.1"); - assertEquals(bigD, - measureColumnDataChunks[0].getMeasureDataHolder().getReadableBigDecimalValueByIndex(0)); - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/datastore/impl/btree/BTreeBlockFinderTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/impl/btree/BTreeBlockFinderTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/impl/btree/BTreeBlockFinderTest.java deleted file mode 100644 index 10cb72b..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/impl/btree/BTreeBlockFinderTest.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * 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.carbon.datastore.impl.btree; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; - -import org.apache.carbondata.common.logging.LogService; -import org.apache.carbondata.common.logging.LogServiceFactory; -import org.apache.carbondata.core.carbon.datastore.BTreeBuilderInfo; -import org.apache.carbondata.core.carbon.datastore.BtreeBuilder; -import org.apache.carbondata.core.carbon.datastore.DataRefNode; -import org.apache.carbondata.core.carbon.datastore.DataRefNodeFinder; -import org.apache.carbondata.core.carbon.datastore.IndexKey; -import org.apache.carbondata.core.carbon.metadata.blocklet.DataFileFooter; -import org.apache.carbondata.core.carbon.metadata.blocklet.index.BlockletBTreeIndex; -import org.apache.carbondata.core.carbon.metadata.blocklet.index.BlockletIndex; -import org.apache.carbondata.core.carbon.metadata.blocklet.index.BlockletMinMaxIndex; -import org.apache.carbondata.core.keygenerator.KeyGenException; -import org.apache.carbondata.core.keygenerator.KeyGenerator; -import org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator; -import org.apache.carbondata.core.util.CarbonUtil; - -import junit.framework.TestCase; -import org.junit.Test; - -public class BTreeBlockFinderTest extends TestCase { - - private static final LogService LOGGER = - LogServiceFactory.getLogService(BTreeBlockFinderTest.class.getName()); - - @Test public void testBtreeBuldingIsPorper() { - BtreeBuilder builder = new BlockBTreeBuilder(); - List<DataFileFooter> footerList = getDataFileFooterList(); - BTreeBuilderInfo infos = new BTreeBuilderInfo(footerList, null); - builder.build(infos); - - } - - @Test public void testBtreeBuilderGetMethodIsGivingNotNullRootNode() { - BtreeBuilder builder = new BlockBTreeBuilder(); - List<DataFileFooter> footerList = getDataFileFooterList(); - BTreeBuilderInfo infos = new BTreeBuilderInfo(footerList, null); - builder.build(infos); - DataRefNode dataBlock = builder.get(); - assertTrue(dataBlock != null); - } - - @Test public void testBtreeSearchIsWorkingAndGivingPorperBlockletWithNoDictionary1() { - BtreeBuilder builder = new BlockBTreeBuilder(); - List<DataFileFooter> footerList = getFileFooterListWithOnlyNoDictionaryKey(); - BTreeBuilderInfo infos = new BTreeBuilderInfo(footerList, null); - builder.build(infos); - DataRefNode dataBlock = builder.get(); - assertTrue(dataBlock != null); - DataRefNodeFinder finder = new BTreeDataRefNodeFinder(new int[] { -1 }); - ByteBuffer buffer = ByteBuffer.allocate(4 + 2); - buffer.rewind(); - buffer.putShort((short) 1); - buffer.putInt(12); - buffer.array(); - IndexKey key = new IndexKey(null, buffer.array()); - DataRefNode findFirstBlock = finder.findFirstDataBlock(dataBlock, key); - assertEquals(1, findFirstBlock.nodeNumber()); - DataRefNode findLastBlock = finder.findLastDataBlock(dataBlock, key); - assertEquals(1, findLastBlock.nodeNumber()); - } - - @Test public void testBtreeSearchIsWorkingAndGivingPorperBlockletWithNoDictionary() { - BtreeBuilder builder = new BlockBTreeBuilder(); - List<DataFileFooter> footerList = getFileFooterListWithOnlyNoDictionaryKey(); - BTreeBuilderInfo infos = new BTreeBuilderInfo(footerList, null); - builder.build(infos); - DataRefNode dataBlock = builder.get(); - assertTrue(dataBlock != null); - DataRefNodeFinder finder = new BTreeDataRefNodeFinder(new int[] { -1 }); - ByteBuffer buffer = ByteBuffer.allocate(4 + 1); - buffer.rewind(); - buffer.put((byte) 1); - buffer.putInt(0); - buffer.array(); - IndexKey key = new IndexKey(null, buffer.array()); - DataRefNode findFirstBlock = finder.findFirstDataBlock(dataBlock, key); - assertEquals(0, findFirstBlock.nodeNumber()); - DataRefNode findLastBlock = finder.findLastDataBlock(dataBlock, key); - assertEquals(0, findLastBlock.nodeNumber()); - } - - @Test public void testBtreeSearchIsWorkingAndGivingPorperBlockletWithDictionaryKey1() - throws KeyGenException { - BtreeBuilder builder = new BlockBTreeBuilder(); - List<DataFileFooter> footerList = getFileFooterListWithOnlyDictionaryKey(); - BTreeBuilderInfo infos = new BTreeBuilderInfo(footerList, null); - builder.build(infos); - DataRefNode dataBlock = builder.get(); - assertTrue(dataBlock != null); - DataRefNodeFinder finder = new BTreeDataRefNodeFinder(new int[] { 2, 2 }); - int[] dimensionBitLength = - CarbonUtil.getDimensionBitLength(new int[] { 10000, 10000 }, new int[] { 1, 1 }); - KeyGenerator multiDimKeyVarLengthGenerator = - new MultiDimKeyVarLengthGenerator(dimensionBitLength); - - IndexKey key = - new IndexKey(multiDimKeyVarLengthGenerator.generateKey(new int[] { 1, 1 }), null); - DataRefNode findFirstBlock = finder.findFirstDataBlock(dataBlock, key); - assertEquals(0, findFirstBlock.nodeNumber()); - DataRefNode findLastBlock = finder.findLastDataBlock(dataBlock, key); - assertEquals(0, findLastBlock.nodeNumber()); - } - - @Test public void testBtreeSearchIsWorkingAndGivingPorperBlockletWithDictionaryKey2() - throws KeyGenException { - BtreeBuilder builder = new BlockBTreeBuilder(); - List<DataFileFooter> footerList = getFileFooterListWithOnlyDictionaryKey(); - BTreeBuilderInfo infos = new BTreeBuilderInfo(footerList, null); - builder.build(infos); - DataRefNode dataBlock = builder.get(); - assertTrue(dataBlock != null); - DataRefNodeFinder finder = new BTreeDataRefNodeFinder(new int[] { 2, 2 }); - int[] dimensionBitLength = - CarbonUtil.getDimensionBitLength(new int[] { 10000, 10000 }, new int[] { 1, 1 }); - KeyGenerator multiDimKeyVarLengthGenerator = - new MultiDimKeyVarLengthGenerator(dimensionBitLength); - - IndexKey key = - new IndexKey(multiDimKeyVarLengthGenerator.generateKey(new int[] { 0, 0 }), null); - - DataRefNode findFirstBlock = finder.findFirstDataBlock(dataBlock, key); - assertEquals(0, findFirstBlock.nodeNumber()); - DataRefNode findLastBlock = finder.findLastDataBlock(dataBlock, key); - assertEquals(0, findLastBlock.nodeNumber()); - } - - @Test - /** - * Below method will test when key which is not present and key which is - * more than - * last node key is passes for searching it should give first block - */ - public void testBtreeSearchIsWorkingAndGivingPorperBlockletWithDictionaryKey() - throws KeyGenException { - BtreeBuilder builder = new BlockBTreeBuilder(); - List<DataFileFooter> footerList = getFileFooterListWithOnlyDictionaryKey(); - BTreeBuilderInfo infos = new BTreeBuilderInfo(footerList, null); - builder.build(infos); - DataRefNode dataBlock = builder.get(); - assertTrue(dataBlock != null); - DataRefNodeFinder finder = new BTreeDataRefNodeFinder(new int[] { 2, 2 }); - int[] dimensionBitLength = - CarbonUtil.getDimensionBitLength(new int[] { 10000, 10000 }, new int[] { 1, 1 }); - KeyGenerator multiDimKeyVarLengthGenerator = - new MultiDimKeyVarLengthGenerator(dimensionBitLength); - - IndexKey key = - new IndexKey(multiDimKeyVarLengthGenerator.generateKey(new int[] { 10001, 10001 }), null); - - DataRefNode findFirstBlock = finder.findFirstDataBlock(dataBlock, key); - assertEquals(99, findFirstBlock.nodeNumber()); - DataRefNode findLastBlock = finder.findLastDataBlock(dataBlock, key); - assertEquals(99, findLastBlock.nodeNumber()); - } - - private List<DataFileFooter> getDataFileFooterList() { - List<DataFileFooter> list = new ArrayList<DataFileFooter>(); - try { - int[] dimensionBitLength = - CarbonUtil.getDimensionBitLength(new int[] { 10000, 10000 }, new int[] { 1, 1 }); - KeyGenerator multiDimKeyVarLengthGenerator = - new MultiDimKeyVarLengthGenerator(dimensionBitLength); - int i = 1; - while (i < 1001) { - byte[] startKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i, i }); - byte[] endKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i + 10, i + 10 }); - ByteBuffer buffer = ByteBuffer.allocate(4 + 1); - buffer.rewind(); - buffer.put((byte) 1); - buffer.putInt(i); - buffer.array(); - byte[] noDictionaryStartKey = buffer.array(); - - ByteBuffer buffer1 = ByteBuffer.allocate(4 + 1); - buffer1.rewind(); - buffer1.put((byte) 1); - buffer1.putInt(i + 10); - buffer1.array(); - byte[] noDictionaryEndKey = buffer.array(); - DataFileFooter footer = - getFileFooter(startKey, endKey, noDictionaryStartKey, noDictionaryEndKey); - list.add(footer); - i = i + 10; - } - } catch (Exception e) { - LOGGER.error(e); - } - return list; - } - - private List<DataFileFooter> getFileFooterListWithOnlyNoDictionaryKey() { - List<DataFileFooter> list = new ArrayList<DataFileFooter>(); - try { - int[] dimensionBitLength = - CarbonUtil.getDimensionBitLength(new int[] { 10000, 10000 }, new int[] { 1, 1 }); - KeyGenerator multiDimKeyVarLengthGenerator = - new MultiDimKeyVarLengthGenerator(dimensionBitLength); - int i = 1; - while (i < 1001) { - byte[] startKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i, i }); - byte[] endKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i + 10, i + 10 }); - ByteBuffer buffer = ByteBuffer.allocate(2 + 4); - buffer.rewind(); - buffer.putShort((short) 1); - buffer.putInt(i); - buffer.array(); - byte[] noDictionaryStartKey = buffer.array(); - - ByteBuffer buffer1 = ByteBuffer.allocate(2 + 4); - buffer1.rewind(); - buffer1.putShort((short) 2); - buffer1.putInt(i + 10); - buffer1.array(); - byte[] noDictionaryEndKey = buffer.array(); - DataFileFooter footer = - getFileMatadataWithOnlyNoDictionaryKey(startKey, endKey, noDictionaryStartKey, - noDictionaryEndKey); - list.add(footer); - i = i + 10; - } - } catch (Exception e) { - LOGGER.error(e); - } - return list; - } - - private List<DataFileFooter> getFileFooterListWithOnlyDictionaryKey() { - List<DataFileFooter> list = new ArrayList<DataFileFooter>(); - try { - int[] dimensionBitLength = - CarbonUtil.getDimensionBitLength(new int[] { 10000, 10000 }, new int[] { 1, 1 }); - KeyGenerator multiDimKeyVarLengthGenerator = - new MultiDimKeyVarLengthGenerator(dimensionBitLength); - int i = 1; - while (i < 1001) { - byte[] startKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i, i }); - byte[] endKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i + 10, i + 10 }); - ByteBuffer buffer = ByteBuffer.allocate(1 + 4); - buffer.rewind(); - buffer.put((byte) 1); - buffer.putInt(i); - buffer.array(); - byte[] noDictionaryStartKey = buffer.array(); - - ByteBuffer buffer1 = ByteBuffer.allocate(1 + 4); - buffer1.rewind(); - buffer1.put((byte) 1); - buffer1.putInt(i + 10); - buffer1.array(); - byte[] noDictionaryEndKey = buffer.array(); - DataFileFooter footer = - getFileFooterWithOnlyDictionaryKey(startKey, endKey, noDictionaryStartKey, - noDictionaryEndKey); - list.add(footer); - i = i + 10; - } - } catch (Exception e) { - LOGGER.error(e); - } - return list; - } - - private DataFileFooter getFileFooter(byte[] startKey, byte[] endKey, - byte[] noDictionaryStartKey, byte[] noDictionaryEndKey) { - DataFileFooter footer = new DataFileFooter(); - BlockletIndex index = new BlockletIndex(); - BlockletBTreeIndex btreeIndex = new BlockletBTreeIndex(); - ByteBuffer buffer = ByteBuffer.allocate(4 + startKey.length + 4 + noDictionaryStartKey.length); - buffer.putInt(startKey.length); - buffer.putInt(noDictionaryStartKey.length); - buffer.put(startKey); - buffer.put(noDictionaryStartKey); - buffer.rewind(); - btreeIndex.setStartKey(buffer.array()); - ByteBuffer buffer1 = ByteBuffer.allocate(4 + startKey.length + 4 + noDictionaryEndKey.length); - buffer1.putInt(endKey.length); - buffer1.putInt(noDictionaryEndKey.length); - buffer1.put(endKey); - buffer1.put(noDictionaryEndKey); - buffer1.rewind(); - btreeIndex.setEndKey(buffer1.array()); - BlockletMinMaxIndex minMax = new BlockletMinMaxIndex(); - minMax.setMaxValues(new byte[][] { endKey, noDictionaryEndKey }); - minMax.setMinValues(new byte[][] { startKey, noDictionaryStartKey }); - index.setBtreeIndex(btreeIndex); - index.setMinMaxIndex(minMax); - footer.setBlockletIndex(index); - return footer; - } - - private DataFileFooter getFileMatadataWithOnlyNoDictionaryKey(byte[] startKey, byte[] endKey, - byte[] noDictionaryStartKey, byte[] noDictionaryEndKey) { - DataFileFooter footer = new DataFileFooter(); - BlockletIndex index = new BlockletIndex(); - BlockletBTreeIndex btreeIndex = new BlockletBTreeIndex(); - ByteBuffer buffer = ByteBuffer.allocate(4 + 0 + 4 + noDictionaryStartKey.length); - buffer.putInt(0); - buffer.putInt(noDictionaryStartKey.length); - buffer.put(noDictionaryStartKey); - buffer.rewind(); - btreeIndex.setStartKey(buffer.array()); - ByteBuffer buffer1 = ByteBuffer.allocate(4 + 0 + 4 + noDictionaryEndKey.length); - buffer1.putInt(0); - buffer1.putInt(noDictionaryEndKey.length); - buffer1.put(noDictionaryEndKey); - buffer1.rewind(); - btreeIndex.setEndKey(buffer1.array()); - BlockletMinMaxIndex minMax = new BlockletMinMaxIndex(); - minMax.setMaxValues(new byte[][] { endKey, noDictionaryEndKey }); - minMax.setMinValues(new byte[][] { startKey, noDictionaryStartKey }); - index.setBtreeIndex(btreeIndex); - index.setMinMaxIndex(minMax); - footer.setBlockletIndex(index); - return footer; - } - - private DataFileFooter getFileFooterWithOnlyDictionaryKey(byte[] startKey, byte[] endKey, - byte[] noDictionaryStartKey, byte[] noDictionaryEndKey) { - DataFileFooter footer = new DataFileFooter(); - BlockletIndex index = new BlockletIndex(); - BlockletBTreeIndex btreeIndex = new BlockletBTreeIndex(); - ByteBuffer buffer = ByteBuffer.allocate(4 + startKey.length + 4 + 0); - buffer.putInt(startKey.length); - buffer.putInt(0); - buffer.put(startKey); - buffer.rewind(); - btreeIndex.setStartKey(buffer.array()); - ByteBuffer buffer1 = ByteBuffer.allocate(4 + 0 + 4 + noDictionaryEndKey.length); - buffer1.putInt(endKey.length); - buffer1.putInt(0); - buffer1.put(endKey); - buffer1.rewind(); - btreeIndex.setEndKey(buffer1.array()); - BlockletMinMaxIndex minMax = new BlockletMinMaxIndex(); - minMax.setMaxValues(new byte[][] { endKey }); - minMax.setMinValues(new byte[][] { startKey }); - index.setBtreeIndex(btreeIndex); - index.setMinMaxIndex(minMax); - footer.setBlockletIndex(index); - return footer; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/ce09aaaf/core/src/test/java/org/apache/carbondata/core/carbon/metadata/CarbonMetadataTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/metadata/CarbonMetadataTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/metadata/CarbonMetadataTest.java deleted file mode 100644 index 9c74a4a..0000000 --- a/core/src/test/java/org/apache/carbondata/core/carbon/metadata/CarbonMetadataTest.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * 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.carbon.metadata; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import org.apache.carbondata.core.carbon.metadata.datatype.DataType; -import org.apache.carbondata.core.carbon.metadata.encoder.Encoding; -import org.apache.carbondata.core.carbon.metadata.schema.table.CarbonTable; -import org.apache.carbondata.core.carbon.metadata.schema.table.TableInfo; -import org.apache.carbondata.core.carbon.metadata.schema.table.TableSchema; -import org.apache.carbondata.core.carbon.metadata.schema.table.column.CarbonDimension; -import org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema; -import org.apache.carbondata.core.constants.CarbonCommonConstants; - -import mockit.Mock; -import mockit.MockUp; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -public class CarbonMetadataTest { - - private static CarbonMetadata carbonMetadata; - - private static String tableUniqueName; - - @BeforeClass public static void setUp() { - carbonMetadata = CarbonMetadata.getInstance(); - carbonMetadata.loadTableMetadata(getTableInfo(10000)); - tableUniqueName = "carbonTestDatabase_carbonTestTable"; - } - - @AfterClass public static void tearDown() { - carbonMetadata.removeTable(tableUniqueName); - carbonMetadata = null; - } - - @Test public void testOnlyOneInstanceIsCreatedofCarbonMetadata() { - CarbonMetadata carbonMetadata1 = CarbonMetadata.getInstance(); - assertEquals(carbonMetadata, carbonMetadata1); - } - - @Test public void testNumberOfTablesPresentInTheMetadata() { - int expectedResult = 1; - assertEquals(expectedResult, carbonMetadata.getNumberOfTables()); - } - - @Test public void testGetCarbonTableReturingProperCarbonTable() { - assertNotNull(carbonMetadata.getCarbonTable(tableUniqueName)); - } - - @Test public void testGetCarbonTableReturingNullWhenInvalidNameIsPassed() { - assertNull(carbonMetadata.getCarbonTable("notpresent")); - } - - @Test public void testGetCarbonTableReturingProperTableWithProperDimensionCount() { - int expectedResult = 1; - assertEquals(expectedResult, - carbonMetadata.getCarbonTable(tableUniqueName).getNumberOfDimensions("carbonTestTable")); - } - - @Test public void testGetCarbonTableReturingProperTableWithProperMeasureCount() { - int expectedResult = 1; - assertEquals(expectedResult, - carbonMetadata.getCarbonTable(tableUniqueName).getNumberOfMeasures("carbonTestTable")); - } - - @Test public void testGetCarbonTableReturingProperTableWithProperDatabaseName() { - String expectedResult = "carbonTestDatabase"; - assertEquals(expectedResult, carbonMetadata.getCarbonTable(tableUniqueName).getDatabaseName()); - } - - @Test public void testGetCarbonTableReturingProperTableWithProperFactTableName() { - String expectedResult = "carbonTestTable"; - assertEquals(expectedResult, carbonMetadata.getCarbonTable(tableUniqueName).getFactTableName()); - } - - @Test public void testGetCarbonTableReturingProperTableWithProperTableUniqueName() { - String expectedResult = "carbonTestDatabase_carbonTestTable"; - assertEquals(expectedResult, - carbonMetadata.getCarbonTable(tableUniqueName).getTableUniqueName()); - } - - @Test public void testloadMetadataTableWhenTableIsAlreadyExistsAndTimeStampIsChanged() { - long expectedLastUpdatedTime = 10000L; - assertEquals(expectedLastUpdatedTime, - carbonMetadata.getCarbonTable(tableUniqueName).getTableLastUpdatedTime()); - CarbonMetadata carbonMetadata1 = CarbonMetadata.getInstance(); - carbonMetadata1.loadTableMetadata(getTableInfo(100001)); - long expectedTableLastUpdatedTime = 100001L; - assertEquals(expectedTableLastUpdatedTime, - carbonMetadata.getCarbonTable(tableUniqueName).getTableLastUpdatedTime()); - long expectedNumberOfTables = 1; - assertEquals(expectedNumberOfTables, carbonMetadata.getNumberOfTables()); - } - - private static ColumnSchema getColumnarDimensionColumn() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnar(true); - dimColumn.setColumnName("IMEI"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - dimColumn.setDimensionColumn(true); - List<Encoding> encodeList = - new ArrayList<Encoding>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); - encodeList.add(Encoding.DICTIONARY); - dimColumn.setEncodingList(encodeList); - dimColumn.setNumberOfChild(0); - return dimColumn; - } - - private static ColumnSchema getColumnarMeasureColumn() { - ColumnSchema dimColumn = new ColumnSchema(); - dimColumn.setColumnName("IMEI_COUNT"); - dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); - dimColumn.setDataType(DataType.STRING); - return dimColumn; - } - - private static TableSchema getTableSchema() { - TableSchema tableSchema = new TableSchema(); - List<ColumnSchema> columnSchemaList = new ArrayList<ColumnSchema>(); - columnSchemaList.add(getColumnarDimensionColumn()); - columnSchemaList.add(getColumnarMeasureColumn()); - tableSchema.setListOfColumns(columnSchemaList); - tableSchema.setTableId(UUID.randomUUID().toString()); - tableSchema.setTableName("carbonTestTable"); - return tableSchema; - } - - private static TableInfo getTableInfo(long timeStamp) { - TableInfo info = new TableInfo(); - info.setDatabaseName("carbonTestDatabase"); - info.setLastUpdatedTime(timeStamp); - info.setTableUniqueName("carbonTestDatabase_carbonTestTable"); - info.setFactTable(getTableSchema()); - info.setStorePath("/test/store"); - return info; - } - - @Test public void testGetCarbonDimensionBasedOnColIdentifier() { - CarbonTable carbonTable = new CarbonTable(); - String columnIdentifier = "1"; - final List<CarbonDimension> carbonDimensions = new ArrayList(); - ColumnSchema colSchema1 = new ColumnSchema(); - ColumnSchema colSchema2 = new ColumnSchema(); - colSchema1.setColumnUniqueId("1"); - colSchema2.setColumnUniqueId("2"); - carbonDimensions.add(new CarbonDimension(colSchema1, 1, 1, 2, 1)); - carbonDimensions.add(new CarbonDimension(colSchema2, 2, 2, 2, 2)); - new MockUp<CarbonTable>() { - @Mock public String getFactTableName() { - return "carbonTestTable"; - } - - @Mock public List<CarbonDimension> getDimensionByTableName(String tableName) { - return carbonDimensions; - } - }; - CarbonDimension expectedResult = carbonDimensions.get(0); - CarbonDimension actualResult = - carbonMetadata.getCarbonDimensionBasedOnColIdentifier(carbonTable, columnIdentifier); - assertEquals(expectedResult, actualResult); - } - - @Test - public void testGetCarbonDimensionBasedOnColIdentifierWhenChildDimensionColumnEqualsColumnIdentifier() { - CarbonTable carbonTable = new CarbonTable(); - String columnIdentifier = "9"; - final List<CarbonDimension> carbonDimensions = new ArrayList(); - ColumnSchema colSchema1 = new ColumnSchema(); - ColumnSchema colSchema2 = new ColumnSchema(); - colSchema1.setColumnUniqueId("1"); - carbonDimensions.add(new CarbonDimension(colSchema1, 1, 1, 2, 1)); - final List<CarbonDimension> carbonChildDimensions = new ArrayList(); - ColumnSchema colSchema3 = new ColumnSchema(); - colSchema3.setColumnUniqueId("9"); - colSchema2.setColumnUniqueId("2"); - carbonChildDimensions.add(new CarbonDimension(colSchema3, 1, 1, 2, 1)); - new MockUp<CarbonTable>() { - @Mock public String getFactTableName() { - return "carbonTestTable"; - } - - @Mock public List<CarbonDimension> getDimensionByTableName(String tableName) { - return carbonDimensions; - } - }; - - new MockUp<CarbonDimension>() { - @Mock public int numberOfChild() { - return 1; - } - - @Mock public List<CarbonDimension> getListOfChildDimensions() { - return carbonChildDimensions; - } - - }; - - CarbonDimension expectedResult = carbonChildDimensions.get(0); - CarbonDimension actualResult = - carbonMetadata.getCarbonDimensionBasedOnColIdentifier(carbonTable, columnIdentifier); - assertEquals(expectedResult, actualResult); - } - - @Test public void testGetCarbonDimensionBasedOnColIdentifierNullCase() { - CarbonTable carbonTable = new CarbonTable(); - String columnIdentifier = "3"; - final List<CarbonDimension> carbonDimensions = new ArrayList(); - ColumnSchema colSchema1 = new ColumnSchema(); - colSchema1.setColumnUniqueId("1"); - colSchema1.setNumberOfChild(1); - CarbonDimension carbonDimension = new CarbonDimension(colSchema1, 1, 1, 2, 1); - carbonDimensions.add(carbonDimension); - final List<CarbonDimension> carbonChildDimensions = new ArrayList(); - ColumnSchema colSchema2 = new ColumnSchema(); - colSchema2.setColumnUniqueId("9"); - colSchema2.setNumberOfChild(0); - carbonChildDimensions.add(new CarbonDimension(colSchema2, 1, 1, 2, 1)); - - new MockUp<CarbonTable>() { - @Mock public String getFactTableName() { - return "carbonTestTable"; - } - - @Mock public List<CarbonDimension> getDimensionByTableName(String tableName) { - return carbonDimensions; - } - }; - - new MockUp<CarbonDimension>() { - @Mock public List<CarbonDimension> getListOfChildDimensions() { - return carbonChildDimensions; - } - }; - - CarbonDimension result = - carbonMetadata.getCarbonDimensionBasedOnColIdentifier(carbonTable, columnIdentifier); - assertNull(result); - } - -} \ No newline at end of file