Refine search
/** * Parses a call to TIMESTAMPDIFF. */ final public SqlCall TimestampDiffFunctionCall() throws ParseException { List<SqlNode> args; SqlNode e; final Span s; TimeUnit interval; SqlNode node; jj_consume_token(TIMESTAMPDIFF); s = span(); jj_consume_token(LPAREN); interval = TimestampInterval(); args = startList(SqlLiteral.createSymbol(interval, getPos())); jj_consume_token(COMMA); e = Expression(ExprContext.ACCEPT_SUB_QUERY); args.add(e); jj_consume_token(COMMA); e = Expression(ExprContext.ACCEPT_SUB_QUERY); args.add(e); jj_consume_token(RPAREN); {if (true) return SqlStdOperatorTable.TIMESTAMP_DIFF.createCall( s.end(this), args);} throw new Error("Missing return statement in function"); }
public AliasedOperatorConversion(final SqlOperatorConversion baseConversion, final String name) { if (!SqlKind.FUNCTION.contains(baseConversion.calciteOperator().getKind())) { throw new IAE("Base operator must be a function but was[%s]", baseConversion.calciteOperator().getKind()); } final SqlFunction baseFunction = (SqlFunction) baseConversion.calciteOperator(); this.baseConversion = baseConversion; this.name = name; this.operator = new SqlFunction( name, baseFunction.getKind(), baseFunction.getReturnTypeInference(), baseFunction.getOperandTypeInference(), baseFunction.getOperandTypeChecker(), baseFunction.getFunctionType() ); }
public CalciteException handleUnresolvedFunction(SqlCall call, SqlFunction unresolvedFunction, List<RelDataType> argTypes, List<String> argNames) { // For builtins, we can give a better error message final List<SqlOperator> overloads = new ArrayList<>(); opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null, SqlSyntax.FUNCTION, overloads); if (overloads.size() == 1) { SqlFunction fun = (SqlFunction) overloads.get(0); if ((fun.getSqlIdentifier() == null) && (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) { final int expectedArgCount = fun.getOperandCountRange().getMin(); throw newValidationError(call, RESOURCE.invalidArgCount(call.getOperator().getName(), expectedArgCount)); } } AssignableOperandTypeChecker typeChecking = new AssignableOperandTypeChecker(argTypes, argNames); String signature = typeChecking.getAllowedSignatures( unresolvedFunction, unresolvedFunction.getName()); throw newValidationError(call, RESOURCE.validatorUnknownFunction(signature)); }
SqlFunction resolvedConstructor, List<RelDataType> argTypes) { SqlIdentifier sqlIdentifier = unresolvedConstructor.getSqlIdentifier(); assert sqlIdentifier != null; RelDataType type = catalogReader.getNamedType(sqlIdentifier); resolvedConstructor.createCall( call.getParserPosition(), call.getOperandList()); RelDataType returnType = resolvedConstructor.validateOperands( this, scope, new SqlFunction( type.getSqlIdentifier(), ReturnTypes.explicit(type),
private SqlCall createOverCall(SqlAggFunction op, List<SqlNode> operands, SqlWindow window) { if (op instanceof SqlSumEmptyIsZeroAggFunction) { // Rewrite "SUM0(x) OVER w" to "COALESCE(SUM(x) OVER w, 0)" final SqlCall node = createOverCall(SqlStdOperatorTable.SUM, operands, window); return SqlStdOperatorTable.COALESCE.createCall(POS, node, SqlLiteral.createExactNumeric("0", POS)); } final SqlCall aggFunctionCall = op.createCall(POS, operands); return SqlStdOperatorTable.OVER.createCall(POS, aggFunctionCall, window); }
@Override public SqlNode visit(SqlCall call) { SqlKind kind = call.getKind(); if (isLogicalNavigation(kind) || isAggregation(kind) || isRunningOrFinal(kind)) { return call; } switch (kind) { case PREV: final List<SqlNode> operands = call.getOperandList(); if (operands.get(0) instanceof SqlIdentifier) { String name = ((SqlIdentifier) operands.get(0)).names.get(0); return name.equals(alpha) ? call : SqlStdOperatorTable.LAST.createCall(SqlParserPos.ZERO, operands); } } return super.visit(call); }
public SqlCall createCall( SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) { assert functionQualifier == null; switch (operands.length) { case 1: // This variant occurs when someone writes TRIM(string) // as opposed to the sugared syntax TRIM(string FROM string). operands = new SqlNode[]{ Flag.BOTH.symbol(SqlParserPos.ZERO), SqlLiteral.createCharString(" ", pos), operands[0] }; break; case 3: assert operands[0] instanceof SqlLiteral && ((SqlLiteral) operands[0]).getValue() instanceof Flag; if (operands[1] == null) { operands[1] = SqlLiteral.createCharString(" ", pos); } break; default: throw new IllegalArgumentException( "invalid operand count " + Arrays.toString(operands)); } return super.createCall(functionQualifier, pos, operands); }
final List<String> argNames = constructArgNameList(call); final List<SqlNode> args = constructOperandList(validator, call, argNames); final List<RelDataType> argTypes = constructArgTypeList(validator, scope, call, args, convertRowArgToColumnList); getNameAsId(), argTypes, argNames, getFunctionType(), SqlSyntax.FUNCTION, getKind()); try { if (convertRowArgToColumnList && containsRowArg(args)) { if (function == null && SqlUtil.matchRoutinesByParameterCount( validator.getOperatorTable(), getNameAsId(), argTypes, getFunctionType())) { return deriveType(validator, scope, call, false); } else if (function != null) { validator.validateColumnListParams(function, argTypes, args); if (getFunctionType() == SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR) { return validator.deriveConstructorType(scope, call, this, function, argTypes); return function.validateOperands( validator, operandScope,
public DrillCalciteSqlFunctionWrapper( final SqlFunction wrappedFunction, final List<DrillFuncHolder> functions) { super(wrappedFunction.getName(), wrappedFunction.getSqlIdentifier(), wrappedFunction.getKind(), TypeInferenceUtils.getDrillSqlReturnTypeInference( wrappedFunction.getName(), functions), wrappedFunction.getOperandTypeInference(), Checker.ANY_CHECKER, wrappedFunction.getParamTypes(), wrappedFunction.getFunctionType()); this.operator = wrappedFunction; }
if (operator instanceof SqlFunction) { SqlFunction function = (SqlFunction) operator; if (function.getKind() == SqlKind.CAST) { if (call.operands.size() < 2) { isSpecialCast = true;
SqlFunction function = (SqlFunction) operator; if (function.getFunctionType().isSpecific()) { writer.keyword("SPECIFIC"); SqlIdentifier id = function.getSqlIdentifier(); if (id == null) { writer.keyword(operator.getName()); final SqlLiteral quantifier = call.getFunctionQuantifier(); if (quantifier != null) { quantifier.unparse(writer, 0, 0);
public void validateCall( SqlCall call, SqlValidatorScope scope) { final SqlOperator operator = call.getOperator(); if ((call.operandCount() == 0) && (operator.getSyntax() == SqlSyntax.FUNCTION_ID) && !call.isExpanded() && !conformance.allowNiladicParentheses()) { // For example, "LOCALTIME()" is illegal. (It should be // "LOCALTIME", which would have been handled as a // 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); }
public SqlFunction build() { return new SqlFunction( name, kind, Preconditions.checkNotNull(returnTypeInference, "returnTypeInference"), null, OperandTypes.family( Preconditions.checkNotNull(operandTypes, "operandTypes"), i -> i + 1 > requiredOperands ), functionCategory ); } }
if (sqlFunction.getFunctionType().isUserDefinedNotSpecificFunction()) { final List<SqlOperator> list = new ArrayList<>(); opTab.lookupOperatorOverloads(sqlFunction.getSqlIdentifier(), sqlFunction.getFunctionType(), SqlSyntax.FUNCTION, list); for (SqlOperator operator2 : list) { if (operator2.isAggregator() && !operator2.requiresOver()) {
rowSignature, rexNode, StringUtils.toLowerCase(calciteOperator().getName()), inputExpressions -> { final DruidExpression arg = inputExpressions.get(0);
public SqlSyntax getSyntax() { if(isNiladic) { return SqlSyntax.FUNCTION_ID; } return super.getSyntax(); }
if (operand.getKind() == SqlKind.OTHER_FUNCTION) { SqlFunction tableFunction = (SqlFunction)((SqlCall)operand).getOperator(); return asList(tableFunction.getSqlIdentifier());
/** Converts a call to an aggregate function to an expression. */ public SqlNode toSql(AggregateCall aggCall) { final SqlOperator op = aggCall.getAggregation(); final List<SqlNode> operandList = Expressions.list(); for (int arg : aggCall.getArgList()) { operandList.add(field(arg)); } final SqlLiteral qualifier = aggCall.isDistinct() ? SqlSelectKeyword.DISTINCT.symbol(POS) : null; final SqlNode[] operands = operandList.toArray(new SqlNode[0]); List<SqlNode> orderByList = Expressions.list(); for (RelFieldCollation field : aggCall.collation.getFieldCollations()) { addOrderItem(orderByList, field); } SqlNodeList orderList = new SqlNodeList(orderByList, POS); if (op instanceof SqlSumEmptyIsZeroAggFunction) { final SqlNode node = withOrder( SqlStdOperatorTable.SUM.createCall(qualifier, POS, operands), orderList); return SqlStdOperatorTable.COALESCE.createCall(POS, node, SqlLiteral.createExactNumeric("0", POS)); } else { return withOrder(op.createCall(qualifier, POS, operands), orderList); } }
private SqlNode maybeCast(SqlNode node, RelDataType currentType, RelDataType desiredType) { return currentType.equals(desiredType) || (currentType.isNullable() != desiredType.isNullable() && typeFactory.createTypeWithNullability(currentType, desiredType.isNullable()).equals(desiredType)) ? node : SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, node, SqlTypeUtil.convertTypeToSpec(desiredType)); }
public SqlCall createCall( SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) { assert functionQualifier == null; switch (operands.length) { case 1: // This variant occurs when someone writes TRIM(string) // as opposed to the sugared syntax TRIM(string FROM string). operands = new SqlNode[]{ Flag.BOTH.symbol(SqlParserPos.ZERO), SqlLiteral.createCharString(" ", pos), operands[0] }; break; case 3: assert operands[0] instanceof SqlLiteral && ((SqlLiteral) operands[0]).getValue() instanceof Flag; if (operands[1] == null) { operands[1] = SqlLiteral.createCharString(" ", pos); } break; default: throw new IllegalArgumentException( "invalid operand count " + Arrays.toString(operands)); } return super.createCall(functionQualifier, pos, operands); }