Return-Path: X-Original-To: apmail-hive-user-archive@www.apache.org Delivered-To: apmail-hive-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AB83B105B2 for ; Mon, 30 Sep 2013 20:56:44 +0000 (UTC) Received: (qmail 2629 invoked by uid 500); 30 Sep 2013 20:56:41 -0000 Delivered-To: apmail-hive-user-archive@hive.apache.org Received: (qmail 2570 invoked by uid 500); 30 Sep 2013 20:56:41 -0000 Mailing-List: contact user-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hive.apache.org Delivered-To: mailing list user@hive.apache.org Received: (qmail 2559 invoked by uid 99); 30 Sep 2013 20:56:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Sep 2013 20:56:40 +0000 X-ASF-Spam-Status: No, hits=2.4 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of timrobertson100@gmail.com designates 209.85.192.171 as permitted sender) Received: from [209.85.192.171] (HELO mail-pd0-f171.google.com) (209.85.192.171) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Sep 2013 20:56:33 +0000 Received: by mail-pd0-f171.google.com with SMTP id g10so6171584pdj.16 for ; Mon, 30 Sep 2013 13:56:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=YEURUke0e8nHI6V57LjpHUeOgPFFXXZUd9bndc2VwD4=; b=mRbn1RykfGkEllPRtMMRG/+2YZFEo1wIEWUFue0nEMGVzzbyUyQQ9pPpEA5RaJIPUn qGkhpTEftMjPPYhQfUjlU9gSyPYd88W3KBi2iSrV84cl8+kLytlmcoWALyUnJu0Z5VIL Eyv3LJ6LYgOxAwhbkaTS5d/vKU6I2/wrtao1iKAdWDGTUwltk4nFjbofpuETBpMxqkU/ tVFAlCk2IOhBtnXzY0BeQjbKNCyb6nKFDB6ad5ALQQt2xMX2ovRdyteTWBK63kaFRbi2 5HYT0QIXF0dzcKHP0dOTRKe+EKl6VIVEia9ad9MUCwpuyWnR/dhQ9k384ayxqz+39KeM sBJQ== MIME-Version: 1.0 X-Received: by 10.66.165.106 with SMTP id yx10mr4806871pab.159.1380574572096; Mon, 30 Sep 2013 13:56:12 -0700 (PDT) Received: by 10.68.148.4 with HTTP; Mon, 30 Sep 2013 13:56:12 -0700 (PDT) In-Reply-To: References: Date: Mon, 30 Sep 2013 22:56:12 +0200 Message-ID: Subject: Re: UDF error? From: Tim Robertson To: user@hive.apache.org Content-Type: multipart/alternative; boundary=047d7b86c342f4b49204e7a01041 X-Virus-Checked: Checked by ClamAV on apache.org --047d7b86c342f4b49204e7a01041 Content-Type: text/plain; charset=ISO-8859-1 That class is: https://code.google.com/p/gbif-occurrencestore/source/browse/trunk/occurrence-store/src/main/java/org/gbif/occurrencestore/hive/udf/UDFRowSequence.java Cheers, Tim On Mon, Sep 30, 2013 at 10:55 PM, Tim Robertson wrote: > It's been ages since I wrote one, but the differences to mine: > > a) I use LongWritable: public LongWritable evaluate(LongWritable startAt) > { > b) I have annotations on the class (but I think they are just for docs) > @Description(name = "row_sequence", > value = "_FUNC_() - Returns a generated row sequence number starting > from 1") > @UDFType(deterministic = false) > public class UDFRowSequence extends UDF { > > Hope this helps! > Tim > > > > On Mon, Sep 30, 2013 at 10:47 PM, Yang wrote: > >> I wrote a super simple UDF, but got some errors: >> >> UDF: >> >> package yy; >> import org.apache.hadoop.hive.ql.exec.UDF; >> import java.util.Random; >> import java.util.UUID; >> import java.lang.management.*; >> >> public class MyUdf extends UDF { >> static Random rand = new Random(System.currentTimeMillis() + >> Thread.currentThread().getId()* 1000000); >> String name = ManagementFactory.getRuntimeMXBean().getName(); >> long startValue = Long.valueOf(name.replaceAll("[^\\d]+", "")) * >> 10000 + Thread.currentThread().getId() * 1000; >> public long evaluate(long x ) { >> //return (long)UUID.randomUUID().hashCode(); >> //return rand.nextLong(); >> return startValue++; >> } >> } >> >> >> >> >> >> sql script: >> >> CREATE TEMPORARY FUNCTION gen_uniq2 AS 'yy.MyUdf'; >> select gen_uniq2(field1), field2 >> from yy_mapping limit 10; >> >> field1 is bigint, field2 is int >> >> >> >> >> >> error: >> >> hive> source aa.sql; >> Added ./MyUdf.jar to class path >> Added resource: ./MyUdf.jar >> OK >> Time taken: 0.0070 seconds >> FAILED: SemanticException [Error 10014]: Line 2:7 Wrong arguments >> 'field1': No matching method for class yy.MyUdf with (bigint). Possible >> choices: _FUNC_() >> >> >> >> >> >> so I'm declaring a UDF with arg of long, so that should work for a bigint >> (more importantly it's complaining not long vs bigint, but bigint vs void >> ). I tried changing both to int, same failure >> >> >> thanks! >> yang >> >> >> > --047d7b86c342f4b49204e7a01041 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On Mon, Sep 30, 2013 at 10:55 PM, T= im Robertson <timrobertson100@gmail.com> wrote:
It's been ages since I = wrote one, but the differences to mine:

a) I use LongWri= table: =A0public LongWritable evaluate(LongWritable startAt) {
b) I have annotations on the class (but I think they are just for docs= )
@Description(name =3D "row_sequence",
=A0 val= ue =3D "_FUNC_() - Returns a generated row sequence number starting fr= om 1")
@UDFType(deterministic =3D false)
public cl= ass UDFRowSequence extends UDF {

Hope this helps!
Tim



On Mon, Sep 30, 2013 at 10:47 PM, Yang <teddyyyy123@gmail.com><= /span> wrote:
I wrote a super simple UDF,= but got some errors:

UDF:

package yy;
import org.apache.hadoop.hive.ql.exec.UDF;
import java.util.= Random;
import java.util.UUID;
import java.lang.management.*;
<= div>
public class MyUdf extends UDF {
=A0 =A0 =A0 = =A0 static Random rand =3D new Random(System.currentTimeMillis() + Thread.c= urrentThread().getId()* 1000000);
=A0 =A0 =A0 =A0 String name =3D ManagementFactory.getRuntimeMXBean().g= etName();
=A0 =A0 =A0 =A0 long startValue =3D Long.valueOf(name.r= eplaceAll("[^\\d]+", "")) * 10000 + Thread.currentThrea= d().getId() * 1000;
=A0 =A0 =A0 =A0 public long evaluate(long x ) {
=A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 //return (long)UUID.randomUUID().hashCode();
= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 //return rand.nextLong();
=A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 return startValue++;
=A0 =A0 =A0 =A0 }
}





sql script:

CREATE TEMPORARY FUNCTION gen_uniq2 AS 'yy.MyUdf';
select gen_uniq2(field1), field2
from yy_mapping limit 10;
<= /div>

field1 is bigint, field2 is int





error:

hive> source aa.sql;
Added ./MyUdf.ja= r to class path
Added resource: ./MyUdf.jar
OK
Time taken: 0.0070 seconds
FAILED: SemanticException [Error 100= 14]: Line 2:7 Wrong arguments 'field1': No matching method for clas= s yy.MyUdf with (bigint). Possible choices: _FUNC_()





=
so I'm declaring a UDF with arg of long, so that should work= for a bigint (more importantly it's complaining not long vs bigint, bu= t bigint vs void ). I tried changing both to int, same failure


thanks!
yang




--047d7b86c342f4b49204e7a01041--