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);
}
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));
}
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);
}
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);
}
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);
}
}
Aggregations