use of com.facebook.presto.common.block.PageBuilderStatus in project presto by prestodb.
the class ArrayCombinationsFunction method combinations.
@TypeParameter("T")
@SqlType("array(array(T))")
public static Block combinations(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block array, @SqlType(StandardTypes.INTEGER) long n) {
int arrayLength = array.getPositionCount();
int combinationLength = toIntExact(n);
checkCondition(combinationLength >= 0, INVALID_FUNCTION_ARGUMENT, "combination size must not be negative: %s", combinationLength);
checkCondition(combinationLength <= MAX_COMBINATION_LENGTH, INVALID_FUNCTION_ARGUMENT, "combination size must not exceed %s: %s", MAX_COMBINATION_LENGTH, combinationLength);
ArrayType arrayType = new ArrayType(elementType);
if (combinationLength > arrayLength) {
return arrayType.createBlockBuilder(new PageBuilderStatus().createBlockBuilderStatus(), 0).build();
}
int combinationCount = combinationCount(arrayLength, combinationLength);
checkCondition(combinationCount * (long) combinationLength <= MAX_RESULT_ELEMENTS, INVALID_FUNCTION_ARGUMENT, "combinations exceed max size");
int[] ids = new int[combinationCount * combinationLength];
int idsPosition = 0;
int[] combination = firstCombination(combinationLength);
do {
arraycopy(combination, 0, ids, idsPosition, combinationLength);
idsPosition += combinationLength;
} while (nextCombination(combination, arrayLength));
verify(idsPosition == ids.length, "idsPosition != ids.length, %s and %s respectively", idsPosition, ids.length);
int[] offsets = new int[combinationCount + 1];
setAll(offsets, i -> i * combinationLength);
return ArrayBlock.fromElementBlock(combinationCount, Optional.empty(), offsets, new DictionaryBlock(array, ids));
}
use of com.facebook.presto.common.block.PageBuilderStatus in project presto by prestodb.
the class PageBuilder method reset.
public void reset() {
if (isEmpty()) {
return;
}
pageBuilderStatus = new PageBuilderStatus(pageBuilderStatus.getMaxPageSizeInBytes());
declaredPositions = 0;
for (int i = 0; i < blockBuilders.length; i++) {
blockBuilders[i] = blockBuilders[i].newBlockBuilderLike(pageBuilderStatus.createBlockBuilderStatus());
}
}
Aggregations