Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-22216 Improving PySpark/Pandas interoperability
  3. SPARK-22978

Register Scalar Vectorized UDFs for SQL Statement

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.3.0
    • 2.3.0
    • PySpark
    • None

    Description

      Capable of registering vectorized UDFs and then use it in SQL statement.

      For example,

      >>> import random
      >>> from pyspark.sql.types import IntegerType
      >>> from pyspark.sql.functions import pandas_udf
      >>> random_pandas_udf = pandas_udf(
      ...     lambda x: random.randint(0, 100) + x, IntegerType())
      ...     .asNondeterministic()  # doctest: +SKIP
      >>> _ = spark.catalog.registerFunction(
      ...     "random_pandas_udf", random_pandas_udf, IntegerType())  # doctest: +SKIP
      >>> spark.sql("SELECT random_pandas_udf(2)").collect()  # doctest: +SKIP
      [Row(random_pandas_udf(2)=84)]
      

      Attachments

        Activity

          People

            smilegator Xiao Li
            smilegator Xiao Li
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: