cloud-fan commented on code in PR #49471: URL: https://github.com/apache/spark/pull/49471#discussion_r1984468771
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala: ########## @@ -1675,6 +1676,86 @@ class SessionCatalog( } } + /** + * Constructs a SQL table function plan. + * This function should be invoked with the captured SQL configs from the function. + * + * Example SQL table function: + * + * CREATE FUNCTION foo(x INT) RETURNS TABLE(a INT) RETURN SELECT x + 1 AS x1 + * + * Query: + * + * SELECT * FROM foo(1); + * + * Plan: + * + * Project [CAST(x1 AS INT) AS a] + * +- LateralJoin lateral-subquery [x] + * : +- Project [(outer(x) + 1) AS x1] + * : +- OneRowRelation + * +- Project [CAST(1 AS INT) AS x] + * +- OneRowRelation + */ + def makeSQLTableFunctionPlan( + name: String, + function: SQLFunction, + input: Seq[Expression], + outputAttrs: Seq[Attribute]): LogicalPlan = { + assert(function.isTableFunc) + val funcName = function.name.funcName + val inputParam = function.inputParam + val returnParam = function.getTableFuncReturnCols + val (_, query) = function.getExpressionAndQuery(parser, isTableFunc = true) + assert(query.isDefined) + + // Check function arguments + val paramSize = inputParam.map(_.size).getOrElse(0) + if (input.size > paramSize) { + throw QueryCompilationErrors.wrongNumArgsError( + name, paramSize.toString, input.size) + } + + val body = if (inputParam.isDefined) { + val param = inputParam.get + // Attributes referencing the input parameters inside the function can use the + // function name as a qualifier. + val qualifier = Seq(funcName) + val paddedInput = input ++ + param.takeRight(paramSize - input.size).map { p => Review Comment: This looks like dead code, `SQLTableFunction` is created by `SessionCatalog#makeSQLTableFunctionBuilder`, which already handles by-name parameters and fills default values. If there are missing parameters that has no default value, it should already failed: https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/FunctionBuilderBase.scala#L192-L193 -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org