use of org.apache.carbondata.core.metadata.schema.table.CarbonTable in project carbondata by apache.
the class CarbonInputFormat method populateCarbonTable.
/**
* this method will read the schema from the physical file and populate into CARBON_TABLE
* @param configuration
* @throws IOException
*/
private static void populateCarbonTable(Configuration configuration) throws IOException {
String dirs = configuration.get(INPUT_DIR, "");
String[] inputPaths = StringUtils.split(dirs);
if (inputPaths.length == 0) {
throw new InvalidPathException("No input paths specified in job");
}
AbsoluteTableIdentifier absoluteTableIdentifier = AbsoluteTableIdentifier.fromTablePath(inputPaths[0]);
// read the schema file to get the absoluteTableIdentifier having the correct table id
// persisted in the schema
CarbonTable carbonTable = SchemaReader.readCarbonTableFromStore(absoluteTableIdentifier);
setCarbonTable(configuration, carbonTable);
}
use of org.apache.carbondata.core.metadata.schema.table.CarbonTable in project carbondata by apache.
the class TableDictionaryGeneratorTest 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.CarbonTable 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.CarbonTable 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.CarbonTable in project carbondata by apache.
the class DataLoadProcessBuilder method createConfiguration.
private CarbonDataLoadConfiguration createConfiguration(CarbonLoadModel loadModel, String storeLocation) throws Exception {
if (!new File(storeLocation).mkdirs()) {
LOGGER.error("Error while creating the temp store path: " + storeLocation);
}
CarbonDataLoadConfiguration configuration = new CarbonDataLoadConfiguration();
String databaseName = loadModel.getDatabaseName();
String tableName = loadModel.getTableName();
String tempLocationKey = CarbonDataProcessorUtil.getTempStoreLocationKey(databaseName, tableName, loadModel.getTaskNo(), false);
CarbonProperties.getInstance().addProperty(tempLocationKey, storeLocation);
CarbonProperties.getInstance().addProperty(CarbonCommonConstants.STORE_LOCATION_HDFS, loadModel.getStorePath());
CarbonTable carbonTable = loadModel.getCarbonDataLoadSchema().getCarbonTable();
AbsoluteTableIdentifier identifier = carbonTable.getAbsoluteTableIdentifier();
configuration.setTableIdentifier(identifier);
configuration.setSchemaUpdatedTimeStamp(carbonTable.getTableLastUpdatedTime());
configuration.setHeader(loadModel.getCsvHeaderColumns());
configuration.setPartitionId(loadModel.getPartitionId());
configuration.setSegmentId(loadModel.getSegmentId());
configuration.setTaskNo(loadModel.getTaskNo());
configuration.setDataLoadProperty(DataLoadProcessorConstants.COMPLEX_DELIMITERS, new String[] { loadModel.getComplexDelimiterLevel1(), loadModel.getComplexDelimiterLevel2() });
configuration.setDataLoadProperty(DataLoadProcessorConstants.SERIALIZATION_NULL_FORMAT, loadModel.getSerializationNullFormat().split(",")[1]);
configuration.setDataLoadProperty(DataLoadProcessorConstants.FACT_TIME_STAMP, loadModel.getFactTimeStamp());
configuration.setDataLoadProperty(DataLoadProcessorConstants.BAD_RECORDS_LOGGER_ENABLE, loadModel.getBadRecordsLoggerEnable().split(",")[1]);
configuration.setDataLoadProperty(DataLoadProcessorConstants.BAD_RECORDS_LOGGER_ACTION, loadModel.getBadRecordsAction().split(",")[1]);
configuration.setDataLoadProperty(DataLoadProcessorConstants.IS_EMPTY_DATA_BAD_RECORD, loadModel.getIsEmptyDataBadRecord().split(",")[1]);
configuration.setDataLoadProperty(DataLoadProcessorConstants.FACT_FILE_PATH, loadModel.getFactFilePath());
configuration.setDataLoadProperty(CarbonCommonConstants.LOAD_SORT_SCOPE, loadModel.getSortScope());
configuration.setDataLoadProperty(CarbonCommonConstants.LOAD_BATCH_SORT_SIZE_INMB, loadModel.getBatchSortSizeInMb());
CarbonMetadata.getInstance().addCarbonTable(carbonTable);
List<CarbonDimension> dimensions = carbonTable.getDimensionByTableName(carbonTable.getFactTableName());
List<CarbonMeasure> measures = carbonTable.getMeasureByTableName(carbonTable.getFactTableName());
Map<String, String> dateFormatMap = CarbonDataProcessorUtil.getDateFormatMap(loadModel.getDateFormat());
List<DataField> dataFields = new ArrayList<>();
List<DataField> complexDataFields = new ArrayList<>();
// And then add complex data types and measures.
for (CarbonColumn column : dimensions) {
DataField dataField = new DataField(column);
dataField.setDateFormat(dateFormatMap.get(column.getColName()));
if (column.isComplex()) {
complexDataFields.add(dataField);
} else {
dataFields.add(dataField);
}
}
dataFields.addAll(complexDataFields);
for (CarbonColumn column : measures) {
// This dummy measure is added when no measure was present. We no need to load it.
if (!(column.getColName().equals("default_dummy_measure"))) {
dataFields.add(new DataField(column));
}
}
configuration.setDataFields(dataFields.toArray(new DataField[dataFields.size()]));
configuration.setBucketingInfo(carbonTable.getBucketingInfo(carbonTable.getFactTableName()));
// configuration for one pass load: dictionary server info
configuration.setUseOnePass(loadModel.getUseOnePass());
configuration.setDictionaryServerHost(loadModel.getDictionaryServerHost());
configuration.setDictionaryServerPort(loadModel.getDictionaryServerPort());
configuration.setPreFetch(loadModel.isPreFetch());
configuration.setNumberOfSortColumns(carbonTable.getNumberOfSortColumns());
configuration.setNumberOfNoDictSortColumns(carbonTable.getNumberOfNoDictSortColumns());
return configuration;
}
Aggregations