Member since
12-22-2016
9
Posts
0
Kudos Received
0
Solutions
09-04-2017
03:14 AM
Hi All, In UDF executing the context->SetError(const char* error_msg) method impala again retries the UDF. Below is my UDF:- IntVal my_udf( FunctionContext* context, IntVal& sInput ) { if( sInput.val == 0 ) { context->SetError( "Off Value" ); return 0; } IntVal iResult(sInput.val + 1); return iResult; } DDL :-- CREATE FUNCTION my_udf(INTEGER) RETURNS INTEGER LOCATION '/opt/impala/udfs/myudf.so' SYMBOL = 'my_udf'; So if we debug this UDF using GDB. If we add the break point at "context->SetError( "Off Value" );" this line then we come to know that if we pass 0 to this UDF this will hit the break point more than one time. So please let me know that it is right behavior? i ran this UDF in CDH 5.10 & CDH 5.11.
... View more
Labels:
- Labels:
-
Apache Impala
12-30-2016
04:42 AM
Thanks Tim, It was really helpful.
... View more
12-23-2016
01:20 AM
While fetching NULL record StringVal's "ptr" pointer behaves to be a dangling pointer Create a table employee, with 1 column: Name String. Inserted few records. Below is the details: [quickstart.cloudera:21000] > desc employee; Query: describe employee +------+--------+---------+ | name | type | comment | +------+--------+---------+ | name | string | | +------+--------+---------+ Fetched 1 row(s) in 0.03s [quickstart.cloudera:21000] > select * from employee order by name asc; Query: select * from employee order by name asc +--------+ | name | +--------+ | | | Dan | | Jack | | Jan | | Magnus | | Sam | | NULL | | NULL | | NULL | +--------+ Fetched 9 row(s) in 0.69s [quickstart.cloudera:21000] > Created a custom UDF stringnull. It would accept StringVal as input and return StringVal as output. There is a check for NULL constraint based on StringVal's is_null property and pointer ptr. If is_null is true and ptr is NULL, the UDF would return NULL else the valid string. UDF Definition: ------------------------------------------------------------------------------------------------------------------ #defineMAX_STRING_SIZE 256 StringVal stringnull( FunctionContext* context, StringVal& sInput ) { char* pbReturnData =(char *) context->Allocate( MAX_STRING_SIZE ); memset( pbReturnData, NULL, MAX_STRING_SIZE ); if( NULL == sInput.ptr && sInput.is_null == 1 ) { StringVal sResult( ( const char* )pbReturnData ); sResult.is_null = 1; context->Free( (char *)pbReturnData ); sResult.len = sInput.len; return sResult; } else { StringVal sResult( ( const char* )pbReturnData ); P_strncpy( ( char*)pbReturnData, MAX_STRING_SIZE, ( const char* )sInput.ptr, sInput.len); sResult.is_null = 0; context->Free( (char *)pbReturnData ); sResult.len = sInput.len; return sResult; } } DDL for custom UDF:- CREATE FUNCTION stringnull(STRING) RETURNS STRING LOCATION '/opt/test.so' SYMBOL = 'stringnull'; --------------------------------------------------------------------------------------------------------------------------- Record returned when select is called with custom UDF: [quickstart.cloudera:21000] > select stringnull(name) from employee order by name asc; Query: select stringnull(name) from employee order by name asc +--------------------------+ | default.stringnull(name) | +--------------------------+ | | | Dan | | Jack | | Jan | | Magnus | | Sam | | Sam | ## It should have been NULL, but to contradict it displays NULL as Sam. | Sam | ## It should have been NULL, but to contradict it displays NULL as Sam. | Sam | ## It should have been NULL, but to contradict it displays NULL as Sam. +--------------------------+ Fetched 9 row(s) in 0.53s
... View more
Labels:
- Labels:
-
Apache Impala