use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.
the class TestSimpleRowType method getGreaterValue.
@Override
protected Object getGreaterValue(Object value) {
RowBlockBuilder blockBuilder = (RowBlockBuilder) TYPE.createBlockBuilder(null, 1);
SingleRowBlockWriter singleRowBlockWriter;
Block block = (Block) value;
singleRowBlockWriter = blockBuilder.beginBlockEntry();
BIGINT.writeLong(singleRowBlockWriter, block.getSingleValueBlock(0).getLong(0, 0) + 1);
VARCHAR.writeSlice(singleRowBlockWriter, block.getSingleValueBlock(1).getSlice(0, 0, 1));
blockBuilder.closeEntry();
return TYPE.getObject(blockBuilder.build(), 0);
}
use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.
the class BlockAssertions method createRowBlock.
public static Block createRowBlock(List<Type> fieldTypes, Object[]... rows) {
BlockBuilder rowBlockBuilder = new RowBlockBuilder(fieldTypes, null, 1);
for (Object[] row : rows) {
if (row == null) {
rowBlockBuilder.appendNull();
continue;
}
BlockBuilder singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
for (Object fieldValue : row) {
if (fieldValue == null) {
singleRowBlockWriter.appendNull();
continue;
}
if (fieldValue instanceof String) {
VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice((String) fieldValue));
} else if (fieldValue instanceof Slice) {
VARBINARY.writeSlice(singleRowBlockWriter, (Slice) fieldValue);
} else if (fieldValue instanceof Double) {
DOUBLE.writeDouble(singleRowBlockWriter, ((Double) fieldValue).doubleValue());
} else if (fieldValue instanceof Long) {
BIGINT.writeLong(singleRowBlockWriter, ((Long) fieldValue).longValue());
} else if (fieldValue instanceof Boolean) {
BOOLEAN.writeBoolean(singleRowBlockWriter, ((Boolean) fieldValue).booleanValue());
} else if (fieldValue instanceof Block) {
singleRowBlockWriter.appendStructure((Block) fieldValue);
} else if (fieldValue instanceof Integer) {
INTEGER.writeLong(singleRowBlockWriter, ((Integer) fieldValue).intValue());
} else {
throw new IllegalArgumentException();
}
}
rowBlockBuilder.closeEntry();
}
return rowBlockBuilder.build();
}
use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.
the class OperatorAssertion method toRow.
public static Block toRow(List<Type> parameterTypes, Object... values) {
checkArgument(parameterTypes.size() == values.length, "parameterTypes.size(" + parameterTypes.size() + ") does not equal to values.length(" + values.length + ")");
RowType rowType = RowType.anonymous(parameterTypes);
BlockBuilder blockBuilder = new RowBlockBuilder(parameterTypes, null, 1);
BlockBuilder singleRowBlockWriter = blockBuilder.beginBlockEntry();
for (int i = 0; i < values.length; i++) {
appendToBlockBuilder(parameterTypes.get(i), values[i], singleRowBlockWriter);
}
blockBuilder.closeEntry();
return rowType.getObject(blockBuilder, 0);
}
use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.
the class TestRowBlock method createBlockBuilderWithValues.
private BlockBuilder createBlockBuilderWithValues(List<Type> fieldTypes, List<Object>[] rows) {
BlockBuilder rowBlockBuilder = new RowBlockBuilder(fieldTypes, null, 1);
for (List<Object> row : rows) {
if (row == null) {
rowBlockBuilder.appendNull();
} else {
BlockBuilder singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
for (Object fieldValue : row) {
if (fieldValue == null) {
singleRowBlockWriter.appendNull();
} else {
if (fieldValue instanceof Long) {
BIGINT.writeLong(singleRowBlockWriter, ((Long) fieldValue).longValue());
} else if (fieldValue instanceof String) {
VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice((String) fieldValue));
} else {
throw new IllegalArgumentException();
}
}
}
rowBlockBuilder.closeEntry();
}
}
return rowBlockBuilder;
}
use of io.prestosql.spi.block.RowBlockBuilder in project hetu-core by openlookeng.
the class TestSimpleRowType method createTestBlock.
private static Block createTestBlock() {
RowBlockBuilder blockBuilder = (RowBlockBuilder) TYPE.createBlockBuilder(null, 3);
SingleRowBlockWriter singleRowBlockWriter;
singleRowBlockWriter = blockBuilder.beginBlockEntry();
BIGINT.writeLong(singleRowBlockWriter, 1);
VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("cat"));
blockBuilder.closeEntry();
singleRowBlockWriter = blockBuilder.beginBlockEntry();
BIGINT.writeLong(singleRowBlockWriter, 2);
VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("cats"));
blockBuilder.closeEntry();
singleRowBlockWriter = blockBuilder.beginBlockEntry();
BIGINT.writeLong(singleRowBlockWriter, 3);
VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("dog"));
blockBuilder.closeEntry();
return blockBuilder.build();
}
Aggregations