Skip to content

Commit 9e17e34

Browse files
committed
Merge remote-tracking branch 'upstream/hbase_compat_3_2.0' into hbase_compat_3_2.0_enable_disable
2 parents e552174 + d192cd4 commit 9e17e34

File tree

7 files changed

+56
-21
lines changed

7 files changed

+56
-21
lines changed

example/simple-hbase-demo/src/main/java/com/oceanbase/example/SimpleHBaseClientDemo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import com.alipay.oceanbase.hbase.OHTableClient;
2121
import org.apache.hadoop.conf.Configuration;
22+
import org.apache.hadoop.hbase.Cell;
23+
import org.apache.hadoop.hbase.CellUtil;
2224
import org.apache.hadoop.hbase.client.Get;
2325
import org.apache.hadoop.hbase.client.Put;
2426
import org.apache.hadoop.hbase.client.Result;
@@ -49,7 +51,7 @@ public static void simpleTest() throws Exception {
4951
byte[] rowKey = toBytes("rowKey1");
5052
byte[] column = toBytes("column1");
5153
Put put = new Put(rowKey);
52-
put.add(family, column, System.currentTimeMillis(), toBytes("value1"));
54+
put.addColumn(family, column, System.currentTimeMillis(), toBytes("value1"));
5355
hTable.put(put);
5456

5557
// 3. get data like hbase
@@ -58,7 +60,7 @@ public static void simpleTest() throws Exception {
5860
Result r = hTable.get(get);
5961
if (!r.isEmpty()) {
6062
Cell cell = r.rawCells()[0];
61-
System.out.printf("column1: " + CellUtil.cloneQualifier(r));
63+
System.out.printf("column1: " + CellUtil.cloneQualifier(cell));
6264
}
6365

6466
// 4. close

src/main/java/com/alipay/oceanbase/hbase/OHTableClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ public HTableDescriptor getTableDescriptor() throws IOException {
223223

224224
@Override
225225
public TableDescriptor getDescriptor() throws IOException {
226-
return null;
226+
checkStatus();
227+
return ohTable.getDescriptor();
227228
}
228229

229230
@Override

src/main/java/com/alipay/oceanbase/hbase/util/OHAdmin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,16 @@ public HTableDescriptor getTableDescriptor(TableName tableName) throws TableNotF
145145
if (e.getCause() instanceof ObTableTransportException
146146
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
147147
throw new TimeoutIOException(e.getCause());
148+
} else if (e.getCause().getMessage().contains("OB_TABLEGROUP_NOT_EXIST")) {
149+
throw new TableNotFoundException(tableName);
148150
} else {
149151
throw e;
150152
}
151153
}
152154
}
153155

154156
@Override
155-
public TableDescriptor getDescriptor(TableName tableName) throws TableNotFoundException, IOException {
157+
public TableDescriptor getDescriptor(TableName tableName) throws IOException {
156158
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
157159
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
158160
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableName.getNameAsString(), tableClient);
@@ -162,6 +164,8 @@ public TableDescriptor getDescriptor(TableName tableName) throws TableNotFoundEx
162164
if (e.getCause() instanceof ObTableTransportException
163165
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
164166
throw new TimeoutIOException(e.getCause());
167+
} else if (e.getCause().getMessage().contains("OB_TABLEGROUP_NOT_EXIST")) {
168+
throw new TableNotFoundException(tableName);
165169
} else {
166170
throw e;
167171
}

src/test/java/com/alipay/oceanbase/hbase/OHTableClientTest.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
2121
import org.apache.hadoop.hbase.HTableDescriptor;
22+
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
23+
import org.apache.hadoop.hbase.client.TableDescriptor;
2224
import org.junit.*;
2325

2426
import java.util.LinkedList;
@@ -77,7 +79,9 @@ public void testNew() throws Exception {
7779
`T` bigint(20) NOT NULL,
7880
`V` varbinary(1024) DEFAULT NULL,
7981
PRIMARY KEY (`K`, `Q`, `T`)
80-
) TABLEGROUP = test_desc PARTITION BY RANGE COLUMNS(K) (
82+
) TABLEGROUP = test_desc
83+
KV_ATTRIBUTES ='{"Hbase": {"TimeToLive": 3600, "MaxVersions": 3}}'
84+
PARTITION BY RANGE COLUMNS(K) (
8185
PARTITION p1 VALUES LESS THAN ('c'),
8286
PARTITION p2 VALUES LESS THAN ('e'),
8387
PARTITION p3 VALUES LESS THAN ('g'),
@@ -96,7 +100,9 @@ PARTITION p10 VALUES LESS THAN (MAXVALUE)
96100
`T` bigint(20) NOT NULL,
97101
`V` varbinary(1024) DEFAULT NULL,
98102
PRIMARY KEY (`K`, `Q`, `T`)
99-
) TABLEGROUP = test_desc PARTITION BY RANGE COLUMNS(K) (
103+
) TABLEGROUP = test_desc
104+
KV_ATTRIBUTES ='{"Hbase": {"TimeToLive": 7200, "MaxVersions": 3}}'
105+
PARTITION BY RANGE COLUMNS(K) (
100106
PARTITION p1 VALUES LESS THAN ('c'),
101107
PARTITION p2 VALUES LESS THAN ('e'),
102108
PARTITION p3 VALUES LESS THAN ('g'),
@@ -116,11 +122,30 @@ public void testGetTableDescriptor() throws Exception {
116122
OHTableClient hTable2 = ObHTableTestUtil.newOHTableClient(tableNameStr);
117123
hTable2.init();
118124
try {
119-
HTableDescriptor descriptor = hTable2.getTableDescriptor();
120-
Assert.assertNotNull(descriptor);
121-
Assert.assertTrue(descriptor.hasFamily("family1".getBytes()));
122-
Assert.assertTrue(descriptor.hasFamily("family2".getBytes()));
123-
Assert.assertFalse(descriptor.hasFamily("family".getBytes()));
125+
{
126+
HTableDescriptor descriptor1 = hTable2.getTableDescriptor();
127+
Assert.assertNotNull(descriptor1);
128+
Assert.assertEquals(2, descriptor1.getColumnFamilyCount());
129+
Assert.assertTrue(descriptor1.hasFamily("family1".getBytes()));
130+
Assert.assertTrue(descriptor1.hasFamily("family2".getBytes()));
131+
Assert.assertFalse(descriptor1.hasFamily("family".getBytes()));
132+
ColumnFamilyDescriptor family1 = descriptor1.getColumnFamily("family1".getBytes());
133+
ColumnFamilyDescriptor family2 = descriptor1.getColumnFamily("family2".getBytes());
134+
Assert.assertEquals(3600, family1.getTimeToLive());
135+
Assert.assertEquals(7200, family2.getTimeToLive());
136+
}
137+
{
138+
TableDescriptor descriptor2 = hTable2.getDescriptor();
139+
Assert.assertNotNull(descriptor2);
140+
Assert.assertEquals(2, descriptor2.getColumnFamilyCount());
141+
Assert.assertTrue(descriptor2.hasColumnFamily("family1".getBytes()));
142+
Assert.assertTrue(descriptor2.hasColumnFamily("family2".getBytes()));
143+
Assert.assertFalse(descriptor2.hasColumnFamily("family".getBytes()));
144+
ColumnFamilyDescriptor family1 = descriptor2.getColumnFamily("family1".getBytes());
145+
ColumnFamilyDescriptor family2 = descriptor2.getColumnFamily("family2".getBytes());
146+
Assert.assertEquals(3600, family1.getTimeToLive());
147+
Assert.assertEquals(7200, family2.getTimeToLive());
148+
}
124149
} finally {
125150
hTable2.close();
126151
}

src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableShareStorageSeriesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static void testGetImpl(String tableName) throws Exception {
7575
long curTs = System.currentTimeMillis();
7676
for (int i = 0; i < recordCount; i++) {
7777
Put put = new Put(toBytes(key + i));
78-
put.add(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value + i));
78+
put.addColumn(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value + i));
7979
hTable.put(put);
8080
}
8181

@@ -107,7 +107,7 @@ public static void testScanImpl(String tableName) throws Exception {
107107
long curTs = System.currentTimeMillis();
108108
for (int i = 0; i < recordCount; i++) {
109109
Put put = new Put(toBytes(key + i));
110-
put.add(family.getBytes(), (column).getBytes(), curTs, toBytes(value + i));
110+
put.addColumn(family.getBytes(), (column).getBytes(), curTs, toBytes(value + i));
111111
hTable.put(put);
112112
}
113113

src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableShareStorageTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static void testGetImpl(String tableName) throws Exception {
8383
long curTs = System.currentTimeMillis();
8484
for (int i = 0; i < recordCount; i++) {
8585
Put put = new Put(toBytes(key + i));
86-
put.add(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value + i));
86+
put.addColumn(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value + i));
8787
hTable.put(put);
8888
}
8989

@@ -119,7 +119,7 @@ public static void testMultiCFGetImpl(Map.Entry<String, List<String>> entry) thr
119119
String family = getColumnFamilyName(tableName);
120120
for (int i = 0; i < recordCount; i++) {
121121
Put put = new Put(toBytes(key + i));
122-
put.add(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value + i));
122+
put.addColumn(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value + i));
123123
hTable.put(put);
124124
}
125125
}
@@ -204,7 +204,7 @@ public static void testBatchGetImpl(String tableName) throws Exception {
204204
long curTs = System.currentTimeMillis();
205205
for (int i = 0; i < recordCount; i++) {
206206
Put put = new Put(toBytes(key + i));
207-
put.add(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value));
207+
put.addColumn(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value));
208208
hTable.put(put);
209209
}
210210

@@ -245,7 +245,7 @@ public static void testScanImpl(String tableName) throws Exception {
245245
long curTs = System.currentTimeMillis();
246246
for (int i = 0; i < recordCount; i++) {
247247
Put put = new Put(toBytes(key + i));
248-
put.add(family.getBytes(), (column).getBytes(), curTs, toBytes(value + i));
248+
put.addColumn(family.getBytes(), (column).getBytes(), curTs, toBytes(value + i));
249249
hTable.put(put);
250250
}
251251

@@ -354,7 +354,7 @@ public static void testMultiCFScanImpl(Map.Entry<String, List<String>> entry) th
354354
String family = getColumnFamilyName(tableName);
355355
for (int i = 0; i < recordCount; i++) {
356356
Put put = new Put(toBytes(key + i));
357-
put.add(family.getBytes(), (column).getBytes(), curTs, toBytes(value));
357+
put.addColumn(family.getBytes(), (column).getBytes(), curTs, toBytes(value));
358358
hTable.put(put);
359359
}
360360
}

src/test/java/unit_test_db.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,15 @@ CREATE TABLE `test_region_locator$family_region_locator` (
298298
);
299299

300300
CREATE TABLEGROUP test_desc SHARDING = 'ADAPTIVE';
301-
302301
CREATE TABLE `test_desc$family1` (
303302
`K` varbinary(1024) NOT NULL,
304303
`Q` varbinary(256) NOT NULL,
305304
`T` bigint(20) NOT NULL,
306305
`V` varbinary(1024) DEFAULT NULL,
307306
PRIMARY KEY (`K`, `Q`, `T`)
308-
) TABLEGROUP = test_desc PARTITION BY RANGE COLUMNS(K) (
307+
) TABLEGROUP = test_desc
308+
KV_ATTRIBUTES ='{"Hbase": {"TimeToLive": 3600, "MaxVersions": 3}}'
309+
PARTITION BY RANGE COLUMNS(K) (
309310
PARTITION p1 VALUES LESS THAN ('c'),
310311
PARTITION p2 VALUES LESS THAN ('e'),
311312
PARTITION p3 VALUES LESS THAN ('g'),
@@ -324,7 +325,9 @@ CREATE TABLE `test_desc$family2` (
324325
`T` bigint(20) NOT NULL,
325326
`V` varbinary(1024) DEFAULT NULL,
326327
PRIMARY KEY (`K`, `Q`, `T`)
327-
) TABLEGROUP = test_desc PARTITION BY RANGE COLUMNS(K) (
328+
) TABLEGROUP = test_desc
329+
KV_ATTRIBUTES ='{"Hbase": {"TimeToLive": 7200, "MaxVersions": 3}}'
330+
PARTITION BY RANGE COLUMNS(K) (
328331
PARTITION p1 VALUES LESS THAN ('c'),
329332
PARTITION p2 VALUES LESS THAN ('e'),
330333
PARTITION p3 VALUES LESS THAN ('g'),

0 commit comments

Comments
 (0)