<?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: Table name as a parameter in SQL UDF in Machine Learning</title>
    <link>https://community.databricks.com/t5/machine-learning/table-name-as-a-parameter-in-sql-udf/m-p/68230#M3246</link>
    <description>&lt;P&gt;Did you find a solutions? I'm having the same problem&lt;/P&gt;</description>
    <pubDate>Mon, 06 May 2024 11:42:39 GMT</pubDate>
    <dc:creator>alm</dc:creator>
    <dc:date>2024-05-06T11:42:39Z</dc:date>
    <item>
      <title>Table name as a parameter in SQL UDF</title>
      <link>https://community.databricks.com/t5/machine-learning/table-name-as-a-parameter-in-sql-udf/m-p/22289#M1266</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We would like to create a UDF function with input parameter a table_name. Please check the below simple example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;CREATE OR REPLACE FUNCTION F_NAME(v_table_name STRING,&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                                 &amp;nbsp;v_where_value INT) &lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;RETURNS INT&amp;nbsp;&amp;nbsp;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;RETURN SELECT MAX(id) FROM v_table_name WHERE code = v_where_value&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, it seems that v_table_name is not recognized as a table in the Select clause. Could you please suggest a workaround?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 11:44:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/table-name-as-a-parameter-in-sql-udf/m-p/22289#M1266</guid>
      <dc:creator>elgeo</dc:creator>
      <dc:date>2022-11-15T11:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Table name as a parameter in SQL UDF</title>
      <link>https://community.databricks.com/t5/machine-learning/table-name-as-a-parameter-in-sql-udf/m-p/68230#M3246</link>
      <description>&lt;P&gt;Did you find a solutions? I'm having the same problem&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 11:42:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/table-name-as-a-parameter-in-sql-udf/m-p/68230#M3246</guid>
      <dc:creator>alm</dc:creator>
      <dc:date>2024-05-06T11:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Table name as a parameter in SQL UDF</title>
      <link>https://community.databricks.com/t5/machine-learning/table-name-as-a-parameter-in-sql-udf/m-p/68475#M3259</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/69823"&gt;@elgeo&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/49711"&gt;@alm&lt;/a&gt;&amp;nbsp;- passing a parameter within a function is not currently available. we can create a python UDF that generate the underlying code to pass the parameter. Then do a select statement to pass the dynamic value to execute the function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say for example,&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;def sayHello(*args):

query = """

CREATE OR REPLACE FUNCTION F_NAME(v_table_name STRING,

                   v_where_value INT)

RETURNS INT  

RETURN SELECT MAX(id) FROM v_table_name WHERE code = {0}


"""

df = spark.sql(query.format(*args))
print(df.show(truncate=False))
return

%sql
select F_NAME('v_where_value')
&lt;/LI-CODE&gt;
&lt;P&gt;Please note: The above code snippet is not syntax verified.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 16:26:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/table-name-as-a-parameter-in-sql-udf/m-p/68475#M3259</guid>
      <dc:creator>shan_chandra</dc:creator>
      <dc:date>2024-05-07T16:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Table name as a parameter in SQL UDF</title>
      <link>https://community.databricks.com/t5/machine-learning/table-name-as-a-parameter-in-sql-udf/m-p/68510#M3263</link>
      <description>&lt;P&gt;Use the identifier clause (more like a function) in Spark SQL. It requires runtime 13.3 LTS or higher.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 21:13:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/table-name-as-a-parameter-in-sql-udf/m-p/68510#M3263</guid>
      <dc:creator>El_Tigre</dc:creator>
      <dc:date>2024-05-07T21:13:35Z</dc:date>
    </item>
  </channel>
</rss>

