use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class MapConstructor method createMap.
@UsedByGeneratedCode
public static Block createMap(MapType mapType, MethodHandle keyEqual, MethodHandle keyHashCode, MethodHandle keyIndeterminate, State state, ConnectorSession session, Block keyBlock, Block valueBlock) {
checkCondition(keyBlock.getPositionCount() == valueBlock.getPositionCount(), INVALID_FUNCTION_ARGUMENT, "Key and value arrays must be the same length");
PageBuilder pageBuilder = state.getPageBuilder();
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
MapBlockBuilder mapBlockBuilder = (MapBlockBuilder) pageBuilder.getBlockBuilder(0);
BlockBuilder blockBuilder = mapBlockBuilder.beginBlockEntry();
for (int i = 0; i < keyBlock.getPositionCount(); i++) {
if (keyBlock.isNull(i)) {
// close block builder before throwing as we may be in a TRY() call
// so that subsequent calls do not find it in an inconsistent state
mapBlockBuilder.closeEntry();
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be null");
}
Object keyObject = readNativeValue(mapType.getKeyType(), keyBlock, i);
try {
if ((boolean) keyIndeterminate.invoke(keyObject, false)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be indeterminate: " + mapType.getKeyType().getObjectValue(session, keyBlock, i));
}
} catch (Throwable t) {
mapBlockBuilder.closeEntry();
throw internalError(t);
}
mapType.getKeyType().appendTo(keyBlock, i, blockBuilder);
mapType.getValueType().appendTo(valueBlock, i, blockBuilder);
}
try {
mapBlockBuilder.closeEntryStrict();
} catch (DuplicateMapKeyException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getDetailedMessage(mapType.getKeyType(), session), e);
} finally {
pageBuilder.declarePosition();
}
return mapType.getObject(mapBlockBuilder, mapBlockBuilder.getPositionCount() - 1);
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class TestRealHistogramAggregation method makeInput.
private static Page makeInput(int numberOfBuckets) {
PageBuilder builder = new PageBuilder(ImmutableList.of(BIGINT, REAL, DOUBLE));
for (int i = 0; i < 100; i++) {
builder.declarePosition();
BIGINT.writeLong(builder.getBlockBuilder(0), numberOfBuckets);
// value
REAL.writeLong(builder.getBlockBuilder(1), i);
// weight
DOUBLE.writeDouble(builder.getBlockBuilder(2), 1);
}
return builder.build();
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class ZipWithFunction method zipWith.
public static Block zipWith(Type leftElementType, Type rightElementType, ArrayType outputArrayType, Object state, Block leftBlock, Block rightBlock, BinaryFunctionInterface function) {
Type outputElementType = outputArrayType.getElementType();
int leftPositionCount = leftBlock.getPositionCount();
int rightPositionCount = rightBlock.getPositionCount();
int outputPositionCount = max(leftPositionCount, rightPositionCount);
PageBuilder pageBuilder = (PageBuilder) state;
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
BlockBuilder arrayBlockBuilder = pageBuilder.getBlockBuilder(0);
BlockBuilder blockBuilder = arrayBlockBuilder.beginBlockEntry();
for (int position = 0; position < outputPositionCount; position++) {
Object left = position < leftPositionCount ? readNativeValue(leftElementType, leftBlock, position) : null;
Object right = position < rightPositionCount ? readNativeValue(rightElementType, rightBlock, position) : null;
Object output;
try {
output = function.apply(left, right);
} catch (Throwable throwable) {
// Restore pageBuilder into a consistent state.
arrayBlockBuilder.closeEntry();
pageBuilder.declarePosition();
throwIfUnchecked(throwable);
throw new RuntimeException(throwable);
}
writeNativeValue(outputElementType, blockBuilder, output);
}
arrayBlockBuilder.closeEntry();
pageBuilder.declarePosition();
return outputArrayType.getObject(arrayBlockBuilder, arrayBlockBuilder.getPositionCount() - 1);
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class BenchmarkGroupByHash method createVarcharPages.
private static List<Page> createVarcharPages(int positionCount, int groupCount, int channelCount, boolean hashEnabled) {
List<Type> types = Collections.nCopies(channelCount, VARCHAR);
ImmutableList.Builder<Page> pages = ImmutableList.builder();
if (hashEnabled) {
types = ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT)));
}
PageBuilder pageBuilder = new PageBuilder(types);
for (int position = 0; position < positionCount; position++) {
int rand = ThreadLocalRandom.current().nextInt(groupCount);
Slice value = Slices.wrappedBuffer(ByteBuffer.allocate(4).putInt(rand));
pageBuilder.declarePosition();
for (int channel = 0; channel < channelCount; channel++) {
VARCHAR.writeSlice(pageBuilder.getBlockBuilder(channel), value);
}
if (hashEnabled) {
BIGINT.writeLong(pageBuilder.getBlockBuilder(channelCount), VarcharOperators.hashCode(value));
}
if (pageBuilder.isFull()) {
pages.add(pageBuilder.build());
pageBuilder.reset();
}
}
pages.add(pageBuilder.build());
return pages.build();
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class BenchmarkGroupByHash method addPagePreCompute.
@Benchmark
@OperationsPerInvocation(POSITIONS)
public Object addPagePreCompute(BenchmarkData data) {
GroupByHash groupByHash = new MultiChannelGroupByHash(data.getTypes(), data.getChannels(), data.getHashChannel(), EXPECTED_SIZE, false, getJoinCompiler(), NOOP);
data.getPages().forEach(p -> groupByHash.addPage(p).process());
ImmutableList.Builder<Page> pages = ImmutableList.builder();
PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
for (int groupId = 0; groupId < groupByHash.getGroupCount(); groupId++) {
pageBuilder.declarePosition();
groupByHash.appendValuesTo(groupId, pageBuilder, 0);
if (pageBuilder.isFull()) {
pages.add(pageBuilder.build());
pageBuilder.reset();
}
}
pages.add(pageBuilder.build());
return pageBuilder.build();
}
Aggregations