Search in sources :

Example 21 with SqlTester

use of org.apache.calcite.sql.test.SqlTester in project calcite by apache.

the class SqlValidatorTest method testUserDefinedConformance.

@Test
public void testUserDefinedConformance() {
    final SqlAbstractConformance c = new SqlDelegatingConformance(SqlConformanceEnum.DEFAULT) {

        public boolean isBangEqualAllowed() {
            return true;
        }
    };
    // Our conformance behaves differently from ORACLE_10 for FROM-less query.
    final SqlTester customTester = tester.withConformance(c);
    final SqlTester defaultTester = tester.withConformance(SqlConformanceEnum.DEFAULT);
    final SqlTester oracleTester = tester.withConformance(SqlConformanceEnum.ORACLE_10);
    sql("^select 2+2^").tester(customTester).ok().tester(defaultTester).ok().tester(oracleTester).fails("SELECT must have a FROM clause");
    // Our conformance behaves like ORACLE_10 for "!=" operator.
    sql("select * from (values 1) where 1 != 2").tester(customTester).ok().tester(defaultTester).fails("Bang equal '!=' is not allowed under the current SQL conformance level").tester(oracleTester).ok();
    sql("select * from (values 1) where 1 != any (2, 3)").tester(customTester).ok().tester(defaultTester).fails("Bang equal '!=' is not allowed under the current SQL conformance level").tester(oracleTester).ok();
}
Also used : SqlAbstractConformance(org.apache.calcite.sql.validate.SqlAbstractConformance) SqlDelegatingConformance(org.apache.calcite.sql.validate.SqlDelegatingConformance) SqlTester(org.apache.calcite.sql.test.SqlTester) Test(org.junit.Test)

Example 22 with SqlTester

use of org.apache.calcite.sql.test.SqlTester in project calcite by apache.

the class SqlValidatorTest method testBrackets.

@Test
public void testBrackets() {
    final SqlTester tester1 = tester.withQuoting(Quoting.BRACKET);
    tester1.checkResultType("select [e].EMPNO from [EMP] as [e]", "RecordType(INTEGER NOT NULL EMPNO) NOT NULL");
    tester1.checkQueryFails("select ^e^.EMPNO from [EMP] as [e]", "Table 'E' not found; did you mean 'e'\\?");
    tester1.checkQueryFails("select ^x^ from (\n" + "  select [e].EMPNO as [x] from [EMP] as [e])", "Column 'X' not found in any table; did you mean 'x'\\?");
    tester1.checkQueryFails("select ^x^ from (\n" + "  select [e].EMPNO as [x ] from [EMP] as [e])", "Column 'X' not found in any table");
    tester1.checkQueryFails("select EMP.^\"x\"^ from EMP", "(?s).*Encountered \"\\. \\\\\"\" at line .*");
    tester1.checkResultType("select [x[y]] z ] from (\n" + "  select [e].EMPNO as [x[y]] z ] from [EMP] as [e])", "RecordType(INTEGER NOT NULL x[y] z ) NOT NULL");
}
Also used : SqlTester(org.apache.calcite.sql.test.SqlTester) Test(org.junit.Test)

Example 23 with SqlTester

use of org.apache.calcite.sql.test.SqlTester in project calcite by apache.

the class SqlValidatorTest method testInsertSubsetFailNullability.

@Test
public void testInsertSubsetFailNullability() {
    final SqlTester pragmaticTester = tester.withConformance(SqlConformanceEnum.PRAGMATIC_2003);
    pragmaticTester.checkQueryFails("insert into ^empnullables^ values (1)", "Column 'ENAME' has no default value and does not allow NULLs");
    pragmaticTester.checkQueryFails("insert into empnullables ^values (null, 'Liam')^", "Column 'EMPNO' has no default value and does not allow NULLs");
    pragmaticTester.checkQueryFails("insert into empnullables ^values (45, null, 5)^", "Column 'ENAME' has no default value and does not allow NULLs");
}
Also used : SqlTester(org.apache.calcite.sql.test.SqlTester) Test(org.junit.Test)

Example 24 with SqlTester

use of org.apache.calcite.sql.test.SqlTester in project calcite by apache.

the class SqlValidatorTest method testLexJavaKeyword.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-145">[CALCITE-145]
 * Unexpected upper-casing of keywords when using java lexer</a>.
 */
@Test
public void testLexJavaKeyword() {
    final SqlTester tester1 = tester.withLex(Lex.JAVA);
    tester1.checkResultType("select path, x from (select 1 as path, 2 as x from (values (true)))", "RecordType(INTEGER NOT NULL path, INTEGER NOT NULL x) NOT NULL");
    tester1.checkResultType("select path, x from (select 1 as `path`, 2 as x from (values (true)))", "RecordType(INTEGER NOT NULL path, INTEGER NOT NULL x) NOT NULL");
    tester1.checkResultType("select `path`, x from (select 1 as path, 2 as x from (values (true)))", "RecordType(INTEGER NOT NULL path, INTEGER NOT NULL x) NOT NULL");
    tester1.checkFails("select ^PATH^ from (select 1 as path from (values (true)))", "Column 'PATH' not found in any table; did you mean 'path'\\?", false);
    tester1.checkFails("select t.^PATH^ from (select 1 as path from (values (true))) as t", "Column 'PATH' not found in table 't'; did you mean 'path'\\?", false);
    tester1.checkQueryFails("select t.x, t.^PATH^ from (values (true, 1)) as t(path, x)", "Column 'PATH' not found in table 't'; did you mean 'path'\\?");
    // Built-in functions can be written in any case, even those with no args,
    // and regardless of spaces between function name and open parenthesis.
    tester1.checkQuery("values (current_timestamp, floor(2.5), ceil (3.5))");
    tester1.checkQuery("values (CURRENT_TIMESTAMP, FLOOR(2.5), CEIL (3.5))");
    tester1.checkResultType("values (CURRENT_TIMESTAMP, CEIL (3.5))", "RecordType(TIMESTAMP(0) NOT NULL CURRENT_TIMESTAMP, DECIMAL(2, 0) NOT NULL EXPR$1) NOT NULL");
}
Also used : SqlTester(org.apache.calcite.sql.test.SqlTester) Test(org.junit.Test)

Example 25 with SqlTester

use of org.apache.calcite.sql.test.SqlTester in project calcite by apache.

the class SqlValidatorTest method testInsertBindWithCustomColumnResolving.

@Test
public void testInsertBindWithCustomColumnResolving() {
    final SqlTester pragmaticTester = tester.withConformance(SqlConformanceEnum.PRAGMATIC_2003);
    final String sql = "insert into struct.t\n" + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
    final String expected = "RecordType(VARCHAR(20) ?0, VARCHAR(20) ?1," + " INTEGER ?2, BOOLEAN ?3, INTEGER ?4, INTEGER ?5, INTEGER ?6," + " INTEGER ?7, INTEGER ?8)";
    sql(sql).ok().bindType(expected);
    final String sql2 = "insert into struct.t_nullables (c0, c2, c1) values (?, ?, ?)";
    final String expected2 = "RecordType(INTEGER ?0, INTEGER ?1, VARCHAR(20) ?2)";
    sql(sql2).tester(pragmaticTester).ok().bindType(expected2);
    final String sql3 = "insert into struct.t_nullables (f1.c0, f1.c2, f0.c1) values (?, ?, ?)";
    final String expected3 = "RecordType(INTEGER ?0, INTEGER ?1, INTEGER ?2)";
    sql(sql3).tester(pragmaticTester).ok().bindType(expected3);
    sql("insert into struct.t_nullables (c0, ^c4^, c1) values (?, ?, ?)").tester(pragmaticTester).fails("Unknown target column 'C4'");
    sql("insert into struct.t_nullables (^a0^, c2, c1) values (?, ?, ?)").tester(pragmaticTester).fails("Unknown target column 'A0'");
    final String sql4 = "insert into struct.t_nullables (\n" + "  f1.c0, ^f0.a0^, f0.c1) values (?, ?, ?)";
    sql(sql4).tester(pragmaticTester).fails("Unknown target column 'F0.A0'");
    final String sql5 = "insert into struct.t_nullables (\n" + "  f1.c0, f1.c2, ^f1.c0^) values (?, ?, ?)";
    sql(sql5).tester(pragmaticTester).fails("Target column '\"F1\".\"C0\"' is assigned more than once");
}
Also used : SqlTester(org.apache.calcite.sql.test.SqlTester) Test(org.junit.Test)

Aggregations

SqlTester (org.apache.calcite.sql.test.SqlTester)26 Test (org.junit.Test)26 SqlAbstractConformance (org.apache.calcite.sql.validate.SqlAbstractConformance)1 SqlDelegatingConformance (org.apache.calcite.sql.validate.SqlDelegatingConformance)1