Search in sources :

Example 11 with SqlTester

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

the class SqlValidatorTest method testInsertSubsetView.

@Test
public void testInsertSubsetView() {
    final SqlTester pragmaticTester = tester.withConformance(SqlConformanceEnum.PRAGMATIC_2003);
    pragmaticTester.checkQuery("insert into empnullables_20\n" + "values (1, 'Karl')");
}
Also used : SqlTester(org.apache.calcite.sql.test.SqlTester) Test(org.junit.Test)

Example 12 with SqlTester

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

the class SqlValidatorTest method testUnquotedBuiltInFunctionNames.

/**
 * Tests matching of built-in operator names.
 */
@Test
public void testUnquotedBuiltInFunctionNames() {
    final SqlTester mysql = tester.withUnquotedCasing(Casing.UNCHANGED).withQuoting(Quoting.BACK_TICK).withCaseSensitive(false);
    final SqlTester oracle = tester.withUnquotedCasing(Casing.TO_UPPER).withCaseSensitive(true);
    // Built-in functions are always case-insensitive.
    oracle.checkQuery("select count(*), sum(deptno), floor(2.5) from dept");
    oracle.checkQuery("select COUNT(*), FLOOR(2.5) from dept");
    oracle.checkQuery("select cOuNt(*), FlOOr(2.5) from dept");
    oracle.checkQuery("select cOuNt (*), FlOOr (2.5) from dept");
    oracle.checkQuery("select current_time from dept");
    oracle.checkQuery("select Current_Time from dept");
    oracle.checkQuery("select CURRENT_TIME from dept");
    mysql.checkQuery("select sum(deptno), floor(2.5) from dept");
    mysql.checkQuery("select count(*), sum(deptno), floor(2.5) from dept");
    mysql.checkQuery("select COUNT(*), FLOOR(2.5) from dept");
    mysql.checkQuery("select cOuNt(*), FlOOr(2.5) from dept");
    mysql.checkQuery("select cOuNt (*), FlOOr (2.5) from dept");
    mysql.checkQuery("select current_time from dept");
    mysql.checkQuery("select Current_Time from dept");
    mysql.checkQuery("select CURRENT_TIME from dept");
    // MySQL assumes that a quoted function name is not a built-in.
    // 
    // mysql> select `sum`(`day`) from days;
    // ERROR 1630 (42000): FUNCTION foodmart.sum does not exist. Check the
    // 'Function Name Parsing and Resolution' section in the Reference Manual
    // mysql> select `SUM`(`day`) from days;
    // ERROR 1630 (42000): FUNCTION foodmart.SUM does not exist. Check the
    // 'Function Name Parsing and Resolution' section in the Reference Manual
    // mysql> select SUM(`day`) from days;
    // +------------+
    // | SUM(`day`) |
    // +------------+
    // |         28 |
    // +------------+
    // 1 row in set (0.00 sec)
    // 
    // We do not follow MySQL in this regard. `count` is preserved in
    // lower-case, and is matched case-insensitively because it is a built-in.
    // So, the query succeeds.
    oracle.checkQuery("select \"count\"(*) from dept");
    mysql.checkQuery("select `count`(*) from dept");
}
Also used : SqlTester(org.apache.calcite.sql.test.SqlTester) Test(org.junit.Test)

Example 13 with SqlTester

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

the class SqlValidatorTest method testCaseInsensitive.

/**
 * Tests using case-insensitive matching of identifiers.
 */
@Test
public void testCaseInsensitive() {
    final SqlTester tester1 = tester.withCaseSensitive(false).withQuoting(Quoting.BRACKET);
    final SqlTester tester2 = tester.withQuoting(Quoting.BRACKET);
    tester1.checkQuery("select EMPNO from EMP");
    tester1.checkQuery("select empno from emp");
    tester1.checkQuery("select [empno] from [emp]");
    tester1.checkQuery("select [E].[empno] from [emp] as e");
    tester1.checkQuery("select t.[x] from (\n" + "  select [E].[empno] as x from [emp] as e) as [t]");
    // correlating variable
    tester1.checkQuery("select * from emp as [e] where exists (\n" + "select 1 from dept where dept.deptno = [E].deptno)");
    tester2.checkQueryFails("select * from emp as [e] where exists (\n" + "select 1 from dept where dept.deptno = ^[E]^.deptno)", "(?s).*Table 'E' not found; did you mean 'e'\\?");
    checkFails("select count(1), ^empno^ from emp", "Expression 'EMPNO' is not being grouped");
}
Also used : SqlTester(org.apache.calcite.sql.test.SqlTester) Test(org.junit.Test)

Example 14 with SqlTester

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

the class SqlValidatorTest method testLexJava.

@Test
public void testLexJava() {
    final SqlTester tester1 = tester.withLex(Lex.JAVA);
    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 ^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 Xx from EMP as e)", "Column 'x' not found in any table");
    // double-quotes are not valid in this lexical convention
    tester1.checkQueryFails("select EMP.^\"x\"^ from EMP", "(?s).*Encountered \"\\. \\\\\"\" at line .*");
    // in Java mode, creating identifiers with spaces is not encouraged, but you
    // can use back-ticks if you really have to
    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 15 with SqlTester

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

the class SqlValidatorTest method testInsertSubsetViewFailNullability.

@Test
public void testInsertSubsetViewFailNullability() {
    final SqlTester pragmaticTester = tester.withConformance(SqlConformanceEnum.PRAGMATIC_2003);
    pragmaticTester.checkQueryFails("insert into ^empnullables_20^ values (1)", "Column 'ENAME' has no default value and does not allow NULLs");
    pragmaticTester.checkQueryFails("insert into empnullables_20 ^values (null, 'Liam')^", "Column 'EMPNO' has no default value and does not allow NULLs");
    pragmaticTester.checkQueryFails("insert into empnullables_20 ^values (45, null)^", "Column 'ENAME' has no default value and does not allow NULLs");
}
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