@@ -467,16 +467,18 @@ public boolean exists(Get get) throws IOException {
467
467
@ Override
468
468
public boolean [] existsAll (List <Get > gets ) throws IOException {
469
469
boolean [] ret = new boolean [gets .size ()];
470
- if (ObGlobal .isHBaseBatchGetSupport ()) {
471
- Result [] results = new Result [gets .size ()];
472
- batch (gets , results );
473
- for (int i = 0 ; i < gets .size (); ++i ) {
474
- ret [i ] = !results [i ].isEmpty ();
475
- }
476
- } else {
477
- for (int i = 0 ; i < gets .size (); ++i ) {
478
- ret [i ] = exists (gets .get (i ));
479
- }
470
+ List <Get > newGets = new ArrayList <>();
471
+ // if just checkExistOnly, batch get will not return any result or row count
472
+ // therefore we have to set checkExistOnly as false and so the result can be returned
473
+ // TODO: adjust ExistOnly in server when using batch get
474
+ for (Get get : gets ) {
475
+ Get newGet = new Get (get );
476
+ newGet .setCheckExistenceOnly (false );
477
+ newGets .add (newGet );
478
+ }
479
+ Result [] results = get (newGets );
480
+ for (int i = 0 ; i < results .length ; ++i ) {
481
+ ret [i ] = !results [i ].isEmpty ();
480
482
}
481
483
return ret ;
482
484
}
@@ -671,33 +673,13 @@ public void batch(final List<? extends Row> actions, final Object[] results) thr
671
673
batchError .add ((ObTableException ) tmpResults .getResults ().get (index ), actions .get (i ), null );
672
674
} else if (actions .get (i ) instanceof Get ) {
673
675
if (results != null ) {
676
+ // get results have been wrapped in MutationResult, need to fetch it
674
677
if (tmpResults .getResults ().get (index ) instanceof MutationResult ) {
675
678
MutationResult mutationResult = (MutationResult ) tmpResults .getResults ().get (index );
676
679
ObPayload innerResult = mutationResult .getResult ();
677
680
if (innerResult instanceof ObTableSingleOpResult ) {
678
681
ObTableSingleOpResult singleOpResult = (ObTableSingleOpResult ) innerResult ;
679
- ObTableSingleOpEntity singleOpEntity = singleOpResult .getEntity ();
680
- List <ObObj > propertiesValues = singleOpEntity .getPropertiesValues ();
681
- List <Cell > cells = new ArrayList <>();
682
- int valueIdx = 0 ;
683
- while (valueIdx < propertiesValues .size ()) {
684
- byte [][] familyAndQualifier = new byte [2 ][];
685
- try {
686
- // split family and qualifier
687
- familyAndQualifier = OHBaseFuncUtils
688
- .extractFamilyFromQualifier ((byte []) propertiesValues .get (valueIdx + 1 ).getValue ());
689
- } catch (Exception e ) {
690
- throw new IOException (e );
691
- }
692
- KeyValue kv = new KeyValue ((byte []) propertiesValues .get (valueIdx ).getValue (),//K
693
- familyAndQualifier [0 ], // family
694
- familyAndQualifier [1 ], // qualifiermat
695
- (Long ) propertiesValues .get (valueIdx + 2 ).getValue (), // T
696
- (byte []) propertiesValues .get (valueIdx + 3 ).getValue ()// V
697
- );
698
- cells .add (kv );
699
- valueIdx += 4 ;
700
- }
682
+ List <Cell > cells = generateGetResult (singleOpResult );
701
683
results [i ] = Result .create (cells );
702
684
} else {
703
685
throw new ObTableUnexpectedException ("Unexpected type of result in MutationResult" );
@@ -719,6 +701,37 @@ public void batch(final List<? extends Row> actions, final Object[] results) thr
719
701
}
720
702
}
721
703
704
+ private List <Cell > generateGetResult (ObTableSingleOpResult getResult ) throws IOException {
705
+ List <Cell > cells = new ArrayList <>();
706
+ ObTableSingleOpEntity singleOpEntity = getResult .getEntity ();
707
+ // all values queried by this get are contained in properties
708
+ // qualifier in batch get result is always appended after family
709
+ List <ObObj > propertiesValues = singleOpEntity .getPropertiesValues ();
710
+ int valueIdx = 0 ;
711
+ while (valueIdx < propertiesValues .size ()) {
712
+ // values in propertiesValues like: [ K, Q, T, V, K, Q, T, V ... ]
713
+ // we need to retrieve K Q T V and construct them to cells: [ cell_0, cell_1, ... ]
714
+ byte [][] familyAndQualifier = new byte [2 ][];
715
+ try {
716
+ // split family and qualifier
717
+ familyAndQualifier = OHBaseFuncUtils
718
+ .extractFamilyFromQualifier ((byte []) propertiesValues .get (valueIdx + 1 ).getValue ());
719
+ } catch (Exception e ) {
720
+ throw new IOException (e );
721
+ }
722
+ KeyValue kv = new KeyValue ((byte []) propertiesValues .get (valueIdx ).getValue (),//K
723
+ familyAndQualifier [0 ], // family
724
+ familyAndQualifier [1 ], // qualifiermat
725
+ (Long ) propertiesValues .get (valueIdx + 2 ).getValue (), // T
726
+ (byte []) propertiesValues .get (valueIdx + 3 ).getValue ()// V
727
+ );
728
+ cells .add (kv );
729
+ valueIdx += 4 ;
730
+ }
731
+ return cells ;
732
+ }
733
+
734
+
722
735
private String getTargetTableName (List <? extends Row > actions ) {
723
736
byte [] family = null ;
724
737
for (Row action : actions ) {
0 commit comments