[ 
https://issues.apache.org/jira/browse/HIVE-25338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17384268#comment-17384268
 ] 

Stamatis Zampetakis commented on HIVE-25338:
--------------------------------------------

[~nareshpr] After having a second look in the PR I kind of change my mind. The 
CONV function is mostly known from MySQL and I think the implementation so far 
tends to stay as close to the MySQL version as possible.

I did a quick test in MySQL (version 8.0) and it returns the following results:

{noformat}
mysql> SELECT CONV('',10,2);
+---------------+
| CONV('',10,2) |
+---------------+
| NULL          |
+---------------+
mysql> SELECT CONV('4?:+',10,2);
+-------------------+
| CONV('4?:+',10,2) |
+-------------------+
| 100               |
+-------------------+
mysql> SELECT CONV('1?:+0',10,2);
+--------------------+
| CONV('1?:+0',10,2) |
+--------------------+
| 1                  |
+--------------------+
mysql> SELECT CONV('*10?:+2',10,2);
+----------------------+
| CONV('*10?:+2',10,2) |
+----------------------+
| 0                    |
+----------------------+
1 row in set, 1 warning (0.00 sec)

Warning (Code 1292): Truncated incorrect DECIMAL value: '*10?:+2'
{noformat}
So for empty string it returns NULL and for invalid literals it tries to kind 
of parse the literal till it finds an illegal character.

Based on the above I would suggest to return NULL for empty string as you had 
it initially. Sorry for the back and forth.



> AIOBE in conv UDF if input is empty
> -----------------------------------
>
>                 Key: HIVE-25338
>                 URL: https://issues.apache.org/jira/browse/HIVE-25338
>             Project: Hive
>          Issue Type: Bug
>            Reporter: Naresh P R
>            Assignee: Naresh P R
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Repro
> {code:java}
> create table test (a string);
> insert into test values ("");
> select conv(a,16,10) from test;{code}
> Exception trace:
> {code:java}
> Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
>  at org.apache.hadoop.hive.ql.udf.UDFConv.evaluate(UDFConv.java:160){code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to