use of org.apache.calcite.sql.SqlFunction in project calcite by apache.
the class SqlValidatorImpl method deriveConstructorType.
@Override
public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, @Nullable SqlFunction resolvedConstructor, List<RelDataType> argTypes) {
SqlIdentifier sqlIdentifier = unresolvedConstructor.getSqlIdentifier();
assert sqlIdentifier != null;
RelDataType type = catalogReader.getNamedType(sqlIdentifier);
if (type == null) {
// TODO jvs 12-Feb-2005: proper type name formatting
throw newValidationError(sqlIdentifier, RESOURCE.unknownDatatypeName(sqlIdentifier.toString()));
}
if (resolvedConstructor == null) {
if (call.operandCount() > 0) {
// no user-defined constructor could be found
throw handleUnresolvedFunction(call, unresolvedConstructor, argTypes, null);
}
} else {
SqlCall testCall = resolvedConstructor.createCall(call.getParserPosition(), call.getOperandList());
RelDataType returnType = resolvedConstructor.validateOperands(this, scope, testCall);
assert type == returnType;
}
if (config.identifierExpansion()) {
if (resolvedConstructor != null) {
((SqlBasicCall) call).setOperator(resolvedConstructor);
} else {
// fake a fully-qualified call to the default constructor
((SqlBasicCall) call).setOperator(new SqlFunction(requireNonNull(type.getSqlIdentifier(), () -> "sqlIdentifier of " + type), ReturnTypes.explicit(type), null, null, null, SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR));
}
}
return type;
}
use of org.apache.calcite.sql.SqlFunction in project calcite by apache.
the class DocumentationTest method addOperators.
private void addOperators(Map<String, PatternOp> map, String prefix, List<SqlOperator> operatorList) {
for (SqlOperator op : operatorList) {
final String name = op.getName().equals("TRANSLATE3") ? "TRANSLATE" : op.getName();
if (op instanceof SqlSpecialOperator || !name.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) {
continue;
}
final String regex;
if (op instanceof SqlOverlapsOperator) {
regex = "[ ]*<td>period1 " + name + " period2</td>";
} else if (op instanceof SqlFunction && (op.getOperandTypeChecker() == null || op.getOperandTypeChecker().getOperandCountRange().getMin() != 0)) {
regex = prefix + "\\| .*" + name + "\\(.*";
} else {
regex = prefix + "\\| .*" + name + ".*";
}
map.put(regex, new PatternOp(Pattern.compile(regex), name));
}
}
use of org.apache.calcite.sql.SqlFunction in project flink-mirror by flink-ci.
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 flink-mirror by flink-ci.
the class SqlValidatorImpl method deriveConstructorType.
public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, SqlFunction resolvedConstructor, List<RelDataType> argTypes) {
SqlIdentifier sqlIdentifier = unresolvedConstructor.getSqlIdentifier();
assert sqlIdentifier != null;
RelDataType type = catalogReader.getNamedType(sqlIdentifier);
if (type == null) {
// TODO jvs 12-Feb-2005: proper type name formatting
throw newValidationError(sqlIdentifier, RESOURCE.unknownDatatypeName(sqlIdentifier.toString()));
}
if (resolvedConstructor == null) {
if (call.operandCount() > 0) {
// no user-defined constructor could be found
throw handleUnresolvedFunction(call, unresolvedConstructor, argTypes, null);
}
} else {
SqlCall testCall = resolvedConstructor.createCall(call.getParserPosition(), call.getOperandList());
RelDataType returnType = resolvedConstructor.validateOperands(this, scope, testCall);
assert type == returnType;
}
if (config.identifierExpansion()) {
if (resolvedConstructor != null) {
((SqlBasicCall) call).setOperator(resolvedConstructor);
} else {
// fake a fully-qualified call to the default constructor
((SqlBasicCall) call).setOperator(new SqlFunction(type.getSqlIdentifier(), ReturnTypes.explicit(type), null, null, null, SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR));
}
}
return type;
}
use of org.apache.calcite.sql.SqlFunction in project Mycat2 by MyCATApache.
the class CheckingUserDefinedAndConvertFunctionVisitor method visitCall.
@Override
public Void visitCall(RexCall call) {
SqlOperator operator = call.getOperator();
String name = operator.getName();
if (operator instanceof SqlFunction) {
containsUsedDefinedFunction |= Information_Functions.containsKey(name, false);
}
if (operator == MycatSessionValueFunction.BIGINT_TYPE_INSTANCE || operator == MycatSessionValueFunction.STRING_TYPE_INSTANCE) {
containsUsedDefinedFunction = true;
}
return super.visitCall(call);
}
Aggregations