use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class TestRowOperators method assertRowHashOperator.
private void assertRowHashOperator(String inputString, List<Type> types, List<Object> elements) {
checkArgument(types.size() == elements.size(), "types and elements must have the same size");
RowType rowType = RowType.anonymous(types);
BlockBuilder blockBuilder = rowType.createBlockBuilder(null, 1);
BlockBuilder singleRowBlockWriter = blockBuilder.beginBlockEntry();
for (int i = 0; i < types.size(); i++) {
appendToBlockBuilder(types.get(i), elements.get(i), singleRowBlockWriter);
}
blockBuilder.closeEntry();
assertOperator(HASH_CODE, inputString, BIGINT, rowType.hash(blockBuilder.build(), 0));
}
use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class TestMapAggAggregation method testDoubleRowMap.
@Test
public void testDoubleRowMap() {
RowType innerRowType = RowType.from(ImmutableList.of(RowType.field("f1", INTEGER), RowType.field("f2", DOUBLE)));
InternalAggregationFunction aggFunc = getAggregation(DOUBLE, innerRowType);
BlockBuilder builder = innerRowType.createBlockBuilder(null, 3);
innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 1L, 1.0));
innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 2L, 2.0));
innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 3L, 3.0));
assertAggregation(aggFunc, ImmutableMap.of(1.0, ImmutableList.of(1, 1.0), 2.0, ImmutableList.of(2, 2.0), 3.0, ImmutableList.of(3, 3.0)), createDoublesBlock(1.0, 2.0, 3.0), builder.build());
}
use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class TestMultimapAggAggregation method testDoubleRowMap.
@Test
public void testDoubleRowMap() {
RowType innerRowType = RowType.from(ImmutableList.of(RowType.field("f1", BIGINT), RowType.field("f2", DOUBLE)));
testMultimapAgg(DOUBLE, ImmutableList.of(1.0, 2.0, 3.0), innerRowType, ImmutableList.of(ImmutableList.of(1L, 1.0), ImmutableList.of(2L, 2.0), ImmutableList.of(3L, 3.0)));
}
use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class TypeConverter method fromRow.
private static org.apache.iceberg.types.Type fromRow(RowType type) {
List<Types.NestedField> fields = new ArrayList<>();
for (RowType.Field field : type.getFields()) {
String name = field.getName().orElseThrow(() -> new PrestoException(NOT_SUPPORTED, "Row type field does not have a name: " + type.getDisplayName()));
fields.add(Types.NestedField.optional(fields.size() + 1, name, toIcebergType(field.getType())));
}
return Types.StructType.of(fields);
}
use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class TestSerDeUtils method testStructBlock.
@Test
public void testStructBlock() {
// test simple structs
InnerStruct innerStruct = new InnerStruct(13, 14L);
com.facebook.presto.common.type.Type rowType = RowType.anonymous(ImmutableList.of(INTEGER, BIGINT));
Block actual = toBinaryBlock(rowType, innerStruct, getInspector(InnerStruct.class));
Block expected = rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 13, 14L);
assertBlockEquals(actual, expected);
// test complex structs
OuterStruct outerStruct = new OuterStruct();
outerStruct.byteVal = (byte) 1;
outerStruct.shortVal = (short) 2;
outerStruct.intVal = 3;
outerStruct.longVal = 4L;
outerStruct.floatVal = 5.01f;
outerStruct.doubleVal = 6.001d;
outerStruct.stringVal = "seven";
outerStruct.byteArray = new byte[] { '2' };
InnerStruct is1 = new InnerStruct(2, -5L);
InnerStruct is2 = new InnerStruct(-10, 0L);
outerStruct.structArray = new ArrayList<>(2);
outerStruct.structArray.add(is1);
outerStruct.structArray.add(is2);
outerStruct.map = new TreeMap<>();
outerStruct.map.put("twelve", new InnerStruct(0, 5L));
outerStruct.map.put("fifteen", new InnerStruct(-5, -10L));
outerStruct.innerStruct = new InnerStruct(18, 19L);
com.facebook.presto.common.type.Type innerRowType = RowType.anonymous(ImmutableList.of(INTEGER, BIGINT));
com.facebook.presto.common.type.Type arrayOfInnerRowType = new ArrayType(innerRowType);
com.facebook.presto.common.type.Type mapOfInnerRowType = mapType(createUnboundedVarcharType(), innerRowType);
List<com.facebook.presto.common.type.Type> outerRowParameterTypes = ImmutableList.of(TINYINT, SMALLINT, INTEGER, BIGINT, REAL, DOUBLE, createUnboundedVarcharType(), createUnboundedVarcharType(), arrayOfInnerRowType, mapOfInnerRowType, innerRowType);
com.facebook.presto.common.type.Type outerRowType = RowType.anonymous(outerRowParameterTypes);
actual = toBinaryBlock(outerRowType, outerStruct, getInspector(OuterStruct.class));
ImmutableList.Builder<Object> outerRowValues = ImmutableList.builder();
outerRowValues.add((byte) 1);
outerRowValues.add((short) 2);
outerRowValues.add(3);
outerRowValues.add(4L);
outerRowValues.add(5.01f);
outerRowValues.add(6.001d);
outerRowValues.add("seven");
outerRowValues.add(new byte[] { '2' });
outerRowValues.add(arrayBlockOf(innerRowType, rowBlockOf(innerRowType.getTypeParameters(), 2, -5L), rowBlockOf(ImmutableList.of(INTEGER, BIGINT), -10, 0L)));
outerRowValues.add(mapBlockOf(VARCHAR, innerRowType, new Object[] { utf8Slice("fifteen"), utf8Slice("twelve") }, new Object[] { rowBlockOf(innerRowType.getTypeParameters(), -5, -10L), rowBlockOf(innerRowType.getTypeParameters(), 0, 5L) }));
outerRowValues.add(rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 18, 19L));
assertBlockEquals(actual, rowBlockOf(outerRowParameterTypes, outerRowValues.build().toArray()));
}
Aggregations