use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlAbstractGroupFunction method validateCall.
@Override
public void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) {
super.validateCall(call, validator, scope, operandScope);
final SelectScope selectScope = SqlValidatorUtil.getEnclosingSelectScope(scope);
assert selectScope != null;
final SqlSelect select = selectScope.getNode();
if (!validator.isAggregate(select)) {
throw validator.newValidationError(call, Static.RESOURCE.groupingInAggregate(getName()));
}
final AggregatingSelectScope aggregatingSelectScope = SqlValidatorUtil.getEnclosingAggregateSelectScope(scope);
if (aggregatingSelectScope == null) {
// We're probably in the GROUP BY clause
throw validator.newValidationError(call, Static.RESOURCE.groupingInWrongClause(getName()));
}
for (SqlNode operand : call.getOperandList()) {
if (scope instanceof OrderByScope) {
operand = validator.expandOrderExpr(select, operand);
} else {
operand = validator.expand(operand, scope);
}
if (!aggregatingSelectScope.resolved.get().isGroupingExpr(operand)) {
throw validator.newValidationError(operand, Static.RESOURCE.groupingArgument(getName()));
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlTesterImpl method getResultType.
public RelDataType getResultType(String sql) {
SqlValidator validator = getValidator();
SqlNode n = parseAndValidate(validator, sql);
return validator.getValidatedNodeType(n);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlTesterImpl method checkFieldOrigin.
public void checkFieldOrigin(String sql, String fieldOriginList) {
SqlValidator validator = getValidator();
SqlNode n = parseAndValidate(validator, sql);
final List<List<String>> list = validator.getFieldOrigins(n);
final StringBuilder buf = new StringBuilder("{");
int i = 0;
for (List<String> strings : list) {
if (i++ > 0) {
buf.append(", ");
}
if (strings == null) {
buf.append("null");
} else {
int j = 0;
for (String s : strings) {
if (j++ > 0) {
buf.append('.');
}
buf.append(s);
}
}
}
buf.append("}");
assertEquals(fieldOriginList, buf.toString());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlTesterImpl method checkIntervalConv.
public void checkIntervalConv(String sql, String expected) {
SqlValidator validator = getValidator();
final SqlCall n = (SqlCall) parseAndValidate(validator, sql);
SqlNode node = null;
for (int i = 0; i < n.operandCount(); i++) {
node = stripAs(n.operand(i));
if (node instanceof SqlCall) {
node = ((SqlCall) node).operand(0);
break;
}
}
assertNotNull(node);
SqlIntervalLiteral intervalLiteral = (SqlIntervalLiteral) node;
SqlIntervalLiteral.IntervalValue interval = (SqlIntervalLiteral.IntervalValue) intervalLiteral.getValue();
long l = interval.getIntervalQualifier().isYearMonth() ? SqlParserUtil.intervalToMonths(interval) : SqlParserUtil.intervalToMillis(interval);
String actual = l + "";
assertEquals(expected, actual);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class InterpreterTest method testInterpretUnionAll.
/**
* Tests executing a UNION ALL query using an interpreter.
*/
@Test
public void testInterpretUnionAll() throws Exception {
rootSchema.add("simple", new ScannableTableTest.SimpleTable());
SqlNode parse = planner.parse("select * from \"simple\"\n" + "union all\n" + "select * from \"simple\"\n");
SqlNode validate = planner.validate(parse);
RelNode convert = planner.rel(validate).rel;
final Interpreter interpreter = new Interpreter(dataContext, convert);
assertRows(interpreter, "[0]", "[10]", "[20]", "[30]", "[0]", "[10]", "[20]", "[30]");
}
Aggregations