<?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>question Re: In Impala UDF -  While fetching NULL record StringVal’s “ptr” pointer behaves to be a dangling p in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/In-Impala-UDF-While-fetching-NULL-record-StringVal-s-ptr/m-p/48923#M49942</link>
    <description>&lt;P&gt;Thanks Tim, It was really helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Dec 2016 12:42:35 GMT</pubDate>
    <dc:creator>RPAT</dc:creator>
    <dc:date>2016-12-30T12:42:35Z</dc:date>
    <item>
      <title>In Impala UDF -  While fetching NULL record StringVal’s “ptr” pointer behaves to be a dangling point</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/In-Impala-UDF-While-fetching-NULL-record-StringVal-s-ptr/m-p/48771#M49940</link>
      <description>&lt;P&gt;While fetching NULL record StringVal's "ptr" pointer behaves to be a dangling pointer&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Create a table employee, with 1 column: Name String.&lt;BR /&gt;Inserted few records. Below is the details:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;[quickstart.cloudera:21000] &amp;gt; desc employee;&lt;BR /&gt;Query: describe employee&lt;BR /&gt;+------+--------+---------+&lt;BR /&gt;| name | type | comment |&lt;BR /&gt;+------+--------+---------+&lt;BR /&gt;| name | string | |&lt;BR /&gt;+------+--------+---------+&lt;BR /&gt;Fetched 1 row(s) in 0.03s&lt;BR /&gt;[quickstart.cloudera:21000] &amp;gt; select * from employee order by name asc;&lt;BR /&gt;Query: select * from employee order by name asc&lt;BR /&gt;+--------+&lt;BR /&gt;| name |&lt;BR /&gt;+--------+&lt;BR /&gt;| |&lt;BR /&gt;| Dan |&lt;BR /&gt;| Jack |&lt;BR /&gt;| Jan |&lt;BR /&gt;| Magnus |&lt;BR /&gt;| Sam |&lt;BR /&gt;| NULL |&lt;BR /&gt;| NULL |&lt;BR /&gt;| NULL |&lt;BR /&gt;+--------+&lt;BR /&gt;Fetched 9 row(s) in 0.69s&lt;BR /&gt;[quickstart.cloudera:21000] &amp;gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Created a custom UDF stringnull. It would accept StringVal as input and return StringVal as output.&lt;BR /&gt;There is a check for NULL constraint based on StringVal's is_null property and pointer ptr.&lt;BR /&gt;If is_null is true and ptr is NULL, the UDF would return NULL else the valid string.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;UDF Definition:&lt;BR /&gt;------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;#define&lt;SPAN&gt;MAX_STRING_SIZE &amp;nbsp;256&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;StringVal stringnull(&lt;BR /&gt;FunctionContext* context,&lt;BR /&gt;StringVal&amp;amp; sInput&lt;BR /&gt;)&lt;BR /&gt;{&lt;BR /&gt;char* pbReturnData =(char *) context-&amp;gt;Allocate( MAX_STRING_SIZE );&lt;BR /&gt;memset( pbReturnData, NULL, MAX_STRING_SIZE );&lt;/P&gt;&lt;P&gt;if( NULL == sInput.ptr &amp;amp;&amp;amp; sInput.is_null == 1 )&lt;BR /&gt;{&lt;BR /&gt;StringVal sResult( ( const char* )pbReturnData );&lt;BR /&gt;sResult.is_null = 1;&lt;BR /&gt;context-&amp;gt;Free( (char *)pbReturnData );&lt;BR /&gt;sResult.len = sInput.len;&lt;BR /&gt;return sResult;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;StringVal sResult( ( const char* )pbReturnData );&lt;BR /&gt;P_strncpy( ( char*)pbReturnData, MAX_STRING_SIZE, ( const char* )sInput.ptr, sInput.len);&lt;BR /&gt;sResult.is_null = 0;&lt;BR /&gt;context-&amp;gt;Free( (char *)pbReturnData );&lt;BR /&gt;sResult.len = sInput.len;&lt;BR /&gt;return sResult;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DDL for custom UDF:-&lt;BR /&gt;CREATE FUNCTION stringnull(STRING) RETURNS STRING LOCATION '/opt/test.so' SYMBOL = 'stringnull';&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Record returned when select is called with custom UDF:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[quickstart.cloudera:21000] &amp;gt; select stringnull(name) from employee order by name asc;&lt;BR /&gt;Query: select stringnull(name) from employee order by name asc&lt;BR /&gt;+--------------------------+&lt;BR /&gt;| default.stringnull(name) |&lt;BR /&gt;+--------------------------+&lt;BR /&gt;| |&lt;BR /&gt;| Dan |&lt;BR /&gt;| Jack |&lt;BR /&gt;| Jan |&lt;BR /&gt;| Magnus |&lt;BR /&gt;| Sam |&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;| Sam | ## It should have been NULL, but to contradict it displays NULL as Sam.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;| Sam | ## It should have been NULL, but to contradict it displays NULL as Sam.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;| Sam | ## It should have been NULL, but to contradict it displays NULL as Sam.&lt;/FONT&gt;&lt;BR /&gt;+--------------------------+&lt;BR /&gt;Fetched 9 row(s) in 0.53s&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 10:52:07 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/In-Impala-UDF-While-fetching-NULL-record-StringVal-s-ptr/m-p/48771#M49940</guid>
      <dc:creator>RPAT</dc:creator>
      <dc:date>2022-09-16T10:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: In Impala UDF -  While fetching NULL record StringVal’s “ptr” pointer behaves to be a dangling p</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/In-Impala-UDF-While-fetching-NULL-record-StringVal-s-ptr/m-p/48777#M49941</link>
      <description>&lt;P&gt;Hi RPAT,&lt;/P&gt;&lt;P&gt;&amp;nbsp; The values of .ptr and .len are invalid if .is_null is true. For a null string value, in some cases Impala just sets the is_null field in this case and doesn't overwrite the ptr and len fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should rewrite the condition as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  if (sInput.is_null) {&lt;BR /&gt;    ...
  } else {
    ...
  }&lt;/PRE&gt;&lt;P&gt;This isn't explicitly documented so we should improve that: &lt;A href="https://issues.cloudera.org/browse/IMPALA-4711" target="_blank"&gt;https://issues.cloudera.org/browse/IMPALA-4711&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 14:42:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/In-Impala-UDF-While-fetching-NULL-record-StringVal-s-ptr/m-p/48777#M49941</guid>
      <dc:creator>Tim Armstrong</dc:creator>
      <dc:date>2016-12-23T14:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: In Impala UDF -  While fetching NULL record StringVal’s “ptr” pointer behaves to be a dangling p</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/In-Impala-UDF-While-fetching-NULL-record-StringVal-s-ptr/m-p/48923#M49942</link>
      <description>&lt;P&gt;Thanks Tim, It was really helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2016 12:42:35 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/In-Impala-UDF-While-fetching-NULL-record-StringVal-s-ptr/m-p/48923#M49942</guid>
      <dc:creator>RPAT</dc:creator>
      <dc:date>2016-12-30T12:42:35Z</dc:date>
    </item>
  </channel>
</rss>

