<?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 Is writing custom function possible in transform(array,func) in databricks sql? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/is-writing-custom-function-possible-in-transform-array-func-in/m-p/9673#M5000</link>
    <description>&lt;P&gt;This is the query I am trying to implement&lt;/P&gt;&lt;P&gt;Create function data_hide(data string)&lt;/P&gt;&lt;P&gt;Return if(is_member('groupName'),data,'****')&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;Table : my_table&lt;/P&gt;&lt;P&gt;Id  Subject&lt;/P&gt;&lt;P&gt;​1.   ['Eng','Bio']&lt;/P&gt;&lt;P&gt;2.  ['Phy','Mat']&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;Select id, transform(Subject, x -&amp;gt; data_hide(x)) as new_data from my_table&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;The above select statement throwing me error​&lt;/P&gt;</description>
    <pubDate>Thu, 09 Feb 2023 12:37:40 GMT</pubDate>
    <dc:creator>Jerry01</dc:creator>
    <dc:date>2023-02-09T12:37:40Z</dc:date>
    <item>
      <title>Is writing custom function possible in transform(array,func) in databricks sql?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-writing-custom-function-possible-in-transform-array-func-in/m-p/9673#M5000</link>
      <description>&lt;P&gt;This is the query I am trying to implement&lt;/P&gt;&lt;P&gt;Create function data_hide(data string)&lt;/P&gt;&lt;P&gt;Return if(is_member('groupName'),data,'****')&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;Table : my_table&lt;/P&gt;&lt;P&gt;Id  Subject&lt;/P&gt;&lt;P&gt;​1.   ['Eng','Bio']&lt;/P&gt;&lt;P&gt;2.  ['Phy','Mat']&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;Select id, transform(Subject, x -&amp;gt; data_hide(x)) as new_data from my_table&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;The above select statement throwing me error​&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 12:37:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-writing-custom-function-possible-in-transform-array-func-in/m-p/9673#M5000</guid>
      <dc:creator>Jerry01</dc:creator>
      <dc:date>2023-02-09T12:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Is writing custom function possible in transform(array,func) in databricks sql?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-writing-custom-function-possible-in-transform-array-func-in/m-p/9674#M5001</link>
      <description>&lt;P&gt;@Naveena G​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error in your SQL query may be caused by the fact that the transform function expects an array or map as its first argument, but you are passing a string instead. In this case, the Subject column appears to contain an array, but you are not specifying which element of the array to apply the data_hide function to. Assuming that you want to apply the data_hide function to each element of the Subject array separately, you can modify your query as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT id, transform(Subject, x -&amp;gt; data_hide(x)) AS new_data FROM my_table&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, if you only want to apply the data_hide function to the entire Subject array if the user is not a member of the groupName group, you can modify your query as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT id, IF(is_member('groupName'), Subject, transform(Subject, x -&amp;gt; data_hide(x))) AS new_data FROM my_table&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This will return the original Subject array if the user is a member of the groupName group, otherwise it will apply the data_hide function to each element of the array.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 15:00:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-writing-custom-function-possible-in-transform-array-func-in/m-p/9674#M5001</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-04-09T15:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Is writing custom function possible in transform(array,func) in databricks sql?</title>
      <link>https://community.databricks.com/t5/data-engineering/is-writing-custom-function-possible-in-transform-array-func-in/m-p/9675#M5002</link>
      <description>&lt;P&gt;Hi @Naveena G​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for posting your question in our community! We are happy to assist you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 08:31:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/is-writing-custom-function-possible-in-transform-array-func-in/m-p/9675#M5002</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-04-10T08:31:21Z</dc:date>
    </item>
  </channel>
</rss>

