use of io.trino.tempto.query.QueryResult in project trino by trinodb.
the class TestJdbc method shouldGetSchemas.
@Test(groups = JDBC)
public void shouldGetSchemas() throws SQLException {
QueryResult result = QueryResult.forResultSet(metaData().getSchemas("hive", null));
assertThat(result).contains(row("default", "hive"));
}
use of io.trino.tempto.query.QueryResult in project trino by trinodb.
the class TestPreparedStatements method preparedInsertVarbinaryApi.
@Test(groups = JDBC)
@Requires(MutableAllTypesTable.class)
public void preparedInsertVarbinaryApi() {
String tableNameInDatabase = mutableTablesState().get(TABLE_NAME_MUTABLE).getNameInDatabase();
String insertSqlWithTable = format(INSERT_SQL, tableNameInDatabase);
String selectSqlWithTable = format(SELECT_STAR_SQL, tableNameInDatabase);
onTrino().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 = onTrino().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 }));
}
use of io.trino.tempto.query.QueryResult in project trino by trinodb.
the class TestPreparedStatements method preparedInsertApi.
@Test(groups = JDBC)
@Requires(MutableAllTypesTable.class)
public void preparedInsertApi() {
String tableNameInDatabase = mutableTablesState().get(TABLE_NAME_MUTABLE).getNameInDatabase();
String insertSqlWithTable = format(INSERT_SQL, tableNameInDatabase);
String selectSqlWithTable = format(SELECT_STAR_SQL, tableNameInDatabase);
onTrino().executeQuery(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 }));
onTrino().executeQuery(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 }));
onTrino().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, null));
QueryResult result = onTrino().executeQuery(selectSqlWithTable);
assertColumnTypes(result);
assertThat(result).containsOnly(row(127, 32767, 2147483647, Long.valueOf("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));
}
use of io.trino.tempto.query.QueryResult in project trino by trinodb.
the class TestPreparedStatements method preparedInsertVarbinarySql.
@Test(groups = JDBC)
@Requires(MutableAllTypesTable.class)
public void preparedInsertVarbinarySql() throws SQLException {
String tableNameInDatabase = mutableTablesState().get(TABLE_NAME_MUTABLE).getNameInDatabase();
String insertSqlWithTable = "PREPARE ps1 from " + format(INSERT_SQL, tableNameInDatabase);
String selectSqlWithTable = format(SELECT_STAR_SQL, tableNameInDatabase);
String executeSql = "EXECUTE ps1 using ";
try (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 = onTrino().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 }));
}
}
use of io.trino.tempto.query.QueryResult in project trino by trinodb.
the class TestReadUniontype method testReadUniontype.
@Test(dataProvider = "storage_formats", groups = SMOKE)
public void testReadUniontype(String storageFormat) {
// According to testing results, the Hive INSERT queries here only work in Hive 1.2
if (getHiveVersionMajor() != 1 || getHiveVersionMinor() != 2) {
throw new SkipException("This test can only be run with Hive 1.2 (default config)");
}
createTestTable(storageFormat);
// Generate a file with rows:
// 0, {0: 36}
// 1, {1: 7.2}
// 2, {2: ['foo', 'bar']}
// 3, {1: 10.8}
// 4, {0: 144}
// 5, {2: ['hello']
onHive().executeQuery(format("INSERT INTO TABLE %s " + "SELECT 0, create_union(0, CAST(36 AS INT), CAST(NULL AS DOUBLE), ARRAY('foo','bar')) " + "UNION ALL " + "SELECT 1, create_union(1, CAST(NULL AS INT), CAST(7.2 AS DOUBLE), ARRAY('foo','bar')) " + "UNION ALL " + "SELECT 2, create_union(2, CAST(NULL AS INT), CAST(NULL AS DOUBLE), ARRAY('foo','bar')) " + "UNION ALL " + "SELECT 3, create_union(1, CAST(NULL AS INT), CAST(10.8 AS DOUBLE), ARRAY('foo','bar')) " + "UNION ALL " + "SELECT 4, create_union(0, CAST(144 AS INT), CAST(NULL AS DOUBLE), ARRAY('foo','bar')) " + "UNION ALL " + "SELECT 5, create_union(2, CAST(NULL AS INT), CAST(NULL AS DOUBLE), ARRAY('hello', 'world'))", TABLE_NAME));
// Generate a file with rows:
// 6, {0: 180}
// 7, {1: 21.6}
// 8, {0: 252}
onHive().executeQuery(format("INSERT INTO TABLE %s " + "SELECT 6, create_union(0, CAST(180 AS INT), CAST(NULL AS DOUBLE), ARRAY('foo','bar')) " + "UNION ALL " + "SELECT 7, create_union(1, CAST(NULL AS INT), CAST(21.6 AS DOUBLE), ARRAY('foo','bar')) " + "UNION ALL " + "SELECT 8, create_union(0, CAST(252 AS INT), CAST(NULL AS DOUBLE), ARRAY('foo','bar'))", TABLE_NAME));
QueryResult selectAllResult = onTrino().executeQuery(format("SELECT * FROM %s", TABLE_NAME));
assertEquals(selectAllResult.rows().size(), 9);
for (List<?> row : selectAllResult.rows()) {
int id = (Integer) row.get(0);
switch(id) {
case 0:
assertStructEquals(row.get(1), new Object[] { (byte) 0, 36, null, null });
break;
case 1:
assertStructEquals(row.get(1), new Object[] { (byte) 1, null, 7.2D, null });
break;
case 2:
assertStructEquals(row.get(1), new Object[] { (byte) 2, null, null, Arrays.asList("foo", "bar") });
break;
case 3:
assertStructEquals(row.get(1), new Object[] { (byte) 1, null, 10.8D, null });
break;
case 4:
assertStructEquals(row.get(1), new Object[] { (byte) 0, 144, null, null });
break;
case 5:
assertStructEquals(row.get(1), new Object[] { (byte) 2, null, null, Arrays.asList("hello", "world") });
break;
case 6:
assertStructEquals(row.get(1), new Object[] { (byte) 0, 180, null, null });
break;
case 7:
assertStructEquals(row.get(1), new Object[] { (byte) 1, null, 21.6, null });
break;
case 8:
assertStructEquals(row.get(1), new Object[] { (byte) 0, 252, null, null });
break;
}
}
}
Aggregations