You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by Ablimit Aji <ab...@gmail.com> on 2012/07/25 22:52:25 UTC

Custom UDF can not handle constant string parameter

Hi,

I wrote several UDF to handle a string typed column. However, when I feed a
constant value to the UDF, it's not recognizing it.
What went wrong ? How can I fix it ?

Example SQL: SELECT MBB("Polygon ((0 1, 1 1, 0 1, 0 0))") FROM myTable
limit 5;

MBB(Text) returns Text value

However the error I get is like this:

FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments '"Polygon
((0 1, 1 1, 0 1, 0 0))"': org.apache.hadoop.hive.ql.metadata.HiveException:
Unable to execute method public org.apache.hadoop.io.Text
edu.emory.cci.hive.udf.UDFMBB.evaluate(org.apache.hadoop.io.Text)  on
object edu.emory.cci.hive.udf.UDFMBB@213e2b4a of class
edu.emory.cci.hive.udf.UDFMBB with arguments {Polygon ((0 1, 1 1, 0 1, 0
0)):org.apache.hadoop.io.Text} of size 1

Re: Custom UDF can not handle constant string parameter

Posted by Edward Capriolo <ed...@gmail.com>.
Compare your code to the ascii udf and then make your code more ascii like :)

On Wed, Jul 25, 2012 at 5:14 PM, Ablimit Aji <ab...@gmail.com> wrote:
> Thanks Edward.
>
> However the following statement works without any problem, and my UDF is no
> different from ascii UDF.
>
> SELECT ascii("A") FROM markup LIMIT 5;
>
> How can I write the correct UDF to achieve original simplicity ?
>
>
>
> On Wed, Jul 25, 2012 at 5:02 PM, Edward Capriolo <ed...@gmail.com>wrote:
>
>> It depends on how you wrote the UDF. One trick you can do trick hive
>> into thinking it is non-constant: select a column of 0 length and then
>> concat it.
>>
>> SELECT concat(substring(colx),0,0), myUDF("constant string") ) from....
>>
>> Now its not constant!
>>
>> On Wed, Jul 25, 2012 at 4:52 PM, Ablimit Aji <ab...@gmail.com> wrote:
>> > Hi,
>> >
>> > I wrote several UDF to handle a string typed column. However, when I
>> feed a
>> > constant value to the UDF, it's not recognizing it.
>> > What went wrong ? How can I fix it ?
>> >
>> > Example SQL: SELECT MBB("Polygon ((0 1, 1 1, 0 1, 0 0))") FROM myTable
>> > limit 5;
>> >
>> > MBB(Text) returns Text value
>> >
>> > However the error I get is like this:
>> >
>> > FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments
>> '"Polygon
>> > ((0 1, 1 1, 0 1, 0 0))"':
>> org.apache.hadoop.hive.ql.metadata.HiveException:
>> > Unable to execute method public org.apache.hadoop.io.Text
>> > edu.emory.cci.hive.udf.UDFMBB.evaluate(org.apache.hadoop.io.Text)  on
>> > object edu.emory.cci.hive.udf.UDFMBB@213e2b4a of class
>> > edu.emory.cci.hive.udf.UDFMBB with arguments {Polygon ((0 1, 1 1, 0 1, 0
>> > 0)):org.apache.hadoop.io.Text} of size 1
>>

Re: Custom UDF can not handle constant string parameter

Posted by Ablimit Aji <ab...@gmail.com>.
Thanks Edward.

However the following statement works without any problem, and my UDF is no
different from ascii UDF.

SELECT ascii("A") FROM markup LIMIT 5;

How can I write the correct UDF to achieve original simplicity ?



On Wed, Jul 25, 2012 at 5:02 PM, Edward Capriolo <ed...@gmail.com>wrote:

> It depends on how you wrote the UDF. One trick you can do trick hive
> into thinking it is non-constant: select a column of 0 length and then
> concat it.
>
> SELECT concat(substring(colx),0,0), myUDF("constant string") ) from....
>
> Now its not constant!
>
> On Wed, Jul 25, 2012 at 4:52 PM, Ablimit Aji <ab...@gmail.com> wrote:
> > Hi,
> >
> > I wrote several UDF to handle a string typed column. However, when I
> feed a
> > constant value to the UDF, it's not recognizing it.
> > What went wrong ? How can I fix it ?
> >
> > Example SQL: SELECT MBB("Polygon ((0 1, 1 1, 0 1, 0 0))") FROM myTable
> > limit 5;
> >
> > MBB(Text) returns Text value
> >
> > However the error I get is like this:
> >
> > FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments
> '"Polygon
> > ((0 1, 1 1, 0 1, 0 0))"':
> org.apache.hadoop.hive.ql.metadata.HiveException:
> > Unable to execute method public org.apache.hadoop.io.Text
> > edu.emory.cci.hive.udf.UDFMBB.evaluate(org.apache.hadoop.io.Text)  on
> > object edu.emory.cci.hive.udf.UDFMBB@213e2b4a of class
> > edu.emory.cci.hive.udf.UDFMBB with arguments {Polygon ((0 1, 1 1, 0 1, 0
> > 0)):org.apache.hadoop.io.Text} of size 1
>

Re: Custom UDF can not handle constant string parameter

Posted by Edward Capriolo <ed...@gmail.com>.
It depends on how you wrote the UDF. One trick you can do trick hive
into thinking it is non-constant: select a column of 0 length and then
concat it.

SELECT concat(substring(colx),0,0), myUDF("constant string") ) from....

Now its not constant!

On Wed, Jul 25, 2012 at 4:52 PM, Ablimit Aji <ab...@gmail.com> wrote:
> Hi,
>
> I wrote several UDF to handle a string typed column. However, when I feed a
> constant value to the UDF, it's not recognizing it.
> What went wrong ? How can I fix it ?
>
> Example SQL: SELECT MBB("Polygon ((0 1, 1 1, 0 1, 0 0))") FROM myTable
> limit 5;
>
> MBB(Text) returns Text value
>
> However the error I get is like this:
>
> FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments '"Polygon
> ((0 1, 1 1, 0 1, 0 0))"': org.apache.hadoop.hive.ql.metadata.HiveException:
> Unable to execute method public org.apache.hadoop.io.Text
> edu.emory.cci.hive.udf.UDFMBB.evaluate(org.apache.hadoop.io.Text)  on
> object edu.emory.cci.hive.udf.UDFMBB@213e2b4a of class
> edu.emory.cci.hive.udf.UDFMBB with arguments {Polygon ((0 1, 1 1, 0 1, 0
> 0)):org.apache.hadoop.io.Text} of size 1