Skip to content

Add ranges to the cache seek API - #304

Merged
em3s merged 2 commits into
mainfrom
fix/cache-compound
May 7, 2026
Merged

em3s merged 2 commits into
mainfrom
fix/cache-compound

Conversation

@zipdoki

@zipdoki zipdoki commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a ranges query parameter to the cache seek API. Predicates form a leading prefix of the cache's fields and translate to a single HBase ColumnRangeFilter over the qualifier bytes. Per-field Order is honored by OrderedBytes (DESC fields are bit-inverted at write time), so the forward column scan yields the declared compound order with no scan-direction handling required.

Closes #303

Changes

  • Plumb ranges: String? from EdgeQueryController and ActionbaseQuery.Item.Seek through QueryService.seek → TableBinding.seek → Label.cache → HBaseIndexedLabel.cache.
  • Validate predicates at V2BackedTableBinding.seek (matching scan): leading-prefix order, trailing-only range, and IN rejection.
  • Add HBaseIndexedLabel.encodeCacheRange to resolve predicates plus offset into one (from, to) byte range; offset, when present, supersedes the predicate-derived from.
  • Add QualifierStartStop/QualifierStartStopItem as the cache-side analogue of IndexedLabelMixin.StartStop/StartStopItem (collapsible in a follow-up).
  • Drop the order parameter and the from/to swap from hbaseGetWideRow; bytes are byte-ordered upstream, so the swap was a no-op.
  • Add ByteArrayBuffer.plusOne (Kotlin port of EdgeBuffer.plusOne) for exclusive boundary bytes on the cache encoder path.

How to Test

  • ./gradlew :core:test --tests "com.kakao.actionbase.core.edge.mapper.EdgeCacheRecordMapperTest"
  • ./gradlew :server:test --tests "com.kakao.actionbase.server.api.graph.v3.EdgeCacheQueryE2ETest"
  • ./gradlew spotlessCheck

AI Assistance

  • This PR was written largely with AI assistance.
    • Tool / model: Claude Code (Opus 4.7, 1M context)

zipdoki and others added 2 commits May 7, 2026 10:11
Mirrors EdgeBuffer.plusOne (codec-java) so Kotlin call sites that
operate on ByteArrayBuffer/SimplePositionedMutableByteRange directly
can construct exclusive boundary bytes for HBase ColumnRangeFilter
without going through an EdgeBuffer wrapper.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Lets callers constrain a wide-row cache scan by leading-prefix predicates,
mirroring the existing ranges parameter on scan (index). Predicates are
translated to a single HBase ColumnRangeFilter start/stop; per-field Order
is honoured by OrderedBytes (DESC fields are bit-inverted at write time),
so a forward column scan over the resulting byte range yields the declared
compound order without any scan-direction handling.

Constraints, dictated by HBase wide-row physics, are enforced at the
TableBinding boundary (matching scan):
- predicates form a contiguous leading prefix of the cache's fields
- only the trailing predicate may be a range; preceding predicates must be `=`
- IN is rejected (would require disjoint byte ranges)

Plumbed through QueryService.seek -> TableBinding.seek -> Label.cache ->
HBaseIndexedLabel.cache. Range encoding is centralised in encodeCacheRange,
which mirrors IndexedLabelMixin.createStartStop and reuses the same plusOne
convention for inclusive/exclusive prefix bounds. The new
QualifierStartStop / QualifierStartStopItem types are the cache-side
analogue of IndexedLabelMixin.StartStop / StartStopItem; a follow-up can
collapse the two once StartStopItem drops its field reference.

Two small refactors fall out of the change:
- hbaseGetWideRow no longer takes an Order. Bytes are byte-ordered upstream,
  so the previous from/to swap was a no-op.
- IN predicates are explicitly rejected at the binding rather than failing
  deeper.

Closes #303

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zipdoki zipdoki self-assigned this May 7, 2026
@zipdoki
zipdoki requested a review from em3s as a code owner May 7, 2026 04:26
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels May 7, 2026

fun ByteArrayBuffer.hasRemaining(): Boolean = remaining > 0

fun ByteArrayBuffer.plusOne(): ByteArrayBuffer {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@em3s
Direct Kotlin port of EdgeBuffer.plusOne (codec-java); exposed as a ByteArrayBuffer extension so the cache prefix encoder doesn't need to wrap in an EdgeBuffer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good 👍

@em3s
em3s removed their request for review May 7, 2026 04:35
@em3s em3s closed this May 7, 2026
@em3s em3s reopened this May 7, 2026
@zipdoki zipdoki closed this May 7, 2026
@zipdoki zipdoki reopened this May 7, 2026
@em3s em3s added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels May 7, 2026
@zipdoki zipdoki changed the title Add ranges to the cache seek API Add ranges to the cache seek API May 7, 2026
@zipdoki zipdoki changed the title Add ranges to the cache seek API Add ranges to the cache seek API May 7, 2026
@em3s

em3s commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Nice Work! @zipdoki

Optimistic merging.

As discussed offline, follow-up PR to:

  • Align scan and seek signatures.
  • seek is backed by multi-scan, so the source parameter should be List<Any> to match

@em3s
em3s merged commit 07c57a9 into main May 7, 2026
9 checks passed
@em3s

em3s commented May 7, 2026

Copy link
Copy Markdown
Contributor

Close #303

@em3s
em3s deleted the fix/cache-compound branch May 7, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ranges to the cache seek API

2 participants