use of io.trino.spi.type.RowType in project trino by trinodb.
the class TestMapAggAggregation method testDoubleRowMap.
@Test
public void testDoubleRowMap() {
RowType innerRowType = RowType.from(ImmutableList.of(RowType.field("f1", INTEGER), RowType.field("f2", DOUBLE)));
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(FUNCTION_RESOLUTION, QualifiedName.of(MapAggregationFunction.NAME), fromTypes(DOUBLE, innerRowType), 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 io.trino.spi.type.RowType in project trino by trinodb.
the class TestDeltaLakeFileStatistics method testStatisticsValues.
private static void testStatisticsValues(DeltaLakeFileStatistics fileStatistics) {
assertEquals(fileStatistics.getNumRecords(), Optional.of(1L));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("byt", TINYINT, REGULAR)), Optional.of(42L));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("dat", DATE, REGULAR)), Optional.of(LocalDate.parse("5000-01-01").toEpochDay()));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("dec_long", DecimalType.createDecimalType(25, 3), REGULAR)), Optional.of(encodeScaledValue(new BigDecimal("999999999999.123"), 3)));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("dec_short", DecimalType.createDecimalType(5, 1), REGULAR)), Optional.of(new BigDecimal("10.1").unscaledValue().longValueExact()));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("dou", DoubleType.DOUBLE, REGULAR)), Optional.of(0.321));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("fl", REAL, REGULAR)), Optional.of((long) floatToIntBits(0.123f)));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("in", INTEGER, REGULAR)), Optional.of(20000000L));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("l", BIGINT, REGULAR)), Optional.of(10000000L));
Type rowType = RowType.rowType(RowType.field("s1", INTEGER), RowType.field("s3", VarcharType.createUnboundedVarcharType()));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("row", rowType, REGULAR)), Optional.empty());
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("arr", new ArrayType(INTEGER), REGULAR)), Optional.empty());
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("m", new MapType(INTEGER, VarcharType.createUnboundedVarcharType(), new TypeOperators()), REGULAR)), Optional.empty());
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("sh", SMALLINT, REGULAR)), Optional.of(123L));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("str", VarcharType.createUnboundedVarcharType(), REGULAR)), Optional.of(utf8Slice("a")));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("ts", TIMESTAMP_TZ_MILLIS, REGULAR)), Optional.of(packDateTimeWithZone(LocalDateTime.parse("2960-10-31T01:00:00.000").toInstant(UTC).toEpochMilli(), UTC_KEY)));
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("bool", BOOLEAN, REGULAR)), Optional.empty());
assertEquals(fileStatistics.getMinColumnValue(new DeltaLakeColumnHandle("bin", VARBINARY, REGULAR)), Optional.empty());
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class AbstractTestHive method assertValueTypes.
private static void assertValueTypes(MaterializedRow row, List<ColumnMetadata> schema) {
for (int columnIndex = 0; columnIndex < schema.size(); columnIndex++) {
ColumnMetadata column = schema.get(columnIndex);
Object value = row.getField(columnIndex);
if (value != null) {
if (BOOLEAN.equals(column.getType())) {
assertInstanceOf(value, Boolean.class);
} else if (TINYINT.equals(column.getType())) {
assertInstanceOf(value, Byte.class);
} else if (SMALLINT.equals(column.getType())) {
assertInstanceOf(value, Short.class);
} else if (INTEGER.equals(column.getType())) {
assertInstanceOf(value, Integer.class);
} else if (BIGINT.equals(column.getType())) {
assertInstanceOf(value, Long.class);
} else if (DOUBLE.equals(column.getType())) {
assertInstanceOf(value, Double.class);
} else if (REAL.equals(column.getType())) {
assertInstanceOf(value, Float.class);
} else if (column.getType() instanceof VarcharType) {
assertInstanceOf(value, String.class);
} else if (column.getType() instanceof CharType) {
assertInstanceOf(value, String.class);
} else if (VARBINARY.equals(column.getType())) {
assertInstanceOf(value, SqlVarbinary.class);
} else if (TIMESTAMP_MILLIS.equals(column.getType())) {
assertInstanceOf(value, SqlTimestamp.class);
} else if (TIMESTAMP_WITH_TIME_ZONE.equals(column.getType())) {
assertInstanceOf(value, SqlTimestampWithTimeZone.class);
} else if (DATE.equals(column.getType())) {
assertInstanceOf(value, SqlDate.class);
} else if (column.getType() instanceof ArrayType || column.getType() instanceof RowType) {
assertInstanceOf(value, List.class);
} else if (column.getType() instanceof MapType) {
assertInstanceOf(value, Map.class);
} else {
fail("Unknown primitive type " + columnIndex);
}
}
}
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class TestPushDownDereferencesRules method testMultiLevelPushdown.
@Test
public void testMultiLevelPushdown() {
Type complexType = rowType(field("f1", rowType(field("f1", BIGINT), field("f2", BIGINT))), field("f2", BIGINT));
tester().assertThat(new PushDownDereferenceThroughProject(tester().getTypeAnalyzer())).on(p -> p.project(Assignments.of(p.symbol("expr_1"), expression("a[1]"), p.symbol("expr_2"), expression("a[1][1] + 2 + b[1][1] + b[1][2]")), p.project(Assignments.identity(ImmutableList.of(p.symbol("a", complexType), p.symbol("b", complexType))), p.values(p.symbol("a", complexType), p.symbol("b", complexType))))).matches(strictProject(ImmutableMap.of("expr_1", PlanMatchPattern.expression("a_f1"), "expr_2", PlanMatchPattern.expression("a_f1[1] + 2 + b_f1_f1 + b_f1_f2")), strictProject(ImmutableMap.of("a", PlanMatchPattern.expression("a"), "b", PlanMatchPattern.expression("b"), "a_f1", PlanMatchPattern.expression("a[1]"), "b_f1_f1", PlanMatchPattern.expression("b[1][1]"), "b_f1_f2", PlanMatchPattern.expression("b[1][2]")), values("a", "b"))));
}
use of io.trino.spi.type.RowType in project trino by trinodb.
the class TestPushDownDereferencesRules method testExtractDereferencesFromFilterAboveScan.
@Test
public void testExtractDereferencesFromFilterAboveScan() {
TableHandle testTable = new TableHandle(new CatalogName(CATALOG_ID), new TpchTableHandle("sf1", "orders", 1.0), TestingTransactionHandle.create());
RowType nestedRowType = RowType.from(ImmutableList.of(new RowType.Field(Optional.of("nested"), ROW_TYPE)));
tester().assertThat(new ExtractDereferencesFromFilterAboveScan(tester().getTypeAnalyzer())).on(p -> p.filter(expression("a[1][1] != 5 AND b[2] = 2 AND CAST(a[1] as JSON) is not null"), p.tableScan(testTable, ImmutableList.of(p.symbol("a", nestedRowType), p.symbol("b", ROW_TYPE)), ImmutableMap.of(p.symbol("a", nestedRowType), new TpchColumnHandle("a", nestedRowType), p.symbol("b", ROW_TYPE), new TpchColumnHandle("b", ROW_TYPE))))).matches(project(filter("expr != 5 AND expr_0 = 2 AND CAST(expr_1 as JSON) is not null", strictProject(ImmutableMap.of("expr", PlanMatchPattern.expression("a[1][1]"), "expr_0", PlanMatchPattern.expression("b[2]"), "expr_1", PlanMatchPattern.expression("a[1]"), "a", PlanMatchPattern.expression("a"), "b", PlanMatchPattern.expression("b")), tableScan(testTable.getConnectorHandle()::equals, TupleDomain.all(), ImmutableMap.of("a", new TpchColumnHandle("a", nestedRowType)::equals, "b", new TpchColumnHandle("b", ROW_TYPE)::equals))))));
}
Aggregations