Search in sources :

Example 36 with QueryResult

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

the class PreparedStatements method preparedInsertVarbinaryApi.

@Test(groups = { JDBC, SIMBA_JDBC })
@Requires(MutableAllTypesTable.class)
public void preparedInsertVarbinaryApi() {
    if (usingTeradataJdbcDriver(connection())) {
        String tableNameInDatabase = mutableTablesState().get(TABLE_NAME_MUTABLE).getNameInDatabase();
        String insertSqlWithTable = String.format(INSERT_SQL, tableNameInDatabase);
        String selectSqlWithTable = String.format(SELECT_STAR_SQL, tableNameInDatabase);
        defaultQueryExecutor().executeQuery(insertSqlWithTable, param(TINYINT, null), param(SMALLINT, null), param(INTEGER, null), param(BIGINT, null), param(FLOAT, null), param(DOUBLE, null), param(DECIMAL, null), param(DECIMAL, null), param(TIMESTAMP, null), param(DATE, null), param(VARCHAR, null), param(VARCHAR, null), param(CHAR, null), param(BOOLEAN, null), param(VARBINARY, new byte[] { 0, 1, 2, 3, 0, 42, -7 }));
        QueryResult result = defaultQueryExecutor().executeQuery(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("preparedInsertVarbinaryApi() only applies to TeradataJdbcDriver");
    }
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest) Requires(io.prestodb.tempto.Requires)

Example 37 with QueryResult

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

the class PreparedStatements method preparedInsertSql.

@Test(groups = { JDBC, SIMBA_JDBC })
@Requires(MutableAllTypesTable.class)
public void preparedInsertSql() 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 + "cast(127 as tinyint), " + "cast(32767 as smallint), " + "2147483647, " + "9223372036854775807, " + "cast(123.345 as real), " + "cast(234.567 as double), " + "cast(345 as decimal(10)), " + "cast(345.678 as decimal(10,5)), " + "timestamp '2015-05-10 12:15:35', " + "date '2015-05-10', " + "'ala ma kota', " + "'ala ma kot', " + "cast('ala ma' as char(10)), " + "true, " + "X'00010203002AF9'");
        statement.execute(executeSql + "cast(1 as tinyint), " + "cast(2 as smallint), " + "3, " + "4, " + "cast(5.6 as real), " + "cast(7.8 as double), " + "cast(9 as decimal(10)), " + "cast(2.3 as decimal(10,5)), " + "timestamp '2012-05-10 1:35:15', " + "date '2014-03-10', " + "'abc', " + "'def', " + "cast('ghi' as char(10)), " + "false, " + "varbinary 'jkl'");
        statement.execute(executeSql + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null, " + "null");
        QueryResult result = query(selectSqlWithTable);
        assertColumnTypes(result);
        assertThat(result).containsOnly(row(127, 32767, 2147483647, new Long("9223372036854775807"), Float.valueOf("123.345"), 234.567, BigDecimal.valueOf(345), new BigDecimal("345.67800"), Timestamp.valueOf("2015-05-10 12:15:35"), Date.valueOf("2015-05-10"), "ala ma kota", "ala ma kot", "ala ma    ", Boolean.TRUE, new byte[] { 0, 1, 2, 3, 0, 42, -7 }), row(1, 2, 3, 4, Float.valueOf("5.6"), 7.8, BigDecimal.valueOf(9), new BigDecimal("2.30000"), Timestamp.valueOf("2012-05-10 1:35:15"), Date.valueOf("2014-03-10"), "abc", "def", "ghi       ", Boolean.FALSE, "jkl".getBytes()), row(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null));
    } else {
        LOGGER.warn("preparedInsertSql() only applies to TeradataJdbcDriver");
    }
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Statement(java.sql.Statement) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest) Requires(io.prestodb.tempto.Requires)

Example 38 with QueryResult

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

the class KafkaAvroSmokeTest method testNullType.

@Test(groups = { KAFKA })
@Requires(NullDataAvroTable.class)
public void testNullType() throws SQLException {
    QueryResult queryResult = query(format("select * from %s.%s", KAFKA_CATALOG, ALL_NULL_AVRO_TABLE_NAME));
    assertThat(queryResult).containsOnly(row(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 39 with QueryResult

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

the class TestHiveStorageFormats method assertSelect.

private static void assertSelect(String query, String tableName) {
    QueryResult expected = query(format(query, "tpch." + TPCH_SCHEMA + ".lineitem"));
    List<Row> expectedRows = expected.rows().stream().map((columns) -> row(columns.toArray())).collect(toImmutableList());
    QueryResult actual = query(format(query, tableName));
    assertThat(actual).hasColumns(expected.getColumnTypes()).containsExactly(expectedRows);
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Connection(java.sql.Connection) DataProvider(org.testng.annotations.DataProvider) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) QueryExecutors.onHive(com.facebook.presto.tests.utils.QueryExecutors.onHive) STORAGE_FORMATS(com.facebook.presto.tests.TestGroups.STORAGE_FORMATS) Test(org.testng.annotations.Test) Row.row(io.prestodb.tempto.assertions.QueryAssert.Row.row) String.format(java.lang.String.format) SQLException(java.sql.SQLException) List(java.util.List) QueryExecutor.query(io.prestodb.tempto.query.QueryExecutor.query) Row(io.prestodb.tempto.assertions.QueryAssert.Row) QueryAssert.assertThat(io.prestodb.tempto.assertions.QueryAssert.assertThat) QueryExecutor.defaultQueryExecutor(io.prestodb.tempto.query.QueryExecutor.defaultQueryExecutor) Locale(java.util.Locale) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) JdbcDriverUtils(com.facebook.presto.tests.utils.JdbcDriverUtils) ProductTest(io.prestodb.tempto.ProductTest) JdbcDriverUtils.setSessionProperty(com.facebook.presto.tests.utils.JdbcDriverUtils.setSessionProperty) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) QueryResult(io.prestodb.tempto.query.QueryResult) Row(io.prestodb.tempto.assertions.QueryAssert.Row)

Example 40 with QueryResult

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

the class TestSyncPartitionMetadata method assertData.

private static void assertData(String tableName, QueryAssert.Row... rows) {
    QueryResult dataResult = query("SELECT payload, col_x, col_y FROM " + tableName + " ORDER BY 1, 2, 3 ASC");
    assertThat(dataResult).containsExactly(rows);
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult)

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