Java Code Examples for io.prestosql.spi.type.Type#createBlockBuilder()
The following examples show how to use
io.prestosql.spi.type.Type#createBlockBuilder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMinMaxNAggregationFunction.java From presto with Apache License 2.0 | 6 votes |
public static void output(ArrayType outputType, MinMaxNState state, BlockBuilder out) { TypedHeap heap = state.getTypedHeap(); if (heap == null || heap.isEmpty()) { out.appendNull(); return; } Type elementType = outputType.getElementType(); BlockBuilder reversedBlockBuilder = elementType.createBlockBuilder(null, heap.getCapacity()); long startSize = heap.getEstimatedSize(); heap.popAll(reversedBlockBuilder); state.addMemoryUsage(heap.getEstimatedSize() - startSize); BlockBuilder arrayBlockBuilder = out.beginBlockEntry(); for (int i = reversedBlockBuilder.getPositionCount() - 1; i >= 0; i--) { elementType.appendTo(reversedBlockBuilder, i, arrayBlockBuilder); } out.closeEntry(); }
Example 2
Source File: DynamicFilterSourceOperator.java From presto with Apache License 2.0 | 5 votes |
private DynamicFilterSourceOperator( OperatorContext context, Consumer<TupleDomain<DynamicFilterId>> dynamicPredicateConsumer, List<Channel> channels, PlanNodeId planNodeId, int maxFilterPositionsCount, DataSize maxFilterSize) { this.context = requireNonNull(context, "context is null"); this.maxFilterPositionsCount = maxFilterPositionsCount; this.maxFilterSizeInBytes = maxFilterSize.toBytes(); this.dynamicPredicateConsumer = requireNonNull(dynamicPredicateConsumer, "dynamicPredicateConsumer is null"); this.channels = requireNonNull(channels, "channels is null"); this.blockBuilders = new BlockBuilder[channels.size()]; this.valueSets = new TypedSet[channels.size()]; for (int channelIndex = 0; channelIndex < channels.size(); ++channelIndex) { Type type = channels.get(channelIndex).type; this.blockBuilders[channelIndex] = type.createBlockBuilder(null, EXPECTED_BLOCK_BUILDER_SIZE); this.valueSets[channelIndex] = new TypedSet( type, Optional.empty(), blockBuilders[channelIndex], EXPECTED_BLOCK_BUILDER_SIZE, String.format("DynamicFilterSourceOperator_%s_%d", planNodeId, channelIndex), Optional.empty() /* maxBlockMemory */); } }
Example 3
Source File: GroupedTypedHistogram.java From presto with Apache License 2.0 | 5 votes |
public GroupedTypedHistogram(Type type, int expectedCount) { checkArgument(expectedCount > 0, "expectedSize must be greater than zero"); this.type = type; this.bucketId = expectedCount; this.bucketCount = computeBucketCount(expectedCount, MAX_FILL_RATIO); this.mask = bucketCount - 1; this.maxFill = calculateMaxFill(bucketCount, MAX_FILL_RATIO); this.values = type.createBlockBuilder(null, computeBucketCount(expectedCount, GroupedTypedHistogram.MAX_FILL_RATIO)); // buckets and node-arrays (bucket "points" to a node, so 1:1 relationship) buckets = new IntBigArray(-1); buckets.ensureCapacity(bucketCount); counts = new LongBigArray(); valuePositions = new IntBigArray(); valueAndGroupHashes = new LongBigArray(); nextPointers = new IntBigArray(NULL); groupIds = new LongBigArray(-1); // here, one bucket is one node in the hash structure (vs a bucket may be a chain of nodes in closed-hashing with linked list hashing) // ie, this is open-address hashing resizeNodeArrays(bucketCount); // end bucket/node based arrays // per-group arrays: size will be set by external call, same as groups since the number will be the same headPointers = new LongBigArray(NULL); // index into counts/valuePositions nextNodePointer = 0; bucketNodeFactory = this.new BucketNodeFactory(); valueStore = new ValueStore(expectedCount, values); }
Example 4
Source File: TestSmallintArrayType.java From presto with Apache License 2.0 | 5 votes |
public static Block createTestBlock(Type arrayType) { BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 4); arrayType.writeObject(blockBuilder, arrayBlockOf(SMALLINT, 1, 2)); arrayType.writeObject(blockBuilder, arrayBlockOf(SMALLINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(SMALLINT, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(SMALLINT, 100, 200, 300)); return blockBuilder.build(); }
Example 5
Source File: AbstractTestApproximateCountDistinct.java From presto with Apache License 2.0 | 5 votes |
/** * Produce a block with the given values in the last field. */ private static Block createBlock(Type type, List<?> values) { BlockBuilder blockBuilder = type.createBlockBuilder(null, values.size()); for (Object value : values) { Class<?> javaType = type.getJavaType(); if (value == null) { blockBuilder.appendNull(); } else if (javaType == boolean.class) { type.writeBoolean(blockBuilder, (Boolean) value); } else if (javaType == long.class) { type.writeLong(blockBuilder, (Long) value); } else if (javaType == double.class) { type.writeDouble(blockBuilder, (Double) value); } else if (javaType == Slice.class) { Slice slice = (Slice) value; type.writeSlice(blockBuilder, slice, 0, slice.length()); } else { type.writeObject(blockBuilder, value); } } return blockBuilder.build(); }
Example 6
Source File: TestIntegerVarcharMapType.java From presto with Apache License 2.0 | 5 votes |
public static Block createTestBlock(Type mapType) { BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 2); mapType.writeObject(blockBuilder, mapBlockOf(INTEGER, VARCHAR, ImmutableMap.of(1, "hi"))); mapType.writeObject(blockBuilder, mapBlockOf(INTEGER, VARCHAR, ImmutableMap.of(1, "2", 2, "hello"))); return blockBuilder.build(); }
Example 7
Source File: ArrayBlockBuilder.java From presto with Apache License 2.0 | 5 votes |
public ArrayBlockBuilder(Type elementType, BlockBuilderStatus blockBuilderStatus, int expectedEntries) { this( blockBuilderStatus, elementType.createBlockBuilder(blockBuilderStatus, expectedEntries), expectedEntries); }
Example 8
Source File: TypedHeap.java From presto with Apache License 2.0 | 5 votes |
public TypedHeap(BlockComparator comparator, Type type, int capacity) { this.comparator = comparator; this.type = type; this.capacity = capacity; this.heapIndex = new int[capacity]; this.heapBlockBuilder = type.createBlockBuilder(null, capacity); }
Example 9
Source File: ArrayConcatUtils.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static Block prependElement(Type elementType, long value, Block block) { BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1); elementType.writeLong(blockBuilder, value); for (int i = 0; i < block.getPositionCount(); i++) { elementType.appendTo(block, i, blockBuilder); } return blockBuilder.build(); }
Example 10
Source File: BlockAssertions.java From presto with Apache License 2.0 | 5 votes |
public static Block createTypedLongsBlock(Type type, Iterable<Long> values) { BlockBuilder builder = type.createBlockBuilder(null, 100); for (Long value : values) { if (value == null) { builder.appendNull(); } else { type.writeLong(builder, value); } } return builder.build(); }
Example 11
Source File: TestColorArrayType.java From presto with Apache License 2.0 | 5 votes |
public static Block createTestBlock(Type arrayType) { BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 4); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2)); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2, 3)); arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 100, 200, 300)); return blockBuilder.build(); }
Example 12
Source File: ConstantPageProjection.java From presto with Apache License 2.0 | 5 votes |
public ConstantPageProjection(Object value, Type type) { this.type = type; BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); writeNativeValue(type, blockBuilder, value); this.value = blockBuilder.build(); }
Example 13
Source File: ArrayConcatUtils.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static Block appendElement(Type elementType, Block block, Object value) { BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1); for (int i = 0; i < block.getPositionCount(); i++) { elementType.appendTo(block, i, blockBuilder); } elementType.writeObject(blockBuilder, value); return blockBuilder.build(); }
Example 14
Source File: StructuralTestUtil.java From presto with Apache License 2.0 | 5 votes |
public static Block arrayBlockOf(Type elementType, Object... values) { BlockBuilder blockBuilder = elementType.createBlockBuilder(null, 1024); for (Object value : values) { appendToBlockBuilder(elementType, value, blockBuilder); } return blockBuilder.build(); }
Example 15
Source File: MapValues.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("K") @TypeParameter("V") @SqlType("array(V)") public static Block getValues( @TypeParameter("V") Type valueType, @SqlType("map(K,V)") Block block) { BlockBuilder blockBuilder = valueType.createBlockBuilder(null, block.getPositionCount() / 2); for (int i = 0; i < block.getPositionCount(); i += 2) { valueType.appendTo(block, i + 1, blockBuilder); } return blockBuilder.build(); }
Example 16
Source File: ArrayConcatUtils.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static Block prependElement(Type elementType, Object value, Block block) { BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1); elementType.writeObject(blockBuilder, value); for (int i = 0; i < block.getPositionCount(); i++) { elementType.appendTo(block, i, blockBuilder); } return blockBuilder.build(); }
Example 17
Source File: TestBigintVarcharMapType.java From presto with Apache License 2.0 | 5 votes |
public static Block createTestBlock(Type mapType) { BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 2); mapType.writeObject(blockBuilder, mapBlockOf(BIGINT, VARCHAR, ImmutableMap.of(1, "hi"))); mapType.writeObject(blockBuilder, mapBlockOf(BIGINT, VARCHAR, ImmutableMap.of(1, "2", 2, "hello"))); return blockBuilder.build(); }
Example 18
Source File: StructuralTestUtil.java From presto with Apache License 2.0 | 5 votes |
public static Block arrayBlockOf(Type elementType, Object... values) { BlockBuilder blockBuilder = elementType.createBlockBuilder(null, values.length); for (Object value : values) { appendToBlockBuilder(elementType, value, blockBuilder); } return blockBuilder.build(); }
Example 19
Source File: PrestoMap.java From transport with BSD 2-Clause "Simplified" License | 5 votes |
public PrestoMap(Type mapType, StdFactory stdFactory) { BlockBuilder mutable = mapType.createBlockBuilder(new PageBuilderStatus().createBlockBuilderStatus(), 1); mutable.beginBlockEntry(); mutable.closeEntry(); _block = ((MapType) mapType).getObject(mutable.build(), 0); _keyType = ((MapType) mapType).getKeyType(); _valueType = ((MapType) mapType).getValueType(); _mapType = mapType; _stdFactory = stdFactory; _keyEqualsMethod = ((PrestoFactory) stdFactory).getScalarFunctionImplementation( ((PrestoFactory) stdFactory).resolveOperator(OperatorType.EQUAL, ImmutableList.of(_keyType, _keyType))) .getMethodHandle(); }
Example 20
Source File: ArrayConcatUtils.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static Block appendElement(Type elementType, Block block, double value) { BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1); for (int i = 0; i < block.getPositionCount(); i++) { elementType.appendTo(block, i, blockBuilder); } elementType.writeDouble(blockBuilder, value); return blockBuilder.build(); }