我正在尝试运行简单的Hbase客户端程序,该程序与Hbase服务器(独立)通信以创建表和单行。但是,遗憾的是,在通过intelliJ运行时遇到异常。
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Initializing HBaseAdmin
log4j:WARN No appenders could be found for logger (org.apache.hadoop.security.Groups).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Hbase running, Creating table
Adding data into table
Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException: Failed 1 action: User: 1 time,
at org.apache.hadoop.hbase.client.AsyncProcess$BatchErrors.makeException(AsyncProcess.java:205)
at org.apache.hadoop.hbase.client.AsyncProcess$BatchErrors.access$500(AsyncProcess.java:189)
at org.apache.hadoop.hbase.client.AsyncProcess.getErrors(AsyncProcess.java:1042)
at org.apache.hadoop.hbase.client.HTable.backgroundFlushCommits(HTable.java:1037)
at org.apache.hadoop.hbase.client.HTable.flushCommits(HTable.java:1352)
at org.apache.hadoop.hbase.client.HTable.put(HTable.java:963)
at HbaseSample.main(HbaseSample.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Done
客户计划:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.*;
public class HbaseSample {
public static void main(String[] args) throws Exception {
System.out.println("Initializing HBaseAdmin");
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.property.clientPort","2181");
conf.set("hbase.master", "localhost:60000");
HBaseAdmin admin = new HBaseAdmin(conf);
try {
HBaseAdmin.checkHBaseAvailable(conf);
System.out.println("Hbase running, Creating table");
HTable table = new HTable(conf, "User");
Put put = new Put(Bytes.toBytes("msameer"));
put.add(Bytes.toBytes("Info"), Bytes.toBytes("addr"), Bytes.toBytes("walnut creek"));
System.out.println("Adding data into table");
table.put(put);
} finally {
admin.close();
System.out.println("Done");
}
}
}
我的hbase-site.xml如下所示:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///Users/msameer/Documents/Hbase/hbase-root</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/Users/msameer/Documents/Hbase/hbase-zookeper</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<property>
<name>hbase.master</name>
<value>localhost:60000</value>
</property>
</configuration>
非常感谢任何帮助。
答案 0 :(得分:6)
你的桌子已经存在吗?因为此代码不会创建表:
HBaseAdmin.checkHBaseAvailable(conf);
System.out.println("Hbase running, Creating table");
HTable table = new HTable(conf, "User");
这将仅使用已存在的表。要创建表格,您需要使用HBaseAdmin
:
HBaseAdmin.checkHBaseAvailable(conf);
System.out.println("Hbase running, Creating table");
HTableDescriptor des = new HTableDescriptor("User");
HBaseAdmin.createTable(des);
查看documentation的架构创建。它还显示更新的API调用。现在不推荐使用以H
开头的类。