Search in sources :

Example 11 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project presto by prestodb.

the class SqlCancelTests method cancelQuery.

private void cancelQuery(String sql) throws InterruptedException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (stopwatch.elapsed(SECONDS) < 30) {
        String findQuerySql = "SELECT query_id from system.runtime.queries WHERE query = '%s' and state = 'RUNNING' LIMIT 2";
        QueryResult queryResult = query(format(findQuerySql, sql));
        checkState(queryResult.getRowsCount() < 2, "Query is executed multiple times");
        if (queryResult.getRowsCount() == 1) {
            String queryId = (String) queryResult.row(0).get(0);
            Response response = queryCanceller.cancel(queryId);
            Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT.code());
            return;
        }
        MILLISECONDS.sleep(100L);
    }
    throw new IllegalStateException("Query did not reach running state or maybe it was too quick.");
}
Also used : Response(com.facebook.airlift.http.client.Response) QueryResult(io.prestodb.tempto.query.QueryResult) Stopwatch(com.google.common.base.Stopwatch)

Example 12 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project presto by prestodb.

the class BlackHoleConnector method blackHoleConnector.

@Test(groups = { BLACKHOLE_CONNECTOR })
public void blackHoleConnector() {
    String nullTable = "\"blackhole\".default.nation_" + UUID.randomUUID().toString().replace("-", "");
    String table = "tpch.tiny.nation";
    assertThat(query(format("SELECT count(*) from %s", table))).containsExactly(row(25));
    QueryResult result = query(format("CREATE TABLE %s AS SELECT * FROM %s", nullTable, table));
    try {
        assertThat(result).updatedRowsCountIsEqualTo(25);
        assertThat(query(format("INSERT INTO %s SELECT * FROM %s", nullTable, table))).updatedRowsCountIsEqualTo(25);
        assertThat(query(format("SELECT * FROM %s", nullTable))).hasNoRows();
    } finally {
        query(format("DROP TABLE %s", nullTable));
    }
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test)

Example 13 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project presto by prestodb.

the class JdbcTests method shouldGetTables.

@Test(groups = JDBC)
@Requires(ImmutableNationTable.class)
public void shouldGetTables() throws SQLException {
    QueryResult result = QueryResult.forResultSet(metaData().getTables("hive", null, null, null));
    assertThat(result).contains(row("hive", "default", "nation", "TABLE", null, null, null, null, null, null));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest) Requires(io.prestodb.tempto.Requires)

Example 14 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project presto by prestodb.

the class JdbcTests method shouldExecuteQuery.

@Test(groups = JDBC)
@Requires(ImmutableNationTable.class)
public void shouldExecuteQuery() throws SQLException {
    try (Statement statement = connection().createStatement()) {
        QueryResult result = queryResult(statement, "select * from hive.default.nation");
        assertThat(result).matches(PRESTO_NATION_RESULT);
    }
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest) Requires(io.prestodb.tempto.Requires)

Example 15 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project presto by prestodb.

the class JdbcTests method shouldSetLocale.

@Test(groups = JDBC)
public void shouldSetLocale() throws SQLException {
    if (usingPrestoJdbcDriver(connection())) {
        ((PrestoConnection) connection()).setLocale(CHINESE);
        try (Statement statement = connection().createStatement()) {
            QueryResult result = queryResult(statement, "SELECT date_format(TIMESTAMP '2001-01-09 09:04', '%M')");
            assertThat(result).contains(row("一月"));
        }
    } else {
        LOGGER.warn("shouldSetLocale() only applies to PrestoJdbcDriver");
    }
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) PrestoConnection(com.facebook.presto.jdbc.PrestoConnection) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Aggregations

QueryResult (io.prestodb.tempto.query.QueryResult)122 Test (org.testng.annotations.Test)110 ProductTest (io.prestodb.tempto.ProductTest)108 Requires (io.prestodb.tempto.Requires)38 BigDecimal (java.math.BigDecimal)14 Statement (java.sql.Statement)12 PreparedStatement (java.sql.PreparedStatement)8 Duration (io.airlift.units.Duration)6 Row (io.prestodb.tempto.assertions.QueryAssert.Row)6 List (java.util.List)6 STORAGE_FORMATS (com.facebook.presto.tests.TestGroups.STORAGE_FORMATS)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Row.row (io.prestodb.tempto.assertions.QueryAssert.Row.row)4 QueryAssert.assertThat (io.prestodb.tempto.assertions.QueryAssert.assertThat)4 QueryExecutor.query (io.prestodb.tempto.query.QueryExecutor.query)4 String.format (java.lang.String.format)4 Connection (java.sql.Connection)4 Response (com.facebook.airlift.http.client.Response)2 PrestoConnection (com.facebook.presto.jdbc.PrestoConnection)2 JdbcDriverUtils (com.facebook.presto.tests.utils.JdbcDriverUtils)2