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 7E287D6C0 for ; Tue, 19 Feb 2013 15:04:19 +0000 (UTC) Received: (qmail 26096 invoked by uid 500); 19 Feb 2013 15:04:17 -0000 Delivered-To: apmail-hive-user-archive@hive.apache.org Received: (qmail 25485 invoked by uid 500); 19 Feb 2013 15:04:12 -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 25432 invoked by uid 99); 19 Feb 2013 15:04:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2013 15:04:10 +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 (nike.apache.org: domain of john.meagher@gmail.com designates 209.85.215.42 as permitted sender) Received: from [209.85.215.42] (HELO mail-la0-f42.google.com) (209.85.215.42) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2013 15:04:03 +0000 Received: by mail-la0-f42.google.com with SMTP id fe20so6651118lab.15 for ; Tue, 19 Feb 2013 07:03:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=Jzav4O6GVQ/u8F7atXHzqebukspo8NTGYsGZgSr1TNo=; b=ngkHemGZjE3ktwvx9TDRDSNAd8OW8BGIpR3tHu60p+4CHoMH3xK87cOVI2MbeZMf7R pLbobZVg/8M/OLJBx72XoXU3RzKc/R2tDh6NMAqGWI/XEAel1lScxnyZDqrfGSxT0M8i 60KGAWIPWwVWQuWIp6NSlISt8q1JFR5ONJYRRhLOWkJoKgy8y9+ABlWPgLhtUwERSMxu tcz6o29z5zK3sF7j/pn3Jl/F3YJqtsqYUOWhWQkpgRelf1PL93Q+vsRPN02YeU8aNCBD K+mRwnil3BBIgU5GniF3UnfWxllFlsZ8bMKLjtQK08G5tngr3MRzxEc670Q9OxIGIAi8 arkQ== MIME-Version: 1.0 X-Received: by 10.152.130.131 with SMTP id oe3mr14450837lab.1.1361286222571; Tue, 19 Feb 2013 07:03:42 -0800 (PST) Received: by 10.112.81.167 with HTTP; Tue, 19 Feb 2013 07:03:42 -0800 (PST) In-Reply-To: References: Date: Tue, 19 Feb 2013 10:03:42 -0500 Message-ID: Subject: Re: Using Reflect: A thread for ideas From: John Meagher To: user@hive.apache.org Content-Type: multipart/alternative; boundary=f46d04095bf7bbe7be04d615254d X-Virus-Checked: Checked by ClamAV on apache.org --f46d04095bf7bbe7be04d615254d Content-Type: text/plain; charset=ISO-8859-1 Another option for this functionality would be to use the Java scripting API. The basic structure of the call would be... select script( scriptLanguage, scriptToRun, args... ) I haven't seen that in Hive, but something similar is available for Pig. Documentation for that is available on http://pig.apache.org/docs/r0.9.2/udf.html#js-udfs. There's also a variation in Jira https://issues.apache.org/jira/browse/PIG-1777. On Wed, Feb 13, 2013 at 11:38 PM, John Omernik wrote: > I stumbled across the little documented reflect function today. I've > always known about it, but java scares me if it's not in a cup so I didn't > dig. Well today I dug, and found an awesome use case for reflect (for me) > and wanted to share. I also thought it would be nice to validate some > thoughts I had on reflect, and how we could possibly share ideas on reflect > so that folks could get more use out of this great feature of hive. > > Here's my example: A simple URL decode function: > > select url, reflect('java.net.URLDecoder', 'decode', url, 'utf-8') as > decoded_url from logs > Basically I am using the decode function of the java.net.URLDecoder class. > Pretty awesome, works great, no files to distribute either. Even works > through JDBC! > > Ok that being said, I realized now that the function I am trying to call > has to return data in a simple data type. For example, I struggle to come > up with a simple reflect() for making an Hex MD5 out of a string because > the built in function return an object, which have methods that can return > what I am looking for. Which is great, but then I have to compile java > code, distribute a jar, and then run the code. I am looking for simple like > the URLDecoding function. > > I love this reflect feature, but I think it's probably underutilized due > to the perceived usability issues for beginners. So that leads me to my > next thought. What if we brain storm here handy functions in Java that are > not included in the standard hive language, that make the transition to > hive well using the reflect function and the show an example of it's use? I > went first with my URLDecode, and obviously will be looking for more, but > have you seen some examples that we neat and worked well for you? Can you > share? > > Perhaps if we get enough examples we could roll some of these into a wiki > page on the hive wiki that folks can use to get over the "perceived" > complexity of using java reflect? > > Thanks to those who have worked hard to implement features like this, it > is truly awesome. > --f46d04095bf7bbe7be04d615254d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Another option for this functionality would be to use the = Java scripting API. =A0The basic structure of the call would be...

=
select script( scriptLanguage, scriptToRun, args... )

I haven't seen that in Hive, but someth= ing similar is available for Pig. =A0Documentation for that is available on= =A0http://pi= g.apache.org/docs/r0.9.2/udf.html#js-udfs. =A0There's also a variat= ion in Jira=A0ht= tps://issues.apache.org/jira/browse/PIG-1777.



On Wed, Feb 13, 2013 at 11:38 PM, John Omernik <john@omernik.= com> wrote:
I stumbled across the little documented refl= ect function today. I've always known about it, but java scares me if i= t's not in a cup so I didn't dig. =A0Well today I dug, and found an= awesome use case for reflect (for me) and wanted to share. =A0I also thoug= ht it would be nice to validate some thoughts I had on reflect, and how we = could possibly share ideas on reflect so that folks could get more use out = of this great feature of hive.=A0

Here's my example: A simple URL decode function:

select url,=A0reflect('java.net.URLDecoder', '= ;decode', url, 'utf-8') as decoded_url from logs
Basi= cally I am using the decode function of the java.net.URLDecoder class. =A0P= retty awesome, works great, no files to distribute either. =A0Even works th= rough JDBC!

Ok that being said, I realized now that the function I = am trying to call has to return data in a simple data type. =A0For example,= I struggle to come up with a simple reflect() for making an Hex MD5 out of= a string because the built in function return an object, which have method= s that can return what I am looking for. Which is great, but then I have to= compile java code, distribute a jar, and then run the code. I am looking f= or simple like the URLDecoding function. =A0

I love this reflect feature, but I think it's proba= bly underutilized due to the perceived usability issues for beginners. =A0S= o that leads me to my next thought. What if we brain storm here handy funct= ions in Java that are not included in the standard hive language, that make= the transition to hive well using the reflect function and the show an exa= mple of it's use? I went first with my URLDecode, and obviously will be= looking for more, but have you seen some examples that we neat and worked = well for you? Can you share? =A0

Perhaps if we get enough examples we could roll some of= these into a wiki page on the hive wiki that folks can use to get over the= "perceived" complexity of using java reflect? =A0

Thanks to those who have worked hard to implement features like = this, it is truly awesome.=A0

--f46d04095bf7bbe7be04d615254d--