use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class CarbonUtilTest method testToGetDictionaryEncodingArray.
@Test
public void testToGetDictionaryEncodingArray() {
QueryDimension column1 = new QueryDimension("Column1");
QueryDimension column2 = new QueryDimension("Column2");
ColumnSchema column1Schema = new ColumnSchema();
ColumnSchema column2Schema = new ColumnSchema();
column1Schema.setColumnName("Column1");
List<Encoding> encoding = new ArrayList<>();
encoding.add(Encoding.DICTIONARY);
column1Schema.setEncodingList(encoding);
column1.setDimension(new CarbonDimension(column1Schema, 1, 1, 1, 1));
column2Schema.setColumnName("Column2");
List<Encoding> encoding2 = new ArrayList<>();
encoding2.add(Encoding.DELTA);
column2Schema.setEncodingList(encoding2);
column2.setDimension(new CarbonDimension(column2Schema, 1, 1, 1, 1));
QueryDimension[] queryDimensions = { column1, column2 };
boolean[] dictionaryEncoding = CarbonUtil.getDictionaryEncodingArray(queryDimensions);
boolean[] expectedDictionaryEncoding = { true, false };
for (int i = 0; i < dictionaryEncoding.length; i++) {
assertEquals(dictionaryEncoding[i], expectedDictionaryEncoding[i]);
}
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class FilterUtilTest method testGetMaskKey.
@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);
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class RangeFilterProcessorTest method createFilterTree_flavor2.
@Test
public void createFilterTree_flavor2() {
// Build 3rd BTree a >= '11' or a > '12' or a <= '20' or a <= '15'
Expression inputFilter;
boolean result = false;
ColumnSchema empColumnSchema = new ColumnSchema();
empColumnSchema.setColumnName("a");
empColumnSchema.setColumnUniqueId("a");
empColumnSchema.setDimensionColumn(true);
empColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
empColumnSchema.setDataType(DataType.STRING);
CarbonDimension empDimension = new CarbonDimension(empColumnSchema, 0, 0, 0, 0, 0);
ColumnExpression cola1 = new ColumnExpression("a", DataType.STRING);
cola1.setDimension(true);
cola1.setDimension(empDimension);
ColumnExpression cola2 = new ColumnExpression("a", DataType.STRING);
cola2.setDimension(true);
cola2.setDimension(empDimension);
ColumnExpression cola3 = new ColumnExpression("a", DataType.STRING);
cola3.setDimension(true);
cola3.setDimension(empDimension);
ColumnExpression cola4 = new ColumnExpression("a", DataType.STRING);
cola4.setDimension(true);
cola4.setDimension(empDimension);
Expression lessThan1 = new LessThanEqualToExpression(cola1, new LiteralExpression("15", DataType.STRING));
Expression lessThan2 = new LessThanEqualToExpression(cola2, new LiteralExpression("20", DataType.STRING));
Expression greaterThan1 = new GreaterThanExpression(cola3, new LiteralExpression("12", DataType.STRING));
Expression greaterThan2 = new GreaterThanEqualToExpression(cola4, new LiteralExpression("11", DataType.STRING));
Expression Or1 = new OrExpression(new NotEqualsExpression(null, null), greaterThan2);
Expression Or2 = new OrExpression(Or1, greaterThan1);
Expression Or3 = new OrExpression(Or2, lessThan2);
inputFilter = new OrExpression(Or3, lessThan1);
// Build The output
ColumnExpression colb1 = new ColumnExpression("a", DataType.STRING);
cola1.setDimension(true);
cola1.setDimension(empDimension);
ColumnExpression colb2 = new ColumnExpression("a", DataType.STRING);
cola2.setDimension(true);
cola2.setDimension(empDimension);
ColumnExpression colb3 = new ColumnExpression("a", DataType.STRING);
cola3.setDimension(true);
cola3.setDimension(empDimension);
ColumnExpression colb4 = new ColumnExpression("a", DataType.STRING);
cola4.setDimension(true);
cola4.setDimension(empDimension);
Expression lessThanb1 = new LessThanEqualToExpression(colb1, new LiteralExpression("15", DataType.STRING));
Expression lessThanb2 = new LessThanEqualToExpression(colb2, new LiteralExpression("20", DataType.STRING));
Expression greaterThanb1 = new GreaterThanExpression(colb3, new LiteralExpression("12", DataType.STRING));
Expression greaterThanb2 = new GreaterThanEqualToExpression(colb4, new LiteralExpression("11", DataType.STRING));
Expression Orb1 = new OrExpression(new NotEqualsExpression(null, null), greaterThanb2);
Expression Orb2 = new OrExpression(Orb1, greaterThanb1);
Expression Orb3 = new OrExpression(Orb2, lessThanb2);
FilterOptimizer rangeFilterOptimizer = new RangeFilterOptmizer(new FilterOptimizerBasic(), inputFilter);
rangeFilterOptimizer.optimizeFilter();
result = checkBothTrees(inputFilter, new OrExpression(Orb3, lessThanb1));
// no change
Assert.assertTrue(result);
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class CarbonMetadataTest method testGetCarbonDimensionBasedOnColIdentifierNullCase.
@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);
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class RangeFilterProcessorTest method createFilterTree_noChange.
@Test
public void createFilterTree_noChange() {
// Build 2nd Tree no change a < 5 and a > 20
Expression inputFilter;
boolean result = false;
ColumnExpression cola = new ColumnExpression("a", DataType.STRING);
cola.setDimension(true);
ColumnSchema empColumnSchema = new ColumnSchema();
empColumnSchema.setColumnName("empNameCol");
empColumnSchema.setColumnUniqueId("empNameCol");
empColumnSchema.setDimensionColumn(true);
empColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
empColumnSchema.setDataType(DataType.STRING);
CarbonDimension empDimension = new CarbonDimension(empColumnSchema, 0, 0, 0, 0, 0);
cola.setDimension(empDimension);
Expression greaterThan = new GreaterThanEqualToExpression(cola, new LiteralExpression("20", DataType.STRING));
ColumnExpression colb = new ColumnExpression("a", DataType.STRING);
colb.setDimension(true);
colb.setDimension(empDimension);
Expression lessThan = new LessThanEqualToExpression(colb, new LiteralExpression("05", DataType.STRING));
inputFilter = new AndExpression(greaterThan, lessThan);
Expression output = new AndExpression(new GreaterThanEqualToExpression(new ColumnExpression("a", DataType.STRING), new LiteralExpression("20", DataType.STRING)), new LessThanEqualToExpression(new ColumnExpression("a", DataType.STRING), new LiteralExpression("05", DataType.STRING)));
FilterOptimizer rangeFilterOptimizer = new RangeFilterOptmizer(new FilterOptimizerBasic(), inputFilter);
rangeFilterOptimizer.optimizeFilter();
result = checkBothTrees(inputFilter, output);
// no change
Assert.assertTrue(result);
}
Aggregations