我正在用Java编写map-reduce作业。
我想使用外部表编写hbase增量对象。
为此,我正在创建新的HbaseConfiguration。
我希望能够创建一次并在所有映射器中使用。
任何的想法?
最佳答案
Job配置已经作为上下文的一部分传递给了映射器(和化简器)。您可以使用它访问任何HBase表。
Job job = new Job(HbaseConfiguration.create(), ...);
/* ... Rest of the job setup ... */
job.waitForCompletion(true);
在您的映射器设置方法中:
Configuration config = context.getConfiguration();
HTable mytable = new HTable(config, "my_table_name");
....
您甚至可以发送自定义参数或自变量,以便实例化映射器上可能需要的任何类型的对象:
Configuration config = HbaseConfiguration.create();
config.set("myStringParam", "customValue");
config.setStrings("myStringsParam", "customValue1", "customValue2", "customValue3");
config.setBoolean("myBooleanParam", true);
Job job = new Job(config, ...);
/* ... Rest of the job setup ... */
job.waitForCompletion(true);
在您的映射器设置方法中:
Configuration config = context.getConfiguration();
String myStringParam = config.get("myStringParam");
String myBooleanParam = config.get("myBooleanParam");
顺便说一句:我不知道为什么这个问题有这么多的否决票,这不是一个坏问题。
关于hadoop - 在MapReduce作业中一次创建HbaseConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22203864/