39
39
import com .alipay .sofa .common .thread .SofaThreadPoolExecutor ;
40
40
import com .alipay .oceanbase .hbase .exception .OperationTimeoutException ;
41
41
42
+ import com .google .protobuf .Descriptors ;
43
+ import com .google .protobuf .Message ;
44
+ import com .google .protobuf .Service ;
45
+ import com .google .protobuf .ServiceException ;
42
46
import org .apache .hadoop .conf .Configuration ;
43
- import org .apache .hadoop .hbase .HConstants ;
44
- import org .apache .hadoop .hbase .HTableDescriptor ;
45
- import org .apache .hadoop .hbase .KeyValue ;
46
- import org .apache .hadoop .hbase .client .Append ;
47
- import org .apache .hadoop .hbase .client .Delete ;
48
- import org .apache .hadoop .hbase .client .Get ;
49
- import org .apache .hadoop .hbase .client .HTableInterface ;
50
- import org .apache .hadoop .hbase .client .Increment ;
51
- import org .apache .hadoop .hbase .client .Mutation ;
52
- import org .apache .hadoop .hbase .client .Put ;
53
- import org .apache .hadoop .hbase .client .Result ;
54
- import org .apache .hadoop .hbase .client .ResultScanner ;
55
- import org .apache .hadoop .hbase .client .Row ;
56
- import org .apache .hadoop .hbase .client .RowLock ;
57
- import org .apache .hadoop .hbase .client .RowMutations ;
58
- import org .apache .hadoop .hbase .client .Scan ;
47
+ import org .apache .hadoop .hbase .*;
48
+ import org .apache .hadoop .hbase .client .*;
59
49
import org .apache .hadoop .hbase .client .coprocessor .Batch ;
50
+ import org .apache .hadoop .hbase .filter .CompareFilter ;
60
51
import org .apache .hadoop .hbase .filter .Filter ;
61
52
import org .apache .hadoop .hbase .io .TimeRange ;
62
- import org .apache .hadoop .hbase .ipc .CoprocessorProtocol ;
53
+ import org .apache .hadoop .hbase .ipc .CoprocessorRpcChannel ;
63
54
import org .apache .hadoop .hbase .util .Bytes ;
64
55
import org .apache .hadoop .hbase .util .Pair ;
65
56
import org .slf4j .Logger ;
@@ -344,6 +335,10 @@ public byte[] getTableName() {
344
335
return tableName ;
345
336
}
346
337
338
+ public TableName getName () {
339
+ return null ;
340
+ }
341
+
347
342
public Configuration getConfiguration () {
348
343
return configuration ;
349
344
}
@@ -368,6 +363,10 @@ public boolean exists(Get get) throws IOException {
368
363
return !r .isEmpty ();
369
364
}
370
365
366
+ public Boolean [] exists (List <Get > gets ) throws IOException {
367
+ throw new FeatureNotSupportedException ("not supported yet'" );
368
+ }
369
+
371
370
public void batch (List <? extends Row > actions , Object [] results ) {
372
371
throw new FeatureNotSupportedException ("not supported yet." );
373
372
}
@@ -376,6 +375,14 @@ public Object[] batch(List<? extends Row> actions) {
376
375
throw new FeatureNotSupportedException ("not supported yet." );
377
376
}
378
377
378
+ public <R > void batchCallback (List <? extends Row > actions , Object [] results , Batch .Callback <R > callback ) throws IOException , InterruptedException {
379
+ throw new FeatureNotSupportedException ("not supported yet'" );
380
+ }
381
+
382
+ public <R > Object [] batchCallback (List <? extends Row > actions , Batch .Callback <R > callback ) throws IOException , InterruptedException {
383
+ throw new FeatureNotSupportedException ("not supported yet'" );
384
+ }
385
+
379
386
public void getKeyValueFromResult (AbstractQueryStreamResult clientQueryStreamResult ,
380
387
List <KeyValue > keyValueList , boolean isTableGroup ,
381
388
byte [] family ) throws Exception {
@@ -503,9 +510,16 @@ public ResultScanner call() throws IOException {
503
510
|| scan .getFamilyMap ().keySet ().size () == 0 ) {
504
511
filter = buildObHTableFilter (scan .getFilter (), scan .getTimeRange (),
505
512
scan .getMaxVersions (), null );
506
- obTableQuery = buildObTableQuery (filter , scan .getStartRow (), true ,
507
- scan .getStopRow (), false , scan .getBatch ());
508
-
513
+ if (scan .isReversed ()) {
514
+ obTableQuery = buildObTableQuery (filter , scan .getStopRow (), false ,
515
+ scan .getStartRow (), true , scan .getBatch ());
516
+ } else {
517
+ obTableQuery = buildObTableQuery (filter , scan .getStartRow (), true ,
518
+ scan .getStopRow (), false , scan .getBatch ());
519
+ }
520
+ if (scan .isReversed ()) { // reverse scan 时设置为逆序
521
+ obTableQuery .setScanOrder (ObScanOrder .Reverse );
522
+ }
509
523
request = buildObTableQueryAsyncRequest (obTableQuery , tableNameString );
510
524
clientQueryAsyncStreamResult = (ObTableClientQueryAsyncStreamResult ) obTableClient
511
525
.execute (request );
@@ -517,22 +531,16 @@ public ResultScanner call() throws IOException {
517
531
family = entry .getKey ();
518
532
filter = buildObHTableFilter (scan .getFilter (), scan .getTimeRange (),
519
533
scan .getMaxVersions (), entry .getValue ());
520
-
521
- // not support reverse scan.
522
- // 由于 HBase 接口与 OB 接口表达范围的差异,reverse scan 需要交换 startRow 和 stopRow
523
- // if (scan.getReversed()) {
524
- // obTableQuery = buildObTableQuery(filter, scan.getStopRow(), false,
525
- // scan.getStartRow(), true, scan.getBatch());
526
- // } else {
527
- obTableQuery = buildObTableQuery (filter , scan .getStartRow (), true ,
528
- scan .getStopRow (), false , scan .getBatch ());
529
- // }
530
-
531
- // not support reverse scan.
532
- // if (scan.getReversed()) { // reverse scan 时设置为逆序
533
- // obTableQuery.setScanOrder(ObScanOrder.Reverse);
534
- // }
535
-
534
+ if (scan .isReversed ()) {
535
+ obTableQuery = buildObTableQuery (filter , scan .getStopRow (), false ,
536
+ scan .getStartRow (), true , scan .getBatch ());
537
+ } else {
538
+ obTableQuery = buildObTableQuery (filter , scan .getStartRow (), true ,
539
+ scan .getStopRow (), false , scan .getBatch ());
540
+ }
541
+ if (scan .isReversed ()) { // reverse scan 时设置为逆序
542
+ obTableQuery .setScanOrder (ObScanOrder .Reverse );
543
+ }
536
544
// no support set maxResultSize.
537
545
// obTableQuery.setMaxResultSize(scan.getMaxResultSize());
538
546
@@ -802,19 +810,18 @@ public Result increment(Increment increment) throws IOException {
802
810
List <byte []> qualifiers = new ArrayList <byte []>();
803
811
804
812
byte [] rowKey = increment .getRow ();
805
- Map .Entry <byte [], NavigableMap < byte [], Long >> entry = increment .getFamilyMap ()
806
- .entrySet ().iterator ().next ();
813
+ Map .Entry <byte [], List < Cell >> entry = increment .getFamilyCellMap ()
814
+ .entrySet ().iterator ().next ();
807
815
808
816
byte [] f = entry .getKey ();
809
817
810
818
ObTableBatchOperation batch = new ObTableBatchOperation ();
811
- for ( Map . Entry < byte [], Long > qualifiersIncrements : entry .getValue ().entrySet ()) {
812
- byte [] qualifier = qualifiersIncrements . getKey ();
819
+ entry .getValue ().forEach ( cell -> {
820
+ byte [] qualifier = cell . getQualifier ();
813
821
qualifiers .add (qualifier );
814
822
batch .addTableOperation (getInstance (INCREMENT , new Object [] { rowKey , qualifier ,
815
- Long .MAX_VALUE }, V_COLUMNS ,
816
- new Object [] { Bytes .toBytes (qualifiersIncrements .getValue ()) }));
817
- }
823
+ Long .MAX_VALUE }, V_COLUMNS , new Object [] { cell .getValue () }));
824
+ });
818
825
819
826
ObHTableFilter filter = buildObHTableFilter (null , increment .getTimeRange (), 1 ,
820
827
qualifiers );
@@ -890,6 +897,10 @@ public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, lo
890
897
}
891
898
}
892
899
900
+ public long incrementColumnValue (byte [] row , byte [] family , byte [] qualifier , long amount , Durability durability ) throws IOException {
901
+ throw new FeatureNotSupportedException ("not supported yet'" );
902
+ }
903
+
893
904
public long incrementColumnValue (byte [] row , byte [] family , byte [] qualifier , long amount ,
894
905
boolean writeToWAL ) throws IOException {
895
906
// WAL ignored
@@ -1001,31 +1012,18 @@ public void close() throws IOException {
1001
1012
}
1002
1013
}
1003
1014
1004
- public RowLock lockRow (byte [] row ) {
1005
- throw new FeatureNotSupportedException ("not supported yet. " );
1015
+ public CoprocessorRpcChannel coprocessorService (byte [] row ) {
1016
+ throw new FeatureNotSupportedException ("not supported yet' " );
1006
1017
}
1007
1018
1008
- public void unlockRow ( RowLock rl ) {
1009
- throw new FeatureNotSupportedException ("not supported yet. " );
1019
+ public < T extends Service , R > Map < byte [], R > coprocessorService ( Class < T > service , byte [] startKey , byte [] endKey , Batch . Call < T , R > callable ) throws ServiceException , Throwable {
1020
+ throw new FeatureNotSupportedException ("not supported yet' " );
1010
1021
}
1011
1022
1012
- public <T extends CoprocessorProtocol > T coprocessorProxy (Class <T > protocol , byte [] row ) {
1013
- throw new FeatureNotSupportedException ("not supported yet. " );
1023
+ public <T extends Service , R > void coprocessorService (Class <T > service , byte [] startKey , byte [] endKey , Batch . Call < T , R > callable , Batch . Callback < R > callback ) throws ServiceException , Throwable {
1024
+ throw new FeatureNotSupportedException ("not supported yet' " );
1014
1025
}
1015
1026
1016
- public <T extends CoprocessorProtocol , R > Map <byte [], R > coprocessorExec (Class <T > protocol ,
1017
- byte [] startKey ,
1018
- byte [] endKey ,
1019
- Batch .Call <T , R > callable ) {
1020
- throw new FeatureNotSupportedException ("not supported yet." );
1021
- }
1022
-
1023
- public <T extends CoprocessorProtocol , R > void coprocessorExec (Class <T > protocol ,
1024
- byte [] startKey , byte [] endKey ,
1025
- Batch .Call <T , R > callable ,
1026
- Batch .Callback <R > callback ) {
1027
- throw new FeatureNotSupportedException ("not supported yet." );
1028
- }
1029
1027
1030
1028
/**
1031
1029
* See {@link #setAutoFlush(boolean, boolean)}
@@ -1066,6 +1064,10 @@ public void setAutoFlush(boolean autoFlush, boolean clearBufferOnFail) {
1066
1064
this .clearBufferOnFail = autoFlush || clearBufferOnFail ;
1067
1065
}
1068
1066
1067
+ public void setAutoFlushTo (boolean autoFlush ) {
1068
+ throw new FeatureNotSupportedException ("not supported yet'" );
1069
+ }
1070
+
1069
1071
/**
1070
1072
* Returns the maximum size in bytes of the write buffer for this HTable.
1071
1073
* <p>
@@ -1094,6 +1096,18 @@ public void setWriteBufferSize(long writeBufferSize) throws IOException {
1094
1096
}
1095
1097
}
1096
1098
1099
+ public <R extends Message > Map <byte [], R > batchCoprocessorService (Descriptors .MethodDescriptor methodDescriptor , Message request , byte [] startKey , byte [] endKey , R responsePrototype ) throws ServiceException , Throwable {
1100
+ throw new FeatureNotSupportedException ("not supported yet'" );
1101
+ }
1102
+
1103
+ public <R extends Message > void batchCoprocessorService (Descriptors .MethodDescriptor methodDescriptor , Message request , byte [] startKey , byte [] endKey , R responsePrototype , Batch .Callback <R > callback ) throws ServiceException , Throwable {
1104
+ throw new FeatureNotSupportedException ("not supported yet'" );
1105
+ }
1106
+
1107
+ public boolean checkAndMutate (byte [] row , byte [] family , byte [] qualifier , CompareFilter .CompareOp compareOp , byte [] value , RowMutations mutation ) throws IOException {
1108
+ throw new FeatureNotSupportedException ("not supported yet'" );
1109
+ }
1110
+
1097
1111
public void setOperationTimeout (int operationTimeout ) {
1098
1112
this .operationTimeout = operationTimeout ;
1099
1113
this .operationExecuteInPool = this .configuration .getBoolean (
0 commit comments