Search in sources :

Example 26 with CarbonDimension

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);
}
Also used : AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) FilterOptimizer(org.apache.carbondata.core.scan.filter.intf.FilterOptimizer) LessThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) GreaterThanExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) Expression(org.apache.carbondata.core.scan.expression.Expression) OrExpression(org.apache.carbondata.core.scan.expression.logical.OrExpression) TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) NotEqualsExpression(org.apache.carbondata.core.scan.expression.conditional.NotEqualsExpression) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) RangeFilterOptmizer(org.apache.carbondata.core.scan.filter.optimizer.RangeFilterOptmizer) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) LessThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression) FilterOptimizerBasic(org.apache.carbondata.core.scan.filter.intf.FilterOptimizerBasic) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) Test(org.junit.Test)

Example 27 with CarbonDimension

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]);
    }
}
Also used : ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) QueryDimension(org.apache.carbondata.core.scan.model.QueryDimension) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) Test(org.junit.Test)

Example 28 with CarbonDimension

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;
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) HashSet(java.util.HashSet) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 29 with CarbonDimension

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]);
    }
}
Also used : ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) Encoding(org.apache.carbondata.core.metadata.encoder.Encoding) QueryDimension(org.apache.carbondata.core.scan.model.QueryDimension) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) Test(org.junit.Test)

Example 30 with CarbonDimension

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);
}
Also used : ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) Test(org.junit.Test)

Aggregations

CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)85 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)31 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)23 CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)15 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)13 QueryDimension (org.apache.carbondata.core.scan.model.QueryDimension)9 CarbonMetadata (org.apache.carbondata.core.metadata.CarbonMetadata)7 HashSet (java.util.HashSet)6 List (java.util.List)5 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)5 Expression (org.apache.carbondata.core.scan.expression.Expression)5 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)5 FilterOptimizer (org.apache.carbondata.core.scan.filter.intf.FilterOptimizer)5 FilterOptimizerBasic (org.apache.carbondata.core.scan.filter.intf.FilterOptimizerBasic)5 RangeFilterOptmizer (org.apache.carbondata.core.scan.filter.optimizer.RangeFilterOptmizer)5 Map (java.util.Map)4 SortedMap (java.util.SortedMap)4 TreeMap (java.util.TreeMap)4 TableInfo (org.apache.carbondata.core.metadata.schema.table.TableInfo)4