http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/scan/filter/FilterUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/scan/filter/FilterUtilTest.java b/core/src/test/java/org/apache/carbondata/core/scan/filter/FilterUtilTest.java new file mode 100644 index 0000000..1da4415 --- /dev/null +++ b/core/src/test/java/org/apache/carbondata/core/scan/filter/FilterUtilTest.java @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.carbondata.core.scan.filter; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest; +import org.apache.carbondata.core.AbsoluteTableIdentifier; +import org.apache.carbondata.core.CarbonTableIdentifier; +import org.apache.carbondata.core.datastore.IndexKey; +import org.apache.carbondata.core.datastore.block.SegmentProperties; +import org.apache.carbondata.core.metadata.DataType; +import org.apache.carbondata.core.metadata.Encoding; +import org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn; +import org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension; +import org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema; +import org.apache.carbondata.core.constants.CarbonCommonConstants; +import org.apache.carbondata.core.keygenerator.KeyGenException; +import org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator; +import org.apache.carbondata.core.scan.expression.ColumnExpression; +import org.apache.carbondata.core.scan.expression.Expression; +import org.apache.carbondata.core.scan.expression.LiteralExpression; +import org.apache.carbondata.core.scan.expression.conditional.ListExpression; +import org.apache.carbondata.core.scan.filter.intf.RowImpl; + +import mockit.Mock; +import mockit.MockUp; +import org.junit.Before; +import org.junit.Test; + +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +public class FilterUtilTest extends AbstractDictionaryCacheTest { + + private ColumnSchema columnSchema; + + @Before public void setUp() throws Exception { + init(); + this.databaseName = props.getProperty("database", "testSchema"); + this.tableName = props.getProperty("tableName", "carbon"); + this.carbonStorePath = props.getProperty("storePath", "carbonStore"); + carbonTableIdentifier = + new CarbonTableIdentifier(databaseName, tableName, UUID.randomUUID().toString()); + this.carbonStorePath = props.getProperty("storePath", "carbonStore"); + columnSchema = new ColumnSchema(); + columnSchema.setColumnar(true); + columnSchema.setColumnName("IMEI"); + columnSchema.setColumnUniqueId(UUID.randomUUID().toString()); + columnSchema.setDataType(DataType.STRING); + columnSchema.setDimensionColumn(true); + } + + @Test public void testCheckIfLeftExpressionRequireEvaluation() { + List<Expression> children = new ArrayList<>(); + ListExpression expression = new ListExpression(children); + boolean result = FilterUtil.checkIfLeftExpressionRequireEvaluation(expression); + assertTrue(result); + } + + @Test + public void testCheckIfLeftExpressionRequireEvaluationWithExpressionNotInstanceOfColumnExpression() { + ColumnExpression expression = new ColumnExpression("test", DataType.STRING); + boolean result = FilterUtil.checkIfLeftExpressionRequireEvaluation(expression); + assertFalse(result); + } + + @Test public void testNanSafeEqualsDoublesWithUnEqualValues() { + Double d1 = new Double(60.67); + Double d2 = new Double(60.69); + boolean result = FilterUtil.nanSafeEqualsDoubles(d1, d2); + assertFalse(result); + } + + @Test public void testNanSafeEqualsDoublesWithEqualValues() { + Double d1 = new Double(60.67); + Double d2 = new Double(60.67); + boolean result = FilterUtil.nanSafeEqualsDoubles(d1, d2); + assertTrue(result); + } + + @Test public void testCompareFilterKeyBasedOnDataTypeForShortValue() { + String dictionaryVal = "1"; + String memberVal = "1"; + int actualResult = + FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.SHORT); + int expectedResult = 0; + assertEquals(expectedResult, actualResult); + } + + @Test public void testCompareFilterKeyBasedOnDataTypeForIntValue() { + String dictionaryVal = "1000"; + String memberVal = "1001"; + int actualResult = + FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.INT); + int expectedResult = -1; + assertEquals(expectedResult, actualResult); + } + + @Test public void testCompareFilterKeyBasedOnDataTypeForDoubleValue() { + String dictionaryVal = "1.90"; + String memberVal = "1.89"; + int actualResult = + FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.DOUBLE); + int expectedResult = 1; + assertEquals(expectedResult, actualResult); + } + + @Test public void testCompareFilterKeyBasedOnDataTypeForLongValue() { + String dictionaryVal = "111111111111111"; + String memberVal = "1111111111111111"; + int actualResult = + FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.LONG); + int expectedResult = -1; + assertEquals(expectedResult, actualResult); + } + + @Test public void testCompareFilterKeyBasedOnDataTypeForBooleanValue() { + String dictionaryVal = "true"; + String memberVal = "false"; + int actualResult = + FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.BOOLEAN); + int expectedResult = 1; + assertEquals(expectedResult, actualResult); + } + + @Test public void testCompareFilterKeyBasedOnDataTypeForDecimalValue() { + String dictionaryVal = "1111111"; + String memberVal = "1111"; + int actualResult = + FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.DECIMAL); + int expectedResult = 1; + assertEquals(expectedResult, actualResult); + } + + @Test public void testCompareFilterKeyBasedOnDataTypeForDefaultValue() { + String dictionaryVal = "11.78"; + String memberVal = "1111.90"; + int actualResult = + FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.FLOAT); + int expectedResult = -1; + assertEquals(expectedResult, actualResult); + } + + @Test public void testCompareFilterKeyBasedOnDataTypeForTimestamp() { + String dictionaryVal = "2008-01-01 00:00:01"; + String memberVal = "2008-01-01 00:00:01"; + int actualValue = + FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.TIMESTAMP); + int expectedValue = 0; + assertEquals(expectedValue, actualValue); + } + + @Test public void testCompareFilterKeyBasedOnDataTypeForException() throws Exception { + String dictionaryVal = "test"; + String memberVal = "1"; + int actualValue = + FilterUtil.compareFilterKeyBasedOnDataType(dictionaryVal, memberVal, DataType.INT); + int expectedValue = -1; + assertEquals(expectedValue, actualValue); + } + + @Test public void testCreateIndexKeyFromResolvedFilterVal() throws Exception { + long[] startOrEndKey = new long[] { 0, 10 }; + byte[] startOrEndKeyForNoDictDimension = { 1, 2 }; + int[] keys = new int[] { 1, 2 }; + MultiDimKeyVarLengthGenerator multiDimKeyVarLengthGenerator = + new MultiDimKeyVarLengthGenerator(keys); + assertTrue(FilterUtil + .createIndexKeyFromResolvedFilterVal(startOrEndKey, multiDimKeyVarLengthGenerator, + startOrEndKeyForNoDictDimension) != null); + + } + + @Test public void testCheckIfExpressionContainsColumn() { + String columnName = "IMEI"; + Expression expression = new ColumnExpression(columnName, DataType.STRING); + boolean result = FilterUtil.checkIfExpressionContainsColumn(expression); + assertTrue(result); + } + + @Test + public void testCheckIfExpressionContainsColumnWithExpressionNotInstanceOfColumnExpression() { + String columnName = "IMEI"; + Expression expression = new LiteralExpression(columnName, DataType.STRING); + boolean result = FilterUtil.checkIfExpressionContainsColumn(expression); + assertFalse(result); + } + + @Test public void testIsExpressionNeedsToResolved() { + boolean isIncludeFilter = true; + Object obj = "test"; + LiteralExpression literalExpression = new LiteralExpression(obj, DataType.STRING); + boolean result = FilterUtil.isExpressionNeedsToResolved(literalExpression, isIncludeFilter); + assertFalse(result); + } + + @Test public void testIsExpressionNeedsToResolvedWithDataTypeNullAndIsIncludeFilterFalse() { + boolean isIncludeFilter = false; + Object obj = "test"; + LiteralExpression literalExpression = new LiteralExpression(obj, DataType.NULL); + boolean result = FilterUtil.isExpressionNeedsToResolved(literalExpression, isIncludeFilter); + assertTrue(result); + } + + @Test public void testGetMaskKey() { + int surrogate = 1; + int[] keys = new int[] { 1, 2 }; + MultiDimKeyVarLengthGenerator multiDimKeyVarLengthGenerator = + new MultiDimKeyVarLengthGenerator(keys); + int ordinal = 1; + int keyOrdinal = 1; + int columnGroupOrdinal = 1; + int complexTypeOrdinal = 1; + ColumnSchema columnSchema = new ColumnSchema(); + columnSchema.setColumnar(true); + columnSchema.setColumnName("IMEI"); + columnSchema.setColumnUniqueId(UUID.randomUUID().toString()); + columnSchema.setDataType(DataType.STRING); + columnSchema.setDimensionColumn(true); + CarbonDimension carbonDimension = + new CarbonDimension(columnSchema, ordinal, keyOrdinal, columnGroupOrdinal, + complexTypeOrdinal); + byte[] expectedResult = new byte[] { 1 }; + byte[] actualResult = + FilterUtil.getMaskKey(surrogate, carbonDimension, multiDimKeyVarLengthGenerator); + assertArrayEquals(expectedResult, actualResult); + } + + @Test public void testGetFilterListForAllMembersRS() throws Exception { + Expression expression = new ColumnExpression("IMEI", DataType.STRING); + ColumnExpression columnExpression = new ColumnExpression("IMEI", DataType.STRING); + String defaultValues = "test"; + int defaultSurrogate = 1; + boolean isIncludeFilter = true; + int ordinal = 1; + ColumnSchema dimColumn = new ColumnSchema(); + dimColumn.setColumnar(true); + dimColumn.setColumnName("IMEI"); + dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); + dimColumn.setDataType(DataType.STRING); + dimColumn.setDimensionColumn(true); + final CarbonColumn carbonColumn = new CarbonColumn(dimColumn, ordinal, -1); + new MockUp<ColumnExpression>() { + @Mock public CarbonColumn getCarbonColumn() { + return carbonColumn; + } + }; + + new MockUp<RowImpl>() { + @Mock public Object getVal(int index) { + return "test"; + } + }; + assertTrue(FilterUtil + .getFilterListForAllMembersRS(expression, columnExpression, defaultValues, defaultSurrogate, + isIncludeFilter) instanceof DimColumnFilterInfo); + } + + @Test public void testGetFilterListForAllMembersRSWithDefaultValuesEqualsToNull() + throws Exception { + Expression expression = new ColumnExpression("IMEI", DataType.STRING); + ColumnExpression columnExpression = new ColumnExpression("IMEI", DataType.STRING); + String defaultValues = CarbonCommonConstants.MEMBER_DEFAULT_VAL; + int defaultSurrogate = 1; + boolean isIncludeFilter = true; + int ordinal = 1; + ColumnSchema dimColumn = new ColumnSchema(); + dimColumn.setColumnar(true); + dimColumn.setColumnName("IMEI"); + dimColumn.setColumnUniqueId(UUID.randomUUID().toString()); + dimColumn.setDataType(DataType.STRING); + dimColumn.setDimensionColumn(true); + final CarbonColumn carbonColumn = new CarbonColumn(dimColumn, ordinal, -1); + new MockUp<ColumnExpression>() { + @Mock public CarbonColumn getCarbonColumn() { + return carbonColumn; + } + }; + + new MockUp<RowImpl>() { + @Mock public Object getVal(int index) { + return "test"; + } + }; + assertTrue(FilterUtil + .getFilterListForAllMembersRS(expression, columnExpression, defaultValues, defaultSurrogate, + isIncludeFilter) instanceof DimColumnFilterInfo); + } + + @Test public void testgetFilterListForRS() throws Exception { + Expression expression = new ColumnExpression("IMEI", DataType.STRING); + ColumnExpression columnExpression = new ColumnExpression("IMEI", DataType.STRING); + String defaultValues = CarbonCommonConstants.MEMBER_DEFAULT_VAL; + int defaultSurrogate = 1; + int ordinal = 1; + final CarbonColumn carbonColumn = new CarbonColumn(columnSchema, ordinal, -1); + new MockUp<ColumnExpression>() { + @Mock public CarbonColumn getCarbonColumn() { + return carbonColumn; + } + }; + + new MockUp<RowImpl>() { + @Mock public Object getVal(int index) { + return "test"; + } + }; + assertTrue(FilterUtil.getFilterListForRS(expression, columnExpression, defaultValues, + defaultSurrogate) instanceof DimColumnFilterInfo); + } + + @Test public void testCheckIfDataTypeNotTimeStamp() { + Expression expression = new ColumnExpression("test", DataType.STRING); + boolean result = FilterUtil.checkIfDataTypeNotTimeStamp(expression); + assertFalse(result); + } + + @Test public void testPrepareDefaultEndIndexKey() throws Exception { + List<ColumnSchema> columnsInTable = new ArrayList<>(); + columnsInTable.add(columnSchema); + int[] columnCardinality = new int[] { 1, 2 }; + new MockUp<ColumnSchema>() { + @Mock public List<Encoding> getEncodingList() { + List<Encoding> encodingList = new ArrayList<>(); + encodingList.add(Encoding.DICTIONARY); + return encodingList; + } + }; + SegmentProperties segmentProperties = new SegmentProperties(columnsInTable, columnCardinality); + assertTrue(FilterUtil.prepareDefaultEndIndexKey(segmentProperties) instanceof IndexKey); + } + + @Test public void testCheckIfRightExpressionRequireEvaluation() { + Expression expression = new ColumnExpression("test", DataType.STRING); + boolean result = FilterUtil.checkIfRightExpressionRequireEvaluation(expression); + assertTrue(result); + } + + @Test + public void testCheckIfRightExpressionRequireEvaluationWithExpressionIsInstanceOfLiteralExpression() { + Expression expression = new LiteralExpression("test", DataType.STRING); + boolean result = FilterUtil.checkIfRightExpressionRequireEvaluation(expression); + assertFalse(result); + } + + @Test public void testGetNoDictionaryValKeyMemberForFilter() { + boolean isIncludeFilter = true; + AbsoluteTableIdentifier absoluteTableIdentifier = + new AbsoluteTableIdentifier(this.carbonStorePath, carbonTableIdentifier); + ColumnExpression expression = new ColumnExpression("test", DataType.STRING); + List<String> evaluateResultListFinal = new ArrayList<>(); + evaluateResultListFinal.add("test1"); + evaluateResultListFinal.add("test2"); + assertTrue(FilterUtil.getNoDictionaryValKeyMemberForFilter(evaluateResultListFinal, isIncludeFilter) instanceof DimColumnFilterInfo); + } + + @Test public void testPrepareDefaultStartIndexKey() throws KeyGenException { + List<ColumnSchema> columnsInTable = new ArrayList<>(); + columnsInTable.add(columnSchema); + int[] columnCardinality = new int[] { 1, 2 }; + new MockUp<ColumnSchema>() { + @Mock public List<Encoding> getEncodingList() { + List<Encoding> encodingList = new ArrayList<>(); + encodingList.add(Encoding.DICTIONARY); + return encodingList; + } + }; + SegmentProperties segmentProperties = new SegmentProperties(columnsInTable, columnCardinality); + assertTrue(FilterUtil.prepareDefaultStartIndexKey(segmentProperties) instanceof IndexKey); + } +}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/scan/result/BatchResultTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/scan/result/BatchResultTest.java b/core/src/test/java/org/apache/carbondata/core/scan/result/BatchResultTest.java new file mode 100644 index 0000000..7bb70a0 --- /dev/null +++ b/core/src/test/java/org/apache/carbondata/core/scan/result/BatchResultTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.carbondata.core.scan.result; + +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; + +import mockit.Mock; +import mockit.MockUp; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class BatchResultTest { + private static BatchResult batchResult; + private static List<Object[]> rowsList = new ArrayList(2); + + @BeforeClass public static void setUp() { + batchResult = new BatchResult(); + rowsList.add(0, new Integer[] { 1, 2 }); + rowsList.add(1, new Integer[] { 3 }); + } + + @Test public void testNext() throws NoSuchElementException { + BatchResult rows = new BatchResult(); + rows.setRows(rowsList); + Object[] result = rows.next(); + assert (result.equals(rowsList.get(0))); + } + + @Test(expected = NoSuchElementException.class) public void testNextWithNoSuchElementException() { + BatchResult rows = new BatchResult(); + List emptyList = new ArrayList(2); + rows.setRows(emptyList); + rows.next(); + } + + @Test public void testGetRows() { + new MockUp<BatchResult>() { + @Mock public void $init() { + //to be left blank + } + }; + BatchResult batchResult = new BatchResult(); + List<Object[]> list = batchResult.getRows(); + assertNull("Number of rows is null", list); + } + + @Test public void testHasNext() { + List<Object[]> list = new ArrayList<>(); + list.add(0, new Integer[] { 1, 2 }); + list.add(1, new Integer[] { 1, 2 }); + batchResult.setRows(list); + boolean result = batchResult.hasNext(); + assert (result); + } + + @Test public void testGetRawRow() { + List<Object[]> list = new ArrayList<>(); + list.add(0, new Integer[] { 1, 2 }); + batchResult.setRows(list); + Object[] actualValue = batchResult.getRawRow(0); + assert (list.get(0) == actualValue); + } + + @Test public void testGetSize() { + List<Object[]> list = new ArrayList<>(); + list.add(0, new Integer[] { 1, 2 }); + list.add(1, new Integer[] { 1, 2 }); + batchResult.setRows(list); + int actualValue = batchResult.getSize(); + int expectedValue = 2; + assertEquals(expectedValue, actualValue); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/scan/result/impl/FilterQueryScannedResultTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/scan/result/impl/FilterQueryScannedResultTest.java b/core/src/test/java/org/apache/carbondata/core/scan/result/impl/FilterQueryScannedResultTest.java new file mode 100644 index 0000000..d77f3e6 --- /dev/null +++ b/core/src/test/java/org/apache/carbondata/core/scan/result/impl/FilterQueryScannedResultTest.java @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.carbondata.core.scan.result.impl; + + +public class FilterQueryScannedResultTest { + +// private static FilterQueryScannedResult filterQueryScannedResult; +// +// @BeforeClass public static void setUp() { +// BlockExecutionInfo blockExecutionInfo = new BlockExecutionInfo(); +// blockExecutionInfo.setFixedLengthKeySize(2); +// blockExecutionInfo.setNoDictionaryBlockIndexes(new int[] { 0, 1 }); +// blockExecutionInfo.setDictionaryColumnBlockIndex(new int[] { 0, 1 }); +// Map<Integer, KeyStructureInfo> columnGourpToKeyInfo = new HashMap<>(); +// columnGourpToKeyInfo.put(1, new KeyStructureInfo()); +// blockExecutionInfo.setColumnGroupToKeyStructureInfo(columnGourpToKeyInfo); +// Map<Integer, GenericQueryType> genericQueryType = new HashMap<>(); +// genericQueryType.put(1, new ArrayQueryType("Query1", "Parent", 1)); +// blockExecutionInfo.setComplexDimensionInfoMap(genericQueryType); +// blockExecutionInfo.setComplexColumnParentBlockIndexes(new int[] { 1 }); +// QueryDimension[] queryDimensions = { new QueryDimension("Col1"), new QueryDimension("Col2") }; +// blockExecutionInfo.setQueryDimensions(queryDimensions); +// filterQueryScannedResult = new FilterQueryScannedResult(blockExecutionInfo); +// filterQueryScannedResult.setIndexes(new int[] { 1, 2, 3, 4 }); +// DimensionChunkAttributes dimensionChunkAttributes = new DimensionChunkAttributes(); +// dimensionChunkAttributes.setEachRowSize(0); +// ColumnGroupDimensionDataChunk[] columnGroupDimensionDataChunks = +// { new ColumnGroupDimensionDataChunk(new byte[] { 1, 2 }, dimensionChunkAttributes), +// new ColumnGroupDimensionDataChunk(new byte[] { 2, 3 }, dimensionChunkAttributes) }; +// filterQueryScannedResult.setDimensionChunks(columnGroupDimensionDataChunks); +// MeasureColumnDataChunk measureColumnDataChunk = new MeasureColumnDataChunk(); +// filterQueryScannedResult +// .setMeasureChunks(new MeasureColumnDataChunk[] { measureColumnDataChunk }); +// } +// +// @Test public void testToGetDictionaryKeyArray() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") public int fillChunkData(byte[] data, int offset, int rowId, +// KeyStructureInfo restructuringInfo) { +// return 1; +// } +// }; +// byte[] keyArray = filterQueryScannedResult.getDictionaryKeyArray(); +// byte[] expectedResult = { 0, 0 }; +// assertThat(expectedResult, is(equalTo(keyArray))); +// } +// +// @Test public void testToGetDictionaryKeyIntegerArray() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") +// public int fillConvertedChunkData(int rowId, int columnIndex, int[] row, +// KeyStructureInfo info) { +// return 1; +// } +// }; +// int[] keyArray = filterQueryScannedResult.getDictionaryKeyIntegerArray(); +// int[] expectedResult = { 0, 0 }; +// assertThat(expectedResult, is(equalTo(keyArray))); +// } +// +// @Test public void testToGetComplexTypeKeyArray() { +// new MockUp<ByteArrayOutputStream>() { +// @Mock @SuppressWarnings("unused") public synchronized byte toByteArray()[] { +// return new byte[] { 1, 2, 3 }; +// } +// }; +// new MockUp<ArrayQueryType>() { +// @Mock @SuppressWarnings("unused") public void parseBlocksAndReturnComplexColumnByteArray( +// DimensionColumnDataChunk[] dimensionColumnDataChunks, int rowNumber, +// DataOutputStream dataOutputStream) throws IOException { +// } +// }; +// filterQueryScannedResult.incrementCounter(); +// byte[][] keyArray = filterQueryScannedResult.getComplexTypeKeyArray(); +// byte[][] expectedResult = { { 1, 2, 3 } }; +// assertThat(expectedResult, is(equalTo(keyArray))); +// } +// +// @Test public void testToGetNoDictionaryKeyArray() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") public byte[] getChunkData(int rowId) { +// return new byte[] { 1, 2, 3 }; +// } +// }; +// byte[][] dictionaryKeyArray = filterQueryScannedResult.getNoDictionaryKeyArray(); +// byte[][] expectedResult = { { 1, 2, 3 }, { 1, 2, 3 } }; +// assertThat(expectedResult, is(equalTo(dictionaryKeyArray))); +// } +// +// @Test public void testToGetNoDictionaryKeyStringArray() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") public byte[] getChunkData(int rowId) { +// return "1".getBytes(); +// } +// }; +// filterQueryScannedResult.incrementCounter(); +// String[] dictionaryKeyStringArray = filterQueryScannedResult.getNoDictionaryKeyStringArray(); +// String[] expectedResult = { "1", "1" }; +// assertThat(expectedResult, is(equalTo(dictionaryKeyStringArray))); +// } +// +// @Test public void testToGetCurrenrRowId() { +// int rowId = filterQueryScannedResult.getCurrenrRowId(); +// int expectedResult = 3; +// assertThat(expectedResult, is(equalTo(rowId))); +// } +// +// @Test public void testToGetDimensionKey() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") public byte[] getChunkData(int rowId) { +// return "1".getBytes(); +// } +// }; +// byte[] dictionaryKeyStringArray = filterQueryScannedResult.getDimensionKey(0); +// byte[] expectedResult = "1".getBytes(); +// assertThat(expectedResult, is(equalTo(dictionaryKeyStringArray))); +// } +// +// @Test public void testToGetIsNullMeasureValue() { +// new MockUp<MeasureColumnDataChunk>() { +// @Mock @SuppressWarnings("unused") public PresenceMeta getNullValueIndexHolder() { +// return new PresenceMeta(); +// +// } +// }; +// new MockUp<PresenceMeta>() { +// @Mock @SuppressWarnings("unused") public BitSet getBitSet() { +// return new BitSet(); +// } +// }; +// new MockUp<BitSet>() { +// @Mock @SuppressWarnings("unused") public boolean get(int bitIndex) { +// return false; +// } +// }; +// +// boolean nullMeasureValue = filterQueryScannedResult.isNullMeasureValue(0); +// assertThat(false, is(equalTo(nullMeasureValue))); +// } +// +// @Test public void testToGetLongMeasureValue() { +// new MockUp<MeasureColumnDataChunk>() { +// @Mock @SuppressWarnings("unused") public CarbonReadDataHolder getMeasureDataHolder() { +// return new CarbonReadDataHolder(); +// +// } +// }; +// new MockUp<CarbonReadDataHolder>() { +// @Mock @SuppressWarnings("unused") public long getReadableLongValueByIndex(int index) { +// return 2L; +// } +// }; +// long longMeasureValue = filterQueryScannedResult.getLongMeasureValue(0); +// long expectedResult = 2L; +// assertThat(expectedResult, is(equalTo(longMeasureValue))); +// } +// +// @Test public void testToGetDoubleMeasureValue() { +// new MockUp<MeasureColumnDataChunk>() { +// @Mock @SuppressWarnings("unused") public CarbonReadDataHolder getMeasureDataHolder() { +// return new CarbonReadDataHolder(); +// +// } +// }; +// new MockUp<CarbonReadDataHolder>() { +// @Mock @SuppressWarnings("unused") public double getReadableDoubleValueByIndex(int index) { +// return 2.0; +// } +// }; +// double longMeasureValue = filterQueryScannedResult.getDoubleMeasureValue(0); +// double expectedResult = 2.0; +// assertThat(expectedResult, is(equalTo(longMeasureValue))); +// } +// +// @Test public void testToGetBigDecimalMeasureValue() { +// new MockUp<MeasureColumnDataChunk>() { +// @Mock @SuppressWarnings("unused") public CarbonReadDataHolder getMeasureDataHolder() { +// return new CarbonReadDataHolder(); +// +// } +// }; +// new MockUp<CarbonReadDataHolder>() { +// @Mock @SuppressWarnings("unused") +// public BigDecimal getReadableBigDecimalValueByIndex(int index) { +// return new BigDecimal(2); +// } +// }; +// BigDecimal longMeasureValue = filterQueryScannedResult.getBigDecimalMeasureValue(0); +// BigDecimal expectedResult = new BigDecimal(2); +// assertThat(expectedResult, is(equalTo(longMeasureValue))); +// } + +} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/scan/result/impl/NonFilterQueryScannedResultTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/scan/result/impl/NonFilterQueryScannedResultTest.java b/core/src/test/java/org/apache/carbondata/core/scan/result/impl/NonFilterQueryScannedResultTest.java new file mode 100644 index 0000000..3a33052 --- /dev/null +++ b/core/src/test/java/org/apache/carbondata/core/scan/result/impl/NonFilterQueryScannedResultTest.java @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.carbondata.core.scan.result.impl; + + +public class NonFilterQueryScannedResultTest { + +// private static NonFilterQueryScannedResult filterQueryScannedResult; +// +// @BeforeClass public static void setUp() { +// BlockExecutionInfo blockExecutionInfo = new BlockExecutionInfo(); +// blockExecutionInfo.setFixedLengthKeySize(2); +// blockExecutionInfo.setNoDictionaryBlockIndexes(new int[] { 0, 1 }); +// blockExecutionInfo.setDictionaryColumnBlockIndex(new int[] { 0, 1 }); +// Map<Integer, KeyStructureInfo> columnGourpToKeyInfo = new HashMap<>(); +// columnGourpToKeyInfo.put(1, new KeyStructureInfo()); +// blockExecutionInfo.setColumnGroupToKeyStructureInfo(columnGourpToKeyInfo); +// Map<Integer, GenericQueryType> genericQueryType = new HashMap<>(); +// genericQueryType.put(1, new ArrayQueryType("Query1", "Parent", 1)); +// blockExecutionInfo.setComplexDimensionInfoMap(genericQueryType); +// blockExecutionInfo.setComplexColumnParentBlockIndexes(new int[] { 1 }); +// QueryDimension[] queryDimensions = { new QueryDimension("Col1"), new QueryDimension("Col2") }; +// blockExecutionInfo.setQueryDimensions(queryDimensions); +// filterQueryScannedResult = new NonFilterQueryScannedResult(blockExecutionInfo); +// DimensionChunkAttributes dimensionChunkAttributes = new DimensionChunkAttributes(); +// dimensionChunkAttributes.setEachRowSize(0); +// ColumnGroupDimensionDataChunk[] columnGroupDimensionDataChunks = +// { new ColumnGroupDimensionDataChunk(new byte[] { 1, 2 }, dimensionChunkAttributes), +// new ColumnGroupDimensionDataChunk(new byte[] { 2, 3 }, dimensionChunkAttributes) }; +// filterQueryScannedResult.setDimensionChunks(columnGroupDimensionDataChunks); +// MeasureColumnDataChunk measureColumnDataChunk = new MeasureColumnDataChunk(); +// filterQueryScannedResult +// .setMeasureChunks(new MeasureColumnDataChunk[] { measureColumnDataChunk }); +// } +// +// @Test public void testToGetDictionaryKeyArray() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") public int fillChunkData(byte[] data, int offset, int rowId, +// KeyStructureInfo restructuringInfo) { +// return 1; +// } +// }; +// byte[] keyArray = filterQueryScannedResult.getDictionaryKeyArray(); +// byte[] expectedResult = { 0, 0 }; +// assertThat(expectedResult, is(equalTo(keyArray))); +// } +// +// @Test public void testToGetDictionaryKeyIntegerArray() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") +// public int fillConvertedChunkData(int rowId, int columnIndex, int[] row, +// KeyStructureInfo info) { +// return 1; +// } +// }; +// int[] keyArray = filterQueryScannedResult.getDictionaryKeyIntegerArray(); +// int[] expectedResult = { 0, 0 }; +// assertThat(expectedResult, is(equalTo(keyArray))); +// } +// +// @Test public void testToGetComplexTypeKeyArray() { +// new MockUp<ByteArrayOutputStream>() { +// @Mock @SuppressWarnings("unused") public synchronized byte toByteArray()[] { +// return new byte[] { 1, 2, 3 }; +// } +// }; +// new MockUp<ArrayQueryType>() { +// @Mock @SuppressWarnings("unused") public void parseBlocksAndReturnComplexColumnByteArray( +// DimensionColumnDataChunk[] dimensionColumnDataChunks, int rowNumber, +// DataOutputStream dataOutputStream) throws IOException { +// } +// }; +// filterQueryScannedResult.incrementCounter(); +// byte[][] keyArray = filterQueryScannedResult.getComplexTypeKeyArray(); +// byte[][] expectedResult = { { 1, 2, 3 } }; +// assertThat(expectedResult, is(equalTo(keyArray))); +// } +// +// @Test public void testToGetNoDictionaryKeyArray() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") public byte[] getChunkData(int rowId) { +// return new byte[] { 1, 2, 3 }; +// } +// }; +// byte[][] dictionaryKeyArray = filterQueryScannedResult.getNoDictionaryKeyArray(); +// byte[][] expectedResult = { { 1, 2, 3 }, { 1, 2, 3 } }; +// assertThat(expectedResult, is(equalTo(dictionaryKeyArray))); +// } +// +// @Test public void testToGetNoDictionaryKeyStringArray() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") public byte[] getChunkData(int rowId) { +// return "1".getBytes(); +// } +// }; +// filterQueryScannedResult.incrementCounter(); +// String[] dictionaryKeyStringArray = filterQueryScannedResult.getNoDictionaryKeyStringArray(); +// String[] expectedResult = { "1", "1" }; +// assertThat(expectedResult, is(equalTo(dictionaryKeyStringArray))); +// } +// +// @Test public void testToGetCurrenrRowId() { +// int rowId = filterQueryScannedResult.getCurrenrRowId(); +// int expectedResult = 2; +// assertThat(expectedResult, is(equalTo(rowId))); +// } +// +// @Test public void testToGetDimensionKey() { +// new MockUp<ColumnGroupDimensionDataChunk>() { +// @Mock @SuppressWarnings("unused") public byte[] getChunkData(int rowId) { +// return "1".getBytes(); +// } +// }; +// byte[] dictionaryKeyStringArray = filterQueryScannedResult.getDimensionKey(0); +// byte[] expectedResult = "1".getBytes(); +// assertThat(expectedResult, is(equalTo(dictionaryKeyStringArray))); +// } +// +// @Test public void testToGetIsNullMeasureValue() { +// new MockUp<MeasureColumnDataChunk>() { +// @Mock @SuppressWarnings("unused") public PresenceMeta getNullValueIndexHolder() { +// return new PresenceMeta(); +// +// } +// }; +// new MockUp<PresenceMeta>() { +// @Mock @SuppressWarnings("unused") public BitSet getBitSet() { +// return new BitSet(); +// } +// }; +// new MockUp<BitSet>() { +// @Mock @SuppressWarnings("unused") public boolean get(int bitIndex) { +// return false; +// } +// }; +// +// boolean nullMeasureValue = filterQueryScannedResult.isNullMeasureValue(0); +// assertThat(false, is(equalTo(nullMeasureValue))); +// } +// +// @Test public void testToGetLongMeasureValue() { +// new MockUp<MeasureColumnDataChunk>() { +// @Mock @SuppressWarnings("unused") public CarbonReadDataHolder getMeasureDataHolder() { +// return new CarbonReadDataHolder(); +// +// } +// }; +// new MockUp<CarbonReadDataHolder>() { +// @Mock @SuppressWarnings("unused") public long getReadableLongValueByIndex(int index) { +// return 2L; +// } +// }; +// long longMeasureValue = filterQueryScannedResult.getLongMeasureValue(0); +// long expectedResult = 2L; +// assertThat(expectedResult, is(equalTo(longMeasureValue))); +// } +// +// @Test public void testToGetDoubleMeasureValue() { +// new MockUp<MeasureColumnDataChunk>() { +// @Mock @SuppressWarnings("unused") public CarbonReadDataHolder getMeasureDataHolder() { +// return new CarbonReadDataHolder(); +// +// } +// }; +// new MockUp<CarbonReadDataHolder>() { +// @Mock @SuppressWarnings("unused") public double getReadableDoubleValueByIndex(int index) { +// return 2.0; +// } +// }; +// double longMeasureValue = filterQueryScannedResult.getDoubleMeasureValue(0); +// double expectedResult = 2.0; +// assertThat(expectedResult, is(equalTo(longMeasureValue))); +// } +// +// @Test public void testToGetBigDecimalMeasureValue() { +// new MockUp<MeasureColumnDataChunk>() { +// @Mock @SuppressWarnings("unused") public CarbonReadDataHolder getMeasureDataHolder() { +// return new CarbonReadDataHolder(); +// +// } +// }; +// new MockUp<CarbonReadDataHolder>() { +// @Mock @SuppressWarnings("unused") +// public BigDecimal getReadableBigDecimalValueByIndex(int index) { +// return new BigDecimal(2); +// } +// }; +// BigDecimal longMeasureValue = filterQueryScannedResult.getBigDecimalMeasureValue(0); +// BigDecimal expectedResult = new BigDecimal(2); +// assertThat(expectedResult, is(equalTo(longMeasureValue))); +// } + +} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/scan/wrappers/ByteArrayWrapperTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/scan/wrappers/ByteArrayWrapperTest.java b/core/src/test/java/org/apache/carbondata/core/scan/wrappers/ByteArrayWrapperTest.java new file mode 100644 index 0000000..cec14df --- /dev/null +++ b/core/src/test/java/org/apache/carbondata/core/scan/wrappers/ByteArrayWrapperTest.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.carbondata.core.scan.wrappers; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertTrue; + +public class ByteArrayWrapperTest { + private static ByteArrayWrapper byteArrayWrapper; + byte[] dictionaryKey = new byte[] { 1 }; + byte[][] complexTypesKeys = { { 1 }, { 1 } }; + byte[][] noDictionaryKeys = new byte[][] { { 1 }, { 1 } }; + + @BeforeClass + + public static void setUp() { + byteArrayWrapper = new ByteArrayWrapper(); + } + + @AfterClass public static void tearDown() { + byteArrayWrapper = null; + } + + @Test public void testHashCodeValue() { + byteArrayWrapper.setDictionaryKey(dictionaryKey); + byteArrayWrapper.setComplexTypesKeys(complexTypesKeys); + byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys); + + int result = byteArrayWrapper.hashCode(); + assert (29583456 == result); + } + + @Test public void testEqualsWithOtherAsInstanceOfByteArrayWrapper() { + ByteArrayWrapper other; + other = null; + boolean result = byteArrayWrapper.equals(other); + assertFalse(result); + } + + @Test public void testEqualsWithNoDictionaryKeysOtherNotEqualNoDictionaryKeys() { + byte[][] noDictionaryKeysOther = { { 1 } }; + byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys); + ByteArrayWrapper other = new ByteArrayWrapper(); + other.setNoDictionaryKeys(noDictionaryKeysOther); + boolean result = byteArrayWrapper.equals(other); + assertFalse(result); + } + + @Test public void testEqualsWithComplexTypesKeysOtherNotEqualComplexTypesKeys() { + byte[][] complexTypesKeysOther = { { 1 } }; + byteArrayWrapper.setComplexTypesKeys(complexTypesKeys); + byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys); + ByteArrayWrapper other = new ByteArrayWrapper(); + other.setComplexTypesKeys(complexTypesKeysOther); + other.setNoDictionaryKeys(noDictionaryKeys); + boolean result = byteArrayWrapper.equals(other); + assertFalse(result); + } + + @Test + + public void testEqualsForFirstElementComplexTypesKeysAndOther() { + ByteArrayWrapper other = new ByteArrayWrapper(); + other.setComplexTypesKeys(complexTypesKeys); + other.setDictionaryKey(dictionaryKey); + other.setNoDictionaryKeys(noDictionaryKeys); + byteArrayWrapper.setComplexTypesKeys(complexTypesKeys); + byteArrayWrapper.setDictionaryKey(dictionaryKey); + byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys); + boolean result = byteArrayWrapper.equals(other); + assertTrue(result); + } + + @Test public void testCompareTo() { + byteArrayWrapper.setDictionaryKey(dictionaryKey); + ByteArrayWrapper other = new ByteArrayWrapper(); + other.setDictionaryKey(dictionaryKey); + other.setNoDictionaryKeys(noDictionaryKeys); + other.setComplexTypesKeys(complexTypesKeys); + byteArrayWrapper.setNoDictionaryKeys(noDictionaryKeys); + byteArrayWrapper.setComplexTypesKeys(complexTypesKeys); + int actualResult = byteArrayWrapper.compareTo(other); + int expectedResult = 0; + assertEquals(expectedResult, actualResult); + } +} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/stats/DriverQueryStatisticsRecorderImplTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/stats/DriverQueryStatisticsRecorderImplTest.java b/core/src/test/java/org/apache/carbondata/core/stats/DriverQueryStatisticsRecorderImplTest.java new file mode 100644 index 0000000..54f601b --- /dev/null +++ b/core/src/test/java/org/apache/carbondata/core/stats/DriverQueryStatisticsRecorderImplTest.java @@ -0,0 +1,124 @@ +/* + * 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.stats; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.carbondata.core.stats.DriverQueryStatisticsRecorderImpl; +import org.apache.carbondata.core.stats.QueryStatistic; +import org.apache.carbondata.core.stats.QueryStatisticsConstants; + +import org.junit.BeforeClass; +import org.junit.Test; + +import static junit.framework.TestCase.assertNotNull; +import static org.pentaho.di.core.util.Assert.assertNull; + +public class DriverQueryStatisticsRecorderImplTest { + private static DriverQueryStatisticsRecorderImpl driverQueryStatisticsRecorderImpl = null; + private static QueryStatistic queryStasticsWithSQL_PARSE = null; + private static QueryStatistic queryStasticsWithLoadMetaData = null; + private static QueryStatistic queryStasticsWithLOAD_BLOCKS_DRIVER = null; + private static QueryStatistic queryStasticsWithBLOCK_ALLOCATION = null; + private static QueryStatistic queryStasticsWithBLOCK_IDENTIFICATION = null; + + private static List<QueryStatistic> queryStatisticList; + + @BeforeClass public static void setUp() { + driverQueryStatisticsRecorderImpl = DriverQueryStatisticsRecorderImpl.getInstance(); + queryStasticsWithSQL_PARSE = new QueryStatistic(); + queryStasticsWithLoadMetaData = new QueryStatistic(); + queryStasticsWithLOAD_BLOCKS_DRIVER = new QueryStatistic(); + queryStasticsWithBLOCK_ALLOCATION = new QueryStatistic(); + queryStasticsWithBLOCK_IDENTIFICATION = new QueryStatistic(); + queryStatisticList = new ArrayList<>(); + + } + + @Test public void testCollectDriverStatistics() { + queryStasticsWithLOAD_BLOCKS_DRIVER + .addCountStatistic(QueryStatisticsConstants.LOAD_BLOCKS_DRIVER, 3); + queryStasticsWithLOAD_BLOCKS_DRIVER + .addStatistics(QueryStatisticsConstants.LOAD_BLOCKS_DRIVER, 5); + queryStasticsWithLOAD_BLOCKS_DRIVER + .addFixedTimeStatistic(QueryStatisticsConstants.LOAD_BLOCKS_DRIVER, 5); + queryStatisticList.add(queryStasticsWithLOAD_BLOCKS_DRIVER); + queryStasticsWithBLOCK_ALLOCATION + .addCountStatistic(QueryStatisticsConstants.BLOCK_ALLOCATION, 3); + queryStasticsWithBLOCK_ALLOCATION.addStatistics(QueryStatisticsConstants.BLOCK_ALLOCATION, 5); + queryStasticsWithLOAD_BLOCKS_DRIVER + .addFixedTimeStatistic(QueryStatisticsConstants.LOAD_BLOCKS_DRIVER, 5); + queryStatisticList.add(queryStasticsWithBLOCK_ALLOCATION); + queryStasticsWithBLOCK_IDENTIFICATION + .addCountStatistic(QueryStatisticsConstants.BLOCK_IDENTIFICATION, 3); + queryStasticsWithBLOCK_IDENTIFICATION + .addStatistics(QueryStatisticsConstants.BLOCK_IDENTIFICATION, 5); + queryStatisticList.add(queryStasticsWithBLOCK_IDENTIFICATION); + queryStasticsWithLoadMetaData.addCountStatistic(QueryStatisticsConstants.LOAD_META, 3); + queryStasticsWithLoadMetaData.addStatistics(QueryStatisticsConstants.LOAD_META, 5); + queryStatisticList.add(queryStasticsWithLoadMetaData); + queryStasticsWithSQL_PARSE.addCountStatistic(QueryStatisticsConstants.SQL_PARSE, 3); + queryStasticsWithSQL_PARSE.addStatistics(QueryStatisticsConstants.SQL_PARSE, 5); + queryStatisticList.add(queryStasticsWithSQL_PARSE); + + String result = + driverQueryStatisticsRecorderImpl.collectDriverStatistics(queryStatisticList, "query1"); + assertNotNull(result); + } + + @Test public void testCollectDriverStatisticsWithBlock_Allocation() { + queryStatisticList.clear(); + queryStasticsWithBLOCK_ALLOCATION + .addCountStatistic(QueryStatisticsConstants.BLOCK_ALLOCATION, 3); + queryStasticsWithBLOCK_ALLOCATION.addStatistics(QueryStatisticsConstants.BLOCK_ALLOCATION, 5); + queryStatisticList.add(queryStasticsWithBLOCK_ALLOCATION); + String result = + driverQueryStatisticsRecorderImpl.collectDriverStatistics(queryStatisticList, "query1"); + assertNull(result); + } + + @Test public void testCollectDriverStatisticsWithBlock_AllocationAndBlock_Identification() { + queryStatisticList.clear(); + queryStasticsWithBLOCK_ALLOCATION + .addCountStatistic(QueryStatisticsConstants.BLOCK_ALLOCATION, 3); + queryStasticsWithBLOCK_ALLOCATION.addStatistics(QueryStatisticsConstants.BLOCK_ALLOCATION, 5); + queryStatisticList.add(queryStasticsWithBLOCK_ALLOCATION); + queryStasticsWithBLOCK_IDENTIFICATION + .addCountStatistic(QueryStatisticsConstants.BLOCK_IDENTIFICATION, 3); + queryStasticsWithBLOCK_IDENTIFICATION + .addStatistics(QueryStatisticsConstants.BLOCK_IDENTIFICATION, 5); + queryStatisticList.add(queryStasticsWithBLOCK_IDENTIFICATION); + String result = + driverQueryStatisticsRecorderImpl.collectDriverStatistics(queryStatisticList, "query1"); + assertNotNull(result); + } + + @Test + public void testCollectDriverStatisticsWithBlock_AllocationAndBlock_IdentificationForException() { + queryStatisticList.clear(); + + driverQueryStatisticsRecorderImpl = DriverQueryStatisticsRecorderImpl.getInstance(); + + String result = + driverQueryStatisticsRecorderImpl.collectDriverStatistics(queryStatisticList, "query1"); + assertNull(result); + } +} + http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/stats/QueryStasticsRecorderImplTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/stats/QueryStasticsRecorderImplTest.java b/core/src/test/java/org/apache/carbondata/core/stats/QueryStasticsRecorderImplTest.java new file mode 100644 index 0000000..ad5fd22 --- /dev/null +++ b/core/src/test/java/org/apache/carbondata/core/stats/QueryStasticsRecorderImplTest.java @@ -0,0 +1,114 @@ +/* + * 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.stats; + +import org.apache.carbondata.core.stats.QueryStatistic; +import org.apache.carbondata.core.stats.QueryStatisticsConstants; +import org.apache.carbondata.core.stats.QueryStatisticsRecorderImpl; + +import org.junit.BeforeClass; +import org.junit.Test; + +import static junit.framework.TestCase.assertNotNull; + +public class QueryStasticsRecorderImplTest { + + private static QueryStatisticsRecorderImpl queryStasticsRecorderImpl = null; + private static QueryStatistic queryStatistic = null; + private static QueryStatistic queryStatisticWithLOAD_BLOCKS_EXECUTOR = null; + private static QueryStatistic queryStatisticWithSCAN_BLOCKS_TIME = null; + private static QueryStatistic queryStatisticWithSCAN_BLOCKS_NUM = null; + private static QueryStatistic queryStatisticWithLOAD_DICTIONARY = null; + private static QueryStatistic queryStatisticWithRESULT_SIZE = null; + private static QueryStatistic queryStatisticWithEXECUTOR_PART = null; + private static QueryStatistic queryStatisticWithTOTAL_BLOCKLET_NUM = null; + private static QueryStatistic queryStatisticWithVALID_SCAN_BLOCKLET_NUM = null; + + @BeforeClass public static void setUp() { + queryStatisticWithLOAD_BLOCKS_EXECUTOR = new QueryStatistic(); + queryStasticsRecorderImpl = new QueryStatisticsRecorderImpl(System.nanoTime() + ""); + queryStasticsRecorderImpl.logStatisticsAsTableDriver(); + queryStatisticWithLOAD_BLOCKS_EXECUTOR + .addStatistics(QueryStatisticsConstants.LOAD_BLOCKS_EXECUTOR, 5L); + queryStatisticWithLOAD_BLOCKS_EXECUTOR + .addCountStatistic(QueryStatisticsConstants.LOAD_BLOCKS_EXECUTOR, 5L); + queryStatisticWithLOAD_BLOCKS_EXECUTOR + .addStatistics(QueryStatisticsConstants.LOAD_BLOCKS_EXECUTOR, 5L); + queryStasticsRecorderImpl.logStatistics(); + queryStasticsRecorderImpl.recordStatistics(queryStatisticWithLOAD_BLOCKS_EXECUTOR); + queryStatisticWithSCAN_BLOCKS_TIME = new QueryStatistic(); + queryStatisticWithSCAN_BLOCKS_TIME.addStatistics(QueryStatisticsConstants.SCAN_BLOCKS_TIME, 5L); + queryStatisticWithSCAN_BLOCKS_TIME + .addCountStatistic(QueryStatisticsConstants.SCAN_BLOCKS_TIME, 5L); + queryStatisticWithSCAN_BLOCKS_TIME.addStatistics(QueryStatisticsConstants.SCAN_BLOCKS_TIME, 5L); + queryStasticsRecorderImpl.logStatistics(); + queryStasticsRecorderImpl.recordStatistics(queryStatisticWithSCAN_BLOCKS_TIME); + queryStatisticWithSCAN_BLOCKS_NUM = new QueryStatistic(); + queryStatisticWithSCAN_BLOCKS_NUM.addStatistics(QueryStatisticsConstants.SCAN_BLOCKS_NUM, 5L); + queryStatisticWithSCAN_BLOCKS_NUM + .addCountStatistic(QueryStatisticsConstants.SCAN_BLOCKS_NUM, 5L); + queryStatisticWithSCAN_BLOCKS_NUM.addStatistics(QueryStatisticsConstants.SCAN_BLOCKS_NUM, 5L); + queryStasticsRecorderImpl.logStatistics(); + queryStasticsRecorderImpl.recordStatistics(queryStatisticWithSCAN_BLOCKS_NUM); + queryStatisticWithLOAD_DICTIONARY = new QueryStatistic(); + queryStatisticWithLOAD_DICTIONARY.addStatistics(QueryStatisticsConstants.LOAD_DICTIONARY, 5L); + queryStatisticWithLOAD_DICTIONARY + .addCountStatistic(QueryStatisticsConstants.LOAD_DICTIONARY, 5L); + queryStatisticWithLOAD_DICTIONARY.addStatistics(QueryStatisticsConstants.LOAD_DICTIONARY, 5L); + queryStasticsRecorderImpl.logStatistics(); + queryStasticsRecorderImpl.recordStatistics(queryStatisticWithLOAD_DICTIONARY); + queryStatisticWithRESULT_SIZE = new QueryStatistic(); + queryStatisticWithRESULT_SIZE.addStatistics(QueryStatisticsConstants.RESULT_SIZE, 5L); + queryStatisticWithRESULT_SIZE.addCountStatistic(QueryStatisticsConstants.RESULT_SIZE, 5L); + queryStatisticWithRESULT_SIZE.addStatistics(QueryStatisticsConstants.RESULT_SIZE, 5L); + queryStasticsRecorderImpl.logStatistics(); + queryStasticsRecorderImpl.recordStatistics(queryStatisticWithRESULT_SIZE); + queryStatisticWithEXECUTOR_PART = new QueryStatistic(); + queryStatisticWithEXECUTOR_PART.addStatistics(QueryStatisticsConstants.EXECUTOR_PART, 5L); + queryStatisticWithEXECUTOR_PART.addCountStatistic(QueryStatisticsConstants.EXECUTOR_PART, 5L); + queryStatisticWithEXECUTOR_PART.addStatistics(QueryStatisticsConstants.EXECUTOR_PART, 5L); + queryStasticsRecorderImpl.logStatistics(); + queryStasticsRecorderImpl.recordStatistics(queryStatisticWithEXECUTOR_PART); + queryStatisticWithTOTAL_BLOCKLET_NUM = new QueryStatistic(); + queryStatisticWithTOTAL_BLOCKLET_NUM + .addStatistics(QueryStatisticsConstants.TOTAL_BLOCKLET_NUM, 5L); + queryStatisticWithTOTAL_BLOCKLET_NUM + .addCountStatistic(QueryStatisticsConstants.TOTAL_BLOCKLET_NUM, 5L); + queryStatisticWithTOTAL_BLOCKLET_NUM + .addStatistics(QueryStatisticsConstants.TOTAL_BLOCKLET_NUM, 5L); + queryStasticsRecorderImpl.logStatistics(); + queryStasticsRecorderImpl.recordStatistics(queryStatisticWithTOTAL_BLOCKLET_NUM); + queryStatisticWithVALID_SCAN_BLOCKLET_NUM = new QueryStatistic(); + queryStatisticWithVALID_SCAN_BLOCKLET_NUM + .addStatistics(QueryStatisticsConstants.VALID_SCAN_BLOCKLET_NUM, 5L); + queryStatisticWithVALID_SCAN_BLOCKLET_NUM + .addCountStatistic(QueryStatisticsConstants.VALID_SCAN_BLOCKLET_NUM, 5L); + queryStatisticWithVALID_SCAN_BLOCKLET_NUM + .addStatistics(QueryStatisticsConstants.VALID_SCAN_BLOCKLET_NUM, 5L); + queryStasticsRecorderImpl.logStatistics(); + queryStasticsRecorderImpl.recordStatistics(queryStatisticWithVALID_SCAN_BLOCKLET_NUM); + queryStasticsRecorderImpl.logStatisticsAsTableExecutor(); + } + + @Test public void testcollectExecutorStatistics() { + assertNotNull(queryStasticsRecorderImpl.collectExecutorStatistics()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/util/CarbonMetadataUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/util/CarbonMetadataUtilTest.java b/core/src/test/java/org/apache/carbondata/core/util/CarbonMetadataUtilTest.java index d8b0f40..5855262 100644 --- a/core/src/test/java/org/apache/carbondata/core/util/CarbonMetadataUtilTest.java +++ b/core/src/test/java/org/apache/carbondata/core/util/CarbonMetadataUtilTest.java @@ -24,7 +24,7 @@ import mockit.MockUp; import org.apache.carbondata.core.datastore.block.SegmentProperties; import org.apache.carbondata.core.metadata.index.BlockIndexInfo; -import org.apache.carbondata.core.datastorage.store.compression.WriterCompressModel; +import org.apache.carbondata.core.datastorage.compression.WriterCompressModel; import org.apache.carbondata.core.metadata.BlockletInfoColumnar; import org.apache.carbondata.core.metadata.ValueEncoderMeta; import org.apache.carbondata.format.*; http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/util/CarbonUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/util/CarbonUtilTest.java b/core/src/test/java/org/apache/carbondata/core/util/CarbonUtilTest.java index 2643758..7f6edd1 100644 --- a/core/src/test/java/org/apache/carbondata/core/util/CarbonUtilTest.java +++ b/core/src/test/java/org/apache/carbondata/core/util/CarbonUtilTest.java @@ -31,12 +31,12 @@ import org.apache.carbondata.core.metadata.Encoding; import org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension; import org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure; import org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema; -import org.apache.carbondata.core.datastorage.store.columnar.ColumnGroupModel; -import org.apache.carbondata.core.datastorage.store.compression.WriterCompressModel; -import org.apache.carbondata.core.datastorage.store.filesystem.LocalCarbonFile; -import org.apache.carbondata.core.datastorage.store.impl.FileFactory; +import org.apache.carbondata.core.datastorage.columnar.ColumnGroupModel; +import org.apache.carbondata.core.datastorage.compression.WriterCompressModel; +import org.apache.carbondata.core.datastorage.filesystem.LocalCarbonFile; +import org.apache.carbondata.core.datastorage.impl.FileFactory; import org.apache.carbondata.core.metadata.ValueEncoderMeta; -import org.apache.carbondata.scan.model.QueryDimension; +import org.apache.carbondata.core.scan.model.QueryDimension; import org.apache.hadoop.security.UserGroupInformation; import org.junit.AfterClass; http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/util/DataFileFooterConverterTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/util/DataFileFooterConverterTest.java b/core/src/test/java/org/apache/carbondata/core/util/DataFileFooterConverterTest.java index 1a1b5c8..f1ee0a0 100644 --- a/core/src/test/java/org/apache/carbondata/core/util/DataFileFooterConverterTest.java +++ b/core/src/test/java/org/apache/carbondata/core/util/DataFileFooterConverterTest.java @@ -26,9 +26,9 @@ import org.apache.carbondata.core.ColumnarFormatVersion; import org.apache.carbondata.core.datastore.block.TableBlockInfo; import org.apache.carbondata.core.metadata.blocklet.DataFileFooter; import org.apache.carbondata.core.metadata.blocklet.SegmentInfo; -import org.apache.carbondata.core.datastorage.store.FileHolder; -import org.apache.carbondata.core.datastorage.store.impl.FileFactory; -import org.apache.carbondata.core.datastorage.store.impl.FileHolderImpl; +import org.apache.carbondata.core.datastorage.FileHolder; +import org.apache.carbondata.core.datastorage.impl.FileFactory; +import org.apache.carbondata.core.datastorage.impl.FileHolderImpl; import org.apache.carbondata.core.reader.CarbonFooterReader; import org.apache.carbondata.core.reader.CarbonIndexFileReader; import org.apache.carbondata.core.reader.ThriftReader; http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/util/ValueCompressionUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/util/ValueCompressionUtilTest.java b/core/src/test/java/org/apache/carbondata/core/util/ValueCompressionUtilTest.java index 6772c9d..17fe306 100644 --- a/core/src/test/java/org/apache/carbondata/core/util/ValueCompressionUtilTest.java +++ b/core/src/test/java/org/apache/carbondata/core/util/ValueCompressionUtilTest.java @@ -23,12 +23,29 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteBuffer; -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.compression.ValueCompressionHolder; -import org.apache.carbondata.core.datastorage.store.compression.decimal.*; -import org.apache.carbondata.core.datastorage.store.compression.nondecimal.*; -import org.apache.carbondata.core.datastorage.store.compression.none.*; +import org.apache.carbondata.core.datastorage.compression.MeasureMetaDataModel; +import org.apache.carbondata.core.datastorage.compression.WriterCompressModel; +import org.apache.carbondata.core.datastorage.compression.ValueCompressionHolder; +import org.apache.carbondata.core.datastorage.compression.decimal.CompressionMaxMinByte; +import org.apache.carbondata.core.datastorage.compression.decimal.CompressionMaxMinDefault; +import org.apache.carbondata.core.datastorage.compression.decimal.CompressionMaxMinInt; +import org.apache.carbondata.core.datastorage.compression.decimal.CompressionMaxMinLong; +import org.apache.carbondata.core.datastorage.compression.decimal.CompressionMaxMinShort; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalByte; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalDefault; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalInt; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalLong; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalMaxMinByte; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalMaxMinDefault; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalMaxMinInt; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalMaxMinLong; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalMaxMinShort; +import org.apache.carbondata.core.datastorage.compression.nondecimal.CompressionNonDecimalShort; +import org.apache.carbondata.core.datastorage.compression.none.CompressionNoneByte; +import org.apache.carbondata.core.datastorage.compression.none.CompressionNoneDefault; +import org.apache.carbondata.core.datastorage.compression.none.CompressionNoneInt; +import org.apache.carbondata.core.datastorage.compression.none.CompressionNoneLong; +import org.apache.carbondata.core.datastorage.compression.none.CompressionNoneShort; import org.apache.carbondata.core.util.ValueCompressionUtil.DataType; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImplTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImplTest.java b/core/src/test/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImplTest.java index ad0abd7..6037ee8 100644 --- a/core/src/test/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImplTest.java +++ b/core/src/test/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImplTest.java @@ -39,8 +39,8 @@ import org.apache.carbondata.core.ColumnIdentifier; import org.apache.carbondata.core.path.CarbonStorePath; import org.apache.carbondata.core.path.CarbonTablePath; import org.apache.carbondata.core.constants.CarbonCommonConstants; -import org.apache.carbondata.core.datastorage.store.filesystem.CarbonFile; -import org.apache.carbondata.core.datastorage.store.impl.FileFactory; +import org.apache.carbondata.core.datastorage.filesystem.CarbonFile; +import org.apache.carbondata.core.datastorage.impl.FileFactory; import org.apache.carbondata.core.reader.CarbonDictionaryColumnMetaChunk; import org.apache.carbondata.core.reader.CarbonDictionaryMetadataReaderImpl; import org.apache.carbondata.core.reader.CarbonDictionaryReaderImpl; http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/core/writer/CarbonFooterWriterTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/core/writer/CarbonFooterWriterTest.java b/core/src/test/java/org/apache/carbondata/core/writer/CarbonFooterWriterTest.java index b8fd0b8..0036265 100644 --- a/core/src/test/java/org/apache/carbondata/core/writer/CarbonFooterWriterTest.java +++ b/core/src/test/java/org/apache/carbondata/core/writer/CarbonFooterWriterTest.java @@ -30,9 +30,9 @@ import org.apache.carbondata.core.datastore.block.SegmentProperties; import org.apache.carbondata.core.metadata.DataType; import org.apache.carbondata.core.metadata.Encoding; import org.apache.carbondata.core.constants.CarbonCommonConstants; -import org.apache.carbondata.core.datastorage.store.compression.WriterCompressModel; -import org.apache.carbondata.core.datastorage.store.filesystem.CarbonFile; -import org.apache.carbondata.core.datastorage.store.impl.FileFactory; +import org.apache.carbondata.core.datastorage.compression.WriterCompressModel; +import org.apache.carbondata.core.datastorage.filesystem.CarbonFile; +import org.apache.carbondata.core.datastorage.impl.FileFactory; import org.apache.carbondata.core.metadata.BlockletInfoColumnar; import org.apache.carbondata.core.reader.CarbonFooterReader; import org.apache.carbondata.core.util.CarbonMetadataUtil; http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/collector/impl/DictionaryBasedResultCollectorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/collector/impl/DictionaryBasedResultCollectorTest.java b/core/src/test/java/org/apache/carbondata/scan/collector/impl/DictionaryBasedResultCollectorTest.java deleted file mode 100644 index 1ae04c5..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/collector/impl/DictionaryBasedResultCollectorTest.java +++ /dev/null @@ -1,154 +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.scan.collector.impl; - - -public class DictionaryBasedResultCollectorTest { - -// private static DictionaryBasedResultCollector dictionaryBasedResultCollector; -// private static BlockExecutionInfo blockExecutionInfo; -// -// @BeforeClass public static void setUp() { -// blockExecutionInfo = new BlockExecutionInfo(); -// KeyStructureInfo keyStructureInfo = new KeyStructureInfo(); -// blockExecutionInfo.setKeyStructureInfo(keyStructureInfo); -// AggregatorInfo aggregatorInfo = new AggregatorInfo(); -// aggregatorInfo.setMeasureOrdinals(new int[] { 10, 20, 30, 40 }); -// aggregatorInfo.setMeasureExists(new boolean[] { true, false, false, false }); -// aggregatorInfo.setDefaultValues(new Object[] { 1, 2, 3, 4 }); -// aggregatorInfo.setMeasureDataTypes( -// new DataType[] { DataType.INT, DataType.TIMESTAMP, DataType.INT, DataType.INT }); -// blockExecutionInfo.setAggregatorInfo(aggregatorInfo); -// QueryDimension queryDimension1 = new QueryDimension("QDCol1"); -// queryDimension1.setQueryOrder(1); -// ColumnSchema columnSchema = new ColumnSchema(); -// queryDimension1.setDimension(new CarbonDimension(columnSchema, 0, 0, 0, 0)); -// QueryDimension queryDimension2 = new QueryDimension("QDCol2"); -// queryDimension2.setQueryOrder(2); -// queryDimension2.setDimension(new CarbonDimension(columnSchema, 1, 1, 1, 1)); -// QueryDimension queryDimension3 = new QueryDimension("QDCol3"); -// queryDimension3.setQueryOrder(3); -// queryDimension3.setDimension(new CarbonDimension(columnSchema, 2, 0, 0, 0)); -// QueryDimension queryDimension4 = new QueryDimension("QDCol4"); -// queryDimension4.setQueryOrder(4); -// queryDimension4.setDimension(new CarbonDimension(columnSchema, 3, 0, 0, 0)); -// blockExecutionInfo.setQueryDimensions( -// new QueryDimension[] { queryDimension1, queryDimension2, queryDimension3, -// queryDimension4 }); -// QueryMeasure queryMeasure1 = new QueryMeasure("QMCol1"); -// queryMeasure1.setQueryOrder(1); -// QueryMeasure queryMeasure2 = new QueryMeasure("QMCol2"); -// queryMeasure1.setQueryOrder(2); -// QueryMeasure queryMeasure3 = new QueryMeasure("QMCol3"); -// queryMeasure1.setQueryOrder(3); -// QueryMeasure queryMeasure4 = new QueryMeasure("QMCol4"); -// queryMeasure1.setQueryOrder(4); -// blockExecutionInfo.setQueryMeasures( -// new QueryMeasure[] { queryMeasure1, queryMeasure2, queryMeasure3, queryMeasure4 }); -// Map<Integer, GenericQueryType> complexDimensionInfoMap = new HashMap<>(); -// complexDimensionInfoMap.put(1, new ArrayQueryType("name1", "parent1", 1)); -// complexDimensionInfoMap.put(2, new ArrayQueryType("name2", "parent2", 2)); -// complexDimensionInfoMap.put(3, new ArrayQueryType("name3", "parent3", 3)); -// complexDimensionInfoMap.put(4, new ArrayQueryType("name4", "parent4", 4)); -// blockExecutionInfo.setComplexDimensionInfoMap(complexDimensionInfoMap); -// dictionaryBasedResultCollector = new DictionaryBasedResultCollector(blockExecutionInfo); -// } -// -// @Test public void testToCollectData() { -// new MockUp<CarbonUtil>() { -// @SuppressWarnings("unused") @Mock boolean[] getDictionaryEncodingArray( -// QueryDimension[] queryDimensions) { -// return new boolean[] { true, false, true, true }; -// } -// -// @SuppressWarnings("unused") @Mock boolean[] getDirectDictionaryEncodingArray( -// QueryDimension[] queryDimensions) { -// return new boolean[] { true, true, false, false }; -// } -// -// @SuppressWarnings("unused") @Mock boolean[] getComplexDataTypeArray( -// QueryDimension[] queryDimensions) { -// return new boolean[] { false, false, true, false }; -// } -// }; -// new MockUp<DataTypeUtil>() { -// @SuppressWarnings("unused") @Mock Object getDataBasedOnDataType(String data, -// DataType actualDataType) { -// return 1; -// } -// }; -// -// new MockUp<NonFilterQueryScannedResult>() { -// @SuppressWarnings("unused") @Mock int[] getDictionaryKeyIntegerArray() { -// this.getMockInstance().incrementCounter(); -// System.out.println("Mocked"); -// return new int[] { 1, 2 }; -// } -// -// @SuppressWarnings("unused") @Mock String[] getNoDictionaryKeyStringArray() { -// return new String[] { "1", "2" }; -// } -// -// @SuppressWarnings("unused") @Mock byte[][] getComplexTypeKeyArray() { -// return new byte[][] { { 1, 2 }, { 1, 2 } }; -// } -// -// @SuppressWarnings("unused") @Mock public MeasureColumnDataChunk getMeasureChunk(int ordinal) { -// MeasureColumnDataChunk measureColumnDataChunk = new MeasureColumnDataChunk(); -// PresenceMeta presenceMeta = new PresenceMeta(); -// BitSet bitSet = new BitSet(); -// bitSet.set(1); -// presenceMeta.setBitSet(bitSet); -// measureColumnDataChunk.setNullValueIndexHolder(presenceMeta); -// CarbonReadDataHolder carbonReadDataHolder = new CarbonReadDataHolder(); -// carbonReadDataHolder.setReadableLongValues(new long[] { 1 }); -// measureColumnDataChunk.setMeasureDataHolder(carbonReadDataHolder); -// return measureColumnDataChunk; -// } -// }; -// -// new MockUp<DirectDictionaryKeyGeneratorFactory>() { -// @SuppressWarnings("unused") @Mock DirectDictionaryGenerator getDirectDictionaryGenerator( -// DataType dataType) { -// if (dataType == DataType.TIMESTAMP) return new TimeStampDirectDictionaryGenerator( -// CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT); -// else return null; -// } -// }; -// new MockUp<TimeStampDirectDictionaryGenerator>() { -// @SuppressWarnings("unused") @Mock Object getValueFromSurrogate(int key) { -// return 100L; -// } -// }; -// -// new MockUp<ArrayQueryType>() { -// @SuppressWarnings("unused") @Mock Object getDataBasedOnDataTypeFromSurrogates( -// ByteBuffer surrogateData) { -// return ByteBuffer.wrap("1".getBytes()); -// } -// }; -// -// AbstractScannedResult abstractScannedResult = -// new NonFilterQueryScannedResult(blockExecutionInfo); -// abstractScannedResult.setNumberOfRows(2); -// List<Object[]> result = dictionaryBasedResultCollector.collectData(abstractScannedResult, 2); -// int expectedResult = 2; -// assertThat(result.size(), is(equalTo(expectedResult))); -// } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/collector/impl/RawBasedResultCollectorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/collector/impl/RawBasedResultCollectorTest.java b/core/src/test/java/org/apache/carbondata/scan/collector/impl/RawBasedResultCollectorTest.java deleted file mode 100644 index a27da72..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/collector/impl/RawBasedResultCollectorTest.java +++ /dev/null @@ -1,132 +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.scan.collector.impl; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -public class RawBasedResultCollectorTest { -// -// private static RawBasedResultCollector rawBasedResultCollector; -// private static BlockExecutionInfo blockExecutionInfo; -// private static KeyGenerator keyGenerator; -// -// @BeforeClass public static void setUp() { -// keyGenerator = new MockUp<KeyGenerator>() { -// @SuppressWarnings("unused") @Mock long[] getKeyArray(byte[] key, int[] maskedByteRanges) { -// return new long[] { 1, 2 }; -// } -// -// @SuppressWarnings("unused") @Mock byte[] generateKey(long[] keys) throws KeyGenException { -// return new byte[] { 1, 2 }; -// } -// -// }.getMockInstance(); -// -// blockExecutionInfo = new BlockExecutionInfo(); -// KeyStructureInfo keyStructureInfo = new KeyStructureInfo(); -// keyStructureInfo.setKeyGenerator(keyGenerator); -// keyStructureInfo.setMaxKey(new byte[] { 1, 2 }); -// keyStructureInfo.setMaskedBytes(new int[] { 1, 2 }); -// keyStructureInfo.setMaskByteRanges(new int[] { 1, 2 }); -// blockExecutionInfo.setKeyStructureInfo(keyStructureInfo); -// AggregatorInfo aggregatorInfo = new AggregatorInfo(); -// aggregatorInfo.setMeasureOrdinals(new int[] { 10, 20, 30, 40 }); -// aggregatorInfo.setMeasureExists(new boolean[] { true, false, false, false }); -// aggregatorInfo.setDefaultValues(new Object[] { 1, 2, 3, 4 }); -// aggregatorInfo.setMeasureDataTypes( -// new DataType[] { DataType.INT, DataType.TIMESTAMP, DataType.INT, DataType.INT }); -// QueryMeasure queryMeasure1 = new QueryMeasure("QMCol1"); -// queryMeasure1.setQueryOrder(1); -// QueryMeasure queryMeasure2 = new QueryMeasure("QMCol2"); -// queryMeasure1.setQueryOrder(2); -// QueryMeasure queryMeasure3 = new QueryMeasure("QMCol3"); -// queryMeasure1.setQueryOrder(3); -// QueryMeasure queryMeasure4 = new QueryMeasure("QMCol4"); -// queryMeasure1.setQueryOrder(4); -// QueryDimension queryDimension1 = new QueryDimension("QDCol1"); -// queryDimension1.setQueryOrder(1); -// ColumnSchema columnSchema = new ColumnSchema(); -// queryDimension1.setDimension(new CarbonDimension(columnSchema, 0, 0, 0, 0)); -// QueryDimension queryDimension2 = new QueryDimension("QDCol2"); -// queryDimension2.setQueryOrder(2); -// queryDimension2.setDimension(new CarbonDimension(columnSchema, 1, 1, 1, 1)); -// QueryDimension queryDimension3 = new QueryDimension("QDCol3"); -// queryDimension3.setQueryOrder(3); -// queryDimension3.setDimension(new CarbonDimension(columnSchema, 2, 0, 0, 0)); -// QueryDimension queryDimension4 = new QueryDimension("QDCol4"); -// queryDimension4.setQueryOrder(4); -// queryDimension4.setDimension(new CarbonDimension(columnSchema, 3, 0, 0, 0)); -// blockExecutionInfo.setQueryDimensions( -// new QueryDimension[] { queryDimension1, queryDimension2, queryDimension3, -// queryDimension4 }); -// blockExecutionInfo.setQueryMeasures( -// new QueryMeasure[] { queryMeasure1, queryMeasure2, queryMeasure3, queryMeasure4 }); -// blockExecutionInfo.setFixedKeyUpdateRequired(true); -// blockExecutionInfo.setAggregatorInfo(aggregatorInfo); -// blockExecutionInfo.setMaskedByteForBlock(new int[] { 1, 2 }); -// blockExecutionInfo.setBlockKeyGenerator(keyGenerator); -// rawBasedResultCollector = new RawBasedResultCollector(blockExecutionInfo); -// } -// -// @Test public void testToCollectData() { -// -// new MockUp<NonFilterQueryScannedResult>() { -// @SuppressWarnings("unused") @Mock byte[] getDictionaryKeyArray() { -// this.getMockInstance().incrementCounter(); -// return new byte[] { 1, 2 }; -// } -// -// @SuppressWarnings("unused") @Mock byte[][] getNoDictionaryKeyArray() { -// return new byte[][] { { 1, 2 } }; -// } -// -// @SuppressWarnings("unused") @Mock byte[][] getComplexTypeKeyArray() { -// return new byte[][] { { 1, 2 }, { 1, 2 } }; -// } -// -// @SuppressWarnings("unused") @Mock public MeasureColumnDataChunk getMeasureChunk(int ordinal) { -// MeasureColumnDataChunk measureColumnDataChunk = new MeasureColumnDataChunk(); -// PresenceMeta presenceMeta = new PresenceMeta(); -// BitSet bitSet = new BitSet(); -// bitSet.set(1); -// presenceMeta.setBitSet(bitSet); -// measureColumnDataChunk.setNullValueIndexHolder(presenceMeta); -// CarbonReadDataHolder carbonReadDataHolder = new CarbonReadDataHolder(); -// carbonReadDataHolder.setReadableLongValues(new long[] { 1 }); -// measureColumnDataChunk.setMeasureDataHolder(carbonReadDataHolder); -// return measureColumnDataChunk; -// } -// }; -// -// new MockUp<QueryUtil>() { -// @SuppressWarnings("unused") @Mock byte[] getMaskedKey(byte[] data, byte[] maxKey, -// int[] maskByteRanges, int byteCount) { -// return new byte[] { 1, 2 }; -// } -// }; -// -// AbstractScannedResult abstractScannedResult = -// new NonFilterQueryScannedResult(blockExecutionInfo); -// abstractScannedResult.setNumberOfRows(2); -// List<Object[]> result = rawBasedResultCollector.collectData(abstractScannedResult, 2); -// int expectedResult = 2; -// assertThat(result.size(), is(equalTo(expectedResult))); -// } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/complextypes/ArrayQueryTypeTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/complextypes/ArrayQueryTypeTest.java b/core/src/test/java/org/apache/carbondata/scan/complextypes/ArrayQueryTypeTest.java deleted file mode 100644 index 8fc5484..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/complextypes/ArrayQueryTypeTest.java +++ /dev/null @@ -1,57 +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.scan.complextypes; - -import java.nio.ByteBuffer; - -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.pentaho.di.core.util.Assert.assertNotNull; -import static org.pentaho.di.core.util.Assert.assertNull; - -public class ArrayQueryTypeTest { - - private static ArrayQueryType arrayQueryType; - - @BeforeClass public static void setUp() { - String name = "test"; - String parentName = "testParent"; - int blockIndex = 1; - arrayQueryType = new ArrayQueryType(name, parentName, blockIndex); - } - - @Test public void testGetDataBasedOnDataTypeFromSurrogatesForNull() { - ByteBuffer surrogateData = ByteBuffer.allocate(10); - surrogateData.put(0, (byte) 0xFF); - surrogateData.put(1, (byte) 0xFF); - surrogateData.put(2, (byte) 0xFF); - surrogateData.put(3, (byte) 0xFF); - assertNull(arrayQueryType.getDataBasedOnDataTypeFromSurrogates(surrogateData)); - } - - @Test public void testGetDataBasedOnDataTypeFromSurrogates() { - ByteBuffer surrogateData = ByteBuffer.allocate(10); - surrogateData.put(3, (byte) 1); - arrayQueryType.setName("testName"); - arrayQueryType.setParentname("testName"); - arrayQueryType.addChildren(arrayQueryType); - assertNotNull(arrayQueryType.getDataBasedOnDataTypeFromSurrogates(surrogateData)); - } -}