Navigate to map items by key, then select items by relative index offset.
// Get all items starting from key + offset
.bin("map").onMapKeyRelativeIndexRange(key, indexOffset).getValues()
// Get limited items starting from key + offset
.bin("map").onMapKeyRelativeIndexRange(key, indexOffset, count).getValues()Supported Key Types: long, String, byte[]
Navigate to map items by value, then select items by relative rank offset.
// Get all items starting from value + rank offset
.bin("map").onMapValueRelativeRankRange(value, rankOffset).getValues()
// Get limited items starting from value + rank offset
.bin("map").onMapValueRelativeRankRange(value, rankOffset, count).getValues()Supported Value Types: long, String, byte[]
All relative range navigation methods support these terminal actions:
| Action | Description | Example |
|---|---|---|
getValues() |
Retrieve values in range | .onMapKeyRelativeIndexRange("key", 2).getValues() |
getKeys() |
Retrieve keys in range | .onMapKeyRelativeIndexRange("key", 2).getKeys() |
count() |
Count items in range | .onMapKeyRelativeIndexRange("key", 2).count() |
countAllOthers() |
Count items NOT in range | .onMapKeyRelativeIndexRange("key", 2).countAllOthers() |
remove() |
Remove items in range | .onMapKeyRelativeIndexRange("key", 2).remove() |
removeAllOthers() |
Remove items NOT in range | .onMapKeyRelativeIndexRange("key", 2).removeAllOthers() |
// Get next 10 items after "lastKey"
.bin("items")
.onMapKeyRelativeIndexRange(lastKey, 1, 10)
.getValues()// Get top 5 highest values
.bin("scores")
.onMapValueRelativeRankRange(Long.MAX_VALUE, -5, 5)
.getValues()// Remove 3 lowest-ranked items
.bin("scores")
.onMapValueRelativeRankRange(0L, 0, 3)
.remove()// Get 5 items starting 2 ranks below value 100
.bin("data")
.onMapValueRelativeRankRange(100L, -2, 5)
.getValues()// Count items in top 25% (assuming 100 items)
.bin("scores")
.onMapValueRelativeRankRange(Long.MAX_VALUE, -25, 25)
.count()- Positive: Move forward from the reference key
- Negative: Move backward from the reference key
- 0: Start at the reference key
- Positive: Move to higher ranks (higher values)
- Negative: Move to lower ranks (lower values)
- 0: Start at the rank of the reference value
- Omitted: Get all items from offset to end
- Positive: Get exactly N items (or less if not enough available)
| Feature | Traditional Range | Relative Range |
|---|---|---|
| Selection | Absolute start/end | Relative to reference |
| Parameters | (startKey, endKey) |
(referenceKey, offset) |
| Flexibility | Fixed boundaries | Dynamic based on reference |
| Use Case | Known exact range | Pagination, windowing |
Both BinBuilder and CdtGetOrRemoveBuilder support these methods:
// Via BinBuilder (from Operation)
session.upsert(key)
.bin("myMap")
.onMapKeyRelativeIndexRange(...)
// Via CdtGetOrRemoveBuilder (during navigation)
session.upsert(key)
.bin("outer")
.onMapKey("inner")
.onMapKeyRelativeIndexRange(...)All methods are type-safe and return appropriate builder interfaces:
CdtActionInvertableBuilder onMapKeyRelativeIndexRange(long key, int index)
CdtActionInvertableBuilder onMapKeyRelativeIndexRange(String key, int index)
CdtActionInvertableBuilder onMapKeyRelativeIndexRange(byte[] key, int index)Invertable: Supports countAllOthers() and removeAllOthers()
The typo in method name has been fixed:
// Old (deprecated but still works)
.onMapKeuRange(10L, 20L)
// New (recommended)
.onMapKeyRange(10L, 20L)// Setup
ClusterDefinition clusterDef = new ClusterDefinition("localhost", 3000);
Cluster cluster = clusterDef.connect();
Session session = cluster.session();
DataSet dataSet = DataSet.of("test", "users");
// Operation: Get 5 scores starting from "Charlie" + 2 positions
RecordStream results = session.upsert(dataSet.id("class123"))
.bin("scores")
.onMapKeyRelativeIndexRange("Charlie", 2, 5)
.getValues()
.execute();
// Process results
results.forEach(record -> {
System.out.println("Result: " + record);
});// KEY RELATIVE INDEX (sorted by key)
.onMapKeyRelativeIndexRange(key, offset) // Unbounded
.onMapKeyRelativeIndexRange(key, offset, n) // Get n items
// VALUE RELATIVE RANK (sorted by value)
.onMapValueRelativeRankRange(val, offset) // Unbounded
.onMapValueRelativeRankRange(val, offset, n) // Get n items
// ACTIONS
.getValues() // Get values
.getKeys() // Get keys
.count() // Count items
.countAllOthers() // Count inverted
.remove() // Remove items
.removeAllOthers() // Remove inverted- Relative range operations are server-side operations (efficient)
- Suitable for large maps where client-side filtering would be expensive
- Use count parameter to limit data transfer
- Combine with inverted operations to process complementary sets
- Full Documentation:
CDT_ENHANCEMENTS_SUMMARY.md - Code Examples:
RelativeRangeExamples.java - Syntax Guide:
SYNTAX_GUIDE.md - API Documentation:
API_DOCUMENTATION.md