use of io.prestosql.spi.block.VariableWidthBlock in project hetu-core by openlookeng.
the class TestVariableWidthBlock method testCompactBlock.
@Test
public void testCompactBlock() {
Slice compactSlice = Slices.copyOf(createExpectedValue(16));
Slice incompactSlice = Slices.copyOf(createExpectedValue(20)).slice(0, 16);
int[] offsets = { 0, 1, 1, 2, 4, 8, 16 };
boolean[] valueIsNull = { false, true, false, false, false, false };
testCompactBlock(new VariableWidthBlock(0, EMPTY_SLICE, new int[1], Optional.empty()));
testCompactBlock(new VariableWidthBlock(valueIsNull.length, compactSlice, offsets, Optional.of(valueIsNull)));
testIncompactBlock(new VariableWidthBlock(valueIsNull.length - 1, compactSlice, offsets, Optional.of(valueIsNull)));
// underlying slice is not compact
testIncompactBlock(new VariableWidthBlock(valueIsNull.length, incompactSlice, offsets, Optional.of(valueIsNull)));
}
use of io.prestosql.spi.block.VariableWidthBlock in project boostkit-bigdata by kunpengcompute.
the class OperatorUtils method buildVariableWidthOmniBlock.
private static VariableWidthOmniBlock buildVariableWidthOmniBlock(VecAllocator vecAllocator, Block block, int positionCount, boolean isRLE) {
if (!isRLE) {
int[] offsets = ((VariableWidthBlock) block).getOffsets();
int offset = block.getBlockOffset();
boolean[] valueIsNull = block.getValueNulls();
Slice slice = ((VariableWidthBlock) block).getRawSlice(0);
return new VariableWidthOmniBlock(vecAllocator, offset, positionCount, slice, offsets, transformBooleanToByte(valueIsNull));
} else {
AbstractVariableWidthBlock variableWidthBlock = (AbstractVariableWidthBlock) ((RunLengthEncodedBlock) block).getValue();
VarcharVec vec = new VarcharVec(vecAllocator, variableWidthBlock.getSliceLength(0) * positionCount, positionCount);
for (int i = 0; i < positionCount; i++) {
if (block.isNull(i)) {
vec.setNull(i);
} else {
vec.set(i, (byte[]) block.get(i));
}
}
return new VariableWidthOmniBlock(positionCount, vec);
}
}
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