use of org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlValidatorTest method testRewriteWithLimitWithoutOrderBy.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1238">[CALCITE-1238]
* Unparsing LIMIT without ORDER BY after validation</a>.
*/
@Test
public void testRewriteWithLimitWithoutOrderBy() {
SqlValidator validator = tester.getValidator();
validator.setIdentifierExpansion(false);
final String sql = "select name from dept limit 2";
final String expected = "SELECT `NAME`\n" + "FROM `DEPT`\n" + "FETCH NEXT 2 ROWS ONLY";
tester.checkRewrite(validator, sql, expected);
}
use of org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlValidatorTest method testRewriteWithColumnReferenceExpansion.
@Test
public void testRewriteWithColumnReferenceExpansion() {
// The names in the ORDER BY clause are not qualified.
// This is because ORDER BY references columns in the SELECT clause
// in preference to columns in tables in the FROM clause.
SqlValidator validator = tester.getValidator();
validator.setIdentifierExpansion(true);
validator.setColumnReferenceExpansion(true);
tester.checkRewrite(validator, "select name from dept where name = 'Moonracer' group by name" + " having sum(deptno) > 3 order by name", "SELECT `DEPT`.`NAME`\n" + "FROM `CATALOG`.`SALES`.`DEPT` AS `DEPT`\n" + "WHERE `DEPT`.`NAME` = 'Moonracer'\n" + "GROUP BY `DEPT`.`NAME`\n" + "HAVING SUM(`DEPT`.`DEPTNO`) > 3\n" + "ORDER BY `NAME`");
}
use of org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlValidatorTest method testRewriteWithColumnReferenceExpansionAndFromAlias.
@Test
public void testRewriteWithColumnReferenceExpansionAndFromAlias() {
// In the ORDER BY clause, 'ename' is not qualified but 'deptno' and 'sal'
// are. This is because 'ename' appears as an alias in the SELECT clause.
// 'sal' is qualified in the ORDER BY clause, so remains qualified.
SqlValidator validator = tester.getValidator();
validator.setIdentifierExpansion(true);
validator.setColumnReferenceExpansion(true);
tester.checkRewrite(validator, "select ename, sal from (select * from emp) as e" + " where ename = 'Moonracer' group by ename, deptno, sal" + " having sum(deptno) > 3 order by ename, deptno, e.sal", "SELECT `E`.`ENAME`, `E`.`SAL`\n" + "FROM (SELECT `EMP`.`EMPNO`, `EMP`.`ENAME`, `EMP`.`JOB`," + " `EMP`.`MGR`, `EMP`.`HIREDATE`, `EMP`.`SAL`, `EMP`.`COMM`," + " `EMP`.`DEPTNO`, `EMP`.`SLACKER`\n" + "FROM `CATALOG`.`SALES`.`EMP` AS `EMP`) AS `E`\n" + "WHERE `E`.`ENAME` = 'Moonracer'\n" + "GROUP BY `E`.`ENAME`, `E`.`DEPTNO`, `E`.`SAL`\n" + "HAVING SUM(`E`.`DEPTNO`) > 3\n" + "ORDER BY `ENAME`, `E`.`DEPTNO`, `E`.`SAL`");
}
use of org.apache.calcite.sql.validate.SqlValidator in project calcite by apache.
the class SqlIdentifier method getMonotonicity.
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
// for "star" column, whether it's static or dynamic return not_monotonic directly.
if (Util.last(names).equals("") || DynamicRecordType.isDynamicStarColName(Util.last(names))) {
return SqlMonotonicity.NOT_MONOTONIC;
}
// First check for builtin functions which don't have parentheses,
// like "LOCALTIME".
final SqlValidator validator = scope.getValidator();
SqlCall call = SqlUtil.makeCall(validator.getOperatorTable(), this);
if (call != null) {
return call.getMonotonicity(scope);
}
final SqlQualified qualified = scope.fullyQualify(this);
final SqlIdentifier fqId = qualified.identifier;
return qualified.namespace.resolve().getMonotonicity(Util.last(fqId.names));
}
use of org.apache.calcite.sql.validate.SqlValidator in project beam by apache.
the class SqlWindowTableFunction method checkOperandTypes.
@Override
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
// There should only be three operands, and number of operands are checked before
// this call.
final SqlNode operand0 = callBinding.operand(0);
final SqlValidator validator = callBinding.getValidator();
final RelDataType type = validator.getValidatedNodeType(operand0);
if (type.getSqlTypeName() != SqlTypeName.ROW) {
return throwValidationSignatureErrorOrReturnFalse(callBinding, throwOnFailure);
}
return true;
}
Aggregations