Thanks Nitin Its done now.
The problem was this that I have to store the class file in the sam directory 
structure as I have described in package declaration line in the java code.

Rishabh


On Wednesday, 9 April 2014 12:43 PM, Nitin Pawar <[email protected]> 
wrote:
 
Follow the steps as it is from the link I shared .. it works

Somehow your package is getting messed and it is not able to find the class 



On Wed, Apr 9, 2014 at 12:27 PM, Rishabh Bhardwaj <[email protected]> wrote:

I added,
>package rishabh.udf.hive; 
>in the above code.
>and repeated the steps.
>But Now getting the following error,
>
>hive> create temporary function helloworld as 
>'rishabh.udf.hive.SimpleUDFExample';
>FAILED: Class rishabh.udf.hive.SimpleUDFExample not found
>FAILED: Execution Error, return code 1 from 
>org.apache.hadoop.hive.ql.exec.FunctionTask
>
>The SimpleUDFExample.class file is in hiveudfs.jar file.
>
>
>
>
>On Wednesday, 9 April 2014 12:20 PM, Nitin Pawar <[email protected]> 
>wrote:
> 
>in your code and that code package is missing 
>
>
>what you need to do is 
>define package something like 
>
>
>package org.apache.hadoop.hive.ql.udf;
>
>
>
>then your add function definition becomes
> 
>CREATE TEMPORARY FUNCTION <function_name> AS 
>'org.apache.hadoop.hive.ql.udf.<ClassName>';
>
>
>feel free to use any package name you wish but make sure its reflected same 
>
>
>also to build and compile and package hive udfs 
>use the shell script if you are on linux 
>
>
>http://yaboolog.blogspot.in/2011/06/compiling-original-hive-udf.html
>
>
>
>
>
>
>On Wed, Apr 9, 2014 at 12:12 PM, Rishabh Bhardwaj <[email protected]> wrote:
>
>Hi Nitin,
>>Thanks for the concern.
>>Here is the code of the UDF,
>>import org.apache.hadoop.hive.ql.exec.Description;
>>import org.apache.hadoop.hive.ql.exec.UDF;
>>import org.apache.hadoop.io.Text;
>>
>>
>>@Description(
>>  name="SimpleUDFExample",
>>  value="returns 'hello x', where x is whatever you give it (STRING)",
>>  extended="SELECT simpleudfexample('world') from foo limit 1;"
>>  )
>>class
 SimpleUDFExample extends UDF {
>>  
>>  public Text evaluate(Text input) {
>>    if(input == null) return null;
>>    return new Text("Hello " + input.toString());
>>  }
>>}
>>From google I came across a blog.
>>
>>I have taken this from here (git link).
>>
>> 
>>On Wednesday, 9 April 2014 12:08 PM, Nitin Pawar <[email protected]> 
>>wrote:
>> 
>>Can you put first few lines of your code here or upload code on github and 
>>share the link? 
>>
>>
>>
>>
>>
>>
>>
>>On Wed, Apr 9, 2014 at 11:59 AM, Rishabh Bhardwaj <[email protected]> wrote:
>>
>>Hi all,
>>>I have done the following steps to create a UDF in hive but getting 
>>>error.Please help me.
>>>1. Created the udf as described here.
>>>2. Compiled it successfully.
>>>3. Copy the class file to a directory hiveudfs.
>>>4. Added it to a jar with this command: jar -cf hiveudfs.jar 
>>>hiveudfs/SimpleUDFExample.class
>>>5. Import the jar into hive. add jar hiveudfs.jar;  (Added Successfully)
>>>
>>>create temporary function helloworld as 'hiveudfs.SimpleUDFExample';
>>>At this I am getting the following error,
>>>
>>>hive> create temporary function helloworld as 'hiveudfs.SimpleUDFExample';
>>>java.lang.NoClassDefFoundError: hiveudfs/SimpleUDFExample (wrong name: 
>>>SimpleUDFExample)
>>>    at java.lang.ClassLoader.defineClass1(Native Method)
>>>    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
>>>    at 
>>>java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
>>>    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
>>>    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
>>>    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
>>>    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
>>>    at
 java.security.AccessController.doPrivileged(Native Method)
>>>    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
>>>    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
>>>    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
>>>    at java.lang.Class.forName0(Native Method)
>>>    at java.lang.Class.forName(Class.java:266)
>>>    at 
>>>org.apache.hadoop.hive.ql.exec.FunctionTask.getUdfClass(FunctionTask.java:105)
>>>    at 
>>>org.apache.hadoop.hive.ql.exec.FunctionTask.createFunction(FunctionTask.java:75)
>>>    at 
>>>org.apache.hadoop.hive.ql.exec.FunctionTask.execute(FunctionTask.java:63)
>>>    at org.apache.hadoop.hive.ql.exec.Task.executeTask(Task.java:138)
>>>    at 
>>>org.apache.hadoop.hive.ql.exec.TaskRunner.runSequential(TaskRunner.java:57)
>>>    at
 org.apache.hadoop.hive.ql.Driver.launchTask(Driver.java:1353)
>>>    at org.apache.hadoop.hive.ql.Driver.execute(Driver.java:1137)
>>>    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:945)
>>>    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:867)
>>>    at 
>>>org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:259)
>>>    at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:216)
>>>    at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:412)
>>>    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:755)
>>>    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:613)
>>>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>    at
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>>    at 
>>>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>    at java.lang.reflect.Method.invoke(Method.java:601)
>>>    at org.apache.hadoop.util.RunJar.main(RunJar.java:208)
>>>FAILED: Execution Error, return code -101 from 
>>>org.apache.hadoop.hive.ql.exec.FunctionTask
>>>
>>>Thanks,
>>>Rishabh.
>>>
>>
>>
>>
>>-- 
>>Nitin Pawar
>>
>>
>>
>
>
>
>-- 
>Nitin Pawar
>
>
>


-- 
Nitin Pawar

Reply via email to