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);
}
}
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();
}
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%)");
}
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");
}
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();
}
Aggregations