JanusGraph / janusgraph-foundationdb

FoundationDB storage adapter for JanusGraph
Other
54 stars 18 forks source link

getSlice() and getSlices() do not work as expected #9

Closed rngcntr closed 4 years ago

rngcntr commented 4 years ago

Disclaimer: I did not find any documentation of KVQuery covering the expected behavior, so this might even be expected but I strongly refuse to believe it is.

When calling getSlice() or getSlices(), these methods receive a KVQuery object as a parameter to define the query. This object includes both a limit for the number of results returned and a KeySelector which filters all considered keys. This can cause the following problem:

Assume the following keys in the database: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}

Furthermore, assume a range [1, 16) and a limit of 8. The given KeySelector accepts all even keys while rejecting odd ones. Now the limit enforcement will narrow down the retreived keys to {0, 1, 2, 3, 4, 5, 6, 7} from which the KeySelector will select {0, 2, 4, 8}. Consequently, only four key-value pairs are returned although there are eight keys within the range that satisfy the conditions.

Looking at the way getRange() works in FoundationDB, I don't see any particularly good solution other than extending the limit over and over again until enough matching values are found.

rngcntr commented 4 years ago

Turns out I was wrong. This is actually intended behavior. I will open a PR for JanusGraph to improve the documentation of their KeySelector.