Search in sources :

Example 1 with BlockBuilder

use of io.prestosql.spi.block.BlockBuilder in project hetu-core by openlookeng.

the class SortBuffer method appendPositionTo.

public static void appendPositionTo(Page page, int position, PageBuilder pageBuilder) {
    pageBuilder.declarePosition();
    for (int i = 0; i < page.getChannelCount(); i++) {
        Type type = pageBuilder.getType(i);
        Block block = page.getBlock(i);
        BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
        type.appendTo(block, position, blockBuilder);
    }
}
Also used : Type(io.prestosql.spi.type.Type) Block(io.prestosql.spi.block.Block) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 2 with BlockBuilder

use of io.prestosql.spi.block.BlockBuilder in project hetu-core by openlookeng.

the class TestReadWrite method generateBigintArray.

private static void generateBigintArray(Random random, BlockBuilder parentBuilder) {
    int numberOfElements = random.nextInt(MAX_ARRAY_GENERATED_LENGTH);
    BlockBuilder builder = parentBuilder.beginBlockEntry();
    for (int i = 0; i < numberOfElements; i++) {
        if (random.nextDouble() < NULL_FRACTION) {
            builder.appendNull();
        } else {
            builder.writeLong(random.nextLong());
        }
    }
    parentBuilder.closeEntry();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 3 with BlockBuilder

use of io.prestosql.spi.block.BlockBuilder in project hetu-core by openlookeng.

the class TestEvaluateClassifierPredictions method testEvaluateClassifierPredictions.

@Test
public void testEvaluateClassifierPredictions() {
    metadata.getFunctionAndTypeManager().registerBuiltInFunctions(extractFunctions(new MLPlugin().getFunctions()));
    InternalAggregationFunction aggregation = metadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction("evaluate_classifier_predictions"), AGGREGATE, parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT)));
    Accumulator accumulator = aggregation.bind(ImmutableList.of(0, 1), Optional.empty()).createAccumulator();
    accumulator.addInput(getPage());
    BlockBuilder finalOut = accumulator.getFinalType().createBlockBuilder(null, 1);
    accumulator.evaluateFinal(finalOut);
    Block block = finalOut.build();
    String output = VARCHAR.getSlice(block, 0).toStringUtf8();
    List<String> parts = ImmutableList.copyOf(Splitter.on('\n').omitEmptyStrings().split(output));
    assertEquals(parts.size(), 7, output);
    assertEquals(parts.get(0), "Accuracy: 1/2 (50.00%)");
}
Also used : Accumulator(io.prestosql.operator.aggregation.Accumulator) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) Block(io.prestosql.spi.block.Block) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 4 with BlockBuilder

use of io.prestosql.spi.block.BlockBuilder in project hetu-core by openlookeng.

the class TestLearnAggregations method assertLearnClassifer.

private static void assertLearnClassifer(Accumulator accumulator) {
    accumulator.addInput(getPage());
    BlockBuilder finalOut = accumulator.getFinalType().createBlockBuilder(null, 1);
    accumulator.evaluateFinal(finalOut);
    Block block = finalOut.build();
    Slice slice = accumulator.getFinalType().getSlice(block, 0);
    Model deserialized = ModelUtils.deserialize(slice);
    assertNotNull(deserialized, "deserialization failed");
    assertTrue(deserialized instanceof Classifier, "deserialized model is not a classifier");
}
Also used : Slice(io.airlift.slice.Slice) Block(io.prestosql.spi.block.Block) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 5 with BlockBuilder

use of io.prestosql.spi.block.BlockBuilder in project hetu-core by openlookeng.

the class Utils method nativeValueToBlock.

public static Block nativeValueToBlock(Type type, Object object) {
    if (object != null && !Primitives.wrap(type.getJavaType()).isInstance(object)) {
        throw new IllegalArgumentException(format("Object '%s' does not match type %s", object, type.getJavaType()));
    }
    BlockBuilder blockBuilder = type.createBlockBuilder(null, 1);
    writeNativeValue(type, blockBuilder, object);
    return blockBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Aggregations

BlockBuilder (io.prestosql.spi.block.BlockBuilder)389 Block (io.prestosql.spi.block.Block)88 Test (org.testng.annotations.Test)80 Slice (io.airlift.slice.Slice)79 Type (io.prestosql.spi.type.Type)57 Page (io.prestosql.spi.Page)42 SqlType (io.prestosql.spi.function.SqlType)42 ArrayType (io.prestosql.spi.type.ArrayType)27 Map (java.util.Map)26 MapType (io.prestosql.spi.type.MapType)23 PageBuilder (io.prestosql.spi.PageBuilder)22 RowType (io.prestosql.spi.type.RowType)21 UsedByGeneratedCode (io.prestosql.spi.annotation.UsedByGeneratedCode)20 PrestoException (io.prestosql.spi.PrestoException)19 TypeParameter (io.prestosql.spi.function.TypeParameter)18 RowBlockBuilder (io.prestosql.spi.block.RowBlockBuilder)17 ScalarFunction (io.prestosql.spi.function.ScalarFunction)17 ImmutableList (com.google.common.collect.ImmutableList)16 List (java.util.List)16 ArrayList (java.util.ArrayList)13