Skip to content

Commit 2f45536

Browse files
authored
Merge pull request #147 from stuBirdFly/client_2_1_0
update obkv-hbase example
2 parents 5b2487f + f474713 commit 2f45536

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ public static void simpleTest() throws Exception {
5656
Get get = new Get(rowKey);
5757
get.addColumn(family, column);
5858
Result r = hTable.get(get);
59-
System.out.printf("column1: " + r.getColumn(family, column));
59+
if (!r.isEmpty()) {
60+
Cell cell = r.rawCells()[0];
61+
System.out.printf("column1: " + CellUtil.cloneQualifier(r));
62+
}
6063

6164
// 4. close
6265
hTable.close();

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

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ private String getTargetTableName(List<? extends Row> actions) {
801801
throw new FeatureNotSupportedException("not supported yet'");
802802
} else {
803803
Set<byte[]> familySet = null;
804-
if (action instanceof Get){
804+
if (action instanceof Get) {
805805
Get get = (Get) action;
806806
familySet = get.familySet();
807807
} else {
@@ -921,7 +921,7 @@ private void processColumnFilters(NavigableSet<byte[]> columnFilters,
921921

922922
@Override
923923
public Result get(final Get get) throws IOException {
924-
if (get.getFamilyMap().keySet() == null || get.getFamilyMap().keySet().isEmpty()) {
924+
if (get.getFamilyMap().keySet().isEmpty()) {
925925
// check nothing, use table group;
926926
} else {
927927
checkFamilyViolation(get.getFamilyMap().keySet(), false);
@@ -934,8 +934,7 @@ public Result call() throws IOException {
934934
byte[] family = new byte[] {};
935935
ObTableQuery obTableQuery;
936936
try {
937-
if (get.getFamilyMap().keySet() == null
938-
|| get.getFamilyMap().keySet().isEmpty()
937+
if (get.getFamilyMap().keySet().isEmpty()
939938
|| get.getFamilyMap().size() > 1) {
940939
// In a Get operation where the family map is greater than 1 or equal to 0,
941940
// we handle this by appending the column family to the qualifier on the client side.
@@ -1024,8 +1023,7 @@ public ResultScanner call() throws IOException {
10241023
ObTableQuery obTableQuery;
10251024
ObHTableFilter filter;
10261025
try {
1027-
if (scan.getFamilyMap().keySet() == null
1028-
|| scan.getFamilyMap().keySet().isEmpty()
1026+
if (scan.getFamilyMap().keySet().isEmpty()
10291027
|| scan.getFamilyMap().size() > 1) {
10301028
// In a Scan operation where the family map is greater than 1 or equal to 0,
10311029
// we handle this by appending the column family to the qualifier on the client side.
@@ -1107,8 +1105,7 @@ public List<ResultScanner> call() throws IOException {
11071105
ObTableQuery obTableQuery;
11081106
ObHTableFilter filter;
11091107
try {
1110-
if (scan.getFamilyMap().keySet() == null
1111-
|| scan.getFamilyMap().keySet().isEmpty()
1108+
if (scan.getFamilyMap().keySet().isEmpty()
11121109
|| scan.getFamilyMap().size() > 1) {
11131110
// In a Scan operation where the family map is greater than 1 or equal to 0,
11141111
// we handle this by appending the column family to the qualifier on the client side.
@@ -1950,20 +1947,20 @@ public static ObTableBatchOperation buildObTableBatchOperation(List<Mutation> ro
19501947
Map<String, Integer> indexMap = new HashMap<>();
19511948
for (Mutation row : rowList) {
19521949
if (row instanceof Put) {
1953-
opType = OHOpType.INSERT_OR_UPDATE;
1950+
opType = OHOpType.Put;
19541951
} else if (row instanceof Delete) {
19551952
opType = OHOpType.Delete;
19561953
} else if (row instanceof Increment) {
19571954
opType = OHOpType.Increment;
19581955
} else if (row instanceof Append) {
1959-
opType = OHOpType.APPEND;
1956+
opType = OHOpType.Append;
19601957
} else {
19611958
throw new FeatureNotSupportedException("not supported other type");
19621959
}
19631960
Set<Map.Entry<byte[], List<Cell>>> familyCellMap = row.getFamilyCellMap().entrySet();
19641961

19651962
for (Map.Entry<byte[], List<Cell>> familyWithCells : familyCellMap) {
1966-
if (opType == OHOpType.Increment || opType == OHOpType.APPEND) {
1963+
if (opType == OHOpType.Increment || opType == OHOpType.Append) {
19671964
indexMap.clear();
19681965
for (int i = 0; i < familyWithCells.getValue().size(); i++) {
19691966
Cell cell = familyWithCells.getValue().get(i);
@@ -2002,12 +1999,12 @@ private com.alipay.oceanbase.rpc.mutation.Mutation buildMutation(Cell kv,
20021999
property = new Object[] { CellUtil.cloneValue(new_cell), TTL };
20032000
}
20042001
switch (operationType) {
2005-
case INSERT_OR_UPDATE:
2002+
case Put:
20062003
return com.alipay.oceanbase.rpc.mutation.Mutation.getInstance(INSERT_OR_UPDATE,
20072004
ROW_KEY_COLUMNS,
20082005
new Object[] { CellUtil.cloneRow(new_cell), CellUtil.cloneQualifier(new_cell),
20092006
new_cell.getTimestamp() }, property_columns, property);
2010-
case APPEND:
2007+
case Append:
20112008
return com.alipay.oceanbase.rpc.mutation.Mutation.getInstance(APPEND,
20122009
ROW_KEY_COLUMNS,
20132010
new Object[] { CellUtil.cloneRow(new_cell), CellUtil.cloneQualifier(new_cell),
@@ -2116,7 +2113,7 @@ private BatchOperation buildBatchOperation(String tableName, List<? extends Row>
21162113
List<Cell> keyValueList = entry.getValue();
21172114
for (Cell kv : keyValueList) {
21182115
singleOpResultNum++;
2119-
batch.addOperation(buildMutation(kv, OHOpType.INSERT_OR_UPDATE,
2116+
batch.addOperation(buildMutation(kv, OHOpType.Put,
21202117
isTableGroup, family, put.getTTL()));
21212118
}
21222119
}
@@ -2156,37 +2153,40 @@ public static ObTableOperation buildObTableOperation(Cell kv, OHOpType operation
21562153
property = new Object[] { CellUtil.cloneValue(kv), TTL };
21572154
}
21582155
switch (operationType) {
2159-
case INSERT_OR_UPDATE:
2160-
return getInstance(
2161-
INSERT_OR_UPDATE,
2162-
new Object[] { CellUtil.cloneRow(kv), CellUtil.cloneQualifier(kv),
2163-
kv.getTimestamp() }, property_columns, property);
2156+
case Put:
21642157
case Increment:
2158+
case Append:
2159+
ObTableOperationType type;
2160+
if (operationType == OHOpType.Put) {
2161+
type = INSERT_OR_UPDATE;
2162+
} else if (operationType == OHOpType.Increment) {
2163+
type = INCREMENT;
2164+
} else {
2165+
type = APPEND;
2166+
}
21652167
return getInstance(
2166-
INCREMENT,
2167-
new Object[] { CellUtil.cloneRow(kv), CellUtil.cloneQualifier(kv),
2168-
kv.getTimestamp() }, property_columns, property);
2169-
case APPEND:
2170-
return getInstance(
2171-
APPEND,
2168+
type,
21722169
new Object[] { CellUtil.cloneRow(kv), CellUtil.cloneQualifier(kv),
21732170
kv.getTimestamp() }, property_columns, property);
21742171
case Delete:
2175-
Cell.Type type = kv.getType();
2176-
if (type == Cell.Type.Delete) {
2172+
Cell.Type delType = kv.getType();
2173+
if (delType == Cell.Type.Delete) {
21772174
return getInstance(
21782175
DEL,
21792176
new Object[] { CellUtil.cloneRow(kv), CellUtil.cloneQualifier(kv),
21802177
kv.getTimestamp() }, null, null);
2181-
} else if (type == Cell.Type.DeleteColumn) {
2178+
} else if (delType == Cell.Type.DeleteColumn) {
21822179
return getInstance(
21832180
DEL,
21842181
new Object[] { CellUtil.cloneRow(kv), CellUtil.cloneQualifier(kv),
21852182
-kv.getTimestamp() }, null, null);
2183+
} else if (delType == Cell.Type.DeleteFamily) {
2184+
return getInstance(DEL,
2185+
new Object[] { CellUtil.cloneRow(kv), null, -kv.getTimestamp() }, null,
2186+
null);
2187+
} else {
2188+
throw new IllegalArgumentException("illegal delete type " + operationType);
21862189
}
2187-
case DeleteFamily:
2188-
return getInstance(DEL,
2189-
new Object[] { CellUtil.cloneRow(kv), null, -kv.getTimestamp() }, null, null);
21902190
default:
21912191
throw new IllegalArgumentException("illegal mutation type " + operationType);
21922192
}
@@ -2214,16 +2214,6 @@ private ObTableQueryAsyncRequest buildObTableQueryAsyncRequest(ObTableQuery obTa
22142214
return asyncRequest;
22152215
}
22162216

2217-
public static ObTableBatchOperationRequest buildObTableBatchOperationRequest(ObTableBatchOperation obTableBatchOperation,
2218-
String targetTableName) {
2219-
ObTableBatchOperationRequest request = new ObTableBatchOperationRequest();
2220-
request.setTableName(targetTableName);
2221-
request.setReturningAffectedRows(true);
2222-
request.setEntityType(ObTableEntityType.HKV);
2223-
request.setBatchOperation(obTableBatchOperation);
2224-
return request;
2225-
}
2226-
22272217
private ObTableQueryAndMutateRequest buildObTableQueryAndMutateRequest(ObTableQuery obTableQuery,
22282218
ObTableBatchOperation obTableBatchOperation,
22292219
String targetTableName) {
@@ -2310,7 +2300,7 @@ public Pair<byte[][], byte[][]> getStartEndKeys() throws IOException {
23102300
}
23112301

23122302
public static enum OHOpType {
2313-
INSERT_OR_UPDATE, APPEND, Delete, DeleteAll, DeleteColumn, DeleteFamily, DeleteFamilyVersion, Increment
2303+
Put, Append, Delete, DeleteAll, DeleteColumn, DeleteFamily, DeleteFamilyVersion, Increment
23142304
}
23152305

23162306
public static OHOpType getDeleteType(Cell.Type type) {

0 commit comments

Comments
 (0)