Search in sources :

Example 96 with QueryResult

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

the class PreparedStatements method preparedInsertApi.

@Test(groups = { JDBC, SIMBA_JDBC })
@Requires(MutableAllTypesTable.class)
public void preparedInsertApi() {
    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);
        query(insertSqlWithTable, param(TINYINT, 127), param(SMALLINT, 32767), param(INTEGER, 2147483647), param(BIGINT, new BigInteger("9223372036854775807")), param(FLOAT, Float.valueOf("123.345")), param(DOUBLE, 234.567), param(DECIMAL, BigDecimal.valueOf(345)), param(DECIMAL, BigDecimal.valueOf(345.678)), param(TIMESTAMP, Timestamp.valueOf("2015-05-10 12:15:35")), param(DATE, Date.valueOf("2015-05-10")), param(VARCHAR, "ala ma kota"), param(VARCHAR, "ala ma kot"), param(CHAR, "    ala ma"), param(BOOLEAN, Boolean.TRUE), param(VARBINARY, new byte[] { 0, 1, 2, 3, 0, 42, -7 }));
        query(insertSqlWithTable, param(TINYINT, 1), param(SMALLINT, 2), param(INTEGER, 3), param(BIGINT, 4), param(FLOAT, Float.valueOf("5.6")), param(DOUBLE, 7.8), param(DECIMAL, BigDecimal.valueOf(91)), param(DECIMAL, BigDecimal.valueOf(2.3)), param(TIMESTAMP, Timestamp.valueOf("2012-05-10 1:35:15")), param(DATE, Date.valueOf("2014-03-10")), param(VARCHAR, "abc"), param(VARCHAR, "def"), param(CHAR, "       ghi"), param(BOOLEAN, Boolean.FALSE), param(VARBINARY, new byte[] { 0, 1, 2, 3, 0, 42, -7 }));
        query(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, 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, 4L, Float.valueOf("5.6"), 7.8, BigDecimal.valueOf(91), BigDecimal.valueOf(2.3), Timestamp.valueOf("2012-05-10 1:35:15"), Date.valueOf("2014-03-10"), "abc", "def", "       ghi", Boolean.FALSE, new byte[] { 0, 1, 2, 3, 0, 42, -7 }), row(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null));
    } else {
        LOGGER.warn("preparedInsertApi() only applies to TeradataJdbcDriver");
    }
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest) Requires(io.prestodb.tempto.Requires)

Example 97 with QueryResult

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

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)

Example 98 with QueryResult

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

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

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

the class KafkaSmokeTest method testSelectSimpleKeyAndValue.

@Test(groups = { KAFKA })
@Requires(SimpleKeyAndValueTable.class)
public void testSelectSimpleKeyAndValue() {
    QueryResult queryResult = query(format("select varchar_key, bigint_key, varchar_value, bigint_value from %s.%s.%s", KAFKA_CATALOG, SCHEMA_NAME, SIMPLE_KEY_AND_VALUE_TABLE_NAME));
    assertThat(queryResult).containsOnly(row("jasio", 1, "ania", 2), row("piotr", 3, "kasia", 4));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest) Requires(io.prestodb.tempto.Requires)

Example 100 with QueryResult

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

the class TestInsert method testInsertNull.

@Test(groups = { SQL_SERVER, PROFILE_SPECIFIC_TESTS })
public void testInsertNull() {
    String sql = format("INSERT INTO %s.%s values (null, null, null, null, null, null, null, null)", SQLSERVER, INSERT_TABLE_NAME);
    onPresto().executeQuery(sql);
    sql = format("SELECT * FROM %s.%s", MASTER, INSERT_TABLE_NAME);
    QueryResult queryResult = onSqlServer().executeQuery(sql);
    assertThat(queryResult).contains(row(null, null, null, null, null, null, null, null));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) 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