use of org.apache.calcite.sql.SqlFunction in project Mycat2 by MyCATApache.
the class SqlValidatorImpl method validateCall.
public void validateCall(SqlCall call, SqlValidatorScope scope) {
final SqlOperator operator = call.getOperator();
if ((call.operandCount() == 0) && (operator.getSyntax() == SqlSyntax.FUNCTION_ID) && !call.isExpanded() && !this.config.sqlConformance().allowNiladicParentheses()) {
// SqlIdentifier.)
throw handleUnresolvedFunction(call, (SqlFunction) operator, ImmutableList.of(), null);
}
SqlValidatorScope operandScope = scope.getOperandScope(call);
if (operator instanceof SqlFunction && ((SqlFunction) operator).getFunctionType() == SqlFunctionCategory.MATCH_RECOGNIZE && !(operandScope instanceof MatchRecognizeScope)) {
throw newValidationError(call, Static.RESOURCE.functionMatchRecognizeOnly(call.toString()));
}
// Delegate validation to the operator.
operator.validateCall(call, this, scope, operandScope);
}
use of org.apache.calcite.sql.SqlFunction in project ignite-3 by apache.
the class RelJson method toJson.
private Object toJson(RexNode node) {
// removes calls to SEARCH and the included Sarg and converts them to comparisons
node = RexUtil.expandSearch(Commons.cluster().getRexBuilder(), null, node);
Map<String, Object> map;
switch(node.getKind()) {
case FIELD_ACCESS:
map = map();
RexFieldAccess fieldAccess = (RexFieldAccess) node;
map.put("field", fieldAccess.getField().getName());
map.put("expr", toJson(fieldAccess.getReferenceExpr()));
return map;
case LITERAL:
RexLiteral literal = (RexLiteral) node;
Object value = literal.getValue3();
map = map();
map.put("literal", toJson(value));
map.put("type", toJson(node.getType()));
return map;
case INPUT_REF:
map = map();
map.put("input", ((RexSlot) node).getIndex());
map.put("name", ((RexVariable) node).getName());
return map;
case DYNAMIC_PARAM:
map = map();
map.put("input", ((RexDynamicParam) node).getIndex());
map.put("name", ((RexVariable) node).getName());
map.put("type", toJson(node.getType()));
map.put("dynamic", true);
return map;
case LOCAL_REF:
map = map();
map.put("input", ((RexSlot) node).getIndex());
map.put("name", ((RexVariable) node).getName());
map.put("type", toJson(node.getType()));
return map;
case CORREL_VARIABLE:
map = map();
map.put("correl", ((RexVariable) node).getName());
map.put("type", toJson(node.getType()));
return map;
default:
if (node instanceof RexCall) {
RexCall call = (RexCall) node;
map = map();
map.put("op", toJson(call.getOperator()));
List<Object> list = list();
for (RexNode operand : call.getOperands()) {
list.add(toJson(operand));
}
map.put("operands", list);
if (node.getKind() == SqlKind.CAST) {
map.put("type", toJson(node.getType()));
}
if (call.getOperator() instanceof SqlFunction) {
if (((SqlFunction) call.getOperator()).getFunctionType().isUserDefined()) {
SqlOperator op = call.getOperator();
map.put("class", op.getClass().getName());
map.put("type", toJson(node.getType()));
map.put("deterministic", op.isDeterministic());
map.put("dynamic", op.isDynamicFunction());
}
}
if (call instanceof RexOver) {
RexOver over = (RexOver) call;
map.put("distinct", over.isDistinct());
map.put("type", toJson(node.getType()));
map.put("window", toJson(over.getWindow()));
}
return map;
}
throw new UnsupportedOperationException("unknown rex " + node);
}
}
Aggregations