use of io.trino.tempto.query.QueryResult in project trino by trinodb.
the class TestPreparedStatements method preparedInsertSql.
@Test(groups = JDBC)
@Requires(MutableAllTypesTable.class)
public void preparedInsertSql() 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 + "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 = 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, 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(UTF_8)), 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 TestHivePartitionsTable method testShowPartitionsFromHiveTable.
@Test(groups = HIVE_PARTITIONING)
@Flaky(issue = ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE, match = ERROR_COMMITTING_WRITE_TO_HIVE_MATCH)
public void testShowPartitionsFromHiveTable() {
String tableNameInDatabase = tablesState.get(PARTITIONED_TABLE).getNameInDatabase();
String partitionsTable = "\"" + tableNameInDatabase + "$partitions\"";
QueryResult partitionListResult;
partitionListResult = onTrino().executeQuery("SELECT * FROM " + partitionsTable);
assertThat(partitionListResult).containsExactlyInOrder(row(1), row(2));
assertColumnNames(partitionListResult, "part_col");
partitionListResult = onTrino().executeQuery(format("SELECT * FROM %s WHERE part_col = 1", partitionsTable));
assertThat(partitionListResult).containsExactlyInOrder(row(1));
assertColumnNames(partitionListResult, "part_col");
assertQueryFailure(() -> onTrino().executeQuery(format("SELECT * FROM %s WHERE no_such_column = 1", partitionsTable))).hasMessageContaining("Column 'no_such_column' cannot be resolved");
assertQueryFailure(() -> onTrino().executeQuery(format("SELECT * FROM %s WHERE col = 1", partitionsTable))).hasMessageContaining("Column 'col' cannot be resolved");
}
use of io.trino.tempto.query.QueryResult in project trino by trinodb.
the class TestKafkaAvroReadsSmokeTest method testSelectPrimitiveDataType.
@Test(groups = { KAFKA, PROFILE_SPECIFIC_TESTS }, dataProvider = "catalogs")
public void testSelectPrimitiveDataType(KafkaCatalog kafkaCatalog, MessageSerializer messageSerializer) throws Exception {
ImmutableMap<String, Object> record = ImmutableMap.of("a_varchar", "foobar", "a_bigint", 127L, "a_double", 234.567, "a_boolean", true);
String topicName = ALL_DATATYPES_AVRO_TOPIC_NAME + kafkaCatalog.getTopicNameSuffix();
createAvroTable(ALL_DATATYPE_SCHEMA_PATH, ALL_DATATYPES_AVRO_TOPIC_NAME, topicName, record, messageSerializer);
assertEventually(new Duration(30, SECONDS), () -> {
QueryResult queryResult = onTrino().executeQuery(format("select * from %s.%s", kafkaCatalog.getCatalogName(), KAFKA_SCHEMA + "." + topicName));
assertThat(queryResult).containsOnly(row("foobar", 127, 234.567, true));
});
}
use of io.trino.tempto.query.QueryResult in project trino by trinodb.
the class TestKafkaAvroReadsSmokeTest method testAvroWithSchemaReferences.
@Test(groups = { KAFKA, PROFILE_SPECIFIC_TESTS })
public void testAvroWithSchemaReferences() throws Exception {
TestingAvroSchema referredSchema = new TestingAvroSchema(Files.readString(new File(ALL_DATATYPE_SCHEMA_PATH).toPath()), ImmutableList.of(), ImmutableList.of());
getSchemaRegistryClient().register(ALL_DATATYPES_AVRO_TOPIC_NAME + "-value", referredSchema);
Map<String, Object> record = ImmutableMap.of("a_varchar", "foobar", "a_bigint", 127L, "a_double", 234.567, "a_boolean", true);
GenericRecordBuilder recordBuilder = new GenericRecordBuilder((Schema) referredSchema.rawSchema());
record.forEach(recordBuilder::set);
TestingAvroSchema actualSchema = new TestingAvroSchema(Files.readString(new File(AVRO_SCHEMA_WITH_REFERENCES_SCHEMA_PATH).toPath()), ImmutableList.of(new SchemaReference(referredSchema.name(), ALL_DATATYPES_AVRO_TOPIC_NAME + "-value", 1)), ImmutableList.of(referredSchema.canonicalString()));
// This is a bit hacky as KafkaTableManager relies on kafka catalog's tables for inserting data into a given topic
createAvroTable(actualSchema, ALL_DATATYPES_AVRO_TOPIC_NAME, AVRO_SCHEMA_WITH_REFERENCES_TOPIC_NAME, ImmutableMap.of("reference", recordBuilder.build()), new SchemaRegistryAvroMessageSerializer());
assertEventually(new Duration(30, SECONDS), () -> {
QueryResult queryResult = onTrino().executeQuery(format("select reference.a_varchar, reference.a_double from kafka_schema_registry.%s.%s", KAFKA_SCHEMA, AVRO_SCHEMA_WITH_REFERENCES_TOPIC_NAME));
assertThat(queryResult).containsOnly(row("foobar", 234.567));
});
}
use of io.trino.tempto.query.QueryResult in project trino by trinodb.
the class TestKafkaAvroReadsSmokeTest method testSelectStructuralDataType.
@Test(groups = { KAFKA, PROFILE_SPECIFIC_TESTS }, dataProvider = "catalogs")
public void testSelectStructuralDataType(KafkaCatalog kafkaCatalog, MessageSerializer messageSerializer) throws Exception {
ImmutableMap<String, Object> record = ImmutableMap.of("a_array", ImmutableList.of(100L, 102L), "a_map", ImmutableMap.of("key1", "value1"));
String topicName = STRUCTURAL_AVRO_TOPIC_NAME + kafkaCatalog.getTopicNameSuffix();
createAvroTable(STRUCTURAL_SCHEMA_PATH, STRUCTURAL_AVRO_TOPIC_NAME, topicName, record, messageSerializer);
assertEventually(new Duration(30, SECONDS), () -> {
QueryResult queryResult = onTrino().executeQuery(format("SELECT a[1], a[2], m['key1'] FROM (SELECT %s as a, %s as m FROM %s.%s) t", kafkaCatalog.isColumnMappingSupported() ? "c_array" : "a_array", kafkaCatalog.isColumnMappingSupported() ? "c_map" : "a_map", kafkaCatalog.getCatalogName(), KAFKA_SCHEMA + "." + topicName));
assertThat(queryResult).containsOnly(row(100, 102, "value1"));
});
}
Aggregations