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 6B37BC17E for ; Tue, 7 Aug 2012 01:40:38 +0000 (UTC) Received: (qmail 74648 invoked by uid 500); 7 Aug 2012 01:40:36 -0000 Delivered-To: apmail-hive-user-archive@hive.apache.org Received: (qmail 74264 invoked by uid 500); 7 Aug 2012 01:40:36 -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 74248 invoked by uid 99); 7 Aug 2012 01:40:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Aug 2012 01:40:36 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jamalraihan@gmail.com designates 209.85.220.176 as permitted sender) Received: from [209.85.220.176] (HELO mail-vc0-f176.google.com) (209.85.220.176) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Aug 2012 01:40:29 +0000 Received: by vcbfl11 with SMTP id fl11so4307245vcb.35 for ; Mon, 06 Aug 2012 18:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=/TcSIY64e/MOuY5cjd1sihRWNv+mxVb8YHRnC3o4HQc=; b=vTP/9guKihvMtKz606Gy3MKUM9fLxRfnp6ng6e1FvGK9/kce2f6Me8kPyqa2Kz9SLi kw4p9P47dhwv6wIyRA1AQs9Gnf9Nv31f+ckWJ/XSlUvUMABFxFbh3cQIkrv0YxSwJs7g rIZ8HiusdGKgkgjDxC+PbCdHqNRFL7ve5T1QD66U76HkwcUpGJejhKNxdirjJYICKCcR hTWS3hTiBn7YC7zwHKTNY03EVYuqLwnU91ojO/Abo9Q0O3YQmnHOMJQIrBi6LqmQ4Yiu qZ8ZD+A7Tzedqf4vOKPx5yEUQt5FjnQqkvELhv69pT3/sIduevJ5ZF6cmptOl/BT0Scy qErQ== Received: by 10.52.89.197 with SMTP id bq5mr8356319vdb.85.1344303608606; Mon, 06 Aug 2012 18:40:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.58.249.33 with HTTP; Mon, 6 Aug 2012 18:39:48 -0700 (PDT) From: Raihan Jamal Date: Mon, 6 Aug 2012 18:39:48 -0700 Message-ID: Subject: Custom UserDefinedFunction in Hive To: user@hive.apache.org, dev@hive.apache.org Content-Type: multipart/alternative; boundary=bcaec5015f510faf0e04c6a31335 X-Virus-Checked: Checked by ClamAV on apache.org --bcaec5015f510faf0e04c6a31335 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable *Problem* I created the below UserDefinedFunction to get the yesterday's day in the format I wanted as I will be passing the format into this below method from the query. *public final class YesterdayDate extends UDF {* * * * public String evaluate(final String format) { * * DateFormat dateFormat =3D new SimpleDateFormat(format); * * Calendar cal =3D Calendar.getInstance();* * cal.add(Calendar.DATE, -1); * * return dateFormat.format(cal.getTime()).toString(); * * } * *}* So whenever I try to run the query like below by adding the jar to classpath and creating the temporary function yesterdaydate, I always get zero result back- hive> create temporary function *yesterdaydate* as 'com.example.hive.udf.YesterdayDate'; OK Time taken: 0.512 seconds Below is the query I am running- *hive> SELECT * FROM REALTIME where dt=3D yesterdaydate('yyyyMMdd') LIMIT 1= 0;* *OK* * * And I always get zero result back but the data is there in that table for Aug 5th.** What wrong I am doing? Any suggestions will be appreciated. NOTE:- As I am working with Hive 0.6 so it doesn=92t support variable substitution thing, so I cannot use hiveconf here and the above table has been partitioned on dt(date) column.** --bcaec5015f510faf0e04c6a31335 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable

= Problem

I created the below UserD= efinedFunction to get the yesterday's day in the format I wanted as I will be passing the format into this below method from the query.

=A0

public final class Yes= terdayDate extends UDF {

=A0

=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 public String evaluate(final String format) {

=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 DateFormat dateFormat =3D new SimpleDateFormat(format);

=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Calendar cal =3D Calendar.getInstance();

=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cal.add(Calendar.DATE, -1);=A0=A0=A0=A0

=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return dateFormat.format(cal.getTime()).toString();

=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 }

}

=A0

=A0

So whenever I try to run = the query like below by adding the jar to classpath and creating the temporary function yesterdaydate, I always ge= t zero result back-

=A0

hive> create temporary= function yesterdaydate as 'com.example.hive.udf.YesterdayDate';

OK

Time taken: 0.512 seconds=

=A0

Below is the query I am r= unning-

=A0

hive> SELECT * FROM= REALTIME where dt=3D yesterdaydate('yyyyMMdd') LIMIT 10;

OK

=A0

And I always get zero res= ult back but the data is there in that table for Aug 5th.

=A0

What wrong I am doing? An= y suggestions will be appreciated.

=A0

=A0

NOTE:- As I am working wi= th Hive 0.6 so it doesn=92t support variable substitution thing, so I cannot use hiveconf here and the above ta= ble has been partitioned on dt(date) column.

--bcaec5015f510faf0e04c6a31335--