use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlTesterImpl method checkFails.
public void checkFails(String expression, String expectedError, boolean runtime) {
if (runtime) {
// We need to test that the expression fails at runtime.
// Ironically, that means that it must succeed at prepare time.
SqlValidator validator = getValidator();
final String sql = buildQuery(expression);
SqlNode n = parseAndValidate(validator, sql);
assertNotNull(n);
} else {
checkQueryFails(buildQuery(expression), expectedError);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlTesterImpl method assertExceptionIsThrown.
public void assertExceptionIsThrown(String sql, String expectedMsgPattern) {
SqlValidator validator;
SqlNode sqlNode;
SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
try {
sqlNode = parseQuery(sap.sql);
validator = getValidator();
} catch (SqlParseException e) {
String errMessage = e.getMessage();
if (expectedMsgPattern == null) {
throw new RuntimeException("Error while parsing query:" + sap.sql, e);
} else if (errMessage == null || !errMessage.matches(expectedMsgPattern)) {
throw new RuntimeException("Error did not match expected [" + expectedMsgPattern + "] while parsing query [" + sap.sql + "]", e);
}
return;
} catch (Throwable e) {
throw new RuntimeException("Error while parsing query: " + sap.sql, e);
}
Throwable thrown = null;
try {
validator.validate(sqlNode);
} catch (Throwable ex) {
thrown = ex;
}
SqlValidatorTestCase.checkEx(thrown, expectedMsgPattern, sap);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlTesterImpl method check.
public void check(String query, TypeChecker typeChecker, ParameterChecker parameterChecker, ResultChecker resultChecker) {
if (typeChecker == null) {
// Parse and validate. There should be no errors.
Util.discard(getResultType(query));
} else {
// Parse and validate. There should be no errors.
// There must be 1 column. Get its type.
RelDataType actualType = getColumnType(query);
// Check result type.
typeChecker.checkType(actualType);
}
SqlValidator validator = getValidator();
SqlNode n = parseAndValidate(validator, query);
final RelDataType parameterRowType = validator.getParameterRowType(n);
parameterChecker.checkParameters(parameterRowType);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlTesterImpl method checkMonotonic.
public void checkMonotonic(String query, SqlMonotonicity expectedMonotonicity) {
SqlValidator validator = getValidator();
SqlNode n = parseAndValidate(validator, query);
final RelDataType rowType = validator.getValidatedNodeType(n);
final SqlValidatorNamespace selectNamespace = validator.getNamespace(n);
final String field0 = rowType.getFieldList().get(0).getName();
final SqlMonotonicity monotonicity = selectNamespace.getMonotonicity(field0);
assertThat(monotonicity, equalTo(expectedMonotonicity));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlTesterImpl method getMonotonicity.
public SqlMonotonicity getMonotonicity(String sql) {
final SqlValidator validator = getValidator();
final SqlNode node = parseAndValidate(validator, sql);
final SqlSelect select = (SqlSelect) node;
final SqlNode selectItem0 = select.getSelectList().get(0);
final SqlValidatorScope scope = validator.getSelectScope(select);
return selectItem0.getMonotonicity(scope);
}
Aggregations