learningchess2003 commented on code in PR #41864:
URL: https://github.com/apache/spark/pull/41864#discussion_r1261777459
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala:
##########
@@ -1015,6 +1050,62 @@ object TableFunctionRegistry {
val functionSet: Set[FunctionIdentifier] = builtin.listFunction().toSet
}
-trait ExpressionBuilder {
- def build(funcName: String, expressions: Seq[Expression]): Expression
+trait Builder[T] {
+ /**
+ * A method that returns the signatures of overloads that is associated with
this function
+ *
+ * @return a list of function signatures
+ */
+ def functionSignatures: Option[Seq[FunctionSignature]] = None
+
+ /**
+ * This function rearranges the arguments provided during function
invocation in positional order
+ * according to the function signature. This method will fill in the default
values if optional
+ * parmaeters do not have their values specified. Any function which
supports named arguments
+ * will have this routine invoked, even if no named arguments are present in
the argument list.
+ * This is done to eliminate constructor overloads in some methods which use
them for default
+ * values prior to the implementation of the named argument framework. This
function will also
+ * check if the number of arguments are correct. If that is not the case,
then an error will be thrown.
+ *
+ * IMPORTANT: This method will be called before the [[Builder.build]] method
is invoked. It is
+ * guaranteed that the expressions provided to the [[Builder.build]]
functions forms a valid set
+ * of argument expressions that can be used in the construction of the
function expression.
+ *
+ * @param expectedSignature The method signature which we rearrange our
arguments according to
+ * @param providedArguments The list of arguments passed from function
invocation
+ * @param functionName The name of the function
+ * @return The rearranged arugument list with arguments in positional order
+ */
+ def rearrange(
+ expectedSignature: FunctionSignature,
+ providedArguments: Seq[Expression],
+ functionName: String) : Seq[Expression] = {
+ SupportsNamedArguments.defaultRearrange(expectedSignature,
providedArguments, functionName)
+ }
+
+ def build(funcName: String, expressions: Seq[Expression]): T
+}
+
+/**
+ * A trait used for scalar valued functions that defines how their expression
representations
+ * are constructed in [[FunctionRegistry]]
+ */
+trait ExpressionBuilder extends Builder[Expression]
+
+/**
+ * A trait used for table valued functions that defines how their expression
representations
+ * are constructed in [[FunctionRegistry]]
+ */
+trait GeneratorBuilder extends Builder[LogicalPlan] {
+ override final def build(funcName: String, expressions: Seq[Expression]) :
LogicalPlan = {
+ Generate(
+ buildGenerator(funcName, expressions),
+ unrequiredChildIndex = Nil,
+ outer = isOuter,
+ qualifier = None,
+ generatorOutput = Nil,
+ child = OneRowRelation())
+ }
+ def isOuter: Boolean
+ def buildGenerator(funcName: String, expressions: Seq[Expression]) :
Generator
Review Comment:
I added this because the build function in ExpressionBuilder requires it.
It's to be consistent with the previous ```ExpressionBuilder#build(name,
arguments)``` method.
--
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]