Search in sources :

Example 96 with TestTable

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");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test) DataTypeTest(io.trino.testing.datatype.DataTypeTest) SqlDataTypeTest(io.trino.testing.datatype.SqlDataTypeTest)

Example 97 with TestTable

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  ')");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable)

Example 98 with TestTable

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();
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable)

Example 99 with TestTable

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  ')");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable)

Example 100 with TestTable

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");
    }
}
Also used : TestTable(io.trino.testing.sql.TestTable) Test(org.testng.annotations.Test)

Aggregations

TestTable (io.trino.testing.sql.TestTable)145 Test (org.testng.annotations.Test)132 SqlDataTypeTest (io.trino.testing.datatype.SqlDataTypeTest)50 BaseConnectorTest (io.trino.testing.BaseConnectorTest)26 Session (io.trino.Session)18 BaseJdbcConnectorTest (io.trino.plugin.jdbc.BaseJdbcConnectorTest)17 DataTypeTest (io.trino.testing.datatype.DataTypeTest)15 SkipException (org.testng.SkipException)14 List (java.util.List)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)8 String.format (java.lang.String.format)8 Stream (java.util.stream.Stream)8 ImmutableList (com.google.common.collect.ImmutableList)7 TestingConnectorBehavior (io.trino.testing.TestingConnectorBehavior)7 JdbcSqlExecutor (io.trino.testing.sql.JdbcSqlExecutor)7 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)7 PlanMatchPattern (io.trino.sql.planner.assertions.PlanMatchPattern)6 ExchangeNode (io.trino.sql.planner.plan.ExchangeNode)6 TableScanNode (io.trino.sql.planner.plan.TableScanNode)6