use of io.trino.spi.type.RowType in project trino by trinodb.
the class TestPushLimitThroughProject method testDoesntPushDownLimitThroughExclusiveDereferences.
@Test
public void testDoesntPushDownLimitThroughExclusiveDereferences() {
RowType rowType = RowType.from(ImmutableList.of(new RowType.Field(Optional.of("x"), BIGINT), new RowType.Field(Optional.of("y"), BIGINT)));
tester().assertThat(new PushLimitThroughProject(tester().getTypeAnalyzer())).on(p -> {
Symbol a = p.symbol("a", rowType);
return p.limit(1, p.project(Assignments.of(p.symbol("b"), new SubscriptExpression(a.toSymbolReference(), new LongLiteral("1")), p.symbol("c"), new SubscriptExpression(a.toSymbolReference(), new LongLiteral("2"))), p.values(a)));
}).doesNotFire();
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class AvroDecoderTestUtil method checkRowValues.
public static void checkRowValues(Block block, Type type, Object value) {
assertNotNull(type, "Type is null");
assertTrue(type instanceof RowType, "Unexpected type");
assertNotNull(block, "Block is null");
assertNotNull(value, "Value is null");
GenericRecord record = (GenericRecord) value;
RowType rowType = (RowType) type;
assertEquals(record.getSchema().getFields().size(), rowType.getFields().size(), "Avro field size mismatch");
assertEquals(block.getPositionCount(), rowType.getFields().size(), "Trino type field size mismatch");
for (int fieldIndex = 0; fieldIndex < rowType.getFields().size(); fieldIndex++) {
RowType.Field rowField = rowType.getFields().get(fieldIndex);
Object expectedValue = record.get(rowField.getName().get());
if (block.isNull(fieldIndex)) {
assertNull(expectedValue);
continue;
}
checkField(block, rowField.getType(), fieldIndex, expectedValue);
}
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class AvroDecoderTestUtil method checkMapValues.
public static void checkMapValues(Block block, Type type, Object value) {
assertNotNull(type, "Type is null");
assertTrue(type instanceof MapType, "Unexpected type");
assertTrue(((MapType) type).getKeyType() instanceof VarcharType, "Unexpected key type");
assertNotNull(block, "Block is null");
assertNotNull(value, "Value is null");
Map<String, ?> expected = (Map<String, ?>) value;
assertEquals(block.getPositionCount(), expected.size() * 2);
Type valueType = ((MapType) type).getValueType();
if (valueType instanceof ArrayType) {
for (int index = 0; index < block.getPositionCount(); index += 2) {
String actualKey = VARCHAR.getSlice(block, index).toStringUtf8();
assertTrue(expected.containsKey(actualKey));
if (block.isNull(index + 1)) {
assertNull(expected.get(actualKey));
continue;
}
Block arrayBlock = block.getObject(index + 1, Block.class);
checkArrayValues(arrayBlock, valueType, expected.get(actualKey));
}
} else if (valueType instanceof MapType) {
for (int index = 0; index < block.getPositionCount(); index += 2) {
String actualKey = VARCHAR.getSlice(block, index).toStringUtf8();
assertTrue(expected.containsKey(actualKey));
if (block.isNull(index + 1)) {
assertNull(expected.get(actualKey));
continue;
}
Block mapBlock = block.getObject(index + 1, Block.class);
checkMapValues(mapBlock, valueType, expected.get(actualKey));
}
} else if (valueType instanceof RowType) {
for (int index = 0; index < block.getPositionCount(); index += 2) {
String actualKey = VARCHAR.getSlice(block, index).toStringUtf8();
assertTrue(expected.containsKey(actualKey));
if (block.isNull(index + 1)) {
assertNull(expected.get(actualKey));
continue;
}
Block rowBlock = block.getObject(index + 1, Block.class);
checkRowValues(rowBlock, valueType, expected.get(actualKey));
}
} else {
for (int index = 0; index < block.getPositionCount(); index += 2) {
String actualKey = VARCHAR.getSlice(block, index).toStringUtf8();
assertTrue(expected.containsKey(actualKey));
checkPrimitiveValue(getObjectValue(valueType, block, index + 1), expected.get(actualKey));
}
}
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class TestAvroDecoder method testRow.
@Test
public void testRow() {
Schema schema = SchemaBuilder.record("record_field").fields().name("f1").type().floatType().noDefault().name("f2").type().doubleType().noDefault().name("f3").type().intType().noDefault().name("f4").type().longType().noDefault().name("f5").type().stringType().noDefault().name("f6").type().enumeration("color").symbols("red", "blue", "green").noDefault().name("f7").type().fixed("fixed5").size(5).noDefault().name("f8").type().bytesType().noDefault().name("f9").type().booleanType().noDefault().name("f10").type().array().items().record("sub_array_field").fields().name("sf1").type().stringType().noDefault().name("sf2").type().longType().noDefault().endRecord().noDefault().name("f11").type().map().values().record("sub_map_field").fields().name("sf1").type().doubleType().noDefault().name("sf2").type().booleanType().noDefault().endRecord().noDefault().name("f12").type().record("sub_row_field").fields().name("sf1").type().intType().noDefault().name("sf2").type().enumeration("state").symbols("initialized", "running", "finished", "failed").noDefault().endRecord().noDefault().endRecord();
RowType rowType = RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("f1", REAL)).add(RowType.field("f2", DOUBLE)).add(RowType.field("f3", INTEGER)).add(RowType.field("f4", BIGINT)).add(RowType.field("f5", VARCHAR)).add(RowType.field("f6", VARCHAR)).add(RowType.field("f7", VARBINARY)).add(RowType.field("f8", VARBINARY)).add(RowType.field("f9", BOOLEAN)).add(RowType.field("f10", new ArrayType(RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("sf1", VARCHAR)).add(RowType.field("sf2", BIGINT)).build())))).add(RowType.field("f11", MAP_OF_RECORD)).add(RowType.field("f12", RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("sf1", INTEGER)).add(RowType.field("sf2", VARCHAR)).build()))).build());
GenericRecord data = new GenericRecordBuilder(schema).set("f1", 1.5F).set("f2", 1.6D).set("f3", 5).set("f4", 6L).set("f5", "hello").set("f6", new GenericData.EnumSymbol(schema.getField("f6").schema(), "blue")).set("f7", new GenericData.Fixed(schema.getField("f7").schema(), new byte[] { 5, 4, 3, 2, 1 })).set("f8", ByteBuffer.wrap("mytext".getBytes(UTF_8))).set("f9", true).set("f10", ImmutableList.builder().add(new GenericRecordBuilder(schema.getField("f10").schema().getElementType()).set("sf1", "string text").set("sf2", 365_000_000L).build()).add(new GenericRecordBuilder(schema.getField("f10").schema().getElementType()).set("sf1", "more string text").set("sf2", 365_000_000_000L).build()).build()).set("f11", ImmutableMap.builder().put("key1", new GenericRecordBuilder(schema.getField("f11").schema().getValueType()).set("sf1", 3.5D).set("sf2", true).build()).put("key2", new GenericRecordBuilder(schema.getField("f11").schema().getValueType()).set("sf1", 4.5D).set("sf2", false).build()).buildOrThrow()).set("f12", new GenericRecordBuilder(schema.getField("f12").schema()).set("sf1", 3).set("sf2", new GenericData.EnumSymbol(schema.getField("f12").schema().getField("sf2").schema(), "running")).build()).build();
DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "record_field", rowType, "record_field", null, null, false, false, false);
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "record_field", schema.toString(), data);
checkRowValue(decodedRow, row, data);
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class RaptorStorageManager method toOrcFileType.
static Type toOrcFileType(Type raptorType, TypeManager typeManager) {
// TIMESTAMPS are stored as BIGINT to void the poor encoding in ORC
if (raptorType.equals(TIMESTAMP_MILLIS)) {
return BIGINT;
}
if (raptorType instanceof ArrayType) {
Type elementType = toOrcFileType(((ArrayType) raptorType).getElementType(), typeManager);
return new ArrayType(elementType);
}
if (raptorType instanceof MapType) {
TypeSignature keyType = toOrcFileType(((MapType) raptorType).getKeyType(), typeManager).getTypeSignature();
TypeSignature valueType = toOrcFileType(((MapType) raptorType).getValueType(), typeManager).getTypeSignature();
return typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(keyType), TypeSignatureParameter.typeParameter(valueType)));
}
if (raptorType instanceof RowType) {
List<Field> fields = ((RowType) raptorType).getFields().stream().map(field -> new Field(field.getName(), toOrcFileType(field.getType(), typeManager))).collect(toImmutableList());
return RowType.from(fields);
}
return raptorType;
}
Aggregations