Search in sources :

Example 1 with VariableWidthBlock

use of io.prestosql.spi.block.VariableWidthBlock in project hetu-core by openlookeng.

the class SliceData method toBlock.

@Override
public Block toBlock(Type desiredType) {
    checkArgument(desiredType.getJavaType() == Slice.class, "type doesn't match: %s", desiredType);
    Slice values = bytes == null ? Slices.EMPTY_SLICE : Slices.wrappedBuffer(bytes);
    int numberOfRecords = numberOfRecords();
    return new VariableWidthBlock(numberOfRecords, values, calculateOffsets(sizes, nulls, numberOfRecords), Optional.ofNullable(nulls));
}
Also used : Slice(io.airlift.slice.Slice) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock)

Example 2 with VariableWidthBlock

use of io.prestosql.spi.block.VariableWidthBlock in project hetu-core by openlookeng.

the class SliceStreamReader method setDictionary.

@Override
public void setDictionary(CarbonDictionary dictionary) {
    super.setDictionary(dictionary);
    if (dictionary == null) {
        dictionaryBlock = null;
        this.isLocalDict = false;
        return;
    }
    boolean[] nulls = new boolean[dictionary.getDictionarySize()];
    nulls[0] = true;
    nulls[1] = true;
    int[] dictOffsets = new int[dictionary.getDictionarySize() + 1];
    int[] truncatedDictOffsets = new int[dictionary.getDictionarySize() + 1];
    int size = 0;
    for (int i = 0; i < dictionary.getDictionarySize(); i++) {
        dictOffsets[i] = size;
        if (dictionary.getDictionaryValue(i) != null) {
            size += dictionary.getDictionaryValue(i).length;
            if (maxLength >= 0) {
                if (i < 2) {
                    truncatedDictOffsets[i] = dictOffsets[i];
                } else {
                    int actualLength = dictionary.getDictionaryValue(i).length;
                    int truncatedLength = computeTruncatedLength(wrappedBuffer(dictionary.getDictionaryValue(i)), 0, actualLength, maxLength, isCharType);
                    truncatedDictOffsets[i + 1] = truncatedDictOffsets[i] + truncatedLength;
                }
            }
        }
    }
    byte[] singleArrayDictValues = new byte[size];
    byte[] truncatedSingleArrayDictValues = new byte[size];
    for (int i = 0; i < dictionary.getDictionarySize(); i++) {
        if (dictionary.getDictionaryValue(i) != null) {
            System.arraycopy(dictionary.getDictionaryValue(i), 0, singleArrayDictValues, dictOffsets[i], dictionary.getDictionaryValue(i).length);
            if (maxLength >= 0) {
                System.arraycopy(dictionary.getDictionaryValue(i), 0, truncatedSingleArrayDictValues, truncatedDictOffsets[i], dictionary.getDictionaryValue(i).length);
            }
        }
    }
    if (maxLength < 0) {
        dictOffsets[dictOffsets.length - 1] = size;
        dictionaryBlock = new VariableWidthBlock(dictionary.getDictionarySize(), Slices.wrappedBuffer(singleArrayDictValues), dictOffsets, Optional.of(nulls));
    } else {
        dictionaryBlock = new VariableWidthBlock(dictionary.getDictionarySize(), Slices.wrappedBuffer(truncatedSingleArrayDictValues), truncatedDictOffsets, Optional.of(nulls));
    }
    this.isLocalDict = true;
}
Also used : VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock)

Example 3 with VariableWidthBlock

use of io.prestosql.spi.block.VariableWidthBlock in project hetu-core by openlookeng.

the class TestHBase method testPageSink.

/**
 * testPageSink
 */
@Test
public void testPageSink() {
    HBasePageSinkProvider hpsp = new HBasePageSinkProvider(hconn);
    HBaseTableHandle insertHandler = new HBaseTableHandle("hbase", "test_table", 0, hconn.getTable("hbase.test_table").getColumns(), hconn.getTable("hbase.test_table").getSerializerClassName(), Optional.of("test_table"), OptionalLong.empty());
    if (insertHandler instanceof ConnectorInsertTableHandle) {
        ConnectorPageSink cps = hpsp.createPageSink(new HBaseTransactionHandle(), session, (ConnectorInsertTableHandle) insertHandler);
        long completedBytes = cps.getCompletedBytes();
        long sysMemUsage = cps.getSystemMemoryUsage();
        long cpuNanos = cps.getValidationCpuNanos();
        assertTrue(cpuNanos >= 0);
        assertTrue(sysMemUsage >= 0);
        assertTrue(completedBytes >= 0);
        int[] offsets = { 0, 4 };
        Block rowkey = new VariableWidthBlock(1, TestSliceUtils.createSlice("0001"), offsets, Optional.empty());
        int[] offset2 = { 0, 5 };
        Block name = new VariableWidthBlock(1, TestSliceUtils.createSlice("name2"), offset2, Optional.empty());
        long[] longs = new long[1];
        longs[0] = 12;
        Block age = new LongArrayBlock(1, Optional.empty(), longs);
        int[] ints = new int[1];
        ints[0] = 17832;
        Block gender = new IntArrayBlock(1, Optional.empty(), ints);
        Block columnT = new LongArrayBlock(1, Optional.empty(), longs);
        Page page = new Page(rowkey, name, age, gender, columnT);
        assertEquals(NOT_BLOCKED, cps.appendPage(page));
        cps.abort();
    }
}
Also used : IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) HBasePageSinkProvider(io.hetu.core.plugin.hbase.query.HBasePageSinkProvider) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) HBaseTransactionHandle(io.hetu.core.plugin.hbase.connector.HBaseTransactionHandle) Page(io.prestosql.spi.Page) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) Block(io.prestosql.spi.block.Block) IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) ConnectorPageSink(io.prestosql.spi.connector.ConnectorPageSink) HBaseTableHandle(io.hetu.core.plugin.hbase.connector.HBaseTableHandle) Test(org.testng.annotations.Test)

Example 4 with VariableWidthBlock

use of io.prestosql.spi.block.VariableWidthBlock in project hetu-core by openlookeng.

the class AbstractTestHBaseRowSerializer method testGetArrayFromBlock.

/**
 * testGetArrayFromBlock
 */
@Test
public void testGetArrayFromBlock() {
    int[] offsets = { 0, 4 };
    Block rowkey = new VariableWidthBlock(1, TestSliceUtils.createSlice("0001"), offsets, Optional.empty());
    HBaseRowSerializer.getArrayFromBlock(VARCHAR, rowkey);
}
Also used : VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) ShortArrayBlock(io.prestosql.spi.block.ShortArrayBlock) Block(io.prestosql.spi.block.Block) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) Test(org.testng.annotations.Test)

Example 5 with VariableWidthBlock

use of io.prestosql.spi.block.VariableWidthBlock in project carbondata by apache.

the class SliceStreamReader method setDictionary.

@Override
public void setDictionary(CarbonDictionary dictionary) {
    super.setDictionary(dictionary);
    if (dictionary == null) {
        dictionaryBlock = null;
        this.isLocalDict = false;
        return;
    }
    boolean[] nulls = new boolean[dictionary.getDictionarySize()];
    nulls[0] = true;
    nulls[1] = true;
    int[] dictOffsets = new int[dictionary.getDictionarySize() + 1];
    int size = 0;
    for (int i = 0; i < dictionary.getDictionarySize(); i++) {
        dictOffsets[i] = size;
        if (dictionary.getDictionaryValue(i) != null) {
            size += dictionary.getDictionaryValue(i).length;
        }
    }
    byte[] singleArrayDictValues = new byte[size];
    for (int i = 0; i < dictionary.getDictionarySize(); i++) {
        if (dictionary.getDictionaryValue(i) != null) {
            System.arraycopy(dictionary.getDictionaryValue(i), 0, singleArrayDictValues, dictOffsets[i], dictionary.getDictionaryValue(i).length);
        }
    }
    dictOffsets[dictOffsets.length - 1] = size;
    dictionaryBlock = new VariableWidthBlock(dictionary.getDictionarySize(), Slices.wrappedBuffer(singleArrayDictValues), dictOffsets, Optional.of(nulls));
    this.isLocalDict = true;
}
Also used : VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock)

Aggregations

VariableWidthBlock (io.prestosql.spi.block.VariableWidthBlock)11 Block (io.prestosql.spi.block.Block)5 Test (org.testng.annotations.Test)4 Slice (io.airlift.slice.Slice)3 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)2 ShortArrayBlock (io.prestosql.spi.block.ShortArrayBlock)2 HBaseTableHandle (io.hetu.core.plugin.hbase.connector.HBaseTableHandle)1 HBaseTransactionHandle (io.hetu.core.plugin.hbase.connector.HBaseTransactionHandle)1 HBasePageSinkProvider (io.hetu.core.plugin.hbase.query.HBasePageSinkProvider)1 OrcCorruptionException (io.prestosql.orc.OrcCorruptionException)1 Page (io.prestosql.spi.Page)1 PrestoException (io.prestosql.spi.PrestoException)1 IntArrayBlock (io.prestosql.spi.block.IntArrayBlock)1 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)1 ConnectorInsertTableHandle (io.prestosql.spi.connector.ConnectorInsertTableHandle)1 ConnectorPageSink (io.prestosql.spi.connector.ConnectorPageSink)1 MapType (io.prestosql.spi.type.MapType)1 MethodHandle (java.lang.invoke.MethodHandle)1