Search in sources :

Example 1 with ComplexColumnPage

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));
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) CarbonDataWriterException(org.apache.carbondata.processing.store.writer.exception.CarbonDataWriterException) GenericDataType(org.apache.carbondata.processing.datatypes.GenericDataType) KeyGenException(org.apache.carbondata.core.keygenerator.KeyGenException) ComplexColumnPage(org.apache.carbondata.core.datastore.page.ComplexColumnPage)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 ComplexColumnPage (org.apache.carbondata.core.datastore.page.ComplexColumnPage)1 KeyGenException (org.apache.carbondata.core.keygenerator.KeyGenException)1 GenericDataType (org.apache.carbondata.processing.datatypes.GenericDataType)1 CarbonDataWriterException (org.apache.carbondata.processing.store.writer.exception.CarbonDataWriterException)1