Search in sources :

Example 16 with MaterializedRow

use of io.trino.testing.MaterializedRow in project trino by trinodb.

the class TestTimestampMicros method testTimestampMicros.

@Test(dataProvider = "testTimestampMicrosDataProvider")
public void testTimestampMicros(HiveTimestampPrecision timestampPrecision, LocalDateTime expected) throws Exception {
    ConnectorSession session = getHiveSession(new HiveConfig().setTimestampPrecision(timestampPrecision));
    File parquetFile = new File(Resources.getResource("issue-5483.parquet").toURI());
    Type columnType = createTimestampType(timestampPrecision.getPrecision());
    try (ConnectorPageSource pageSource = createPageSource(session, parquetFile, "created", HIVE_TIMESTAMP, columnType)) {
        MaterializedResult result = materializeSourceDataStream(session, pageSource, List.of(columnType)).toTestTypes();
        assertThat(result.getMaterializedRows()).containsOnly(new MaterializedRow(List.of(expected)));
    }
}
Also used : Type(io.trino.spi.type.Type) HiveType(io.trino.plugin.hive.HiveType) TimestampType.createTimestampType(io.trino.spi.type.TimestampType.createTimestampType) TimestampWithTimeZoneType.createTimestampWithTimeZoneType(io.trino.spi.type.TimestampWithTimeZoneType.createTimestampWithTimeZoneType) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorPageSource(io.trino.spi.connector.ConnectorPageSource) MaterializedResult(io.trino.testing.MaterializedResult) File(java.io.File) MaterializedRow(io.trino.testing.MaterializedRow) HiveConfig(io.trino.plugin.hive.HiveConfig) Test(org.testng.annotations.Test)

Example 17 with MaterializedRow

use of io.trino.testing.MaterializedRow in project trino by trinodb.

the class TestTimestampMicros method testTimestampMicrosAsTimestampWithTimeZone.

@Test(dataProvider = "testTimestampMicrosDataProvider")
public void testTimestampMicrosAsTimestampWithTimeZone(HiveTimestampPrecision timestampPrecision, LocalDateTime expected) throws Exception {
    ConnectorSession session = getHiveSession(new HiveConfig().setTimestampPrecision(timestampPrecision));
    File parquetFile = new File(Resources.getResource("issue-5483.parquet").toURI());
    Type columnType = createTimestampWithTimeZoneType(timestampPrecision.getPrecision());
    try (ConnectorPageSource pageSource = createPageSource(session, parquetFile, "created", HIVE_TIMESTAMP, columnType)) {
        MaterializedResult result = materializeSourceDataStream(session, pageSource, List.of(columnType)).toTestTypes();
        assertThat(result.getMaterializedRows()).containsOnly(new MaterializedRow(List.of(expected.atZone(ZoneId.of("UTC")))));
    }
}
Also used : Type(io.trino.spi.type.Type) HiveType(io.trino.plugin.hive.HiveType) TimestampType.createTimestampType(io.trino.spi.type.TimestampType.createTimestampType) TimestampWithTimeZoneType.createTimestampWithTimeZoneType(io.trino.spi.type.TimestampWithTimeZoneType.createTimestampWithTimeZoneType) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorPageSource(io.trino.spi.connector.ConnectorPageSource) MaterializedResult(io.trino.testing.MaterializedResult) File(java.io.File) MaterializedRow(io.trino.testing.MaterializedRow) HiveConfig(io.trino.plugin.hive.HiveConfig) Test(org.testng.annotations.Test)

Example 18 with MaterializedRow

use of io.trino.testing.MaterializedRow in project trino by trinodb.

the class BaseIcebergConnectorTest method testPartitionedTableStatistics.

@Test
public void testPartitionedTableStatistics() {
    assertUpdate("CREATE TABLE iceberg.tpch.test_partitioned_table_statistics (col1 REAL, col2 BIGINT) WITH (partitioning = ARRAY['col2'])");
    String insertStart = "INSERT INTO test_partitioned_table_statistics";
    assertUpdate(insertStart + " VALUES (-10, -1)", 1);
    assertUpdate(insertStart + " VALUES (100, 10)", 1);
    MaterializedResult result = computeActual("SHOW STATS FOR iceberg.tpch.test_partitioned_table_statistics");
    assertEquals(result.getRowCount(), 3);
    MaterializedRow row0 = result.getMaterializedRows().get(0);
    assertEquals(row0.getField(0), "col1");
    assertEquals(row0.getField(3), 0.0);
    assertEquals(row0.getField(5), "-10.0");
    assertEquals(row0.getField(6), "100.0");
    MaterializedRow row1 = result.getMaterializedRows().get(1);
    assertEquals(row1.getField(0), "col2");
    assertEquals(row1.getField(3), 0.0);
    assertEquals(row1.getField(5), "-1");
    assertEquals(row1.getField(6), "10");
    MaterializedRow row2 = result.getMaterializedRows().get(2);
    assertEquals(row2.getField(4), 2.0);
    assertUpdate(insertStart + " VALUES " + IntStream.rangeClosed(1, 5).mapToObj(i -> format("(%d, 10)", i + 100)).collect(joining(", ")), 5);
    assertUpdate(insertStart + " VALUES " + IntStream.rangeClosed(6, 10).mapToObj(i -> "(NULL, 10)").collect(joining(", ")), 5);
    result = computeActual("SHOW STATS FOR iceberg.tpch.test_partitioned_table_statistics");
    assertEquals(result.getRowCount(), 3);
    row0 = result.getMaterializedRows().get(0);
    assertEquals(row0.getField(0), "col1");
    assertEquals(row0.getField(3), 5.0 / 12.0);
    assertEquals(row0.getField(5), "-10.0");
    assertEquals(row0.getField(6), "105.0");
    row1 = result.getMaterializedRows().get(1);
    assertEquals(row1.getField(0), "col2");
    assertEquals(row1.getField(3), 0.0);
    assertEquals(row1.getField(5), "-1");
    assertEquals(row1.getField(6), "10");
    row2 = result.getMaterializedRows().get(2);
    assertEquals(row2.getField(4), 12.0);
    assertUpdate(insertStart + " VALUES " + IntStream.rangeClosed(6, 10).mapToObj(i -> "(100, NULL)").collect(joining(", ")), 5);
    result = computeActual("SHOW STATS FOR iceberg.tpch.test_partitioned_table_statistics");
    row0 = result.getMaterializedRows().get(0);
    assertEquals(row0.getField(0), "col1");
    assertEquals(row0.getField(3), 5.0 / 17.0);
    assertEquals(row0.getField(5), "-10.0");
    assertEquals(row0.getField(6), "105.0");
    row1 = result.getMaterializedRows().get(1);
    assertEquals(row1.getField(0), "col2");
    assertEquals(row1.getField(3), 5.0 / 17.0);
    assertEquals(row1.getField(5), "-1");
    assertEquals(row1.getField(6), "10");
    row2 = result.getMaterializedRows().get(2);
    assertEquals(row2.getField(4), 17.0);
    dropTable("iceberg.tpch.test_partitioned_table_statistics");
}
Also used : SkipException(org.testng.SkipException) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.testng.annotations.Test) TestTable(io.trino.testing.sql.TestTable) BROADCAST(io.trino.sql.planner.OptimizerConfig.JoinDistributionType.BROADCAST) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Matcher(java.util.regex.Matcher) Map(java.util.Map) MaterializedRow(io.trino.testing.MaterializedRow) Path(java.nio.file.Path) Assert.assertFalse(org.testng.Assert.assertFalse) Assert.assertEquals(io.trino.testing.assertions.Assert.assertEquals) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) Schema(org.apache.avro.Schema) DataProviders(io.trino.testing.DataProviders) Domain(io.trino.spi.predicate.Domain) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) DataFileWriter(org.apache.avro.file.DataFileWriter) HDFS_ENVIRONMENT(io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT) Collectors.joining(java.util.stream.Collectors.joining) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) Stream(java.util.stream.Stream) ORC(io.trino.plugin.iceberg.IcebergFileFormat.ORC) Session(io.trino.Session) NullableValue(io.trino.spi.predicate.NullableValue) GenericData(org.apache.avro.generic.GenericData) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) String.join(java.lang.String.join) ColumnHandle(io.trino.spi.connector.ColumnHandle) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) LongStream(java.util.stream.LongStream) OperatorStats(io.trino.operator.OperatorStats) Language(org.intellij.lang.annotations.Language) Files(java.nio.file.Files) IOException(java.io.IOException) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) File(java.io.File) BaseConnectorTest(io.trino.testing.BaseConnectorTest) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Paths(java.nio.file.Paths) QueryRunner(io.trino.testing.QueryRunner) Domain.multipleValues(io.trino.spi.predicate.Domain.multipleValues) QueryId(io.trino.spi.QueryId) TransactionBuilder.transaction(io.trino.transaction.TransactionBuilder.transaction) IntStream.range(java.util.stream.IntStream.range) MaterializedResult(io.trino.testing.MaterializedResult) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PREFERRED_WRITE_PARTITIONING_MIN_NUMBER_OF_PARTITIONS(io.trino.SystemSessionProperties.PREFERRED_WRITE_PARTITIONING_MIN_NUMBER_OF_PARTITIONS) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) ICEBERG_DOMAIN_COMPACTION_THRESHOLD(io.trino.plugin.iceberg.IcebergSplitManager.ICEBERG_DOMAIN_COMPACTION_THRESHOLD) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) QueryAssertions.assertEqualsIgnoreOrder(io.trino.testing.QueryAssertions.assertEqualsIgnoreOrder) Locale(java.util.Locale) Iterables.concat(com.google.common.collect.Iterables.concat) TestingConnectorBehavior(io.trino.testing.TestingConnectorBehavior) TestTable.randomTableSuffix(io.trino.testing.sql.TestTable.randomTableSuffix) TpchTable(io.trino.tpch.TpchTable) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collections.nCopies(java.util.Collections.nCopies) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ICEBERG_CATALOG(io.trino.plugin.iceberg.IcebergQueryRunner.ICEBERG_CATALOG) DataSize(io.airlift.units.DataSize) List(java.util.List) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) BIGINT(io.trino.spi.type.BigintType.BIGINT) Domain.singleValue(io.trino.spi.predicate.Domain.singleValue) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) DataFileReader(org.apache.avro.file.DataFileReader) GenericDatumReader(org.apache.avro.generic.GenericDatumReader) IcebergQueryRunner.createIcebergQueryRunner(io.trino.plugin.iceberg.IcebergQueryRunner.createIcebergQueryRunner) LINE_ITEM(io.trino.tpch.TpchTable.LINE_ITEM) IntStream(java.util.stream.IntStream) Constraint(io.trino.spi.connector.Constraint) DataProvider(org.testng.annotations.DataProvider) PARQUET(io.trino.plugin.iceberg.IcebergFileFormat.PARQUET) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Objects.requireNonNull(java.util.Objects.requireNonNull) TableStatistics(io.trino.spi.statistics.TableStatistics) NoSuchElementException(java.util.NoSuchElementException) VerifyException(com.google.common.base.VerifyException) OutputStream(java.io.OutputStream) ResultWithQueryId(io.trino.testing.ResultWithQueryId) TupleDomain(io.trino.spi.predicate.TupleDomain) Consumer(java.util.function.Consumer) Assert.assertEventually(io.trino.testing.assertions.Assert.assertEventually) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) Metadata(io.trino.metadata.Metadata) Assert.assertTrue(org.testng.Assert.assertTrue) MaterializedResult.resultBuilder(io.trino.testing.MaterializedResult.resultBuilder) MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 19 with MaterializedRow

use of io.trino.testing.MaterializedRow in project trino by trinodb.

the class BaseIcebergConnectorTest method testLocalDynamicFilteringWithSelectiveBuildSizeJoin.

@Test
public void testLocalDynamicFilteringWithSelectiveBuildSizeJoin() {
    long fullTableScan = (Long) computeActual("SELECT count(*) FROM lineitem").getOnlyValue();
    // Pick a value for totalprice where file level stats will not be able to filter out any data
    // This assumes the totalprice ranges in every file have some overlap, otherwise this test will fail.
    MaterializedRow range = getOnlyElement(computeActual("SELECT max(lower_bounds[4]), min(upper_bounds[4]) FROM \"orders$files\"").getMaterializedRows());
    double totalPrice = (Double) computeActual(format("SELECT totalprice FROM orders WHERE totalprice > %s AND totalprice < %s LIMIT 1", range.getField(0), range.getField(1))).getOnlyValue();
    Session session = Session.builder(getSession()).setSystemProperty(JOIN_DISTRIBUTION_TYPE, BROADCAST.name()).build();
    ResultWithQueryId<MaterializedResult> result = getDistributedQueryRunner().executeWithQueryId(session, "SELECT * FROM lineitem JOIN orders ON lineitem.orderkey = orders.orderkey AND orders.totalprice = " + totalPrice);
    OperatorStats probeStats = searchScanFilterAndProjectOperatorStats(result.getQueryId(), new QualifiedObjectName(ICEBERG_CATALOG, "tpch", "lineitem"));
    // Assert some lineitem rows were filtered out on file level
    assertThat(probeStats.getInputPositions()).isLessThan(fullTableScan);
}
Also used : OperatorStats(io.trino.operator.OperatorStats) MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Session(io.trino.Session) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 20 with MaterializedRow

use of io.trino.testing.MaterializedRow in project trino by trinodb.

the class BaseMongoConnectorTest method testInsertWithEveryType.

@Test
public void testInsertWithEveryType() {
    String createSql = "" + "CREATE TABLE test_insert_types_table " + "(" + "  vc varchar" + ", vb varbinary" + ", bi bigint" + ", d double" + ", b boolean" + ", dt  date" + ", ts  timestamp" + ", objid objectid" + ", _json json" + ")";
    getQueryRunner().execute(getSession(), createSql);
    String insertSql = "" + "INSERT INTO test_insert_types_table " + "SELECT" + " 'foo' _varchar" + ", cast('bar' as varbinary) _varbinary" + ", cast(1 as bigint) _bigint" + ", 3.14E0 _double" + ", true _boolean" + ", DATE '1980-05-07' _date" + ", TIMESTAMP '1980-05-07 11:22:33.456' _timestamp" + ", ObjectId('ffffffffffffffffffffffff') _objectid" + ", JSON '{\"name\":\"alice\"}' _json";
    getQueryRunner().execute(getSession(), insertSql);
    MaterializedResult results = getQueryRunner().execute(getSession(), "SELECT * FROM test_insert_types_table").toTestTypes();
    assertEquals(results.getRowCount(), 1);
    MaterializedRow row = results.getMaterializedRows().get(0);
    assertEquals(row.getField(0), "foo");
    assertEquals(row.getField(1), "bar".getBytes(UTF_8));
    assertEquals(row.getField(2), 1L);
    assertEquals(row.getField(3), 3.14);
    assertEquals(row.getField(4), true);
    assertEquals(row.getField(5), LocalDate.of(1980, 5, 7));
    assertEquals(row.getField(6), LocalDateTime.of(1980, 5, 7, 11, 22, 33, 456_000_000));
    assertEquals(row.getField(8), "{\"name\":\"alice\"}");
    assertUpdate("DROP TABLE test_insert_types_table");
    assertFalse(getQueryRunner().tableExists(getSession(), "test_insert_types_table"));
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Aggregations

MaterializedRow (io.trino.testing.MaterializedRow)67 MaterializedResult (io.trino.testing.MaterializedResult)58 Test (org.testng.annotations.Test)44 BaseConnectorTest (io.trino.testing.BaseConnectorTest)21 Constraint (io.trino.spi.connector.Constraint)11 Language (org.intellij.lang.annotations.Language)11 Session (io.trino.Session)9 ConnectorPageSource (io.trino.spi.connector.ConnectorPageSource)9 ConnectorSession (io.trino.spi.connector.ConnectorSession)9 ImmutableList (com.google.common.collect.ImmutableList)8 ColumnHandle (io.trino.spi.connector.ColumnHandle)8 Type (io.trino.spi.type.Type)8 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)7 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)7 HiveColumnHandle.bucketColumnHandle (io.trino.plugin.hive.HiveColumnHandle.bucketColumnHandle)6 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)6 LocalDate (java.time.LocalDate)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)5 TableMetadata (io.trino.metadata.TableMetadata)5