allisonwang-db commented on code in PR #49471: URL: https://github.com/apache/spark/pull/49471#discussion_r1984271562
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala: ########## @@ -1675,6 +1676,91 @@ class SessionCatalog( } } + /** + * Constructs a table SQL function plan. + * + * 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 + + // Use captured SQL configs when parsing a SQL function. + val conf = new SQLConf() + function.getSQLConfigs.foreach { case (k, v) => conf.settings.put(k, v) } + SQLConf.withExistingConf(conf) { + 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: Yea we support it. It's in `makeSQLTableFunctionBuilder` (rearrangeArguments) -- 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