Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-39247

Support returning a table or set of rows in CREATE FUNCTION

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.3.0
    • None
    • SQL
    • None

    Description

      The Databricks version supports create a function which returns a result set:
      "Creates a SQL scalar or table function that takes a set of arguments and returns a scalar value or a set of rows."
      Such functions are very useful as the user can pass a list of parameters which can be used in the function to create a dynamic result set (a query which will use the passed parameters). 

      See the example from databricks:
      "-- Produce all weekdays between two dates > CREATE FUNCTION weekdays(start DATE, end DATE) RETURNS TABLE(day_of_week STRING, day DATE) RETURN SELECT extract(DAYOFWEEK_ISO FROM day), day FROM (SELECT sequence(weekdays.start, weekdays.end)) AS T(days) LATERAL VIEW explode(days) AS day WHERE extract(DAYOFWEEK_ISO FROM day) BETWEEN 1 AND 5;"

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Erik Jansen Erik Jansen
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: