cloud-fan commented on code in PR #41864: URL: https://github.com/apache/spark/pull/41864#discussion_r1259022421
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/SupportsNamedArguments.scala: ########## @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.catalyst.plans.logical + +import org.apache.spark.sql.catalyst.expressions.{Expression, NamedArgumentExpression} +import org.apache.spark.sql.errors.QueryCompilationErrors +import org.apache.spark.sql.types.AbstractDataType + +/** + * The class which companion objects of function expression may implement to + * support named arguments for that function expression. Please note that variadic final + * arguments are NOT supported for named arguments. Do not use for functions that + * has variadic final arguments! + * + * Example: + * object CountMinSketchAgg extends SupportsNamedArguments { + * final val functionSignature = FunctionSignature(Seq( + * NamedArgument("column", + * FixedArgumentType(TypeCollection(IntegralType, StringType, BinaryType))), + * NamedArgument("epsilon", FixedArgumentType(DoubleType)), + * NamedArgument("confidence", FixedArgumentType(DoubleType)), + * NamedArgument("seed", FixedArgumentType(IntegerType)) + * )) + * override def functionSignatures: Seq[FunctionSignature] = Seq(functionSignature) + * } + */ +abstract class SupportsNamedArguments { + /** + * This is the method overridden by function expressions to define their method signatures. + * Currently, we don't support overloads, so we restrict each function expression to return + * only one FunctionSignature. + * + * @return the signature of the function expression + */ + def functionSignatures: Seq[FunctionSignature] + + /** + * This function rearranges the list of expressions according to the function signature + * It is recommended to use this provided implementation as it is consistent with + * the SQL standard. If absolutely necessary the developer can choose to override the default + * behavior for additional flexibility. + * + * @param expectedSignature Function signature that denotes positional order of arguments + * @param providedArguments The sequence of expressions from function invocation + * @param functionName The name of the function invoked for debugging purposes + * @return positional order of arguments according to FunctionSignature obtained + * by changing the order of the above provided arguments + */ + protected def rearrange( + expectedSignature: FunctionSignature, + providedArguments: Seq[Expression], + functionName: String): Seq[Expression] = { + SupportsNamedArguments.defaultRearrange(expectedSignature, providedArguments, functionName) + } +} + +object SupportsNamedArguments { + final def defaultRearrange(functionSignature: FunctionSignature, Review Comment: looking at this function, seems it doesn't care about the required data types of the arguments? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
