title: Read an HDFS File from a HIVE UDF - Execution Error, return code 101 FunctionTask. Could not initialize class
body: <p>We have been trying to create a simple Hive UDF to mask some fields in a Hive Table.  We are using an external file (placed on HDFS) to grab a piece of text to make a salting to the masking process.  It seems we are doing everything ok but when we tried to create the external function it throws the error:</p>
  
  <pre><code>org.apache.hive.service.cli.HiveSQLException: Error while processing statement: FAILED: Execution Error, return code -101 from org.apache.hadoop.hive.ql.exec.FunctionTask. Could not initialize class co.company.Mask
  </code></pre>
  
  <p>This is our code for the UDF:</p>
  
  <pre><code>package co.company;
  
  import org.apache.hadoop.hive.ql.exec.UDF;
  import org.apache.hadoop.hive.ql.exec.Description;
  import org.apache.hadoop.io.Text;
  import org.apache.hadoop.conf.Configuration;
  import org.apache.hadoop.fs.FSDataInputStream;
  import org.apache.hadoop.fs.FileSystem;
  import org.apache.hadoop.fs.Path;
  
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  
  import org.apache.commons.codec.digest.DigestUtils;
  
  @Description( 
          name = "masker",
          value = "_FUNC_(str) - mask a string",      
          extended = "Example: \n" +
                  " SELECT masker(column) FROM hive_table; "      
          )
  public class Mask extends UDF  {
  
      private static final String arch_clave = "/user/username/filename.dat";
      private static String clave = null; 
  
      public static String getFirstLine( String arch ) {
  
          try {
              FileSystem fs = FileSystem.get(new Configuration());
              FSDataInputStream in = fs.open(new Path(arch));
              BufferedReader br = new BufferedReader(new InputStreamReader(in));    
  
              String ret = br.readLine();
              br.close();
              return ret;
  
          } catch (Exception e) { 
  
          System.out.println("out: Error Message: " + arch + " exc: " + e.getMessage());
          return null;
      } 
  }
  
  public Text evaluate(Text s) {
  
      clave = getFirstLine( arch_clave );
  
      Text to_value = new Text( DigestUtils.shaHex( s + clave) );
      return to_value;
  }
  }
  </code></pre>
  
  <p>We are uploading the jar file and creating the UDF through HUE's interface (Sadly, we don't have yet console access to the Hadoop cluster.</p>
  
  <p>On Hue's Hive Interface, our commands are:</p>
  
  <pre><code>add jar hdfs:///user/my_username/myJar.jar
  </code></pre>
  
  <p>And then to create the Function we execute:</p>
  
  <pre><code>CREATE TEMPORARY FUNCTION masker as 'co.company.Mask';
  </code></pre>
  
  <p>Sadly the error thrown when we tried to create the UDF is not very helpful.  This is the log for the creation of the UDF.  Any Help is greatly appreciated.  Thank you very much.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=compile from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=parse from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO parse.ParseDriver: Parsing command: CREATE TEMPORARY FUNCTION enmascarar as 'co.bancolombia.analitica.Enmascarar'
  14/12/10 08:32:15 INFO parse.ParseDriver: Parse Completed
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;/PERFLOG method=parse start=1418218335753 end=1418218335754 duration=1 from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=semanticAnalyze from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO parse.FunctionSemanticAnalyzer: analyze done
  14/12/10 08:32:15 INFO ql.Driver: Semantic Analysis Completed
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;/PERFLOG method=semanticAnalyze start=1418218335754 end=1418218335757 duration=3 from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO ql.Driver: Returning Hive schema: Schema(fieldSchemas:null, properties:null)
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;/PERFLOG method=compile start=1418218335753 end=1418218335757 duration=4 from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=Driver.run from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=TimeToSubmit from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=acquireReadWriteLocks from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO lockmgr.DummyTxnManager: Creating lock manager of type org.apache.hadoop.hive.ql.lockmgr.zookeeper.ZooKeeperHiveLockManager
  14/12/10 08:32:15 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=server1.domain:2181,server2.domain.corp:2181,server3.domain:2181 sessionTimeout=600000 watcher=org.apache.hadoop.hive.ql.lockmgr.zookeeper.ZooKeeperHiveLockManager$DummyWatcher@2ebe4e81
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;/PERFLOG method=acquireReadWriteLocks start=1418218335760 end=1418218335797 duration=37 from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=Driver.execute from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO ql.Driver: Starting command: CREATE TEMPORARY FUNCTION enmascarar as 'co.company.Mask'
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;/PERFLOG method=TimeToSubmit start=1418218335760 end=1418218335798 duration=38 from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=runTasks from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=task.FUNCTION.Stage-0 from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 ERROR ql.Driver: FAILED: Execution Error, return code -101 from org.apache.hadoop.hive.ql.exec.FunctionTask. Could not initialize class co.company.MasK
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;/PERFLOG method=Driver.execute start=1418218335797 end=1418218335800 duration=3 from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;PERFLOG method=releaseLocks from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 INFO ZooKeeperHiveLockManager:  about to release lock for default
  14/12/10 08:32:15 INFO ZooKeeperHiveLockManager:  about to release lock for colaboradores
  14/12/10 08:32:15 INFO log.PerfLogger: &lt;/PERFLOG method=releaseLocks start=1418218335800 end=1418218335822 duration=22 from=org.apache.hadoop.hive.ql.Driver&gt;
  14/12/10 08:32:15 ERROR operation.Operation: Error running hive query: 
  org.apache.hive.service.cli.HiveSQLException: Error while processing statement: FAILED: Execution Error, return code -101 from org.apache.hadoop.hive.ql.exec.FunctionTask. Could not initialize class co.company.Mask
   at org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:147)
   at org.apache.hive.service.cli.operation.SQLOperation.access$000(SQLOperation.java:69)
   at org.apache.hive.service.cli.operation.SQLOperation$1$1.run(SQLOperation.java:200)
   at java.security.AccessController.doPrivileged(Native Method)
   at javax.security.auth.Subject.doAs(Subject.java:415)
   at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1614)
   at org.apache.hadoop.hive.shims.HadoopShimsSecure.doAs(HadoopShimsSecure.java:502)
   at org.apache.hive.service.cli.operation.SQLOperation$1.run(SQLOperation.java:213)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
   at java.util.concurrent.FutureTask.run(FutureTask.java:262)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:744)</code></pre>
  </div>
  </div>
  </p>