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);
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class CarbonUtilTest method testToGetComplexDataTypeArray.
@Test
public void testToGetComplexDataTypeArray() {
QueryDimension column1 = new QueryDimension("Column1");
QueryDimension column2 = new QueryDimension("Column2");
ColumnSchema column1Schema = new ColumnSchema();
ColumnSchema column2Schema = new ColumnSchema();
column1Schema.setColumnName("Column1");
column1Schema.setDataType(DataType.DATE);
column1.setDimension(new CarbonDimension(column1Schema, 1, 1, 1, 1));
column2Schema.setColumnName("Column2");
column2Schema.setDataType(DataType.ARRAY);
column2.setDimension(new CarbonDimension(column2Schema, 1, 1, 1, 1));
QueryDimension[] queryDimensions = { column1, column2 };
boolean[] dictionaryEncoding = CarbonUtil.getComplexDataTypeArray(queryDimensions);
boolean[] expectedDictionaryEncoding = { false, true };
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 CarbonDataProcessorUtil method getSchemaColumnNames.
/**
* This method update the column Name
*
* @param schema
* @param tableName
*/
public static Set<String> getSchemaColumnNames(CarbonDataLoadSchema schema, String tableName) {
Set<String> columnNames = new HashSet<String>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
String factTableName = schema.getCarbonTable().getFactTableName();
if (tableName.equals(factTableName)) {
List<CarbonDimension> dimensions = schema.getCarbonTable().getDimensionByTableName(factTableName);
for (CarbonDimension dimension : dimensions) {
columnNames.add(dimension.getColName());
}
List<CarbonMeasure> measures = schema.getCarbonTable().getMeasureByTableName(factTableName);
for (CarbonMeasure msr : measures) {
columnNames.add(msr.getColName());
}
} else {
List<CarbonDimension> dimensions = schema.getCarbonTable().getDimensionByTableName(tableName);
for (CarbonDimension dimension : dimensions) {
columnNames.add(dimension.getColName());
}
List<CarbonMeasure> measures = schema.getCarbonTable().getMeasureByTableName(tableName);
for (CarbonMeasure msr : measures) {
columnNames.add(msr.getColName());
}
}
return columnNames;
}
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 IncrementalColumnDictionaryGeneratorTest method getOrGenerateKey.
@Test
public void getOrGenerateKey() throws Exception {
//Create required column schema
ColumnSchema columnSchema = new ColumnSchema();
columnSchema.setColumnName("empName");
CarbonDimension carbonDimension = new CarbonDimension(columnSchema, 0, 0, 0, 0, 0);
IncrementalColumnDictionaryGenerator generator = new IncrementalColumnDictionaryGenerator(carbonDimension, 10);
// Test first with generating a key and then trying geOrGenerate
Integer generatedKey = generator.generateKey("First");
Integer obtainedKey = generator.getOrGenerateKey("First");
assertEquals(generatedKey, obtainedKey);
// Test directly with getOrGenerate for another key
obtainedKey = generator.getOrGenerateKey("Second");
assertEquals(new Integer(12), obtainedKey);
}
Aggregations