Search in sources :

Example 21 with MaterializedRow

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

the class BaseMongoConnectorTest method createTableWithEveryType.

@Test
public void createTableWithEveryType() {
    String query = "" + "CREATE TABLE test_types_table AS " + "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";
    assertUpdate(query, 1);
    MaterializedResult results = getQueryRunner().execute(getSession(), "SELECT * FROM test_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_types_table");
    assertFalse(getQueryRunner().tableExists(getSession(), "test_types_table"));
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 22 with MaterializedRow

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

the class BaseMySqlConnectorTest method testMySqlTinyint.

@Test
public void testMySqlTinyint() {
    onRemoteDatabase().execute("CREATE TABLE tpch.mysql_test_tinyint1 (c_tinyint tinyint(1))");
    MaterializedResult actual = computeActual("SHOW COLUMNS FROM mysql_test_tinyint1");
    MaterializedResult expected = MaterializedResult.resultBuilder(getSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR).row("c_tinyint", "tinyint", "", "").build();
    assertEquals(actual, expected);
    onRemoteDatabase().execute("INSERT INTO tpch.mysql_test_tinyint1 VALUES (127), (-128)");
    MaterializedResult materializedRows = computeActual("SELECT * FROM tpch.mysql_test_tinyint1 WHERE c_tinyint = 127");
    assertEquals(materializedRows.getRowCount(), 1);
    MaterializedRow row = getOnlyElement(materializedRows);
    assertEquals(row.getFields().size(), 1);
    assertEquals(row.getField(0), (byte) 127);
    assertUpdate("DROP TABLE mysql_test_tinyint1");
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test) BaseJdbcConnectorTest(io.trino.plugin.jdbc.BaseJdbcConnectorTest)

Example 23 with MaterializedRow

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

the class TestPrometheusIntegrationStatus method testConfirmMetricAvailableAndCheckUp.

@Test
public void testConfirmMetricAvailableAndCheckUp() throws Exception {
    int maxTries = 60;
    int timeBetweenTriesMillis = 1000;
    int tries = 0;
    final OkHttpClient httpClient = new OkHttpClient.Builder().connectTimeout(120, TimeUnit.SECONDS).readTimeout(120, TimeUnit.SECONDS).build();
    HttpUrl.Builder urlBuilder = HttpUrl.parse(server.getUri().toString()).newBuilder().encodedPath("/api/v1/query");
    urlBuilder.addQueryParameter("query", "up[1d]");
    String url = urlBuilder.build().toString();
    Request request = new Request.Builder().url(url).build();
    String responseBody;
    // this seems to be a reliable way to ensure Prometheus has `up` metric data
    while (tries < maxTries) {
        responseBody = httpClient.newCall(request).execute().body().string();
        if (responseBody.contains("values")) {
            Logger log = Logger.get(TestPrometheusIntegrationStatus.class);
            log.info("prometheus response: %s", responseBody);
            break;
        }
        Thread.sleep(timeBetweenTriesMillis);
        tries++;
    }
    if (tries == maxTries) {
        fail("Prometheus container not available for metrics query in " + maxTries * timeBetweenTriesMillis + " milliseconds.");
    }
    // now we're making sure the client is ready
    tries = 0;
    while (tries < maxTries) {
        if (getQueryRunner().tableExists(getSession(), "up")) {
            break;
        }
        Thread.sleep(timeBetweenTriesMillis);
        tries++;
    }
    if (tries == maxTries) {
        fail("Prometheus container, or client, not available for metrics query in " + maxTries * timeBetweenTriesMillis + " milliseconds.");
    }
    MaterializedResult results = computeActual("SELECT * FROM prometheus.default.up LIMIT 1");
    assertEquals(results.getRowCount(), 1);
    MaterializedRow row = results.getMaterializedRows().get(0);
    assertEquals(row.getField(0).toString(), "{instance=localhost:9090, __name__=up, job=prometheus}");
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Logger(io.airlift.log.Logger) MaterializedResult(io.trino.testing.MaterializedResult) HttpUrl(okhttp3.HttpUrl) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test)

Example 24 with MaterializedRow

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

the class BaseRaptorConnectorTest method testTableStatsSystemTable.

@SuppressWarnings("OverlyStrongTypeCast")
@Test
public void testTableStatsSystemTable() {
    // basic sanity tests
    assertQuery("" + "SELECT table_schema, table_name, sum(row_count)\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + "  AND table_name IN ('orders', 'region')\n" + "GROUP BY 1, 2", "" + "SELECT 'tpch', 'orders', (SELECT count(*) FROM orders)\n" + "UNION ALL\n" + "SELECT 'tpch', 'region', (SELECT count(*) FROM region)");
    assertQuery("" + "SELECT\n" + "  bool_and(row_count >= shard_count)\n" + ", bool_and(update_time >= create_time)\n" + ", bool_and(table_version >= 1)\n" + "FROM system.table_stats\n" + "WHERE row_count > 0", "SELECT true, true, true");
    // create empty table
    assertUpdate("CREATE TABLE test_table_stats (x bigint)");
    @Language("SQL") String sql = "" + "SELECT create_time, update_time, table_version," + "  shard_count, row_count, uncompressed_size\n" + "FROM system.table_stats\n" + "WHERE table_schema = 'tpch'\n" + "  AND table_name = 'test_table_stats'";
    MaterializedRow row = getOnlyElement(computeActual(sql).getMaterializedRows());
    LocalDateTime createTime = (LocalDateTime) row.getField(0);
    LocalDateTime updateTime1 = (LocalDateTime) row.getField(1);
    assertEquals(createTime, updateTime1);
    // table_version
    assertEquals(row.getField(2), 1L);
    // shard_count
    assertEquals(row.getField(3), 0L);
    // row_count
    assertEquals(row.getField(4), 0L);
    // uncompressed_size
    long size1 = (long) row.getField(5);
    // insert
    assertUpdate("INSERT INTO test_table_stats VALUES (1), (2), (3), (4)", 4);
    row = getOnlyElement(computeActual(sql).getMaterializedRows());
    assertEquals(row.getField(0), createTime);
    LocalDateTime updateTime2 = (LocalDateTime) row.getField(1);
    assertLessThan(updateTime1, updateTime2);
    // table_version
    assertEquals(row.getField(2), 2L);
    // shard_count
    assertGreaterThanOrEqual((Long) row.getField(3), 1L);
    // row_count
    assertEquals(row.getField(4), 4L);
    // uncompressed_size
    long size2 = (long) row.getField(5);
    assertGreaterThan(size2, size1);
    // delete
    assertUpdate("DELETE FROM test_table_stats WHERE x IN (2, 4)", 2);
    row = getOnlyElement(computeActual(sql).getMaterializedRows());
    assertEquals(row.getField(0), createTime);
    LocalDateTime updateTime3 = (LocalDateTime) row.getField(1);
    assertLessThan(updateTime2, updateTime3);
    // table_version
    assertEquals(row.getField(2), 3L);
    // shard_count
    assertGreaterThanOrEqual((Long) row.getField(3), 1L);
    // row_count
    assertEquals(row.getField(4), 2L);
    // uncompressed_Size
    long size3 = (long) row.getField(5);
    assertLessThan(size3, size2);
    // add column
    assertUpdate("ALTER TABLE test_table_stats ADD COLUMN y bigint");
    row = getOnlyElement(computeActual(sql).getMaterializedRows());
    assertEquals(row.getField(0), createTime);
    assertLessThan(updateTime3, (LocalDateTime) row.getField(1));
    // table_version
    assertEquals(row.getField(2), 4L);
    // row_count
    assertEquals(row.getField(4), 2L);
    // uncompressed_size
    assertEquals(row.getField(5), size3);
    // cleanup
    assertUpdate("DROP TABLE test_table_stats");
}
Also used : LocalDateTime(java.time.LocalDateTime) Language(org.intellij.lang.annotations.Language) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 25 with MaterializedRow

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

the class BaseRaptorConnectorTest method testShardingByTemporalTimestampColumn.

@Test
public void testShardingByTemporalTimestampColumn() {
    assertUpdate("CREATE TABLE test_shard_temporal_timestamp(col1 BIGINT, col2 TIMESTAMP) WITH (temporal_column = 'col2')");
    int rows = 20;
    StringJoiner joiner = new StringJoiner(", ", "INSERT INTO test_shard_temporal_timestamp VALUES ", "");
    for (int i = 0; i < rows; i++) {
        joiner.add(format("(%s, TIMESTAMP '2016-08-08 01:00' + interval '%s' hour)", i, i * 4));
    }
    assertUpdate(joiner.toString(), format("VALUES(%s)", rows));
    MaterializedResult results = computeActual("SELECT cast(cast(col2 as DATE) as VARCHAR), \"$shard_uuid\" FROM test_shard_temporal_timestamp");
    assertEquals(results.getRowCount(), rows);
    // Each shard will only contain data of one date.
    SetMultimap<String, String> shardDateMap = HashMultimap.create();
    for (MaterializedRow row : results.getMaterializedRows()) {
        shardDateMap.put((String) row.getField(1), (String) row.getField(0));
    }
    for (Collection<String> dates : shardDateMap.asMap().values()) {
        assertEquals(dates.size(), 1);
    }
    // Ensure one shard can contain different timestamps from the same day
    assertLessThan(shardDateMap.size(), rows);
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) StringJoiner(java.util.StringJoiner) 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