use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestPhoenixTypeMapping method testArrayNulls.
@Test
public void testArrayNulls() {
// Verify only SELECT instead of using SqlDataTypeTest because array comparison not supported for arrays with null elements
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_array_nulls", "(c1 ARRAY(boolean), c2 ARRAY(varchar), c3 ARRAY(varchar))", ImmutableList.of("(NULL, ARRAY[NULL], ARRAY['foo', NULL, 'bar', NULL])"))) {
assertThat(query("SELECT c1 FROM " + table.getName())).matches("VALUES CAST(NULL AS ARRAY(boolean))");
assertThat(query("SELECT c2 FROM " + table.getName())).matches("VALUES CAST(ARRAY[NULL] AS ARRAY(varchar))");
assertThat(query("SELECT c3 FROM " + table.getName())).matches("VALUES CAST(ARRAY['foo', NULL, 'bar', NULL] AS ARRAY(varchar))");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestPhoenixTypeMapping method testArrayNulls.
@Test
public void testArrayNulls() {
// Verify only SELECT instead of using SqlDataTypeTest because array comparison not supported for arrays with null elements
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_array_nulls", "(c1 ARRAY(boolean), c2 ARRAY(varchar), c3 ARRAY(varchar))", ImmutableList.of("(NULL, ARRAY[NULL], ARRAY['foo', NULL, 'bar', NULL])"))) {
assertThat(query("SELECT c1 FROM " + table.getName())).matches("VALUES CAST(NULL AS ARRAY(boolean))");
assertThat(query("SELECT c2 FROM " + table.getName())).matches("VALUES CAST(ARRAY[NULL] AS ARRAY(varchar))");
assertThat(query("SELECT c3 FROM " + table.getName())).matches("VALUES CAST(ARRAY['foo', NULL, 'bar', NULL] AS ARRAY(varchar))");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestPhoenixTypeMapping method testUnsupportedTinyint.
@Test
public void testUnsupportedTinyint() {
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_tinyint", "(data tinyint, pk tinyint primary key)")) {
assertPhoenixQueryFails(// min - 1
format("INSERT INTO %s VALUES (-129, 1)", table.getName()), "ERROR 203 (22005): Type mismatch. BIGINT and TINYINT for expression: -129 in column 0.DATA");
assertPhoenixQueryFails(// max + 1
format("INSERT INTO %s VALUES (128, 2)", table.getName()), "ERROR 203 (22005): Type mismatch. TINYINT and INTEGER for 128");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestPhoenixTypeMapping method testUnsupportedBigInt.
@Test
public void testUnsupportedBigInt() {
try (TestTable table = new TestTable(new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()), "tpch.test_unsupported_bigint", "(data bigint, pk bigint primary key)")) {
assertPhoenixQueryFails(// min - 1
format("INSERT INTO %s VALUES (-9223372036854775809, 1)", table.getName()), "ERROR 203 (22005): Type mismatch. DECIMAL and BIGINT for expression: -9223372036854775809 in column 0.DATA");
// Phoenix JDBC driver throws ArithmeticException instead of SQLException when the value is larger than max of bigint
// max + 1
assertThatThrownBy(() -> new PhoenixSqlExecutor(phoenixServer.getJdbcUrl()).execute(format("INSERT INTO %s VALUES (9223372036854775808, 2)", table.getName()))).isInstanceOf(ArithmeticException.class).hasMessage("Overflow");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class TestPhoenixConnectorTest method testCountDistinctWithStringTypes.
// Overridden because Phoenix requires a ROWID column
@Override
public void testCountDistinctWithStringTypes() {
assertThatThrownBy(super::testCountDistinctWithStringTypes).hasStackTraceContaining("Illegal data. CHAR types may only contain single byte characters");
// Skipping the ą test case because it is not supported
List<String> rows = Streams.mapWithIndex(Stream.of("a", "b", "A", "B", " a ", "a", "b", " b "), (value, idx) -> String.format("%d, '%2$s', '%2$s'", idx, value)).collect(toImmutableList());
String tableName = "count_distinct_strings" + randomTableSuffix();
try (TestTable testTable = new TestTable(getQueryRunner()::execute, tableName, "(id int, t_char CHAR(5), t_varchar VARCHAR(5)) WITH (ROWKEYS='id')", rows)) {
assertQuery("SELECT count(DISTINCT t_varchar) FROM " + testTable.getName(), "VALUES 6");
assertQuery("SELECT count(DISTINCT t_char) FROM " + testTable.getName(), "VALUES 6");
assertQuery("SELECT count(DISTINCT t_char), count(DISTINCT t_varchar) FROM " + testTable.getName(), "VALUES (6, 6)");
}
}
Aggregations