hive :text to ORC

http://c.360webcache.com/c?m=edfc672e16b7d63631a7133a0bd6c571&q=java+-+How+to+convert+.txt+%2F+.csv+file+to+ORC+format+-+Stack+Ov...&u=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F25117760%2Fhow-to-convert-txt-csv-file-to-orc-format 



/*ORCMapper.java*/
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.hive.ql.io.orc.*;
import org.apache.hadoop.io.*;
public class ORCMapper extends MapReduceBase implements
Mapper<LongWritable, Text, NullWritable, Writable>{OrcSerde serde;
@Override
public void configure(JobConf job) {
serde = new OrcSerde();
}
@Override
public void map(LongWritable key, Text value,
OutputCollector<NullWritable, Writable> output, Reporter reporter)
throws IOException {
output.collect(NullWritable.get(),serde.serialize(value, null));
}
}
/*ORCReducer.java*/
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
public class ORCReducer extends MapReduceBase implements Reducer<NullWritable, Writable, NullWritable, Writable>{
@Override
public void reduce(NullWritable key, Iterator<Writable> values,
OutputCollector<NullWritable, Writable> output, Reporter reporter)
throws IOException {
Writable value = values.next();
output.collect(key, value);
}
}
/*ORCDriver.java*/
import java.io.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.hive.ql.io.orc.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
public class ORCDriver {
public static void main(String[] args) throws IOException,
InterruptedException, ClassNotFoundException {
JobClient client = new JobClient();
JobConf conf = new JobConf("ORC_Generator");
conf.setInputFormat(TextInputFormat.class);
conf.setOutputKeyClass(NullWritable.class);
conf.setOutputValueClass(Writable.class);
conf.setOutputFormat(OrcOutputFormat.class);FileInputFormat.addInputPath(conf, new Path("hdfs://localhost:9000/path/to/ipdir/textfile"));OrcOutputFormat.setOutputPath(conf, new Path("hdfs://localhost:9000/path/to/opdir/orcfile"));
conf.setMapperClass(ORCMapper.class);
System.out.println(OrcOutputFormat.getWorkOutputPath(conf));
conf.setNumReduceTasks(0);
client.setConf(conf);
try {
JobClient.runJob(conf);
} catch (Exception e) {
e.printStackTrace();
}
}
}

http://fandy9587.blog.51cto.com/ 

http://hugh-wangp.iteye.com/blog/1405804 

http://www.tuicool.com/articles/YNfQn2 

http://www.cnblogs.com/chengxin1982/p/3981954.html 

https://stackoverflow.com/questions/25117760/how-to-convert-txt-csv-file-to-orc-format 

你可能感兴趣的:(表,一行数据写入hive)