当前位置: 首页>>代码示例>>Java>>正文


Java BlockBuilder类代码示例

本文整理汇总了Java中com.facebook.presto.spi.block.BlockBuilder的典型用法代码示例。如果您正苦于以下问题:Java BlockBuilder类的具体用法?Java BlockBuilder怎么用?Java BlockBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BlockBuilder类属于com.facebook.presto.spi.block包,在下文中一共展示了BlockBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseAgent

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
@ScalarFunction("parse_agent")
@Description("Returns Map, which has keys such as 'category', 'name', 'os', 'version', 'vendor' and 'os_version'")
@SqlType("map<varchar,varchar>")
public Block parseAgent(@TypeParameter("map<varchar,varchar>") Type mapType, @SqlType(StandardTypes.VARCHAR) Slice slice) {
    String argument = slice.toStringUtf8();
    Map<String, String> stringMap = Classifier.parse(argument);

    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }

    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder singleMapBlockBuilder = blockBuilder.beginBlockEntry();
    for (Map.Entry<String, String> entry : stringMap.entrySet()) {
        VARCHAR.writeSlice(singleMapBlockBuilder, Slices.utf8Slice(entry.getKey()));
        VARCHAR.writeSlice(singleMapBlockBuilder, Slices.utf8Slice(entry.getValue()));
    }
    blockBuilder.closeEntry();
    pageBuilder.declarePosition();

    return (Block) mapType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1);
}
 
开发者ID:wyukawa,项目名称:presto-woothee,代码行数:23,代码来源:ParseAgentFuntion.java

示例2: output

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
@OutputFunction("array<bigint>")
public static void output(DigestAndPercentileArrayState state, BlockBuilder out)
{
    QuantileDigest digest = state.getDigest();
    List<Double> percentiles = state.getPercentiles();

    if (percentiles == null || digest == null) {
        out.appendNull();
        return;
    }

    BlockBuilder blockBuilder = out.beginBlockEntry();

    for (int i = 0; i < percentiles.size(); i++) {
        Double percentile = percentiles.get(i);
        BIGINT.writeLong(blockBuilder, digest.getQuantile(percentile));
    }

    out.closeEntry();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:21,代码来源:ApproximateLongPercentileArrayAggregations.java

示例3: serializePrimitive

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
private static void serializePrimitive(Type type, BlockBuilder builder, Object object) {
    requireNonNull(builder, "parent builder is null");

    if (object == null) {
        builder.appendNull();
        return;
    }

    if (BOOLEAN.equals(type)) {
        BOOLEAN.writeBoolean(builder, (Boolean) object);
    } else if (BIGINT.equals(type) || INTEGER.equals(type) || SMALLINT.equals(type) || TINYINT.equals(type)
            || REAL.equals(type) || DATE.equals(type) || TIMESTAMP.equals(type)) {
        type.writeLong(builder, getLongExpressedValue(object));
    } else if (DOUBLE.equals(type)) {
        DOUBLE.writeDouble(builder, ((Number) object).doubleValue());
    } else if (isVarcharType(type) || VARBINARY.equals(type) || isCharType(type)) {
        type.writeSlice(builder, getSliceExpressedValue(object, type));
    } else {
        throw new UnsupportedOperationException("Unsupported primitive type: " + type);
    }
}
 
开发者ID:xiaoyao1991,项目名称:presto-ethereum,代码行数:22,代码来源:EthereumRecordCursor.java

示例4: testStateDeserializer

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
@Test
public void testStateDeserializer()
        throws Exception
{
    String[] keys = {"loooooong string", "short string"};
    double[] values = {3.14, 2.71};

    MaxOrMinByStateSerializer serializer = new MaxOrMinByStateSerializer(DOUBLE, VARCHAR);
    BlockBuilder builder = new RowType(ImmutableList.of(VARCHAR, DOUBLE), Optional.empty()).createBlockBuilder(new BlockBuilderStatus(), 2);

    for (int i = 0; i < keys.length; i++) {
        serializer.serialize(makeState(keys[i], values[i]), builder);
    }

    Block serialized = builder.build();

    for (int i = 0; i < keys.length; i++) {
        MaxOrMinByState deserialized = new MaxOrMinByStateFactory().createSingleState();
        serializer.deserialize(serialized, i, deserialized);
        assertEquals(VARCHAR.getSlice(deserialized.getKey(), 0), Slices.utf8Slice(keys[i]));
        assertEquals(DOUBLE.getDouble(deserialized.getValue(), 0), values[i]);
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:24,代码来源:TestMinMaxByAggregation.java

示例5: createAlternatingNullsBlock

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
public Block[] createAlternatingNullsBlock(List<Type> types, Block... sequenceBlocks)
{
    Block[] alternatingNullsBlocks = new Block[sequenceBlocks.length];
    for (int i = 0; i < sequenceBlocks.length; i++) {
        int positionCount = sequenceBlocks[i].getPositionCount();
        Type type = types.get(i);
        BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), positionCount);
        for (int position = 0; position < positionCount; position++) {
            // append null
            blockBuilder.appendNull();
            // append value
            type.appendTo(sequenceBlocks[i], position, blockBuilder);
        }
        alternatingNullsBlocks[i] = blockBuilder.build();
    }
    return alternatingNullsBlocks;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:18,代码来源:AbstractTestAggregationFunction.java

示例6: createTestBlock

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
public static Block createTestBlock()
{
    BlockBuilder blockBuilder = DATE.createBlockBuilder(new BlockBuilderStatus(), 15);
    DATE.writeLong(blockBuilder, 1111);
    DATE.writeLong(blockBuilder, 1111);
    DATE.writeLong(blockBuilder, 1111);
    DATE.writeLong(blockBuilder, 2222);
    DATE.writeLong(blockBuilder, 2222);
    DATE.writeLong(blockBuilder, 2222);
    DATE.writeLong(blockBuilder, 2222);
    DATE.writeLong(blockBuilder, 2222);
    DATE.writeLong(blockBuilder, 3333);
    DATE.writeLong(blockBuilder, 3333);
    DATE.writeLong(blockBuilder, 4444);
    return blockBuilder.build();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:17,代码来源:TestDateType.java

示例7: testPrimitiveByteSerialization

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
@Test
public void testPrimitiveByteSerialization()
{
    StateCompiler compiler = new StateCompiler();

    AccumulatorStateFactory<ByteState> factory = compiler.generateStateFactory(ByteState.class);
    AccumulatorStateSerializer<ByteState> serializer = compiler.generateStateSerializer(ByteState.class);
    ByteState state = factory.createSingleState();
    ByteState deserializedState = factory.createSingleState();

    state.setByte((byte) 3);

    BlockBuilder builder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), 1);
    serializer.serialize(state, builder);

    Block block = builder.build();
    serializer.deserialize(block, 0, deserializedState);
    assertEquals(deserializedState.getByte(), state.getByte());
}
 
开发者ID:y-lan,项目名称:presto,代码行数:20,代码来源:TestStateCompiler.java

示例8: testMapHistograms

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
@Test
public void testMapHistograms()
        throws Exception
{
    MapType innerMapType = new MapType(VARCHAR, VARCHAR);
    MapType mapType = new MapType(innerMapType, BIGINT);
    InternalAggregationFunction aggregationFunction = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature().toString(), innerMapType.getTypeSignature().toString()));

    BlockBuilder builder = innerMapType.createBlockBuilder(new BlockBuilderStatus(), 3);
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("a", "b")));
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("c", "d")));
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("e", "f")));

    assertAggregation(
            aggregationFunction,
            1.0,
            ImmutableMap.of(ImmutableMap.of("a", "b"), 1L, ImmutableMap.of("c", "d"), 1L, ImmutableMap.of("e", "f"), 1L),
            builder.build());
}
 
开发者ID:y-lan,项目名称:presto,代码行数:20,代码来源:TestHistogram.java

示例9: testMassive

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
@Test
public void testMassive()
    throws Exception
{
    BlockBuilder inputBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), 5000);

    TypedHistogram typedHistogram = new TypedHistogram(BIGINT, 1000);
    IntStream.range(1, 2000)
            .flatMap(i -> IntStream.iterate(i, IntUnaryOperator.identity()).limit(i))
            .forEach(j -> BIGINT.writeLong(inputBlockBuilder, j));

    Block inputBlock = inputBlockBuilder.build();
    for (int i = 0; i < inputBlock.getPositionCount(); i++) {
        typedHistogram.add(i, inputBlock, 1);
    }

    Block outputBlock = typedHistogram.serialize();
    for (int i = 0; i < outputBlock.getPositionCount(); i += 2) {
        assertEquals(BIGINT.getLong(outputBlock, i + 1), BIGINT.getLong(outputBlock, i));
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:22,代码来源:TestTypedHistogram.java

示例10: createBlockBuilderWithValues

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
private BlockBuilder createBlockBuilderWithValues(long[][][] expectedValues)
{
    BlockBuilder blockBuilder = new ArrayBlockBuilder(new ArrayBlockBuilder(BIGINT, new BlockBuilderStatus(), 100, 100), new BlockBuilderStatus(), 100);
    for (long[][] expectedValue : expectedValues) {
        if (expectedValue == null) {
            blockBuilder.appendNull();
        }
        else {
            BlockBuilder intermediateBlockBuilder = new ArrayBlockBuilder(BIGINT, new BlockBuilderStatus(), 100, 100);
            for (int j = 0; j < expectedValue.length; j++) {
                if (expectedValue[j] == null) {
                    intermediateBlockBuilder.appendNull();
                }
                else {
                    BlockBuilder innerMostBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), expectedValue.length);
                    for (long v : expectedValue[j]) {
                        BIGINT.writeLong(innerMostBlockBuilder, v);
                    }
                    intermediateBlockBuilder.writeObject(innerMostBlockBuilder.build()).closeEntry();
                }
            }
            blockBuilder.writeObject(intermediateBlockBuilder.build()).closeEntry();
        }
    }
    return blockBuilder;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:27,代码来源:TestArrayBlock.java

示例11: processRow

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
@Override
public void processRow(BlockBuilder output, int peerGroupStart, int peerGroupEnd, int frameStart, int frameEnd)
{
    if (frameStart < 0) {
        // empty frame
        resetAccumulator();
    }
    else if ((frameStart == currentStart) && (frameEnd >= currentEnd)) {
        // same or expanding frame
        accumulate(currentEnd + 1, frameEnd);
        currentEnd = frameEnd;
    }
    else {
        // different frame
        resetAccumulator();
        accumulate(frameStart, frameEnd);
        currentStart = frameStart;
        currentEnd = frameEnd;
    }

    accumulator.evaluateFinal(output);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:23,代码来源:AggregateWindowFunction.java

示例12: createTestBlock

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
public static Block createTestBlock()
{
    BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 15);
    VARCHAR.writeString(blockBuilder, "apple");
    VARCHAR.writeString(blockBuilder, "apple");
    VARCHAR.writeString(blockBuilder, "apple");
    VARCHAR.writeString(blockBuilder, "banana");
    VARCHAR.writeString(blockBuilder, "banana");
    VARCHAR.writeString(blockBuilder, "banana");
    VARCHAR.writeString(blockBuilder, "banana");
    VARCHAR.writeString(blockBuilder, "banana");
    VARCHAR.writeString(blockBuilder, "cherry");
    VARCHAR.writeString(blockBuilder, "cherry");
    VARCHAR.writeString(blockBuilder, "date");
    return blockBuilder.build();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:17,代码来源:TestVarcharType.java

示例13: output

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
public static void output(ArrayType outputType, MinMaxByNState state, BlockBuilder out)
{
    TypedKeyValueHeap heap = state.getTypedKeyValueHeap();
    if (heap == null || heap.isEmpty()) {
        out.appendNull();
        return;
    }

    Type elementType = outputType.getElementType();

    BlockBuilder arrayBlockBuilder = out.beginBlockEntry();
    BlockBuilder reversedBlockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), heap.getCapacity());
    long startSize = heap.getEstimatedSize();
    heap.popAll(reversedBlockBuilder);
    state.addMemoryUsage(heap.getEstimatedSize() - startSize);

    for (int i = reversedBlockBuilder.getPositionCount() - 1; i >= 0; i--) {
        elementType.appendTo(reversedBlockBuilder, i, arrayBlockBuilder);
    }
    out.closeEntry();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:22,代码来源:AbstractMinMaxByNAggregationFunction.java

示例14: test

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
private void test(IntStream inputStream, BlockComparator comparator, PrimitiveIterator.OfInt outputIterator)
{
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), INPUT_SIZE);
    inputStream.forEach(x -> BIGINT.writeLong(blockBuilder, x));

    TypedHeap heap = new TypedHeap(comparator, BIGINT, OUTPUT_SIZE);
    heap.addAll(blockBuilder);

    BlockBuilder resultBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), OUTPUT_SIZE);
    heap.popAll(resultBlockBuilder);

    Block resultBlock = resultBlockBuilder.build();
    assertEquals(resultBlock.getPositionCount(), OUTPUT_SIZE);
    for (int i = 0; i < OUTPUT_SIZE; i++) {
        assertEquals(BIGINT.getLong(resultBlock, i), outputIterator.nextInt());
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:18,代码来源:TestTypedHeap.java

示例15: createArrayBigintBlock

import com.facebook.presto.spi.block.BlockBuilder; //导入依赖的package包/类
public static Block createArrayBigintBlock(Iterable<? extends Iterable<Long>> values)
{
    ArrayType arrayType = new ArrayType(BIGINT);
    BlockBuilder builder = arrayType.createBlockBuilder(new BlockBuilderStatus(), 100);

    for (Iterable<Long> value : values) {
        if (value == null) {
            builder.appendNull();
        }
        else {
            arrayType.writeObject(builder, createLongsBlock(value));
        }
    }

    return builder.build();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:17,代码来源:BlockAssertions.java


注:本文中的com.facebook.presto.spi.block.BlockBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。