use of org.apache.carbondata.core.datastore.page.ComplexColumnPage in project carbondata by apache.
the class TablePage method addComplexColumn.
/**
* add a complex column into internal member compleDimensionPage
*
* @param index index of the complexDimensionPage
* @param rowId Id of the input row
* @param complexColumns byte array the complex columm to be added, extracted of input row
*/
// TODO: this function should be refactoried, ColumnPage should support complex type encoding
// directly instead of doing it here
private void addComplexColumn(int index, int rowId, byte[] complexColumns) {
GenericDataType complexDataType = model.getComplexIndexMap().get(index + model.getPrimitiveDimLens().length);
// initialize the page if first row
if (rowId == 0) {
int depthInComplexColumn = complexDataType.getColsCount();
getComplexDimensionPage()[index] = new ComplexColumnPage(pageSize, depthInComplexColumn);
}
int depthInComplexColumn = getComplexDimensionPage()[index].getDepth();
// this is the encoded columnar data which will be added to page,
// size of this list is the depth of complex column, we will fill it by input data
List<ArrayList<byte[]>> encodedComplexColumnar = new ArrayList<>();
for (int k = 0; k < depthInComplexColumn; k++) {
encodedComplexColumnar.add(new ArrayList<byte[]>());
}
// encode the complex type data and fill columnsArray
try {
ByteBuffer byteArrayInput = ByteBuffer.wrap(complexColumns);
ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutput);
complexDataType.parseAndBitPack(byteArrayInput, dataOutputStream, model.getComplexDimensionKeyGenerator());
complexDataType.getColumnarDataForComplexType(encodedComplexColumnar, ByteBuffer.wrap(byteArrayOutput.toByteArray()));
byteArrayOutput.close();
} catch (IOException | KeyGenException e) {
throw new CarbonDataWriterException("Problem while bit packing and writing complex datatype", e);
}
for (int depth = 0; depth < depthInComplexColumn; depth++) {
getComplexDimensionPage()[index].putComplexData(rowId, depth, encodedComplexColumnar.get(depth));
}
}
Aggregations