use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class ServerDictionaryGeneratorTest method setUp.
@Before
public void setUp() throws Exception {
// enable lru cache by setting cache size
CarbonProperties.getInstance().addProperty(CarbonCommonConstants.CARBON_MAX_DRIVER_LRU_CACHE_SIZE, "10");
// Create two column schemas and dimensions for the table
empColumnSchema = new ColumnSchema();
empColumnSchema.setColumnName("empNameCol");
empColumnSchema.setColumnUniqueId("empNameCol");
empColumnSchema.setDimensionColumn(true);
empColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
empDimension = new CarbonDimension(empColumnSchema, 0, 0, 0, 0, 0);
ageColumnSchema = new ColumnSchema();
ageColumnSchema.setColumnName("empNameCol");
ageColumnSchema.setColumnUniqueId("empNameCol");
ageColumnSchema.setDimensionColumn(true);
ageColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
ageDimension = new CarbonDimension(ageColumnSchema, 0, 0, 0, 0, 0);
// Create a Table
tableSchema = new TableSchema();
tableSchema.setTableName("TestTable");
tableSchema.setListOfColumns(Arrays.asList(empColumnSchema, ageColumnSchema));
CarbonMetadata metadata = CarbonMetadata.getInstance();
tableInfo = new TableInfo();
tableInfo.setFactTable(tableSchema);
tableInfo.setTableUniqueName("TestTable");
tableInfo.setDatabaseName("test");
storePath = System.getProperty("java.io.tmpdir") + "/tmp";
tableInfo.setStorePath(storePath);
CarbonTable carbonTable = new CarbonTable();
carbonTable.loadCarbonTable(tableInfo);
// Add the created table to metadata
metadata.addCarbonTable(carbonTable);
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class IncrementalColumnDictionaryGeneratorTest method generateKeyTwice.
@Test
public void generateKeyTwice() 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");
// Add one more key and check if it works fine.
key = generator.generateKey("Second");
assertEquals(new Integer(12), key);
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class IncrementalColumnDictionaryGeneratorTest method generateKeyAgain.
@Test
public void generateKeyAgain() 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");
// Add the same key again anc check if the value is correct
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 CarbonMetadataTest method testGetCarbonDimensionBasedOnColIdentifierWhenChildDimensionColumnEqualsColumnIdentifier.
@Test
public void testGetCarbonDimensionBasedOnColIdentifierWhenChildDimensionColumnEqualsColumnIdentifier() {
CarbonTable carbonTable = new CarbonTable();
String columnIdentifier = "9";
final List<CarbonDimension> carbonDimensions = new ArrayList();
ColumnSchema colSchema1 = new ColumnSchema();
ColumnSchema colSchema2 = new ColumnSchema();
colSchema1.setColumnUniqueId("1");
carbonDimensions.add(new CarbonDimension(colSchema1, 1, 1, 2, 1));
final List<CarbonDimension> carbonChildDimensions = new ArrayList();
ColumnSchema colSchema3 = new ColumnSchema();
colSchema3.setColumnUniqueId("9");
colSchema2.setColumnUniqueId("2");
carbonChildDimensions.add(new CarbonDimension(colSchema3, 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 int numberOfChild() {
return 1;
}
@Mock
public List<CarbonDimension> getListOfChildDimensions() {
return carbonChildDimensions;
}
};
CarbonDimension expectedResult = carbonChildDimensions.get(0);
CarbonDimension actualResult = carbonMetadata.getCarbonDimensionBasedOnColIdentifier(carbonTable, columnIdentifier);
assertEquals(expectedResult, actualResult);
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.
the class CarbonCompactionUtil method updateColumnSchemaAndGetCardinality.
/**
* This method will return the updated cardinality according to the master schema
*
* @param columnCardinalityMap
* @param carbonTable
* @param updatedColumnSchemaList
* @return
*/
public static int[] updateColumnSchemaAndGetCardinality(Map<String, Integer> columnCardinalityMap, CarbonTable carbonTable, List<ColumnSchema> updatedColumnSchemaList) {
List<CarbonDimension> masterDimensions = carbonTable.getDimensionByTableName(carbonTable.getFactTableName());
List<Integer> updatedCardinalityList = new ArrayList<>(columnCardinalityMap.size());
for (CarbonDimension dimension : masterDimensions) {
Integer value = columnCardinalityMap.get(dimension.getColumnId());
if (null == value) {
updatedCardinalityList.add(getDimensionDefaultCardinality(dimension));
} else {
updatedCardinalityList.add(value);
}
updatedColumnSchemaList.add(dimension.getColumnSchema());
}
// add measures to the column schema list
List<CarbonMeasure> masterSchemaMeasures = carbonTable.getMeasureByTableName(carbonTable.getFactTableName());
for (CarbonMeasure measure : masterSchemaMeasures) {
updatedColumnSchemaList.add(measure.getColumnSchema());
}
return ArrayUtils.toPrimitive(updatedCardinalityList.toArray(new Integer[updatedCardinalityList.size()]));
}
Aggregations