use of org.apache.carbondata.core.metadata.ColumnarFormatVersion in project carbondata by apache.
the class CarbonMetadataUtil method getFileHeader.
/**
* Below method will be used to prepare the file header object for carbondata file
*
* @param isFooterPresent is footer present in carbon data file
* @param columnSchemaList list of column schema
* @param schemaUpdatedTimeStamp schema updated time stamp to be used for restructure scenarios
* @return file header thrift object
*/
public static FileHeader getFileHeader(boolean isFooterPresent, List<ColumnSchema> columnSchemaList, long schemaUpdatedTimeStamp) {
FileHeader fileHeader = new FileHeader();
ColumnarFormatVersion version = CarbonProperties.getInstance().getFormatVersion();
fileHeader.setIs_footer_present(isFooterPresent);
fileHeader.setColumn_schema(columnSchemaList);
fileHeader.setVersion(version.number());
fileHeader.setTime_stamp(schemaUpdatedTimeStamp);
return fileHeader;
}
use of org.apache.carbondata.core.metadata.ColumnarFormatVersion in project carbondata by apache.
the class CarbonMetadataUtil method getFileFooter.
/**
* Below method will be used to get the file footer object
*
* @param infoList blocklet info
* @param cardinalities cardinlaity of dimension columns
* @param columnSchemaList column schema list
* @return file footer
*/
private static FileFooter getFileFooter(List<BlockletInfoColumnar> infoList, int[] cardinalities, List<ColumnSchema> columnSchemaList) {
SegmentInfo segmentInfo = new SegmentInfo();
segmentInfo.setNum_cols(columnSchemaList.size());
segmentInfo.setColumn_cardinalities(CarbonUtil.convertToIntegerList(cardinalities));
ColumnarFormatVersion version = CarbonProperties.getInstance().getFormatVersion();
FileFooter footer = new FileFooter();
footer.setVersion(version.number());
footer.setNum_rows(getTotalNumberOfRows(infoList));
footer.setSegment_info(segmentInfo);
footer.setTable_columns(columnSchemaList);
for (BlockletInfoColumnar info : infoList) {
footer.addToBlocklet_index_list(getBlockletIndex(info));
}
return footer;
}
use of org.apache.carbondata.core.metadata.ColumnarFormatVersion in project carbondata by apache.
the class CarbonMetadataUtil method getIndexHeader.
/**
* Below method will be used to get the index header
*
* @param columnCardinality cardinality of each column
* @param columnSchemaList list of column present in the table
* @return Index header object
*/
public static IndexHeader getIndexHeader(int[] columnCardinality, List<ColumnSchema> columnSchemaList, int bucketNumber) {
// create segment info object
SegmentInfo segmentInfo = new SegmentInfo();
// set the number of columns
segmentInfo.setNum_cols(columnSchemaList.size());
// setting the column cardinality
segmentInfo.setColumn_cardinalities(CarbonUtil.convertToIntegerList(columnCardinality));
// create index header object
IndexHeader indexHeader = new IndexHeader();
ColumnarFormatVersion version = CarbonProperties.getInstance().getFormatVersion();
indexHeader.setVersion(version.number());
// set the segment info
indexHeader.setSegment_info(segmentInfo);
// set the column names
indexHeader.setTable_columns(columnSchemaList);
// set the bucket number
indexHeader.setBucket_id(bucketNumber);
return indexHeader;
}
use of org.apache.carbondata.core.metadata.ColumnarFormatVersion in project carbondata by apache.
the class CarbonFactDataWriterImplV2 method writeBlockletData.
/**
* Below method will be used to write the data to carbon data file
*
* @param holder
* @throws CarbonDataWriterException any problem in writing operation
*/
@Override
public void writeBlockletData(NodeHolder holder) throws CarbonDataWriterException {
if (holder.getEntryCount() == 0) {
return;
}
// size to calculate the size of the blocklet
int size = 0;
// get the blocklet info object
BlockletInfoColumnar blockletInfo = getBlockletInfo(holder, 0);
List<DataChunk2> datachunks = null;
try {
// get all the data chunks
datachunks = CarbonMetadataUtil.getDatachunk2(blockletInfo, thriftColumnSchemaList, dataWriterVo.getSegmentProperties());
} catch (IOException e) {
throw new CarbonDataWriterException("Problem while getting the data chunks", e);
}
// data chunk byte array
byte[][] dataChunkByteArray = new byte[datachunks.size()][];
for (int i = 0; i < dataChunkByteArray.length; i++) {
dataChunkByteArray[i] = CarbonUtil.getByteArray(datachunks.get(i));
// add the data chunk size
size += dataChunkByteArray[i].length;
}
// add row id index length
for (int i = 0; i < holder.getKeyBlockIndexLength().length; i++) {
size += holder.getKeyBlockIndexLength()[i];
}
// add rle index length
for (int i = 0; i < holder.getDataIndexMapLength().length; i++) {
size += holder.getDataIndexMapLength()[i];
}
// add dimension column data page and measure column data page size
long blockletDataSize = holder.getTotalDimensionArrayLength() + holder.getTotalMeasureArrayLength() + size;
// if size of the file already reached threshold size then create a new file and get the file
// channel object
updateBlockletFileChannel(blockletDataSize);
// this is done so carbondata file can be read separately
try {
if (fileChannel.size() == 0) {
ColumnarFormatVersion version = CarbonProperties.getInstance().getFormatVersion();
byte[] header = (CarbonCommonConstants.CARBON_DATA_VERSION_HEADER + version).getBytes();
ByteBuffer buffer = ByteBuffer.allocate(header.length);
buffer.put(header);
buffer.rewind();
fileChannel.write(buffer);
}
} catch (IOException e) {
throw new CarbonDataWriterException("Problem while getting the file channel size", e);
}
// write data to file and get its offset
writeDataToFile(holder, dataChunkByteArray, fileChannel);
// add blocklet info to list
blockletInfoList.add(blockletInfo);
LOGGER.info("A new blocklet is added, its data size is: " + blockletDataSize + " Byte");
}
Aggregations