apple / apple/foundationdb

[Java] the KeySelector API is unclear

Open
#4,364 5 comments 0 reactions 1 assignee Claimed by @scottfines View on GitHub
Dominant language
C++
Stars
16.7k
Forks
1.6k
Avg merge
1d 20h
Merged PRs (30d)
126

Description

The KeySelector API is slightly unclear, and it should be possible to make it a little more useable in practice.

In particular, imagine wanting to perform a range scan on the interval `[A,B)`. All `getRange()` calls in `ReadTransaction` are inclusive on start and exclusive on end, so it should be possible to write `getRange([A,B))` for all the possible `getRange` methods. For the `byte[]` and `Range` versions, this is pretty trivial. However, when using `KeySelector`, the API becomes confusing.

In order to do `getRange([A,B))` using `KeySelector`s, you have to issue

```
getRange(KeySelector.firstGreaterOrEqual(A),KeySelector.firstGreaterOrEqual(B))
```
which is confusing, because an instinctive (and incorrect) reading of the API would suggest that you would want
```
getRange(KeySelector.firstGreaterOrEqual(A),KeySelector.lastLessOrEqual(B))`
```
But doing that would be incorrect.

It would be nice (not essential, but nice) if there was a syntactically clean way of getting that particular scan correct. I propose adding a `KeySelector.exact()` functionality which would emulate the `firstGreaterOrEqual` in practice, but visually would look more obvious:
```
getRange(KeySelector.exact(A),KeySelector.exact(B))
```
is obviously a scan on `[A,B)` and will capture the intent of the caller without any special understanding by the caller themself.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.