Search in sources :

Example 1 with SqlValidatorWithHints

use of org.apache.calcite.sql.validate.SqlValidatorWithHints in project calcite by apache.

the class SqlAdvisorTest method assertComplete.

/**
 * Tests that a given SQL which may be invalid or incomplete simplifies
 * itself and yields the salesTables set of completion hints. This is an
 * integration test of {@link #assertHint} and {@link #assertSimplify}.
 *
 * @param sql             SQL statement
 * @param expectedResults Expected list of hints
 * @param expectedWord    Word that we expect to be replaced, or null if we
 *                        don't care
 */
protected void assertComplete(String sql, String expectedResults, String expectedWord) {
    SqlValidatorWithHints validator = (SqlValidatorWithHints) tester.getValidator();
    SqlAdvisor advisor = tester.getFactory().createAdvisor(validator);
    SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
    final String[] replaced = { null };
    List<SqlMoniker> results = advisor.getCompletionHints(sap.sql, sap.cursor, replaced);
    assertNotNull(replaced[0]);
    assertNotNull(results);
    Assert.assertEquals(expectedResults, convertCompletionHints(results));
    if (expectedWord != null) {
        Assert.assertEquals(expectedWord, replaced[0]);
    }
}
Also used : SqlMoniker(org.apache.calcite.sql.validate.SqlMoniker) SqlParserUtil(org.apache.calcite.sql.parser.SqlParserUtil) SqlValidatorWithHints(org.apache.calcite.sql.validate.SqlValidatorWithHints) SqlAdvisor(org.apache.calcite.sql.advise.SqlAdvisor)

Example 2 with SqlValidatorWithHints

use of org.apache.calcite.sql.validate.SqlValidatorWithHints in project calcite by apache.

the class SqlAdvisorTest method assertHint.

/**
 * Checks that a given SQL statement yields the expected set of completion
 * hints.
 *
 * @param sql             SQL statement
 * @param expectedResults Expected list of hints
 * @throws Exception on error
 */
protected void assertHint(String sql, String expectedResults) throws Exception {
    SqlValidatorWithHints validator = (SqlValidatorWithHints) tester.getValidator();
    SqlAdvisor advisor = tester.getFactory().createAdvisor(validator);
    SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
    List<SqlMoniker> results = advisor.getCompletionHints(sap.sql, sap.pos);
    Assert.assertEquals(expectedResults, convertCompletionHints(results));
}
Also used : SqlMoniker(org.apache.calcite.sql.validate.SqlMoniker) SqlParserUtil(org.apache.calcite.sql.parser.SqlParserUtil) SqlValidatorWithHints(org.apache.calcite.sql.validate.SqlValidatorWithHints) SqlAdvisor(org.apache.calcite.sql.advise.SqlAdvisor)

Example 3 with SqlValidatorWithHints

use of org.apache.calcite.sql.validate.SqlValidatorWithHints in project calcite by apache.

the class SqlAdvisorTest method assertSimplify.

/**
 * Tests that a given SQL statement simplifies to the salesTables result.
 *
 * @param sql      SQL statement to simplify. The SQL statement must contain
 *                 precisely one caret '^', which marks the location where
 *                 completion is to occur.
 * @param expected Expected result after simplification.
 */
protected void assertSimplify(String sql, String expected) {
    SqlValidatorWithHints validator = (SqlValidatorWithHints) tester.getValidator();
    SqlAdvisor advisor = tester.getFactory().createAdvisor(validator);
    SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
    String actual = advisor.simplifySql(sap.sql, sap.cursor);
    Assert.assertEquals(expected, actual);
}
Also used : SqlParserUtil(org.apache.calcite.sql.parser.SqlParserUtil) SqlValidatorWithHints(org.apache.calcite.sql.validate.SqlValidatorWithHints) SqlAdvisor(org.apache.calcite.sql.advise.SqlAdvisor)

Aggregations

SqlAdvisor (org.apache.calcite.sql.advise.SqlAdvisor)3 SqlParserUtil (org.apache.calcite.sql.parser.SqlParserUtil)3 SqlValidatorWithHints (org.apache.calcite.sql.validate.SqlValidatorWithHints)3 SqlMoniker (org.apache.calcite.sql.validate.SqlMoniker)2