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]);
}
}
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));
}
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);
}
Aggregations