keith-turner commented on code in PR #3480:
URL: https://github.com/apache/accumulo/pull/3480#discussion_r1263185947
##########
core/src/main/java/org/apache/accumulo/core/metadata/StoredTabletFile.java:
##########
@@ -121,11 +150,105 @@ public String toString() {
* Validates that the provided metadata string for the StoredTabletFile is
valid.
*/
public static void validate(String metadataEntry) {
- ReferencedTabletFile.parsePath(new Path(URI.create(metadataEntry)));
+ ReferencedTabletFile.parsePath(deserialize(metadataEntry).path);
+ }
+
+ public static StoredTabletFile of(final Text metadataEntry) {
+ return new
StoredTabletFile(Objects.requireNonNull(metadataEntry).toString());
}
public static StoredTabletFile of(final String metadataEntry) {
return new StoredTabletFile(metadataEntry);
}
+ public static StoredTabletFile of(final URI path, Range range) {
+ return of(new Path(Objects.requireNonNull(path)), range);
+ }
+
+ public static StoredTabletFile of(final Path path, Range range) {
+ return new StoredTabletFile(new TabletFileCq(Objects.requireNonNull(path),
range));
+ }
+
+ private static final Gson gson =
ByteArrayToBase64TypeAdapter.createBase64Gson();
+
+ private static TabletFileCq deserialize(String json) {
+ final TabletFileCqMetadataGson metadata =
+ gson.fromJson(Objects.requireNonNull(json),
TabletFileCqMetadataGson.class);
+ // If we have previously enforced the exclusive/inclusive of a range then
can just set that here
+ return new TabletFileCq(new Path(URI.create(metadata.path)),
+ new Range(decodeRow(metadata.startRow), false,
decodeRow(metadata.endRow), true));
Review Comment:
Could probably avoid encoding the entire Key with the following change.
```suggestion
new Range(decodeRow(metadata.startRow), true,
decodeRow(metadata.endRow), false));
```
The reason being if you look at this [Range
constructor](https://github.com/apache/accumulo/blob/0a3feba20f2a0d0d542748776777969ba9dcd9b1/core/src/main/java/org/apache/accumulo/core/data/Range.java#L115-L124)
it does a few things.
* It does not mutate the start row when startRowInclusive is true, it takes
it as is.
* It does not mutate the end row when endRowInclusive is false, it takes it
as is.
* No matter what startRowInclusive and endRowInclusive are set to, the
inclusivity of the range is always true, false.
I wrote the following little unit test to double check this and it passed.
```java
@Test
public void testMisc() {
Range range1 = new Range("abc", false, "def", true);
Range range2 = new Range(range1.getStartKey().getRow(), true,
range1.getEndKey().getRow(), false);
assertEquals(range1, range2);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]