use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlTypeUtil method isCharTypeComparable.
/**
* Returns whether the operands to a call are char type-comparable.
*
* @param binding Binding of call to operands
* @param operands Operands to check for compatibility; usually the
* operands of the bound call, but not always
* @param throwOnFailure Whether to throw an exception on failure
* @return whether operands are valid
*/
public static boolean isCharTypeComparable(SqlCallBinding binding, List<SqlNode> operands, boolean throwOnFailure) {
final SqlValidator validator = binding.getValidator();
final SqlValidatorScope scope = binding.getScope();
assert operands != null;
assert operands.size() >= 2;
if (!isCharTypeComparable(deriveAndCollectTypes(validator, scope, operands))) {
if (throwOnFailure) {
String msg = "";
for (int i = 0; i < operands.size(); i++) {
if (i > 0) {
msg += ", ";
}
msg += operands.get(i).toString();
}
throw binding.newError(RESOURCE.operandNotComparable(msg));
}
return false;
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class RelOptRulesTest method testSemiJoinTrim.
@Test
public void testSemiJoinTrim() throws Exception {
final DiffRepository diffRepos = getDiffRepos();
String sql = diffRepos.expand(null, "${sql}");
TesterImpl t = (TesterImpl) tester;
final RelDataTypeFactory typeFactory = t.getTypeFactory();
final Prepare.CatalogReader catalogReader = t.createCatalogReader(typeFactory);
final SqlValidator validator = t.createValidator(catalogReader, typeFactory);
SqlToRelConverter converter = t.createSqlToRelConverter(validator, catalogReader, typeFactory, SqlToRelConverter.Config.DEFAULT);
final SqlNode sqlQuery = t.parseQuery(sql);
final SqlNode validatedQuery = validator.validate(sqlQuery);
RelRoot root = converter.convertQuery(validatedQuery, false, true);
root = root.withRel(converter.decorrelate(sqlQuery, root.rel));
final HepProgram program = HepProgram.builder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterJoinRule.FILTER_ON_JOIN).addRuleInstance(ProjectMergeRule.INSTANCE).addRuleInstance(SemiJoinRule.PROJECT).build();
HepPlanner planner = new HepPlanner(program);
planner.setRoot(root.rel);
root = root.withRel(planner.findBestExp());
String planBefore = NL + RelOptUtil.toString(root.rel);
diffRepos.assertEquals("planBefore", "${planBefore}", planBefore);
converter = t.createSqlToRelConverter(validator, catalogReader, typeFactory, SqlToRelConverter.configBuilder().withTrimUnusedFields(true).build());
root = root.withRel(converter.trimUnusedFields(false, root.rel));
String planAfter = NL + RelOptUtil.toString(root.rel);
diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlValidatorTest method testCoalesceWithRewrite.
@Test
public void testCoalesceWithRewrite() {
SqlValidator validator = tester.getValidator();
validator.setCallRewrite(true);
if (validator.shouldExpandIdentifiers()) {
tester.checkRewrite(validator, "select coalesce(deptno, empno) from emp", "SELECT CASE WHEN `EMP`.`DEPTNO` IS NOT NULL THEN `EMP`.`DEPTNO` ELSE `EMP`.`EMPNO` END\n" + "FROM `CATALOG`.`SALES`.`EMP` AS `EMP`");
} else {
tester.checkRewrite(validator, "select coalesce(deptno, empno) from emp", "SELECT CASE WHEN `DEPTNO` IS NOT NULL THEN `DEPTNO` ELSE `EMPNO` END\n" + "FROM `EMP`");
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlValidatorTest method testRewriteWithOffsetWithoutOrderBy.
@Test
public void testRewriteWithOffsetWithoutOrderBy() {
SqlValidator validator = tester.getValidator();
validator.setIdentifierExpansion(false);
final String sql = "select name from dept offset 2";
final String expected = "SELECT `NAME`\n" + "FROM `DEPT`\n" + "OFFSET 2 ROWS";
tester.checkRewrite(validator, sql, expected);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlValidatorTest method testRewriteWithLimitWithDynamicParameters.
@Test
public void testRewriteWithLimitWithDynamicParameters() {
SqlValidator validator = tester.getValidator();
validator.setIdentifierExpansion(false);
final String sql = "select name from dept offset ? rows fetch next ? rows only";
final String expected = "SELECT `NAME`\n" + "FROM `DEPT`\n" + "OFFSET ? ROWS\n" + "FETCH NEXT ? ROWS ONLY";
tester.checkRewrite(validator, sql, expected);
}
Aggregations