Search in sources :

Example 31 with QueryResult

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

the class TestAllDatatypesFromHiveConnector method testSelectAllDatatypesOrc.

@Requires(OrcRequirements.class)
@Test(groups = { JDBC })
public void testSelectAllDatatypesOrc() {
    String tableName = mutableTableInstanceOf(ALL_HIVE_SIMPLE_TYPES_ORC).getNameInDatabase();
    populateDataToHiveTable(tableName);
    assertProperAllDatatypesSchema(tableName);
    QueryResult queryResult = query(format("SELECT * FROM %s", tableName));
    assertColumnTypes(queryResult);
    assertThat(queryResult).containsOnly(row(127, 32767, 2147483647, 9223372036854775807L, 123.345f, 234.567, new BigDecimal("346"), new BigDecimal("345.67800"), Timestamp.valueOf(LocalDateTime.of(2015, 5, 10, 12, 15, 35, 123_000_000)), Date.valueOf("2015-05-10"), "ala ma kota", "ala ma kot", "ala ma    ", true, "kot binarny".getBytes()));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) BigDecimal(java.math.BigDecimal) Requires(io.prestodb.tempto.Requires) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 32 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 33 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 34 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.

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 35 with QueryResult

use of io.prestodb.tempto.query.QueryResult in project urban-eureka by errir503.

the class PreparedStatements method preparedInsertVarbinarySql.

@Test(groups = { JDBC, SIMBA_JDBC })
@Requires(MutableAllTypesTable.class)
public void preparedInsertVarbinarySql() throws SQLException {
    if (usingTeradataJdbcDriver(connection())) {
        String tableNameInDatabase = mutableTablesState().get(TABLE_NAME_MUTABLE).getNameInDatabase();
        String insertSqlWithTable = "PREPARE ps1 from " + String.format(INSERT_SQL, tableNameInDatabase);
        String selectSqlWithTable = String.format(SELECT_STAR_SQL, tableNameInDatabase);
        String executeSql = "EXECUTE ps1 using ";
        Statement statement = connection().createStatement();
        statement.execute(insertSqlWithTable);
        statement.execute(executeSql + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "X'00010203002AF9'");
        QueryResult result = query(selectSqlWithTable);
        assertColumnTypes(result);
        assertThat(result).containsOnly(row(null, null, null, null, null, null, null, null, null, null, null, null, null, null, new byte[] { 0, 1, 2, 3, 0, 42, -7 }));
    } else {
        LOGGER.warn("preparedInsertVarbinarySql() only applies to TeradataJdbcDriver");
    }
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Statement(java.sql.Statement) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest) Requires(io.prestodb.tempto.Requires)

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