Hbase事例基本方法--60
来源:互联网 发布:网上挂号预约软件 编辑:程序博客网 时间:2024/04/30 09:09
package llf.com;import java.io.IOException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.KeyValue;import org.apache.hadoop.hbase.client.Result;import org.apache.hadoop.hbase.client.Scan;import org.apache.hadoop.hbase.io.ImmutableBytesWritable;import org.apache.hadoop.hbase.mapreduce.TableInputFormat;import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;import org.apache.hadoop.hbase.mapreduce.TableMapper;import org.apache.hadoop.hbase.util.Bytes;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;import org.apache.hadoop.util.GenericOptionsParser;public class TabelFinder {final static String NAME = "find table";static class Exporter extends TableMapper<Text, Text> {@SuppressWarnings("deprecation")public void map(ImmutableBytesWritable rowk, Result result, Context context) throws IOException, InterruptedException {if (rowk == null || result == null) return;KeyValue[] kvs = result.rawk();String KeyA = "";String KeyB = "";String KeyC = "";String KeyD = "";String KeyE = "";String KeyF = "";for (KeyValue kv : kvs) {String qualifier = Bytes.toString(kv.getQualifier());String value = Bytes.toString(kv.getValue());if (qualifier.equals("KeyA")) {KeyA = value;} else if (qualifier.equals("KeyB")) {KeyB = value;} else if (qualifier.equals("KeyC")) {KeyC = value;} else if (qualifier.equals("KeyD")) {KeyD = value;} else if (qualifier.equals("KeyE")) {KeyE = value;} else if (qualifier.equals("KeyF")) {KeyF = value;} }StringBuffer sb = new StringBuffer();sb.append(KeyA).append("\\\");sb.append(KeyB).append("\\\");sb.append(KeyC).append("\\\");sb.append(KeyD).append("\\\");sb.append(KeyE).append("\\\");sb.append(KeyF).append("\\\");context.write(new Text(KeyF), new Text(sb.toString()));}}@SuppressWarnings("deprecation")public static Job createSubmittableJob(Configuration conf, String[] args) throws IOException {String tableName = "xx_test";Path outputDir = new Path(args[0]);Job job = new Job(conf, NAME + " " + tableName);job.setJobName(NAME + "_" + tableName);job.setJarByClass(EXXXX.class);Scan s = getConfiguredScanForJob(conf, args);TableMapReduceUtil.initTableMapperJob(tableName, s, Exporter.class, null, null, job);job.setNumReduceTasks(0);job.setOutputFormatClass(EYYYY.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(Text.class);FileOutputFormat.setOutputPath(job, outputDir);return job;}private static Scan getConddsss(Configuration conf, String[] args) throws IOException {Scan s = new Scan();s.setTimeRange(141999999999, 145999999999);s.addColumn("folm".getBytes(), "KeyA".getBytes());s.addColumn("folm".getBytes(), "KeyB".getBytes());s.addColumn("folm".getBytes(), "KeyC".getBytes());s.addColumn("folm".getBytes(), "KeyD".getBytes());s.addColumn("folm".getBytes(), "KeyE".getBytes());s.addColumn("folm".getBytes(), "KeyF".getBytes());s.setCaching(100);s.setCacheBlocks(false);return s;}private static void usage(final String errorMsg) {if (errorMsg != null && errorMsg.length() > 0) {System.err.println("ERROR: " + errorMsg);}System.err.println("Usage: TabelScanner [-D <property=value>]* <outputdir> \n");System.err.println(" Note: -D properties will be applied to the conf used. ");System.err.println(" For example: ");System.err.println(" -D mapred.output.compress=true");System.err.println(" -D mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec");System.err.println(" -D mapred.output.compression.type=BLOCK");System.err.println(" eeeeeeeee, the foououoproperties can be specified");System.err.println(" to control/limit what is exported..");System.err.println(" -D " + ggeewywy + "=<familyName>");System.err.println("For performance consider the following properties:\n"+ " -Dhbase.client.scanner.caching=100\n"+ " -Dmapred.map.tasks.speculative.execution=false\n"+ " -Dmapred.reduce.tasks.speculative.execution=false");}public static void main(String[] args) throws Exception {Configuration conf = HBaseConfiguration.create();String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();if (otherArgs.length < 1) {usage("Wrong number of arguments: " + otherArgs.length);System.exit(-1);}Job job = createSubmittableJob(conf, otherArgs);System.exit(job.waitForCompletion(true) ? 0 : 1);}}
0 0
- Hbase事例基本方法--60
- 事例详解DOM的基本方法
- Hbase练习事例--61
- Jms 基本事例
- IOCP 基本模型 事例
- fasync方法事例
- noSql-Hbase-php读写操作hbase数据库的基本方法
- java生成二维码方法事例
- 【java生成二维码方法事例】
- 【swift_1】swift基本语法及事例Demo
- 【swift_1】swift基本语法及事例Demo
- php读写操作hbase数据库的基本方法
- C#事例调用类静态方法
- ecshop系统中的Ajax使用事例方法
- struts2 调用默认方法execute()的事例
- HashMap能够调用的方法和事例
- HBase基本命令
- HBase 基本操作
- windows8 安装教程
- 获取手机存储空间信息
- SpringMVC-Mybatis 个人总结
- 进程间通信(IPC)之共享内存
- Android中Bitmap, Drawable, Byte,ID之间的转化
- Hbase事例基本方法--60
- Nginx
- 用IDEA追忆一下童年
- Android 按钮事件两种经典写法
- 面向对象和面向过程
- C 语言的运算符表达式 if switch while
- BaseAdapter的用法
- Mac OS X 系统配置 Apache+MySql+PHP 详细教程
- oracle动态sql的简单使用