hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Robertson <timrobertson...@gmail.com>
Subject Re: Only a single expression in the SELECT clause is supported with UDTF's
Date Mon, 08 Nov 2010 13:53:27 GMT
Thank you once again Sonal.

The following worked just nicely:
  select k,p from temp_kingdom_phylum lateral view
taxonDensityUDTF(kingdom_concept_id, phylum_concept_id) e as k,p;

[For anyone stumbling across this thread: I also had to change the
close() and issue the forward() in the process andnot in the close()
which is against the example shipped with hive, but in accord with the
docs which say one must not do this]

Cheers,
Tim



On Mon, Nov 8, 2010 at 2:18 PM, Sonal Goyal <sonalgoyal4@gmail.com> wrote:
> Hi Tim,
>
> I guess you are running into limitations while using UDTFs. Check
> http://wiki.apache.org/hadoop/Hive/LanguageManual/UDF#UDTF. I think you
> should be able to use lateral view in your query.
>
> Thanks and Regards,
> Sonal
>
> Sonal Goyal | Founder and CEO | Nube Technologies LLP
> http://www.nubetech.co
> http://code.google.com/p/hiho/
>
>
>
>
>
>
> On Mon, Nov 8, 2010 at 2:11 PM, Tim Robertson <timrobertson100@gmail.com>
> wrote:
>>
>> Hi all,
>>
>> I am trying my first UDTF, but can't seem to get it to run.  Can
>> anyone spot anything wrong with this please:
>>
>> hive> select taxonDensityUDTF(kingdom_concept_id, phylum_concept_id)
>> as p,k from temp_kingdom_phylum;
>> FAILED: Error in semantic analysis: Only a single expression in the
>> SELECT clause is supported with UDTF's
>> hive>
>>
>> Below is my code.  Thanks for any pointers,
>>
>> Tim
>>
>>
>>
>> @description(
>>                  name = "taxonDensityUDTF",
>>                  value = "_FUNC_(kingdom_concept_id, phylum_concept_id)"
>>                )
>> public class TaxonDensityUDTF extends GenericUDTF {
>>        Integer kingdom_concept_id = Integer.valueOf(0);
>>        Integer phylum_concept_id = Integer.valueOf(0);
>>
>>        /**
>>         * @see org.apache.hadoop.hive.ql.udf.generic.GenericUDTF#close()
>>         */
>>        @Override
>>        public void close() throws HiveException {
>>                Object[] forwardObj = new Object[2];
>>                forwardObj[0] = kingdom_concept_id;
>>                forwardObj[1] = phylum_concept_id;
>>                forward(forwardObj);
>>                // TEST STUFF FOR NOW
>>                forwardObj = new Object[2];
>>                forwardObj[0] = kingdom_concept_id+1;
>>                forwardObj[1] = phylum_concept_id+1;
>>                forward(forwardObj);
>>        }
>>
>>        /**
>>         * @see
>> org.apache.hadoop.hive.ql.udf.generic.GenericUDTF#initialize(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector[])
>>         */
>>        @Override
>>        public StructObjectInspector initialize(ObjectInspector[] arg0)
>> throws UDFArgumentException {
>>                ArrayList<String> fieldNames = new ArrayList<String>();
>>                ArrayList<ObjectInspector> fieldOIs = new
>> ArrayList<ObjectInspector>();
>>                fieldNames.add("kingdom_concept_id");
>>                fieldNames.add("phylum_concept_id");
>>
>>  fieldOIs.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
>>
>>  fieldOIs.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
>>                return
>> ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames,fieldOIs);
>>        }
>>
>>        /**
>>         * @see
>> org.apache.hadoop.hive.ql.udf.generic.GenericUDTF#process(java.lang.Object[])
>>         */
>>        @Override
>>        public void process(Object[] args) throws HiveException {
>>                kingdom_concept_id = (Integer) args[0];
>>                phylum_concept_id = (Integer) args[1];
>>        }
>> }
>
>

Mime
View raw message