IMPALA-4266: Java udf returning string can give incorrect results

The memory management of string results was wrong: strings returned from
Exprs must live until the next time FreeLocalAllocations() is called.
Otherwise the buffer holding the string is freed or reused by the next
UDF call. The fix is to copy string values into a buffer with the
right lifetime.

Testing:
Added a regression test based on Bharath's example that reproduced the
bug reliably.

Change-Id: I705d271814cb1143f67d8a12f4fd87bab7a8e161
Reviewed-on: http://gerrit.cloudera.org:8080/4941
Reviewed-by: Tim Armstrong <tarmstrong@cloudera.com>
Tested-by: Internal Jenkins
This commit is contained in:
Tim Armstrong
2016-11-03 17:36:42 -07:00
committed by Internal Jenkins
parent 10fa472fa6
commit 381e719065
4 changed files with 70 additions and 1 deletions

View File

@@ -29,6 +29,8 @@ drop function if exists udf_test.throws_exception();
drop function if exists java_udfs_test.identity;
drop function if exists udf_test.replace_string(string);
create function udf_test.hive_pi() returns double
location '$FILESYSTEM_PREFIX/test-warehouse/hive-exec.jar'
symbol='org.apache.hadoop.hive.ql.udf.UDFPI';
@@ -121,4 +123,8 @@ symbol='org.apache.impala.TestUdf';
create function udf_test.throws_exception() returns boolean
location '$FILESYSTEM_PREFIX/test-warehouse/impala-hive-udfs.jar'
symbol='org.apache.impala.TestUdfException';
create function udf_test.replace_string(string) returns string
location '$FILESYSTEM_PREFIX/test-warehouse/impala-hive-udfs.jar'
symbol='org.apache.impala.ReplaceStringUdf';
====