use of org.apache.carbondata.core.util.path.CarbonTablePath in project carbondata by apache.
the class CarbonInputFormat method getFileStatus.
private void getFileStatus(JobContext job, String[] segmentsToConsider, String[] filesToConsider, List<FileStatus> result) throws IOException {
String[] partitionsToConsider = getValidPartitions(job);
if (partitionsToConsider.length == 0) {
throw new IOException("No partitions/data found");
}
PathFilter inputFilter = getDataFileFilter();
AbsoluteTableIdentifier absIdentifier = getAbsoluteTableIdentifier(job.getConfiguration());
CarbonTablePath tablePath = getTablePath(absIdentifier);
// get tokens for all the required FileSystem for table path
TokenCache.obtainTokensForNamenodes(job.getCredentials(), new Path[] { tablePath }, job.getConfiguration());
//get all data files of valid partitions and segments
for (int i = 0; i < partitionsToConsider.length; ++i) {
String partition = partitionsToConsider[i];
for (int j = 0; j < segmentsToConsider.length; ++j) {
String segmentId = segmentsToConsider[j];
String dataDirectoryPath = absIdentifier.appendWithLocalPrefix(tablePath.getCarbonDataDirectoryPath(partition, segmentId));
if (filesToConsider.length == 0) {
Path segmentPath = new Path(dataDirectoryPath);
FileSystem fs = segmentPath.getFileSystem(job.getConfiguration());
getFileStatusInternal(inputFilter, fs, segmentPath, result);
} else {
for (int k = 0; k < filesToConsider.length; ++k) {
String dataPath = absIdentifier.appendWithLocalPrefix(tablePath.getCarbonDataDirectoryPath(partition, segmentId) + File.separator + filesToConsider[k]);
Path filePath = new Path(dataPath);
FileSystem fs = filePath.getFileSystem(job.getConfiguration());
getFileStatusInternal(inputFilter, fs, filePath, result);
}
}
}
}
}
use of org.apache.carbondata.core.util.path.CarbonTablePath in project carbondata by apache.
the class CarbonUtil method readCarbonIndexFile.
/**
* Below method will be used to get all the block index info from index file
*
* @param taskId task id of the file
* @param tableBlockInfoList list of table block
* @param absoluteTableIdentifier absolute table identifier
* @return list of block info
* @throws IOException if any problem while reading
*/
public static List<DataFileFooter> readCarbonIndexFile(String taskId, String bucketNumber, List<TableBlockInfo> tableBlockInfoList, AbsoluteTableIdentifier absoluteTableIdentifier) throws IOException {
// need to sort the block info list based for task in ascending order so
// it will be sinkup with block index read from file
Collections.sort(tableBlockInfoList);
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
// geting the index file path
//TODO need to pass proper partition number when partiton will be supported
String carbonIndexFilePath = carbonTablePath.getCarbonIndexFilePath(taskId, "0", tableBlockInfoList.get(0).getSegmentId(), bucketNumber, CarbonTablePath.DataFileUtil.getTimeStampFromFileName(tableBlockInfoList.get(0).getFilePath()), tableBlockInfoList.get(0).getVersion());
DataFileFooterConverter fileFooterConverter = new DataFileFooterConverter();
// read the index info and return
return fileFooterConverter.getIndexInfo(carbonIndexFilePath, tableBlockInfoList);
}
use of org.apache.carbondata.core.util.path.CarbonTablePath in project carbondata by apache.
the class CarbonUtil method isFileExistsForGivenColumn.
/**
* This method will check if dictionary and its metadata file exists for a given column
*
* @param dictionaryColumnUniqueIdentifier unique identifier which contains dbName,
* tableName and columnIdentifier
* @return
*/
public static boolean isFileExistsForGivenColumn(String carbonStorePath, DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier) {
PathService pathService = CarbonCommonFactory.getPathService();
CarbonTablePath carbonTablePath = pathService.getCarbonTablePath(carbonStorePath, dictionaryColumnUniqueIdentifier.getCarbonTableIdentifier());
String dictionaryFilePath = carbonTablePath.getDictionaryFilePath(dictionaryColumnUniqueIdentifier.getColumnIdentifier().getColumnId());
String dictionaryMetadataFilePath = carbonTablePath.getDictionaryMetaFilePath(dictionaryColumnUniqueIdentifier.getColumnIdentifier().getColumnId());
// check if both dictionary and its metadata file exists for a given column
return isFileExists(dictionaryFilePath) && isFileExists(dictionaryMetadataFilePath);
}
use of org.apache.carbondata.core.util.path.CarbonTablePath in project carbondata by apache.
the class SegmentUpdateStatusManager method getDeltaFiles.
/**
* Returns all delta file paths of specified block
*
* @param tupleId
* @param extension
* @return
* @throws Exception
*/
public List<String> getDeltaFiles(String tupleId, String extension) throws Exception {
try {
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
String segment = CarbonUpdateUtil.getRequiredFieldFromTID(tupleId, TupleIdEnum.SEGMENT_ID);
String carbonDataDirectoryPath = carbonTablePath.getCarbonDataDirectoryPath("0", segment);
String completeBlockName = CarbonTablePath.addDataPartPrefix(CarbonUpdateUtil.getRequiredFieldFromTID(tupleId, TupleIdEnum.BLOCK_ID) + CarbonCommonConstants.FACT_FILE_EXT);
String blockPath = carbonDataDirectoryPath + CarbonCommonConstants.FILE_SEPARATOR + completeBlockName;
CarbonFile file = FileFactory.getCarbonFile(blockPath, FileFactory.getFileType(blockPath));
if (!file.exists()) {
throw new Exception("Invalid tuple id " + tupleId);
}
String blockNameWithoutExtn = completeBlockName.substring(0, completeBlockName.indexOf('.'));
//blockName without timestamp
final String blockNameFromTuple = blockNameWithoutExtn.substring(0, blockNameWithoutExtn.lastIndexOf("-"));
SegmentUpdateDetails[] listOfSegmentUpdateDetailsArray = readLoadMetadata();
return getDeltaFiles(file, blockNameFromTuple, listOfSegmentUpdateDetailsArray, extension, segment);
} catch (Exception ex) {
String errorMsg = "Invalid tuple id " + tupleId;
LOG.error(errorMsg);
throw new Exception(errorMsg);
}
}
use of org.apache.carbondata.core.util.path.CarbonTablePath in project carbondata by apache.
the class StoreCreator method createTable.
private static CarbonTable createTable() throws IOException {
TableInfo tableInfo = new TableInfo();
tableInfo.setStorePath(absoluteTableIdentifier.getStorePath());
tableInfo.setDatabaseName(absoluteTableIdentifier.getCarbonTableIdentifier().getDatabaseName());
TableSchema tableSchema = new TableSchema();
tableSchema.setTableName(absoluteTableIdentifier.getCarbonTableIdentifier().getTableName());
List<ColumnSchema> columnSchemas = new ArrayList<ColumnSchema>();
ArrayList<Encoding> encodings = new ArrayList<>();
encodings.add(Encoding.DICTIONARY);
ColumnSchema id = new ColumnSchema();
id.setColumnName("ID");
id.setColumnar(true);
id.setDataType(DataType.INT);
id.setEncodingList(encodings);
id.setColumnUniqueId(UUID.randomUUID().toString());
id.setDimensionColumn(true);
id.setColumnGroup(1);
columnSchemas.add(id);
ColumnSchema date = new ColumnSchema();
date.setColumnName("date");
date.setColumnar(true);
date.setDataType(DataType.STRING);
date.setEncodingList(encodings);
date.setColumnUniqueId(UUID.randomUUID().toString());
date.setDimensionColumn(true);
date.setColumnGroup(2);
columnSchemas.add(date);
ColumnSchema country = new ColumnSchema();
country.setColumnName("country");
country.setColumnar(true);
country.setDataType(DataType.STRING);
country.setEncodingList(encodings);
country.setColumnUniqueId(UUID.randomUUID().toString());
country.setDimensionColumn(true);
country.setColumnGroup(3);
columnSchemas.add(country);
ColumnSchema name = new ColumnSchema();
name.setColumnName("name");
name.setColumnar(true);
name.setDataType(DataType.STRING);
name.setEncodingList(encodings);
name.setColumnUniqueId(UUID.randomUUID().toString());
name.setDimensionColumn(true);
name.setColumnGroup(4);
columnSchemas.add(name);
ColumnSchema phonetype = new ColumnSchema();
phonetype.setColumnName("phonetype");
phonetype.setColumnar(true);
phonetype.setDataType(DataType.STRING);
phonetype.setEncodingList(encodings);
phonetype.setColumnUniqueId(UUID.randomUUID().toString());
phonetype.setDimensionColumn(true);
phonetype.setColumnGroup(5);
columnSchemas.add(phonetype);
ColumnSchema serialname = new ColumnSchema();
serialname.setColumnName("serialname");
serialname.setColumnar(true);
serialname.setDataType(DataType.STRING);
serialname.setEncodingList(encodings);
serialname.setColumnUniqueId(UUID.randomUUID().toString());
serialname.setDimensionColumn(true);
serialname.setColumnGroup(6);
columnSchemas.add(serialname);
ColumnSchema salary = new ColumnSchema();
salary.setColumnName("salary");
salary.setColumnar(true);
salary.setDataType(DataType.INT);
salary.setEncodingList(new ArrayList<Encoding>());
salary.setColumnUniqueId(UUID.randomUUID().toString());
salary.setDimensionColumn(false);
salary.setColumnGroup(7);
columnSchemas.add(salary);
tableSchema.setListOfColumns(columnSchemas);
SchemaEvolution schemaEvol = new SchemaEvolution();
schemaEvol.setSchemaEvolutionEntryList(new ArrayList<SchemaEvolutionEntry>());
tableSchema.setSchemaEvalution(schemaEvol);
tableSchema.setTableId(UUID.randomUUID().toString());
tableInfo.setTableUniqueName(absoluteTableIdentifier.getCarbonTableIdentifier().getDatabaseName() + "_" + absoluteTableIdentifier.getCarbonTableIdentifier().getTableName());
tableInfo.setLastUpdatedTime(System.currentTimeMillis());
tableInfo.setFactTable(tableSchema);
tableInfo.setAggregateTableList(new ArrayList<TableSchema>());
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
String schemaFilePath = carbonTablePath.getSchemaFilePath();
String schemaMetadataPath = CarbonTablePath.getFolderContainingFile(schemaFilePath);
tableInfo.setMetaDataFilepath(schemaMetadataPath);
CarbonMetadata.getInstance().loadTableMetadata(tableInfo);
SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
org.apache.carbondata.format.TableInfo thriftTableInfo = schemaConverter.fromWrapperToExternalTableInfo(tableInfo, tableInfo.getDatabaseName(), tableInfo.getFactTable().getTableName());
org.apache.carbondata.format.SchemaEvolutionEntry schemaEvolutionEntry = new org.apache.carbondata.format.SchemaEvolutionEntry(tableInfo.getLastUpdatedTime());
thriftTableInfo.getFact_table().getSchema_evolution().getSchema_evolution_history().add(schemaEvolutionEntry);
FileFactory.FileType fileType = FileFactory.getFileType(schemaMetadataPath);
if (!FileFactory.isFileExist(schemaMetadataPath, fileType)) {
FileFactory.mkdirs(schemaMetadataPath, fileType);
}
ThriftWriter thriftWriter = new ThriftWriter(schemaFilePath, false);
thriftWriter.open();
thriftWriter.write(thriftTableInfo);
thriftWriter.close();
return CarbonMetadata.getInstance().getCarbonTable(tableInfo.getTableUniqueName());
}
Aggregations