22
22
import com .google .cloud .bigtable .hbase .adapters .read .RowCell ;
23
23
import com .google .cloud .bigtable .hbase .util .ByteStringer ;
24
24
import com .google .cloud .bigtable .hbase .util .TimestampConverter ;
25
- import com .google .common .annotations .VisibleForTesting ;
26
25
import com .google .common .base .Preconditions ;
27
26
import com .google .common .collect .ImmutableList ;
28
27
import com .google .protobuf .ByteString ;
47
46
* on duplicate labelled cells for its implementation. So this adapter will not deduplicate labelled
48
47
* cells.
49
48
*
49
+ * <p>This adapter will also return and check for scan marker rows, which will be an empty row with
50
+ * the scan marker row label.
51
+ *
50
52
* <p>For internal use only - public for technical reasons.
51
53
*/
52
54
@ InternalApi ("For internal usage only" )
53
55
public class RowResultAdapter implements RowAdapter <Result > {
54
56
55
57
private static final byte [] EMPTY_VALUE = new byte [0 ];
58
+ private static final String SCAN_MARKER_ROW_LABEL = "bigtable-scan-marker-row" ;
56
59
57
60
@ Override
58
61
public RowBuilder <Result > createRowBuilder () {
59
62
return new RowResultBuilder ();
60
63
}
61
64
65
+ /**
66
+ * Checks if the result is a scan marker row. Returns true if the row's family, qualifier, and
67
+ * value are empty, and only has a scan marker row label.
68
+ */
62
69
@ Override
63
70
public boolean isScanMarkerRow (Result result ) {
64
- Preconditions .checkState (result instanceof RowResult , "Should be an instance of RowResult" );
65
- return ((RowResult ) result ).isMarkerRow ();
71
+ if (result .rawCells ().length != 1 || !(result .rawCells ()[0 ] instanceof RowCell )) {
72
+ return false ;
73
+ }
74
+
75
+ RowCell cell = (RowCell ) result .rawCells ()[0 ];
76
+ return cell .getLabels ().size () == 1
77
+ && cell .getLabels ().get (0 ).equals (SCAN_MARKER_ROW_LABEL )
78
+ && cell .getValueArray ().length == 0
79
+ && cell .getFamilyArray ().length == 0
80
+ && cell .getQualifierArray ().length == 0 ;
66
81
}
67
82
68
83
@ Override
69
84
public ByteString getKey (Result result ) {
70
- Preconditions .checkState (result instanceof RowResult , "Should be an instance of RowResult" );
71
- return ((RowResult ) result ).getKey ();
72
- }
73
-
74
- @ VisibleForTesting
75
- static class RowResult extends Result {
76
- private final ByteString rowKey ;
77
- private final boolean isMarkerRow ;
78
-
79
- static RowResult create (ByteString rowKey , List <Cell > cells ) {
80
- return new RowResult (rowKey , false , cells );
81
- }
82
-
83
- static RowResult createMarker (ByteString rowKey ) {
84
- return new RowResult (rowKey , true , ImmutableList .<Cell >of ());
85
- }
86
-
87
- private RowResult (ByteString rowKey , boolean isMarkerRow , List <Cell > cells ) {
88
- this .rowKey = rowKey ;
89
- this .isMarkerRow = isMarkerRow ;
90
-
91
- // Only default ctor of Result is public, so instantiating cells through copyFrom() because
92
- // value(), size(), isEmpty() rawCells() etc. directly usages Result's cells field.
93
- this .copyFrom (Result .create (cells ));
94
- }
95
-
96
- ByteString getKey () {
97
- return rowKey ;
98
- }
99
-
100
- boolean isMarkerRow () {
101
- return isMarkerRow ;
102
- }
85
+ Cell cell = result .rawCells ()[0 ];
86
+ return ByteStringer .wrap (cell .getRowArray (), cell .getRowOffset (), cell .getRowLength ());
103
87
}
104
88
105
89
static class RowResultBuilder implements RowBuilder <Result > {
@@ -226,7 +210,7 @@ public Result finishRow() {
226
210
combined .addAll (familyCellList );
227
211
}
228
212
229
- return RowResult .create (currentKey , combined .build ());
213
+ return Result .create (combined .build ());
230
214
}
231
215
232
216
@ Override
@@ -243,9 +227,21 @@ public void reset() {
243
227
this .previousNoLabelCell = null ;
244
228
}
245
229
230
+ /**
231
+ * Creates a marker row with rowKey with a scan marker row label and empty family, qualifier and
232
+ * value.
233
+ */
246
234
@ Override
247
235
public Result createScanMarkerRow (ByteString rowKey ) {
248
- return RowResult .createMarker (rowKey );
236
+ return Result .create (
237
+ ImmutableList .<Cell >of (
238
+ new RowCell (
239
+ ByteStringer .extract (rowKey ),
240
+ EMPTY_VALUE ,
241
+ EMPTY_VALUE ,
242
+ 0l ,
243
+ EMPTY_VALUE ,
244
+ ImmutableList .<String >of (SCAN_MARKER_ROW_LABEL ))));
249
245
}
250
246
}
251
247
}
0 commit comments