<?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: [INTERNAL_ERROR] Cannot generate code for expression: claimsconifer.default.decrypt_colA( in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/internal-error-cannot-generate-code-for-expression-claimsconifer/m-p/49369#M28536</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/9"&gt;@Retired_mod&lt;/a&gt;&amp;nbsp;After removing "TABLE" keyword from create or replace statement this function got registered as builtin function. Just to verify that I displayed all the functions and I can see that function--&amp;gt; &lt;STRONG&gt;decrypt_if_valid_user&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nikhil1991_0-1697541657408.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/4471iE7899FFCFF970D08/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="nikhil1991_0-1697541657408.png" alt="nikhil1991_0-1697541657408.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now I am trying to alter the table using below command and it is giving below error:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;%sql
ALTER TABLE test.default.sampletbl ALTER COLUMN col_a SET MASK decrypt_if_valid_user&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nikhil1991_1-1697541801866.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/4472i467A69E0742B6565/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="nikhil1991_1-1697541801866.png" alt="nikhil1991_1-1697541801866.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Although I can see this function in the list but still it is not able recognize that function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Oct 2023 11:24:59 GMT</pubDate>
    <dc:creator>nikhilkumawat</dc:creator>
    <dc:date>2023-10-17T11:24:59Z</dc:date>
    <item>
      <title>[INTERNAL_ERROR] Cannot generate code for expression: claimsconifer.default.decrypt_colA(</title>
      <link>https://community.databricks.com/t5/data-engineering/internal-error-cannot-generate-code-for-expression-claimsconifer/m-p/48933#M28425</link>
      <description>&lt;P&gt;A column contains encrypted data at rest.&amp;nbsp;I am trying to create a sql function which will decrypt the data if the user is a part of a particular group. Below is the function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;%sql
CREATE OR REPLACE FUNCTION test.default.decrypt_if_valid_user(col_a STRING) 
RETURN CASE WHEN is_account_group_member('admin') THEN test.default.decrypt_colA (col_a ,secret('fernet_key', 'fernet_key_secret'))
    ELSE col_a
  END&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here "&lt;STRONG&gt;test.default.decrypt_colA&lt;/STRONG&gt;" is already created. When I ran the query to retreive data I got decrypted data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;%sql
select test.default.decrypt_if_valid_user(col_a) from test.default.sampletbl limit 2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this I am getting decrypted data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I applied this function directly on column by altering the table like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;%sql
ALTER TABLE tes.default.sampletbl ALTER COLUMN col_a SET MASK test.default.decrypt_if_valid_user&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now when I try to query the above table I am getting below error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;%sql
select * from test.default.sampletbl limit 2&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;org.apache.spark.SparkException: [INTERNAL_ERROR] Cannot generate code for expression: test.default.decrypt_colA (input[11, string, true], secret_value)
	at org.apache.spark.SparkException$.internalError(SparkException.scala:85)
	at org.apache.spark.SparkException$.internalError(SparkException.scala:89)
	at org.apache.spark.sql.errors.QueryExecutionErrors$.cannotGenerateCodeForExpressionError(QueryExecutionErrors.scala:77)
	at org.apache.spark.sql.catalyst.expressions.Unevaluable.doGenCode(Expression.scala:503)
	at org.apache.spark.sql.catalyst.expressions.Unevaluable.doGenCode$(Expression.scala:502)
	at com.databricks.sql.analyzer.ExternalUDFExpression.doGenCode(ExternalUDFExpression.scala:37)
	at org.apache.spark.sql.catalyst.expressions.Expression.genCodeInternal(Expression.scala:249)
	at org.apache.spark.sql.catalyst.expressions.Expression.$anonfun$genCode$2(Expression.scala:225)
	at scala.Option.getOrElse(Option.scala:189)
	at org.apache.spark.sql.catalyst.expressions.Expression.genCode(Expression.scala:225)
	at org.apache.spark.sql.catalyst.expressions.Alias.genCodeInternal(namedExpressions.scala:170)
	at com.databricks.sql.expressions.codegen.EdgeExpressionCodegen$.$anonfun$genCodeWithFallback$2(EdgeExpressionCodegen.scala:269)
	at scala.Option.getOrElse(Option.scala:189)
	at com.databricks.sql.expressions.codegen.EdgeExpressionCodegen$.$anonfun$genCodeWithFallback$1(EdgeExpressionCodegen.scala:269)
	at scala.Option.getOrElse(Option.scala:189)
	at com.databricks.sql.expressions.codegen.EdgeExpressionCodegen$.genCodeWithFallback(EdgeExpressionCodegen.scala:267)
	at org.apache.spark.sql.catalyst.expressions.codegen.CodegenContext.generateExpression(CodeGenerator.scala:1450)
	at org.apache.spark.sql.catalyst.expressions.codegen.CodegenContext.$anonfun$generateExpressionsForWholeStageWithCSE$2(CodeGenerator.scala:1531)
	at scala.collection.immutable.List.map(List.scala:297)
	at org.apache.spark.sql.catalyst.expressions.codegen.CodegenContext.$anonfun$generateExpressionsForWholeStageWithCSE$1(CodeGenerator.scala:1529)
	at org.apache.spark.sql.catalyst.expressions.codegen.CodegenContext.withSubExprEliminationExprs(CodeGenerator.scala:1183)
	at org.apache.spark.sql.catalyst.expressions.codegen.CodegenContext.generateExpressionsForWholeStageWithCSE(CodeGenerator.scala:1529)
	at org.apache.spark.sql.execution.ProjectExec.doConsume(basicPhysicalOperators.scala:76)
	at org.apache.spark.sql.execution.CodegenSupport.consume(WholeStageCodegenExec.scala:199)
	at org.apache.spark.sql.execution.CodegenSupport.consume$(WholeStageCodegenExec.scala:154)
	at org.apache.spark.sql.execution.ColumnarToRowExec.consume(Columnar.scala:78)
	at org.apache.spark.sql.execution.ColumnarToRowExec.doProduce(Columnar.scala:218)
	at org.apache.spark.sql.execution.CodegenSupport.$anonfun$produce$1(WholeStageCodegenExec.scala:99)
	at org.apache.spark.sql.execution.SparkPlan$.org$apache$spark$sql$execution$SparkPlan$$withExecuteQueryLogging(SparkPlan.scala:107)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea on how to resolve this issue ?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 09:07:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/internal-error-cannot-generate-code-for-expression-claimsconifer/m-p/48933#M28425</guid>
      <dc:creator>nikhilkumawat</dc:creator>
      <dc:date>2023-10-11T09:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: [INTERNAL_ERROR] Cannot generate code for expression: claimsconifer.default.decrypt_colA(</title>
      <link>https://community.databricks.com/t5/data-engineering/internal-error-cannot-generate-code-for-expression-claimsconifer/m-p/49344#M28528</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/9"&gt;@Retired_mod&lt;/a&gt;&amp;nbsp;I tried to create same function that you described . It is giving the error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nikhil1991_0-1697522742982.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/4467i15E2648BC0D6EEF0/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="nikhil1991_0-1697522742982.png" alt="nikhil1991_0-1697522742982.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 06:06:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/internal-error-cannot-generate-code-for-expression-claimsconifer/m-p/49344#M28528</guid>
      <dc:creator>nikhilkumawat</dc:creator>
      <dc:date>2023-10-17T06:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: [INTERNAL_ERROR] Cannot generate code for expression: claimsconifer.default.decrypt_colA(</title>
      <link>https://community.databricks.com/t5/data-engineering/internal-error-cannot-generate-code-for-expression-claimsconifer/m-p/49369#M28536</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/9"&gt;@Retired_mod&lt;/a&gt;&amp;nbsp;After removing "TABLE" keyword from create or replace statement this function got registered as builtin function. Just to verify that I displayed all the functions and I can see that function--&amp;gt; &lt;STRONG&gt;decrypt_if_valid_user&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nikhil1991_0-1697541657408.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/4471iE7899FFCFF970D08/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="nikhil1991_0-1697541657408.png" alt="nikhil1991_0-1697541657408.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now I am trying to alter the table using below command and it is giving below error:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;%sql
ALTER TABLE test.default.sampletbl ALTER COLUMN col_a SET MASK decrypt_if_valid_user&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nikhil1991_1-1697541801866.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/4472i467A69E0742B6565/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="nikhil1991_1-1697541801866.png" alt="nikhil1991_1-1697541801866.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Although I can see this function in the list but still it is not able recognize that function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 11:24:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/internal-error-cannot-generate-code-for-expression-claimsconifer/m-p/49369#M28536</guid>
      <dc:creator>nikhilkumawat</dc:creator>
      <dc:date>2023-10-17T11:24:59Z</dc:date>
    </item>
  </channel>
</rss>

