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 9DABC9A43 for ; Tue, 17 Jan 2012 11:40:21 +0000 (UTC) Received: (qmail 87222 invoked by uid 500); 17 Jan 2012 11:40:20 -0000 Delivered-To: apmail-hive-user-archive@hive.apache.org Received: (qmail 87083 invoked by uid 500); 17 Jan 2012 11:40:19 -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 87075 invoked by uid 99); 17 Jan 2012 11:40:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jan 2012 11:40:19 +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 smallputao@gmail.com designates 209.85.220.176 as permitted sender) Received: from [209.85.220.176] (HELO mail-vx0-f176.google.com) (209.85.220.176) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jan 2012 11:40:12 +0000 Received: by vcbfk13 with SMTP id fk13so1897304vcb.35 for ; Tue, 17 Jan 2012 03:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=ONxbH58k1vN8qwBh/vm+f9fkIlaoPaEim2JXbOX0QrU=; b=P8VZ17Y74+OTowR6uPI92fw7qcTIk2aSyoxZqgM25K7yFyTRz8KJDkI+/lnPxG53c3 6PfuhCquBoE9szfGMqElHHiTe5/r+4CnCfwsvK1zeB8fJviFf49sh78X61BXpKCXEbfu /Rz2AHmgKQsMK95CmV0sQgJI6Ri3XbH1vHP68= MIME-Version: 1.0 Received: by 10.220.148.138 with SMTP id p10mr9808297vcv.28.1326800391943; Tue, 17 Jan 2012 03:39:51 -0800 (PST) Received: by 10.220.5.80 with HTTP; Tue, 17 Jan 2012 03:39:51 -0800 (PST) Date: Tue, 17 Jan 2012 19:39:51 +0800 Message-ID: Subject: Cannot create an instance of InputFormat From: Bing Li To: user@hive.apache.org Content-Type: multipart/alternative; boundary=f46d043892910cb4a604b6b7caf0 --f46d043892910cb4a604b6b7caf0 Content-Type: text/plain; charset=ISO-8859-1 My Steps: I define a class "public class myInputFormat extends TextInputFormat implements JobConfigurable" to specify input format. hive> add jar /home/biadmin/hiveudf/myFileFormat.jar; Added /home/biadmin/hiveudf/myFileFormat.jar to class path Added resource: /home/biadmin/hiveudf/myFileFormat.jar hive> list jars; /home/biadmin/hiveudf/myFileFormat.jar hive> create table IOtable(str1 string, str2 string, str3 string) stored as INPUTFORMAT 'com.mytest.fileformat.myInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat' ; OK Time taken: 0.081 seconds hive> load data local inpath '/home/biadmin/hivetbl/IOtable_data.txt' into table IOtable; Copying data from file:/home/biadmin/hivetbl/IOtable_data.txt Copying file: file:/home/biadmin/hivetbl/IOtable_data.txt Loading data to table default.iotable OK Time taken: 0.147 seconds hive> select * from IOtable; OK Failed with exception java.io.IOException:java.io.IOException: Cannot create an instance of InputFormat class com.mytest.fileformat.myInputFormat as specified in mapredWork! Time taken: 0.059 seconds *Here is my source code :* =============================== package com.mytest.fileformat; import java.io.IOException; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.mapred.FileSplit; import org.apache.hadoop.mapred.InputSplit; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.JobConfigurable; import org.apache.hadoop.mapred.LineRecordReader; import org.apache.hadoop.mapred.RecordReader; import org.apache.hadoop.mapred.Reporter; import org.apache.hadoop.mapred.InputFormat; import org.apache.hadoop.mapred.TextInputFormat; @SuppressWarnings("deprecation") public class myInputFormat extends TextInputFormat implements JobConfigurable { TextInputFormat format; JobConf job; public myInputFormat() { format = new TextInputFormat(); } @Override public void configure(JobConf job) { this.job = job; format.configure(job); } public RecordReader getRecordReader( InputSplit genericSplit, JobConf job, Reporter reporter) throws IOException { reporter.setStatus(genericSplit.toString()); return new myLineRecordReader(job, (FileSplit) genericSplit); } public static class myLineRecordReader implements RecordReader { LineRecordReader lineReader; LongWritable lineKey; Text lineValue; public myLineRecordReader(JobConf job, FileSplit split) throws IOException { lineReader = new LineRecordReader(job, split); lineKey = lineReader.createKey(); lineValue = lineReader.createValue(); } public boolean next(LongWritable key, Text value) throws IOException { while (lineReader.next(lineKey, lineValue)) { String strReplace = lineValue.toString().toLowerCase().replace( "$$$$" , "\001" ); Text txtReplace = new Text(); txtReplace.set(strReplace); value.set(txtReplace.getBytes(), 0, txtReplace.getLength()); return true ; } // no more data return false; } /** end next **/ public LongWritable createKey() { return lineReader.createKey(); } public Text createValue() { return lineReader.createValue(); } public long getPos() throws IOException{ return lineReader.getPos(); } public float getProgress() throws IOException{ return lineReader.getProgress(); } public void close() throws IOException{ lineReader.close(); } } /** end class myLineRecordReader **/ } --f46d043892910cb4a604b6b7caf0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
My Steps:
I define a class "public class myInputFormat = extends TextInputFormat implements JobConfigurable" to specify input f= ormat.=A0

hive> add jar /home/biadmin/hiveudf/m= yFileFormat.jar;
Added /home/biadmin/hiveudf/myFileFormat.jar to class path
A= dded resource: /home/biadmin/hiveudf/myFileFormat.jar

<= div>hive> list jars;
/home/biadmin/hiveudf/myFileFormat.jar

hive> create table IOtable(str1 string, str2 string,= str3 string) stored as INPUTFORMAT 'com.mytest.fileformat.myInputForma= t' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFo= rmat' ;
OK
Time taken: 0.081 seconds

hive&g= t; load data local inpath '/home/biadmin/hivetbl/IOtable_data.txt' = into table IOtable;
Copying data from file:/home/biadmin/hivetbl/= IOtable_data.txt
Copying file: file:/home/biadmin/hivetbl/IOtable_data.txt
Lo= ading data to table default.iotable
OK
Time taken: 0.14= 7 seconds

hive> =A0select * from IOtable;
OK
Failed with exception java.io.IOException:java.io.IOExcep= tion: Cannot create an instance of InputFormat class com.mytest.fileformat.= myInputFormat as specified in mapredWork!
Time taken: 0.059 secon= ds




Here is= my source code :
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
package = com.mytest.fileformat;

import java.io.IOException;= =A0
=A0=A0
import org.apache.hadoop.io.LongWritable; =A0
import org.apache.hadoop.io.Text; =A0
import org.apache.common= s.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.mapred.FileSplit; =A0
import org.apache.= hadoop.mapred.InputSplit; =A0
import org.apache.hadoop.mapred.Job= Conf; =A0
import org.apache.hadoop.mapred.JobConfigurable;=A0
import org.apache.hadoop.mapred.LineRecordReader;
import org.apac= he.hadoop.mapred.RecordReader; =A0
import org.apache.hadoop.mapre= d.Reporter; =A0
import org.apache.hadoop.mapred.InputFormat;
import org.apache.hadoop.mapred.TextInputFormat; =A0

@SuppressWarnings("deprecation")
public class m= yInputFormat extends TextInputFormat implements JobConfigurable {
TextInput= Format format;
=A0 =A0 JobConf job;
=A0 =A0=A0
public m= yInputFormat() {
=A0 =A0 =A0 =A0 format =3D new TextInputFormat();
=A0 =A0 }<= /div>
=A0
@Override
public void configure(JobConf job) {
=A0 = =A0 =A0 =A0this.job =3D job;
=A0 =A0 =A0 =A0format.configure(job);
}
=A0 =A0 public RecordReader<LongWritable, Text> getRecordReader(= =A0
=A0 =A0 =A0 =A0 =A0 =A0 InputSplit genericSplit, JobConf job= , Reporter reporter) =A0
=A0 =A0 =A0 =A0 =A0 =A0 throws IOExcepti= on { =A0
=A0=A0
=A0 =A0 =A0 =A0 reporter.setStatus(genericSplit.toString()); =A0
= =A0 =A0 =A0 =A0 return new myLineRecordReader(job, (FileSplit) genericSplit= ); =A0
=A0 =A0 } =A0

=A0
=A0 =A0 public static class myLineRecordReader implements
= =A0 =A0 RecordReader<LongWritable, Text> {
=A0 =A0 =A0 Lin= eRecordReader lineReader;
=A0 =A0 =A0 LongWritable lineKey;
=A0 =A0 =A0 Text lineValue= ;

=A0 =A0 =A0 public myLineRecordReader(JobConf jo= b, FileSplit split) throws IOException {
=A0 =A0 =A0 =A0 lineRead= er =3D new LineRecordReader(job, split);
=A0 =A0 =A0 =A0 lineKey =3D lineReader.createKey();
=A0 =A0 = =A0 =A0 lineValue =3D lineReader.createValue();
=A0 =A0 =A0 }
=A0 =A0=A0
=A0 =A0 =A0 public boolean next(LongWritable ke= y, Text value) throws IOException {
=A0 =A0 =A0 =A0 while (lineReader.next(lineKey, lineValue)) {
=A0 =A0 =A0 =A0 =A0 String strReplace =3D lineValue.toString().toLowerCas= e().replace( "$$$$" , "\001" );
=A0 =A0 =A0 = =A0 =A0 Text txtReplace =3D new Text();
=A0 =A0 =A0 =A0 =A0 txtReplace.set(strReplace);
=A0 =A0 =A0 = =A0 =A0 value.set(txtReplace.getBytes(), 0, txtReplace.getLength());
<= div>=A0 =A0 =A0 =A0 =A0 return true ;
=A0 =A0 =A0 =A0 =A0}
<= div>=A0 =A0 =A0 =A0 =A0// no more data
=A0 =A0 =A0 =A0 =A0return false; =A0 =A0=A0
=A0 =A0 =A0 } =A0/** = end next **/
=A0 =A0 =A0=A0
=A0 =A0=A0
=A0 = =A0 =A0 public LongWritable createKey() {
=A0 =A0 =A0 =A0 return = lineReader.createKey();
=A0 =A0 =A0 }
=A0 =A0 =A0 public Text createValue() {
=A0 =A0 =A0 =A0 return li= neReader.createValue();
=A0 =A0 =A0 }
=A0 =A0 =A0 publi= c long getPos() throws IOException{
=A0 =A0 =A0 =A0 return lineRe= ader.getPos();
=A0 =A0 =A0 }
=A0 =A0 =A0 public float getProgress() throws IOException{
= =A0 =A0 =A0 =A0 return lineReader.getProgress();
=A0 =A0 =A0 }
=A0 =A0 =A0 public void close() throws IOException{
=A0 = =A0 =A0 =A0 lineReader.close();
=A0 =A0 =A0 }
=A0 =A0 =A0} =A0/** end class myLineRecordRead= er **/
}
--f46d043892910cb4a604b6b7caf0--