<?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: Row filtering based on condition not working in Warehousing &amp; Analytics</title>
    <link>https://community.databricks.com/t5/warehousing-analytics/row-filtering-based-on-condition-not-working/m-p/110327#M1888</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/149385"&gt;@HeathDG1&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P class=""&gt;I think your function isn’t behaving the way you expect because of how the logic is set up:&lt;/P&gt;&lt;P class=""&gt;•If the user is in Stern MA, they only see rows where state = 'MA'&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;(which is good).&lt;BR /&gt;•BUT for everyone else, the function returns true, meaning they see all the data&lt;/P&gt;&lt;P class=""&gt;To properly &lt;SPAN class=""&gt;&lt;STRONG&gt;restrict access&lt;/STRONG&gt;&lt;/SPAN&gt; for users outside &lt;SPAN class=""&gt;Stern MA&lt;/SPAN&gt;, you need to &lt;SPAN class=""&gt;&lt;STRONG&gt;return false by default&lt;/STRONG&gt;&lt;/SPAN&gt; instead of &lt;SPAN class=""&gt;true&lt;/SPAN&gt;:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE FUNCTION dream_team.stern_portfolio.state_filter(state STRING) 
RETURNS BOOLEAN 
RETURN
IF(IS_ACCOUNT_GROUP_MEMBER('Stern MA'), state = 'MA', false);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;•&amp;nbsp;&lt;SPAN class=""&gt;&lt;STRONG&gt;If the user is in Stern MA&lt;/STRONG&gt;&lt;/SPAN&gt; → They get &lt;SPAN class=""&gt;state = 'MA'&lt;/SPAN&gt; (so they only see data for MA).&lt;/P&gt;&lt;P class=""&gt;•&lt;SPAN class=""&gt;&lt;STRONG&gt;If the user is NOT in Stern MA&lt;/STRONG&gt;&lt;/SPAN&gt; → The function returns &lt;SPAN class=""&gt;false&lt;/SPAN&gt;, meaning they see &lt;SPAN class=""&gt;nothing at all&lt;/SPAN&gt;.&lt;/P&gt;&lt;P class=""&gt;Once the function is corrected, apply the row filter to your table&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;To various groups:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE FUNCTION dream_team.stern_portfolio.state_filter(state STRING) 
RETURNS BOOLEAN 
RETURN
CASE 
    WHEN IS_ACCOUNT_GROUP_MEMBER('Stern MA') THEN state = 'MA'
    WHEN IS_ACCOUNT_GROUP_MEMBER('Stern NY') THEN state = 'NY'
    WHEN IS_ACCOUNT_GROUP_MEMBER('Stern CA') THEN state = 'CA'
    ELSE false
END;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 16 Feb 2025 15:32:39 GMT</pubDate>
    <dc:creator>Isi</dc:creator>
    <dc:date>2025-02-16T15:32:39Z</dc:date>
    <item>
      <title>Row filtering based on condition not working</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/row-filtering-based-on-condition-not-working/m-p/110319#M1887</link>
      <description>&lt;DIV&gt;Hi-&lt;/DIV&gt;&lt;DIV&gt;We have a delta table in our unity catalog called&amp;nbsp;&lt;SPAN&gt;dream_team.stern_portfolio.location_info.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;We are trying to use row level security to filter our data based on a users group membership. This way when users look at out dashboard&amp;nbsp;they can only see the data they are allowed to me (as in only MA data)&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;HOWEVER, the row filter is being applied to ALL users, not just the users in the group Stern MA.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;PLEASE HELP US.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;Below is the SQL code we have used to create and apply the function.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;CREATE OR REPLACE FUNCTION dream_team.stern_portfolio.state_filter(state STRING) RETURNS BOOLEAN RETURN&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;IF(IS_ACCOUNT_GROUP_MEMBER('Stern MA'), state = 'MA', true)&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;-- Apply the row filter to the table ALTER TABLE dream_team.stern_portfolio.location_info SET ROW FILTER dream_team.stern_portfolio.state_filter ON (state);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 16 Feb 2025 01:17:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/row-filtering-based-on-condition-not-working/m-p/110319#M1887</guid>
      <dc:creator>HeathDG1</dc:creator>
      <dc:date>2025-02-16T01:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Row filtering based on condition not working</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/row-filtering-based-on-condition-not-working/m-p/110327#M1888</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/149385"&gt;@HeathDG1&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P class=""&gt;I think your function isn’t behaving the way you expect because of how the logic is set up:&lt;/P&gt;&lt;P class=""&gt;•If the user is in Stern MA, they only see rows where state = 'MA'&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;(which is good).&lt;BR /&gt;•BUT for everyone else, the function returns true, meaning they see all the data&lt;/P&gt;&lt;P class=""&gt;To properly &lt;SPAN class=""&gt;&lt;STRONG&gt;restrict access&lt;/STRONG&gt;&lt;/SPAN&gt; for users outside &lt;SPAN class=""&gt;Stern MA&lt;/SPAN&gt;, you need to &lt;SPAN class=""&gt;&lt;STRONG&gt;return false by default&lt;/STRONG&gt;&lt;/SPAN&gt; instead of &lt;SPAN class=""&gt;true&lt;/SPAN&gt;:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE FUNCTION dream_team.stern_portfolio.state_filter(state STRING) 
RETURNS BOOLEAN 
RETURN
IF(IS_ACCOUNT_GROUP_MEMBER('Stern MA'), state = 'MA', false);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;•&amp;nbsp;&lt;SPAN class=""&gt;&lt;STRONG&gt;If the user is in Stern MA&lt;/STRONG&gt;&lt;/SPAN&gt; → They get &lt;SPAN class=""&gt;state = 'MA'&lt;/SPAN&gt; (so they only see data for MA).&lt;/P&gt;&lt;P class=""&gt;•&lt;SPAN class=""&gt;&lt;STRONG&gt;If the user is NOT in Stern MA&lt;/STRONG&gt;&lt;/SPAN&gt; → The function returns &lt;SPAN class=""&gt;false&lt;/SPAN&gt;, meaning they see &lt;SPAN class=""&gt;nothing at all&lt;/SPAN&gt;.&lt;/P&gt;&lt;P class=""&gt;Once the function is corrected, apply the row filter to your table&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;To various groups:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE FUNCTION dream_team.stern_portfolio.state_filter(state STRING) 
RETURNS BOOLEAN 
RETURN
CASE 
    WHEN IS_ACCOUNT_GROUP_MEMBER('Stern MA') THEN state = 'MA'
    WHEN IS_ACCOUNT_GROUP_MEMBER('Stern NY') THEN state = 'NY'
    WHEN IS_ACCOUNT_GROUP_MEMBER('Stern CA') THEN state = 'CA'
    ELSE false
END;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2025 15:32:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/row-filtering-based-on-condition-not-working/m-p/110327#M1888</guid>
      <dc:creator>Isi</dc:creator>
      <dc:date>2025-02-16T15:32:39Z</dc:date>
    </item>
  </channel>
</rss>

