APISonar


org.apache.calcite.config.Lex.JAVA

> org > apache > calcite > config > Lex > JAVA
org APIs apache APIs calcite APIs config APIs Lex APIs JAVA APIs

Example 1
@Test public void testCalciteEscapeJava()
      throws SqlParseException, ValidationException, RelConversionException {
    String sql = "select `localtime`, localtime, `current_timestamp`, current_timestamp from TMP";
    runProjectQueryWithLex(Lex.JAVA, sql);
  }
Example 2
@Test public void testJoinCorrelatedScalarSubQuery() throws SQLException {
    final String sql = "select e.employee_id, d.department_id "
        + " from employee e, department d "
        + " where e.department_id = d.department_id "
        + " and e.salary > (select avg(e2.salary) "
        + "                 from employee e2 "
        + "                 where e2.store_id = e.store_id)";
    CalciteAssert.that()
        .with(CalciteAssert.Config.FOODMART_CLONE)
        .with(Lex.JAVA)
        .query(sql)
        .returnsCount(599);
  }
Example 3
@Test public void testCalciteCaseJava()
      throws SqlParseException, ValidationException, RelConversionException {
    String sql = "select empid as EMPID, empid from (\n"
        + "  select empid from emps order by emps.deptno)";
    runProjectQueryWithLex(Lex.JAVA, sql);
  }
Example 4
private CalciteAssert.AssertThat tester(boolean forceDecorrelate,
      Object schema) {
    return CalciteAssert.that()
        .with(CalciteConnectionProperty.LEX, Lex.JAVA)
        .with(CalciteConnectionProperty.FORCE_DECORRELATE, forceDecorrelate)
        .withSchema("s", new ReflectiveSchema(schema));
  }
Example 5
@Test @WithLex(Lex.JAVA) public void testAdviceEmptyFrom() {
    String sql;
    sql = "select * from^";
    assertComplete(sql, "KEYWORD(FROM)\n", "from",
        ImmutableMap.of("KEYWORD(FROM)", "from"));
  }
Example 6
@Test @WithLex(Lex.JAVA) public void testAdviceKeywordsJava() {
    String sql;
    sql = "select deptno, exi^ from emp where 1+2<3+4";
    assertComplete(sql, "KEYWORD(EXISTS)\n", "exi",
        ImmutableMap.of("KEYWORD(EXISTS)", "exists"));
  }
Example 7
static CalciteAssert.AssertQuery sql(String sql) {
    return CalciteAssert.that()
        .withModel(SqlShell.MODEL)
        .with(CalciteConnectionProperty.LEX, Lex.JAVA)
        .with(CalciteConnectionProperty.CONFORMANCE, SqlConformanceEnum.LENIENT)
        .query(sql);
  }
Example 8
@Test public void testLexAndQuoting() {
    final SqlTester tester1 = tester
        .withLex(Lex.JAVA)
        .withQuoting(Quoting.DOUBLE_QUOTE);
    // in Java mode, creating identifiers with spaces is not encouraged, but you
    // can use double-quote 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");
  }
Example 9
@Test @WithLex(Lex.JAVA) public void testAdviceMixedCase() {
    String sql;
    sql = "select is^ from (select 1 isOne from emp)";
    assertComplete(sql, "COLUMN(isOne)\n", "is",
        ImmutableMap.of("COLUMN(isOne)", "isOne"));
  }
Example 10
@Test @WithLex(Lex.JAVA) public void testAdviceExpression() {
    String sql;
    sql = "select s.`count`+s.co^ from (select 1 `count` from emp) s";
    assertComplete(sql, "COLUMN(count)\n", "co",
        ImmutableMap.of("COLUMN(count)", "`count`"));
  }
Example 11
@Test public void testLexCaseInsensitive() {
    final CalciteAssert.AssertThat with =
        CalciteAssert.that().with(Lex.MYSQL);
    with.query("select COUNT(*) as c from metaData.tAbles")
        .returns("c=2\n");
    with.query("select COUNT(*) as c from `metaData`.`tAbles`")
        .returns("c=2\n");

    // case-sensitive gives error
    final CalciteAssert.AssertThat with2 =
        CalciteAssert.that().with(Lex.JAVA);
    with2.query("select COUNT(*) as c from `metaData`.`tAbles`")
        .throws_("Table 'metaData.tAbles' not found");
  }