use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class AbstractTestOracleTypeMapping method testRoundingOfUnspecifiedNumber.
@Test
public void testRoundingOfUnspecifiedNumber() {
try (TestTable table = oracleTable("rounding", "col NUMBER", "(0.123456789)")) {
assertQuery(number(9), "SELECT * FROM " + table.getName(), "VALUES 0.123456789");
assertQuery(number(HALF_EVEN, 6), "SELECT * FROM " + table.getName(), "VALUES 0.123457");
assertQuery(number(HALF_EVEN, 3), "SELECT * FROM " + table.getName(), "VALUES 0.123");
assertQueryFails(number(UNNECESSARY, 3), "SELECT * FROM " + table.getName(), "Rounding necessary");
}
try (TestTable table = oracleTable("rounding", "col NUMBER", "(123456789012345678901234567890.123456789)")) {
assertQueryFails(number(9), "SELECT * FROM " + table.getName(), "Decimal overflow");
assertQuery(number(HALF_EVEN, 8), "SELECT * FROM " + table.getName(), "VALUES 123456789012345678901234567890.12345679");
assertQuery(number(HALF_EVEN, 6), "SELECT * FROM " + table.getName(), "VALUES 123456789012345678901234567890.123457");
assertQuery(number(HALF_EVEN, 3), "SELECT * FROM " + table.getName(), "VALUES 123456789012345678901234567890.123");
assertQueryFails(number(UNNECESSARY, 3), "SELECT * FROM " + table.getName(), "Rounding necessary");
}
try (TestTable table = oracleTable("rounding", "col NUMBER", "(123456789012345678901234567890123456789)")) {
assertQueryFails(number(0), "SELECT * FROM " + table.getName(), "Decimal overflow");
assertQueryFails(number(HALF_EVEN, 8), "SELECT * FROM " + table.getName(), "Decimal overflow");
assertQueryFails(number(HALF_EVEN, 0), "SELECT * FROM " + table.getName(), "Decimal overflow");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class BaseOracleConnectorTest method testVarcharCharComparison.
@Override
public void testVarcharCharComparison() {
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_varchar_char", "(k, v) AS VALUES" + " (-1, CAST(NULL AS varchar(3))), " + // '' gets replaced with null in Oracle
" (0, CAST('' AS varchar(3)))," + " (1, CAST(' ' AS varchar(3))), " + " (2, CAST(' ' AS varchar(3))), " + " (3, CAST(' ' AS varchar(3)))," + " (4, CAST('x' AS varchar(3)))," + " (5, CAST('x ' AS varchar(3)))," + " (6, CAST('x ' AS varchar(3)))")) {
assertQuery("SELECT k, v FROM " + table.getName() + " WHERE v = CAST(' ' AS char(2))", // The 3-spaces value is included because both sides of the comparison are coerced to char(3)
"VALUES (1, ' '), (2, ' '), (3, ' ')");
// value that's not all-spaces
assertQuery("SELECT k, v FROM " + table.getName() + " WHERE v = CAST('x ' AS char(2))", // The 3-spaces value is included because both sides of the comparison are coerced to char(3)
"VALUES (4, 'x'), (5, 'x '), (6, 'x ')");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class BaseOracleConnectorTest method predicatePushdownTest.
private void predicatePushdownTest(String oracleType, String oracleLiteral, String operator, String filterLiteral) {
String tableName = ("test_pdown_" + oracleType.replaceAll("[^a-zA-Z0-9]", "")).replaceFirst("^(.{18}).*", "$1__");
try (TestTable table = new TestTable(onRemoteDatabase(), getUser() + "." + tableName, format("(c %s)", oracleType))) {
onRemoteDatabase().execute(format("INSERT INTO %s VALUES (%s)", table.getName(), oracleLiteral));
assertThat(query(format("SELECT * FROM %s WHERE c %s %s", table.getName(), operator, filterLiteral))).isFullyPushedDown();
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class BaseOracleConnectorTest method testCharVarcharComparison.
@Override
public void testCharVarcharComparison() {
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_char_varchar", "(k, v) AS VALUES" + " (-1, CAST(NULL AS char(3))), " + " (3, CAST('x ' AS char(3)))")) {
assertQuery("SELECT k, v FROM " + table.getName() + " WHERE v = CAST('x ' AS varchar(2))", // The value is included because both sides of the comparison are coerced to char(3)
"VALUES (3, 'x ')");
assertQuery("SELECT k, v FROM " + table.getName() + " WHERE v = CAST('x ' AS varchar(4))", // The value is included because both sides of the comparison are coerced to char(4)
"VALUES (3, 'x ')");
}
}
use of io.trino.testing.sql.TestTable in project trino by trinodb.
the class BaseConnectorSmokeTest method testUpdate.
@Test
public void testUpdate() {
if (!hasBehavior(SUPPORTS_UPDATE)) {
// Note this change is a no-op, if actually run
assertQueryFails("UPDATE nation SET nationkey = nationkey + regionkey WHERE regionkey < 1", "This connector does not support updates");
return;
}
try (TestTable table = new TestTable(getQueryRunner()::execute, "test_update", "AS TABLE tpch.tiny.nation")) {
String tableName = table.getName();
assertUpdate("UPDATE " + tableName + " SET nationkey = 100 + nationkey WHERE regionkey = 2", 5);
assertThat(query("SELECT * FROM " + tableName)).skippingTypesCheck().matches("SELECT IF(regionkey=2, nationkey + 100, nationkey) nationkey, name, regionkey, comment FROM tpch.tiny.nation");
}
}
Aggregations