<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I register UDF in sql in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-do-i-register-udf-in-sql/m-p/21802#M14894</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;def squared(s):
  return s * s
spark.udf.register("squaredWithPython", squared)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can optionally set the return type of your UDF. The default return type is&amp;nbsp;&lt;/P&gt;&lt;P&gt;StringType&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from pyspark.sql.types import LongType
def squared_typed(s):
  return s * s
spark.udf.register("squaredWithPython", squared_typed, LongType())&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;spark.range(1, 20).createOrReplaceTempView("test")&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;%sql select id, squaredWithPython(id) as id_squared from test&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jun 2021 12:41:16 GMT</pubDate>
    <dc:creator>User16826994223</dc:creator>
    <dc:date>2021-06-22T12:41:16Z</dc:date>
    <item>
      <title>How do I register UDF in sql</title>
      <link>https://community.databricks.com/t5/data-engineering/how-do-i-register-udf-in-sql/m-p/21801#M14893</link>
      <description>&lt;P&gt;Can I get an example of how do create UDF in python and use in sql &lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 12:36:42 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-do-i-register-udf-in-sql/m-p/21801#M14893</guid>
      <dc:creator>User16826994223</dc:creator>
      <dc:date>2021-06-22T12:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I register UDF in sql</title>
      <link>https://community.databricks.com/t5/data-engineering/how-do-i-register-udf-in-sql/m-p/21802#M14894</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;def squared(s):
  return s * s
spark.udf.register("squaredWithPython", squared)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can optionally set the return type of your UDF. The default return type is&amp;nbsp;&lt;/P&gt;&lt;P&gt;StringType&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from pyspark.sql.types import LongType
def squared_typed(s):
  return s * s
spark.udf.register("squaredWithPython", squared_typed, LongType())&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;spark.range(1, 20).createOrReplaceTempView("test")&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;%sql select id, squaredWithPython(id) as id_squared from test&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 12:41:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-do-i-register-udf-in-sql/m-p/21802#M14894</guid>
      <dc:creator>User16826994223</dc:creator>
      <dc:date>2021-06-22T12:41:16Z</dc:date>
    </item>
  </channel>
</rss>

