Search in sources :

Example 31 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)

Example 32 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class IncrementalColumnDictionaryGeneratorTest method writeDictionaryData.

@Test
public void writeDictionaryData() throws Exception {
    //Create required column schema
    ColumnSchema columnSchema = new ColumnSchema();
    columnSchema.setColumnName("empNameCol");
    columnSchema.setColumnUniqueId("empNameCol");
    CarbonDimension carbonDimension = new CarbonDimension(columnSchema, 0, 0, 0, 0, 0);
    // Create the generator and add the keys to dictionary
    IncrementalColumnDictionaryGenerator generator = new IncrementalColumnDictionaryGenerator(carbonDimension, 10);
    // Create a table schema for saving the dictionary
    TableSchema tableSchema = new TableSchema();
    tableSchema.setTableName("TestTable");
    tableSchema.setListOfColumns(Arrays.asList(columnSchema));
    CarbonMetadata metadata = CarbonMetadata.getInstance();
    TableInfo tableInfo = new TableInfo();
    tableInfo.setFactTable(tableSchema);
    tableInfo.setTableUniqueName("TestTable");
    tableInfo.setDatabaseName("test");
    String storePath = System.getProperty("java.io.tmpdir") + "/tmp";
    File dictPath = new File(storePath + "/test/TestTable/Metadata/");
    System.out.print(dictPath.mkdirs());
    tableInfo.setStorePath(storePath);
    CarbonTable carbonTable = new CarbonTable();
    carbonTable.loadCarbonTable(tableInfo);
    // Add the table to metadata
    metadata.addCarbonTable(carbonTable);
    /// Write the dictionary and verify whether its written successfully
    generator.writeDictionaryData("TestTable");
    File dictionaryFile = new File(dictPath, "empNameCol.dict");
    System.out.println(dictionaryFile.getCanonicalPath());
    assertTrue(dictionaryFile.exists());
    dictionaryFile.delete();
    // cleanup created files
    metadata.removeTable(carbonTable.getTableUniqueName());
    cleanUpDirectory(new File(storePath));
}
Also used : CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) TableSchema(org.apache.carbondata.core.metadata.schema.table.TableSchema) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) CarbonMetadata(org.apache.carbondata.core.metadata.CarbonMetadata) File(java.io.File) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) Test(org.junit.Test)

Example 33 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class IncrementalColumnDictionaryGeneratorTest method generateKeyOnce.

@Test
public void generateKeyOnce() throws Exception {
    //Create required column schema
    ColumnSchema columnSchema = new ColumnSchema();
    columnSchema.setColumnName("empName");
    CarbonDimension carbonDimension = new CarbonDimension(columnSchema, 0, 0, 0, 0, 0);
    // Create the generator and add the key to dictionary
    IncrementalColumnDictionaryGenerator generator = new IncrementalColumnDictionaryGenerator(carbonDimension, 10);
    Integer key = generator.generateKey("First");
    assertEquals(new Integer(11), key);
}
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)

Example 34 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class IncrementalColumnDictionaryGeneratorTest method getKey.

@Test
public void getKey() throws Exception {
    //Create required column schema
    ColumnSchema columnSchema = new ColumnSchema();
    columnSchema.setColumnName("empName");
    CarbonDimension carbonDimension = new CarbonDimension(columnSchema, 0, 0, 0, 0, 0);
    // Create the generator and add the key to dictionary
    IncrementalColumnDictionaryGenerator generator = new IncrementalColumnDictionaryGenerator(carbonDimension, 10);
    Integer generatedKey = generator.generateKey("First");
    // Get the value of the key from dictionary and check if it matches with the created value
    Integer obtainedKey = generator.getKey("First");
    assertEquals(generatedKey, 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)

Example 35 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class FieldEncoderFactory method createComplexType.

/**
   * This method may be called recursively if the carbon column is complex type.
   *
   * @return GenericDataType
   */
private static GenericDataType createComplexType(CarbonColumn carbonColumn, String parentName, Cache<DictionaryColumnUniqueIdentifier, Dictionary> cache, CarbonTableIdentifier carbonTableIdentifier, DictionaryClient client, Boolean useOnePass, String storePath, boolean tableInitialize, Map<Object, Integer> localCache) {
    switch(carbonColumn.getDataType()) {
        case ARRAY:
            List<CarbonDimension> listOfChildDimensions = ((CarbonDimension) carbonColumn).getListOfChildDimensions();
            // Create array parser with complex delimiter
            ArrayDataType arrayDataType = new ArrayDataType(carbonColumn.getColName(), parentName, carbonColumn.getColumnId());
            for (CarbonDimension dimension : listOfChildDimensions) {
                arrayDataType.addChildren(createComplexType(dimension, carbonColumn.getColName(), cache, carbonTableIdentifier, client, useOnePass, storePath, tableInitialize, localCache));
            }
            return arrayDataType;
        case STRUCT:
            List<CarbonDimension> dimensions = ((CarbonDimension) carbonColumn).getListOfChildDimensions();
            // Create struct parser with complex delimiter
            StructDataType structDataType = new StructDataType(carbonColumn.getColName(), parentName, carbonColumn.getColumnId());
            for (CarbonDimension dimension : dimensions) {
                structDataType.addChildren(createComplexType(dimension, carbonColumn.getColName(), cache, carbonTableIdentifier, client, useOnePass, storePath, tableInitialize, localCache));
            }
            return structDataType;
        case MAP:
            throw new UnsupportedOperationException("Complex type Map is not supported yet");
        default:
            return new PrimitiveDataType(carbonColumn.getColName(), parentName, carbonColumn.getColumnId(), (CarbonDimension) carbonColumn, cache, carbonTableIdentifier, client, useOnePass, storePath, tableInitialize, localCache);
    }
}
Also used : PrimitiveDataType(org.apache.carbondata.processing.datatypes.PrimitiveDataType) StructDataType(org.apache.carbondata.processing.datatypes.StructDataType) ArrayDataType(org.apache.carbondata.processing.datatypes.ArrayDataType) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

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