Search in sources :

Example 26 with MaterializedRow

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

the class BaseRaptorConnectorTest method testShardingByTemporalDateColumnBucketed.

@Test
public void testShardingByTemporalDateColumnBucketed() {
    // Make sure we have at least 2 different orderdate.
    assertEquals(computeActual("SELECT count(DISTINCT orderdate) >= 2 FROM orders WHERE orderdate < date '1992-02-08'").getOnlyValue(), true);
    assertUpdate("CREATE TABLE test_shard_temporal_date_bucketed " + "WITH (temporal_column = 'orderdate', bucket_count = 10, bucketed_on = ARRAY ['orderkey']) AS " + "SELECT orderdate, orderkey " + "FROM orders " + "WHERE orderdate < date '1992-02-08'", "SELECT count(*) " + "FROM orders " + "WHERE orderdate < date '1992-02-08'");
    MaterializedResult results = computeActual("SELECT orderdate, \"$shard_uuid\" FROM test_shard_temporal_date_bucketed");
    // Each shard will only contain data of one date.
    SetMultimap<String, LocalDate> shardDateMap = HashMultimap.create();
    for (MaterializedRow row : results.getMaterializedRows()) {
        shardDateMap.put((String) row.getField(1), (LocalDate) row.getField(0));
    }
    for (Collection<LocalDate> dates : shardDateMap.asMap().values()) {
        assertEquals(dates.size(), 1);
    }
    // Make sure we have all the rows
    assertQuery("SELECT orderdate, orderkey FROM test_shard_temporal_date_bucketed", "SELECT orderdate, orderkey FROM orders WHERE orderdate < date '1992-02-08'");
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) LocalDate(java.time.LocalDate) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 27 with MaterializedRow

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

the class BaseRaptorConnectorTest method testTablesSystemTable.

@Test
public void testTablesSystemTable() {
    assertUpdate("" + "CREATE TABLE system_tables_test0 (c00 timestamp, c01 varchar, c02 double, c03 bigint, c04 bigint)");
    assertUpdate("" + "CREATE TABLE system_tables_test1 (c10 timestamp, c11 varchar, c12 double, c13 bigint, c14 bigint) " + "WITH (temporal_column = 'c10')");
    assertUpdate("" + "CREATE TABLE system_tables_test2 (c20 timestamp, c21 varchar, c22 double, c23 bigint, c24 bigint) " + "WITH (temporal_column = 'c20', ordering = ARRAY['c22', 'c21'])");
    assertUpdate("" + "CREATE TABLE system_tables_test3 (c30 timestamp, c31 varchar, c32 double, c33 bigint, c34 bigint) " + "WITH (temporal_column = 'c30', bucket_count = 40, bucketed_on = ARRAY ['c34', 'c33'])");
    assertUpdate("" + "CREATE TABLE system_tables_test4 (c40 timestamp, c41 varchar, c42 double, c43 bigint, c44 bigint) " + "WITH (temporal_column = 'c40', ordering = ARRAY['c41', 'c42'], distribution_name = 'test_distribution', bucket_count = 50, bucketed_on = ARRAY ['c43', 'c44'])");
    assertUpdate("" + "CREATE TABLE system_tables_test5 (c50 timestamp, c51 varchar, c52 double, c53 bigint, c54 bigint) " + "WITH (ordering = ARRAY['c51', 'c52'], distribution_name = 'test_distribution', bucket_count = 50, bucketed_on = ARRAY ['c53', 'c54'], organized = true)");
    MaterializedResult actualResults = computeActual("SELECT * FROM system.tables");
    assertEquals(actualResults.getTypes(), ImmutableList.builder().add(// table_schema
    VARCHAR).add(// table_name
    VARCHAR).add(// temporal_column
    VARCHAR).add(// ordering_columns
    new ArrayType(VARCHAR)).add(// distribution_name
    VARCHAR).add(// bucket_count
    BIGINT).add(// bucket_columns
    new ArrayType(VARCHAR)).add(// organized
    BOOLEAN).build());
    Map<String, MaterializedRow> map = actualResults.getMaterializedRows().stream().filter(row -> ((String) row.getField(1)).startsWith("system_tables_test")).collect(toImmutableMap(row -> ((String) row.getField(1)), identity()));
    assertEquals(map.size(), 6);
    assertEquals(map.get("system_tables_test0").getFields(), asList("tpch", "system_tables_test0", null, null, null, null, null, Boolean.FALSE));
    assertEquals(map.get("system_tables_test1").getFields(), asList("tpch", "system_tables_test1", "c10", null, null, null, null, Boolean.FALSE));
    assertEquals(map.get("system_tables_test2").getFields(), asList("tpch", "system_tables_test2", "c20", ImmutableList.of("c22", "c21"), null, null, null, Boolean.FALSE));
    assertEquals(map.get("system_tables_test3").getFields(), asList("tpch", "system_tables_test3", "c30", null, null, 40L, ImmutableList.of("c34", "c33"), Boolean.FALSE));
    assertEquals(map.get("system_tables_test4").getFields(), asList("tpch", "system_tables_test4", "c40", ImmutableList.of("c41", "c42"), "test_distribution", 50L, ImmutableList.of("c43", "c44"), Boolean.FALSE));
    assertEquals(map.get("system_tables_test5").getFields(), asList("tpch", "system_tables_test5", null, ImmutableList.of("c51", "c52"), "test_distribution", 50L, ImmutableList.of("c53", "c54"), Boolean.TRUE));
    actualResults = computeActual("SELECT * FROM system.tables WHERE table_schema = 'tpch'");
    long actualRowCount = actualResults.getMaterializedRows().stream().filter(row -> ((String) row.getField(1)).startsWith("system_tables_test")).count();
    assertEquals(actualRowCount, 6);
    actualResults = computeActual("SELECT * FROM system.tables WHERE table_name = 'system_tables_test3'");
    assertEquals(actualResults.getMaterializedRows().size(), 1);
    actualResults = computeActual("SELECT * FROM system.tables WHERE table_schema = 'tpch' and table_name = 'system_tables_test3'");
    assertEquals(actualResults.getMaterializedRows().size(), 1);
    actualResults = computeActual("" + "SELECT distribution_name, bucket_count, bucketing_columns, ordering_columns, temporal_column, organized " + "FROM system.tables " + "WHERE table_schema = 'tpch' and table_name = 'system_tables_test3'");
    assertEquals(actualResults.getTypes(), ImmutableList.of(VARCHAR, BIGINT, new ArrayType(VARCHAR), new ArrayType(VARCHAR), VARCHAR, BOOLEAN));
    assertEquals(actualResults.getMaterializedRows().size(), 1);
    assertUpdate("DROP TABLE system_tables_test0");
    assertUpdate("DROP TABLE system_tables_test1");
    assertUpdate("DROP TABLE system_tables_test2");
    assertUpdate("DROP TABLE system_tables_test3");
    assertUpdate("DROP TABLE system_tables_test4");
    assertUpdate("DROP TABLE system_tables_test5");
    assertEquals(computeActual("SELECT * FROM system.tables WHERE table_schema IN ('foo', 'bar')").getRowCount(), 0);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) SkipException(org.testng.SkipException) IntStream(java.util.stream.IntStream) Assertions.assertInstanceOf(io.airlift.testing.Assertions.assertInstanceOf) MaterializedResult(io.trino.testing.MaterializedResult) LocalDateTime(java.time.LocalDateTime) Assertions.assertGreaterThan(io.airlift.testing.Assertions.assertGreaterThan) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) TestTable(io.trino.testing.sql.TestTable) SHARD_UUID_COLUMN_TYPE(io.trino.plugin.raptor.legacy.RaptorColumnHandle.SHARD_UUID_COLUMN_TYPE) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) TestingConnectorBehavior(io.trino.testing.TestingConnectorBehavior) Assertions.assertLessThan(io.airlift.testing.Assertions.assertLessThan) Assertions.assertGreaterThanOrEqual(io.airlift.testing.Assertions.assertGreaterThanOrEqual) MaterializedRow(io.trino.testing.MaterializedRow) INTEGER(io.trino.spi.type.IntegerType.INTEGER) Assert.assertFalse(org.testng.Assert.assertFalse) TestTable.randomTableSuffix(io.trino.testing.sql.TestTable.randomTableSuffix) Collectors.toSet(java.util.stream.Collectors.toSet) Flaky(io.trino.testng.services.Flaky) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) Language(org.intellij.lang.annotations.Language) Collection(java.util.Collection) Set(java.util.Set) ArrayType(io.trino.spi.type.ArrayType) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) UUID(java.util.UUID) Assert.assertNotNull(org.testng.Assert.assertNotNull) SetMultimap(com.google.common.collect.SetMultimap) String.format(java.lang.String.format) BaseConnectorTest(io.trino.testing.BaseConnectorTest) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) BIGINT(io.trino.spi.type.BigintType.BIGINT) LocalDate(java.time.LocalDate) StringJoiner(java.util.StringJoiner) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) DATE(io.trino.spi.type.DateType.DATE) MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 28 with MaterializedRow

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

the class TestIcebergSystemTables method testPartitionTableOnDropColumn.

@Test
public void testPartitionTableOnDropColumn() {
    assertUpdate("CREATE TABLE test_schema.test_table_multi_column (_varchar VARCHAR, _bigint BIGINT, _date DATE) WITH (partitioning = ARRAY['_date'])");
    assertUpdate("INSERT INTO test_schema.test_table_multi_column VALUES ('a', 0, CAST('2019-09-08' AS DATE)), ('a', 1, CAST('2019-09-09' AS DATE)), ('b', 2, CAST('2019-09-09' AS DATE))", 3);
    assertUpdate("INSERT INTO test_schema.test_table_multi_column VALUES ('c', 3, CAST('2019-09-09' AS DATE)), ('a', 4, CAST('2019-09-10' AS DATE)), ('b', 5, CAST('2019-09-10' AS DATE))", 3);
    assertQuery("SELECT count(*) FROM test_schema.test_table_multi_column", "VALUES 6");
    MaterializedResult result = computeActual("SELECT * from test_schema.\"test_table_multi_column$partitions\"");
    assertEquals(result.getRowCount(), 3);
    Map<LocalDate, MaterializedRow> rowsByPartition = result.getMaterializedRows().stream().collect(toImmutableMap(row -> ((LocalDate) ((MaterializedRow) row.getField(0)).getField(0)), Function.identity()));
    assertEquals(rowsByPartition.get(LocalDate.parse("2019-09-08")).getField(4), new MaterializedRow(DEFAULT_PRECISION, new MaterializedRow(DEFAULT_PRECISION, "a", "a", 0L), new MaterializedRow(DEFAULT_PRECISION, 0L, 0L, 0L)));
    assertUpdate("ALTER TABLE test_schema.test_table_multi_column drop column _varchar");
    MaterializedResult resultAfterDrop = computeActual("SELECT * from test_schema.\"test_table_multi_column$partitions\"");
    assertEquals(resultAfterDrop.getRowCount(), 3);
    Map<LocalDate, MaterializedRow> rowsByPartitionAfterDrop = resultAfterDrop.getMaterializedRows().stream().collect(toImmutableMap(row -> ((LocalDate) ((MaterializedRow) row.getField(0)).getField(0)), Function.identity()));
    assertEquals(rowsByPartitionAfterDrop.get(LocalDate.parse("2019-09-08")).getField(4), new MaterializedRow(DEFAULT_PRECISION, new MaterializedRow(DEFAULT_PRECISION, 0L, 0L, 0L)));
    assertUpdate("DROP TABLE IF EXISTS test_schema.test_table_multi_column");
}
Also used : AfterClass(org.testng.annotations.AfterClass) MaterializedResult(io.trino.testing.MaterializedResult) BeforeClass(org.testng.annotations.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Function(java.util.function.Function) AbstractTestQueryFramework(io.trino.testing.AbstractTestQueryFramework) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) LocalDate(java.time.LocalDate) Map(java.util.Map) DEFAULT_PRECISION(io.trino.testing.MaterializedResult.DEFAULT_PRECISION) MaterializedRow(io.trino.testing.MaterializedRow) IcebergQueryRunner.createIcebergQueryRunner(io.trino.plugin.iceberg.IcebergQueryRunner.createIcebergQueryRunner) MaterializedResult(io.trino.testing.MaterializedResult) LocalDate(java.time.LocalDate) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 29 with MaterializedRow

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

the class TestRecordAccess method testJsonStream.

@Test(dataProvider = "testJsonStreamProvider")
public void testJsonStream(int uncompressedMessages, int compressedMessages, String streamName) {
    // Simple case: add a few specific items, query object and internal fields:
    if (uncompressedMessages > 0) {
        createJsonMessages(streamName, uncompressedMessages, 100, false);
    }
    if (compressedMessages > 0) {
        createJsonMessages(streamName, compressedMessages, 100 + uncompressedMessages, true);
    }
    MaterializedResult result = queryRunner.execute("Select id, name, _shard_id, _message_length, _message from " + streamName + " where _message_length >= 1");
    assertEquals(result.getRowCount(), uncompressedMessages + compressedMessages);
    List<Type> types = result.getTypes();
    assertEquals(types.size(), 5);
    assertEquals(types.get(0).toString(), "bigint");
    assertEquals(types.get(1).toString(), "varchar");
    log.info("Types : %s", types);
    List<MaterializedRow> rows = result.getMaterializedRows();
    assertEquals(rows.size(), uncompressedMessages + compressedMessages);
    for (MaterializedRow row : rows) {
        assertEquals(row.getFieldCount(), 5);
        assertTrue((long) row.getFields().get(0) >= 100);
        log.info("ROW: %s", row);
    }
}
Also used : Type(io.trino.spi.type.Type) BigintType(io.trino.spi.type.BigintType) MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 30 with MaterializedRow

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

the class TestMemoryConnectorTest method assertQueryResult.

private void assertQueryResult(@Language("SQL") String sql, Object... expected) {
    MaterializedResult rows = computeActual(sql);
    assertEquals(rows.getRowCount(), expected.length);
    for (int i = 0; i < expected.length; i++) {
        MaterializedRow materializedRow = rows.getMaterializedRows().get(i);
        int fieldCount = materializedRow.getFieldCount();
        assertEquals(fieldCount, 1, format("Expected only one column, but got '%d'", fieldCount));
        Object value = materializedRow.getField(0);
        assertEquals(value, expected[i]);
        assertEquals(materializedRow.getFieldCount(), 1);
    }
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow)

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