Search in sources :

Example 6 with Requires

use of io.prestodb.tempto.Requires 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 7 with Requires

use of io.prestodb.tempto.Requires in project presto by prestodb.

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 8 with Requires

use of io.prestodb.tempto.Requires in project presto by prestodb.

the class TestHiveCoercion method testHiveCoercionAvro.

@Requires(AvroRequirements.class)
@Test(groups = { HIVE_COERCION, JDBC })
public void testHiveCoercionAvro() {
    String tableName = mutableTableInstanceOf(HIVE_COERCION_AVRO).getNameInDatabase();
    onHive().executeQuery(format("INSERT INTO TABLE %s " + "PARTITION (id=1) " + "VALUES" + "(2323, 0.5)," + "(-2323, -1.5)", tableName));
    onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN int_to_bigint int_to_bigint bigint", tableName));
    onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN float_to_double float_to_double double", tableName));
    assertThat(query("SHOW COLUMNS FROM " + tableName).project(1, 2)).containsExactly(row("int_to_bigint", "bigint"), row("float_to_double", "double"), row("id", "bigint"));
    QueryResult queryResult = query("SELECT * FROM " + tableName);
    assertThat(queryResult).hasColumns(BIGINT, DOUBLE, BIGINT);
    assertThat(queryResult).containsOnly(row(2323L, 0.5, 1), row(-2323L, -1.5, 1));
}
Also used : QueryResult(io.prestodb.tempto.query.QueryResult) Requires(io.prestodb.tempto.Requires) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest)

Example 9 with Requires

use of io.prestodb.tempto.Requires in project presto by prestodb.

the class JdbcTests method shouldInsertSelectQuery.

@Test(groups = JDBC)
@Requires(ImmutableAndMutableNationTable.class)
public void shouldInsertSelectQuery() throws SQLException {
    String tableNameInDatabase = mutableTablesState().get(TABLE_NAME).getNameInDatabase();
    assertThat(query("SELECT * FROM " + tableNameInDatabase)).hasNoRows();
    try (Statement statement = connection().createStatement()) {
        assertThat(statement.executeUpdate("insert into " + tableNameInDatabase + " select * from nation")).isEqualTo(25);
    }
    assertThat(query("SELECT * FROM " + tableNameInDatabase)).matches(PRESTO_NATION_RESULT);
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Test(org.testng.annotations.Test) ProductTest(io.prestodb.tempto.ProductTest) Requires(io.prestodb.tempto.Requires)

Example 10 with Requires

use of io.prestodb.tempto.Requires in project presto by prestodb.

the class JdbcTests method shouldExecuteQueryWithSelectedCatalogAndSchema.

@Test(groups = JDBC)
@Requires(ImmutableNationTable.class)
public void shouldExecuteQueryWithSelectedCatalogAndSchema() throws SQLException {
    if (usingTeradataJdbc4Driver(connection())) {
        LOGGER.warn("connection().setSchema() is not supported in JDBC 4");
    } else {
        connection().setCatalog("hive");
        connection().setSchema("default");
        try (Statement statement = connection().createStatement()) {
            QueryResult result = queryResult(statement, "select * from 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)

Aggregations

ProductTest (io.prestodb.tempto.ProductTest)21 Requires (io.prestodb.tempto.Requires)21 Test (org.testng.annotations.Test)21 QueryResult (io.prestodb.tempto.query.QueryResult)19 BigDecimal (java.math.BigDecimal)7 Statement (java.sql.Statement)6 PreparedStatement (java.sql.PreparedStatement)3 BigInteger (java.math.BigInteger)1