Search in sources :

Example 11 with MaterializedRow

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

the class BaseHiveConnectorTest method testFileModifiedTimeHiddenColumn.

@Test(dataProvider = "timestampPrecision")
public void testFileModifiedTimeHiddenColumn(HiveTimestampPrecision precision) {
    long testStartTime = Instant.now().toEpochMilli();
    @Language("SQL") String createTable = "CREATE TABLE test_file_modified_time " + "WITH (" + "partitioned_by = ARRAY['col1']" + ") AS " + "SELECT * FROM (VALUES " + "(0, 0), (3, 0), (6, 0), " + "(1, 1), (4, 1), (7, 1), " + "(2, 2), (5, 2) " + " ) t(col0, col1) ";
    assertUpdate(createTable, 8);
    assertTrue(getQueryRunner().tableExists(getSession(), "test_file_modified_time"));
    TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_file_modified_time");
    List<String> columnNames = ImmutableList.of("col0", "col1", PATH_COLUMN_NAME, FILE_SIZE_COLUMN_NAME, FILE_MODIFIED_TIME_COLUMN_NAME, PARTITION_COLUMN_NAME);
    List<ColumnMetadata> columnMetadatas = tableMetadata.getColumns();
    assertEquals(columnMetadatas.size(), columnNames.size());
    for (int i = 0; i < columnMetadatas.size(); i++) {
        ColumnMetadata columnMetadata = columnMetadatas.get(i);
        assertEquals(columnMetadata.getName(), columnNames.get(i));
        if (columnMetadata.getName().equals(FILE_MODIFIED_TIME_COLUMN_NAME)) {
            assertTrue(columnMetadata.isHidden());
        }
    }
    assertEquals(getPartitions("test_file_modified_time").size(), 3);
    Session sessionWithTimestampPrecision = withTimestampPrecision(getSession(), precision);
    MaterializedResult results = computeActual(sessionWithTimestampPrecision, format("SELECT *, \"%s\" FROM test_file_modified_time", FILE_MODIFIED_TIME_COLUMN_NAME));
    Map<Integer, Instant> fileModifiedTimeMap = new HashMap<>();
    for (int i = 0; i < results.getRowCount(); i++) {
        MaterializedRow row = results.getMaterializedRows().get(i);
        int col0 = (int) row.getField(0);
        int col1 = (int) row.getField(1);
        Instant fileModifiedTime = ((ZonedDateTime) row.getField(2)).toInstant();
        assertThat(fileModifiedTime.toEpochMilli()).isCloseTo(testStartTime, offset(2000L));
        assertEquals(col0 % 3, col1);
        if (fileModifiedTimeMap.containsKey(col1)) {
            assertEquals(fileModifiedTimeMap.get(col1), fileModifiedTime);
        } else {
            fileModifiedTimeMap.put(col1, fileModifiedTime);
        }
    }
    assertEquals(fileModifiedTimeMap.size(), 3);
    assertUpdate("DROP TABLE test_file_modified_time");
}
Also used : TableMetadata(io.trino.metadata.TableMetadata) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Instant(java.time.Instant) ColumnConstraint(io.trino.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint) Constraint(io.trino.spi.connector.Constraint) Language(org.intellij.lang.annotations.Language) ZonedDateTime(java.time.ZonedDateTime) MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) HiveQueryRunner.createBucketedSession(io.trino.plugin.hive.HiveQueryRunner.createBucketedSession) Session(io.trino.Session) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 12 with MaterializedRow

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

the class TestCassandraConnectorTest method testNestedCollectionType.

@Test
public void testNestedCollectionType() {
    session.execute("CREATE KEYSPACE keyspace_test_nested_collection WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor': 1}");
    assertContainsEventually(() -> execute("SHOW SCHEMAS FROM cassandra"), resultBuilder(getSession(), createUnboundedVarcharType()).row("keyspace_test_nested_collection").build(), new Duration(1, MINUTES));
    session.execute("CREATE TABLE keyspace_test_nested_collection.table_set (column_5 bigint PRIMARY KEY, nested_collection frozen<set<set<bigint>>>)");
    session.execute("CREATE TABLE keyspace_test_nested_collection.table_list (column_5 bigint PRIMARY KEY, nested_collection frozen<list<list<bigint>>>)");
    session.execute("CREATE TABLE keyspace_test_nested_collection.table_map (column_5 bigint PRIMARY KEY, nested_collection frozen<map<int, map<bigint, bigint>>>)");
    assertContainsEventually(() -> execute("SHOW TABLES FROM cassandra.keyspace_test_nested_collection"), resultBuilder(getSession(), createUnboundedVarcharType()).row("table_set").row("table_list").row("table_map").build(), new Duration(1, MINUTES));
    session.execute("INSERT INTO keyspace_test_nested_collection.table_set (column_5, nested_collection) VALUES (1, {{1, 2, 3}})");
    assertEquals(execute("SELECT nested_collection FROM cassandra.keyspace_test_nested_collection.table_set").getMaterializedRows().get(0), new MaterializedRow(DEFAULT_PRECISION, "[[1,2,3]]"));
    session.execute("INSERT INTO keyspace_test_nested_collection.table_list (column_5, nested_collection) VALUES (1, [[4, 5, 6]])");
    assertEquals(execute("SELECT nested_collection FROM cassandra.keyspace_test_nested_collection.table_list").getMaterializedRows().get(0), new MaterializedRow(DEFAULT_PRECISION, "[[4,5,6]]"));
    session.execute("INSERT INTO keyspace_test_nested_collection.table_map (column_5, nested_collection) VALUES (1, {7:{8:9}})");
    assertEquals(execute("SELECT nested_collection FROM cassandra.keyspace_test_nested_collection.table_map").getMaterializedRows().get(0), new MaterializedRow(DEFAULT_PRECISION, "{7:{8:9}}"));
    session.execute("DROP KEYSPACE keyspace_test_nested_collection");
}
Also used : Duration(io.airlift.units.Duration) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 13 with MaterializedRow

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

the class QueryAssertions method assertQuery.

private void assertQuery(Session session, @Language("SQL") String actual, @Language("SQL") String expected, boolean ensureOrdering) {
    MaterializedResult actualResults = null;
    try {
        actualResults = execute(session, actual);
    } catch (RuntimeException ex) {
        fail("Execution of 'actual' query failed: " + actual, ex);
    }
    MaterializedResult expectedResults = null;
    try {
        expectedResults = execute(expected);
    } catch (RuntimeException ex) {
        fail("Execution of 'expected' query failed: " + expected, ex);
    }
    assertEquals(expectedResults.getTypes(), actualResults.getTypes(), "Types mismatch for query: \n " + actual + "\n:");
    List<MaterializedRow> actualRows = actualResults.getMaterializedRows();
    List<MaterializedRow> expectedRows = expectedResults.getMaterializedRows();
    if (ensureOrdering) {
        if (!actualRows.equals(expectedRows)) {
            assertEquals(expectedRows, actualRows, "For query: \n " + actual + "\n:");
        }
    } else {
        assertEqualsIgnoreOrder(actualRows, expectedRows, "For query: \n " + actual);
    }
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow)

Example 14 with MaterializedRow

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

the class TestAtopSmoke method assertThatQueryReturnsValue.

private void assertThatQueryReturnsValue(@Language("SQL") String sql, Object expected) {
    MaterializedResult rows = queryRunner.execute(sql);
    MaterializedRow materializedRow = Iterables.getOnlyElement(rows);
    assertEquals(materializedRow.getFieldCount(), 1, "column count");
    Object value = materializedRow.getField(0);
    assertEquals(value, expected);
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow)

Example 15 with MaterializedRow

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

the class TestBlackHoleSmoke method dataGenerationUsage.

@Test
public void dataGenerationUsage() {
    Session session = testSessionBuilder().setCatalog("blackhole").setSchema("default").build();
    assertThatQueryReturnsValue(format("CREATE TABLE nation WITH ( %s = 3, %s = 2, %s = 1 ) as SELECT * FROM tpch.tiny.nation", ROWS_PER_PAGE_PROPERTY, PAGES_PER_SPLIT_PROPERTY, SPLIT_COUNT_PROPERTY), 25L, session);
    assertThatQueryReturnsValue("SELECT count(*) FROM nation", 6L, session);
    assertThatQueryReturnsValue("INSERT INTO nation SELECT * FROM tpch.tiny.nation", 25L, session);
    assertThatQueryReturnsValue("SELECT count(*) FROM nation", 6L, session);
    MaterializedResult rows = queryRunner.execute(session, "SELECT * FROM nation LIMIT 1");
    assertEquals(rows.getRowCount(), 1);
    MaterializedRow row = Iterables.getOnlyElement(rows);
    assertEquals(row.getFieldCount(), 4);
    assertEquals(row.getField(0), 0L);
    assertEquals(row.getField(1), "****************");
    assertEquals(row.getField(2), 0L);
    assertEquals(row.getField(3), "****************");
    assertThatQueryReturnsValue("DROP TABLE nation", true);
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) Session(io.trino.Session) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

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