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));
}
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;
}
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();
}
}
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);
}
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;
}
Aggregations