Skip to content

Repository files navigation

OBKV HBase Client

OBKV HBase Client is Java Library that can be used to access data from OceanBase by HBase-1.x API or Hbase-2.x API.

Quick start

Create table in the OceanBase database:

CREATE TABLEGROUP test1;
CREATE TABLE `test1$family1` (
`K` varbinary(1024) NOT NULL,
`Q` varbinary(256) NOT NULL,
`T`bigint(20) NOT NULL,
`V` varbinary(1024) DEFAULT NULL,
PRIMARY KEY (`K`, `Q`, `T`))
TABLEGROUP = test1;

Note:

  • test1: HBase table name;
  • family1: HBase column family name.

Import the dependency for your maven project:

<dependency>
<groupId>com.oceanbase</groupId>
<artifactId>obkv-hbase-client</artifactId>
<version>1.5.0</version>
</dependency>

Note:

  • This example version is not kept up-to-date. So check the releases page for the latest version frequently.

The code demo:

importorg.apache.hadoop.hbase.HBaseConfiguration;
importorg.apache.hadoop.hbase.TableName;
importorg.apache.hadoop.hbase.client.*;
importstaticorg.apache.hadoop.hbase.util.Bytes.toBytes;
publicclassSimpleHBaseClientDemo {
publicstaticvoidsimpleTest() throwsException {
// 1. initial connection for table test1HBaseConfigurationconf = newHBaseConfiguration();
Connectionconnection = ConnectionFactory.createConnection(conf);
TableNametableName = TableName.valueOf("test1");
TablehTable = connection.getTable(tableName);
// 2. put data like hbasebyte[] family = toBytes("family1");
byte[] rowKey = toBytes("rowKey1");
byte[] column = toBytes("column1");
Putput = newPut(rowKey);
put.add(family, column, System.currentTimeMillis(), toBytes("value1"));
hTable.put(put);
// 3. get data like hbaseGetget = newGet(rowKey);
get.addColumn(family, column);
Resultr = hTable.get(get);
System.out.println("column1: " + r.getColumn(family, column));
// 4. closehTable.close();
connection.close();
}
publicstaticvoidmain(String[] args) throwsException {
simpleTest();
}
}

The Hbase Configuration in hbase-site.xml for direct-connect mode:

<configuration>
<property>
<name>hbase.client.connection.impl</name>
<value>com.alipay.oceanbase.hbase.util.OHConnectionImpl</value>
</property>
<property>
<name>hbase.oceanbase.fullUserName</name>
<value></value>
</property>
<property>
<name>hbase.oceanbase.password</name>
<value></value>
</property>
<property>
<name>hbase.oceanbase.paramURL</name>
<value></value>
</property>
<property>
<name>hbase.oceanbase.sysUserName</name>
<value></value>
</property>
<property>
<name>hbase.oceanbase.sysPassword</name>
<value></value>
</property>
</configuration>

The Hbase Configuration in hbase-site.xml for ODP mode:

<configuration>
<property>
<name>hbase.client.connection.impl</name>
<value>com.alipay.oceanbase.hbase.util.OHConnectionImpl</value>
</property>
<property>
<name>hbase.oceanbase.odpMode</name>
<value>true</value>
</property>
<property>
<name>hbase.oceanbase.fullUserName</name>
<value></value>
</property>
<property>
<name>hbase.oceanbase.password</name>
<value></value>
</property>
<property>
<name>hbase.oceanbase.odpAddr</name>
<value></value>
</property>
<property>
<name>hbase.oceanbase.odpPort</name>
<value>3307</value>
</property>
<property>
<name>hbase.oceanbase.database</name>
<value></value>
</property>
</configuration>

NOTE:

  • hbase.client.connection.impl: the implementation of hbase connenction, which must be set to com.alipay.oceanbase.hbase.util.OHConnectionImpl
  • hbase.oceanbase.odpMode: true indicate is in ODP mode, false(in default) indicate is in direct-connect mode
  • hbase.oceanbase.fullUserName: the user for accessing obkv, which format is user_name@tenant_name#cluster_name
  • hbase.oceanbase.password: the password associated with the specified user
  • hbase.oceanbase.paramURL: which is generated by ConfigServer
  • hbase.oceanbase.sysUserName: root@sys or proxy@sys, which have privileges to access routing system view
  • hbase.oceanbase.sysPassword: the password associated with the specified sys user
  • hbase.oceanbase.odpAddr: the ODP's IP address
  • hbase.oceanbase.odpPort: the ODP's OBKV port
  • hbase.oceanbase.database: the target database to operate on

Documentation

Licencing

OBKV HBase Client is under MulanPSL - 2.0 licence. You can freely copy and use the source code. When you modify or distribute the source code, please obey the MulanPSL - 2.0 licence.

Contributing

Contributions are warmly welcomed and greatly appreciated. Here are a few ways you can contribute:

Support

In case you have any problems when using OceanBase Database, welcome reach out for help:

About

OBKV HBase Client is a Java library that enables access to OceanBase data by the HBase 0.94, 1.x, or 2.x APIs.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

21 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages