use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.fun.SqlStdOperatorTable in project calcite by apache.
the class SqlOperatorBaseTest method testSqlOperatorOverloading.
@Test
public void testSqlOperatorOverloading() {
final SqlStdOperatorTable operatorTable = SqlStdOperatorTable.instance();
for (SqlOperator sqlOperator : operatorTable.getOperatorList()) {
String operatorName = sqlOperator.getName();
List<SqlOperator> routines = new ArrayList<>();
operatorTable.lookupOperatorOverloads(new SqlIdentifier(operatorName, SqlParserPos.ZERO), null, sqlOperator.getSyntax(), routines);
Iterator<SqlOperator> iter = routines.iterator();
while (iter.hasNext()) {
SqlOperator operator = iter.next();
if (!sqlOperator.getClass().isInstance(operator)) {
iter.remove();
}
}
assertThat(routines.size(), equalTo(1));
assertThat(sqlOperator, equalTo(routines.get(0)));
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.fun.SqlStdOperatorTable in project calcite by apache.
the class PlannerTest method testValidateUserDefinedAggregate.
@Test
public void testValidateUserDefinedAggregate() throws Exception {
final SqlStdOperatorTable stdOpTab = SqlStdOperatorTable.instance();
SqlOperatorTable opTab = ChainedSqlOperatorTable.of(stdOpTab, new ListSqlOperatorTable(ImmutableList.<SqlOperator>of(new MyCountAggFunction())));
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
final FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.HR)).operatorTable(opTab).build();
final Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse("select \"deptno\", my_count(\"empid\") from \"emps\"\n" + "group by \"deptno\"");
assertThat(Util.toLinux(parse.toString()), equalTo("SELECT `deptno`, `MY_COUNT`(`empid`)\n" + "FROM `emps`\n" + "GROUP BY `deptno`"));
// MY_COUNT is recognized as an aggregate function, and therefore it is OK
// that its argument empid is not in the GROUP BY clause.
SqlNode validate = planner.validate(parse);
assertThat(validate, notNullValue());
// The presence of an aggregate function in the SELECT clause causes it
// to become an aggregate query. Non-aggregate expressions become illegal.
planner.close();
planner.reset();
parse = planner.parse("select \"deptno\", count(1) from \"emps\"");
try {
validate = planner.validate(parse);
fail("expected exception, got " + validate);
} catch (ValidationException e) {
assertThat(e.getCause().getCause().getMessage(), containsString("Expression 'deptno' is not being grouped"));
}
}
Aggregations