Skip to content

Encode EdgeGroup records in the bulk-load path (BulkEdgeEncoder) - #397

Merged
zipdoki merged 15 commits into
mainfrom
feat/bulk-load-edge-group
Jul 28, 2026
Merged

zipdoki merged 15 commits into
mainfrom
feat/bulk-load-edge-group

Conversation

@eazyhozy

@eazyhozy eazyhozy commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

The bulk-load encoding path (BulkEdgeEncoder.bulkEncodeAll in codec-java) only encoded EdgeState/EdgeIndex/EdgeCache/EdgeCount from a BulkLoadEdge. It never encoded EdgeGroup (aggregation) records, so tables initialized via bulk-load had empty aggregation data until it accumulated incrementally through the online write path.

This PR ports the online (V3) group-encoding model into codec-java (V2) and wires it into BulkEdgeEncoder, so bulk-loaded edges emit EdgeGroup records too.

Closes #389

Changes

  • metadata/Bucket.java (new): ports V3's date bucket — epoch value → formatted string — used to bucket group fields (e.g. daily aggregation). Query-time handleQueryValue is intentionally not ported; bulk encoding only ever applies buckets to concrete property values.
  • metadata/Group.java: Group.Field gains an optional bucket and an applyBucket helper.
  • code/EdgeEncoder.java / code/AbstractEdgeEncoder.java / code/BytesKeyValueEdgeEncoder.java / code/StringKeyFieldValueEdgeEncoder.java: new encodeGroupEdge/encodeAllGroupEdges methods mirroring the existing EdgeCache encoding path. Encodes the full V3-compatible EdgeGroup record bytes for a single edge — row key (hash|directedSrc|labelId|EDGE_GROUP|direction|groupCode), qualifier (bucketed groupValues, Order.DESC, matching EdgeGroupRecordMapper's GROUP_RECORD_ORDER), and this edge's single contribution as a raw 8-byte long (1 for COUNT, the valueField's value for SUM) — matching the raw buffer.long V3 uses for its HBase Increment cell, not an OrderedBytes header.
  • code/BulkEdgeEncoder.java: wires EdgeGroup encoding into bulkEncodeAll for INDEXED and MULTI_EDGE labels, one row per (group, direction), iterating each group's own directionType (not the label's) — matching V3 EdgeMutationBuilder.buildGroupRecords. Skips the __count__ sentinel group, matching core's online mutation path (Skip __count__ sentinel group in mutation path #396) — it delegates to the native EdgeCount query and never persists an EdgeGroup row.
  • Tests: BulkEdgeEncoderTests, MultiEdgeBulkEdgeEncoderTests, BucketTests (codec-java), and V2MultiEdgeBulkLoadTest (core) — the bulk-encoded group key/qualifier/value round-trips through V3's EdgeGroupRecordMapper decoder byte-for-byte, the same safety net already used for EdgeCount/EdgeCache.

Out of scope

Consuming these EDGE_GROUP_TYPE records downstream (aggregating per-edge contributions into absolute cell values, writing to HFiles) happens in the external bulk-load pipeline, not in this repo. This follows the same two-step precedent as EdgeCache: land the codec encoding first, update the pipeline separately.

How to Test

./gradlew :codec-java:test
./gradlew :core:test --tests "*V2MultiEdgeBulkLoadTest*"

All tests pass, including the existing count/cache round-trips and the groups-absent backward-compatibility case.

AI Assistance

  • This PR was written largely with AI assistance.
    • Tool / model: Claude Code (Sonnet 5)

eazyhozy added 4 commits July 8, 2026 13:44
Groups commonly bucket a field by time (e.g. daily aggregation), but
codec-java's Group.Field had no way to express that — only V3's
metadata.common.Group.Field carried a `bucket`. Port the `date`
Bucket variant from V3 (epoch value -> formatted string) and add an
optional `bucket` to Group.Field with an `applyBucket` helper,
matching V3 EdgeMutationBuilder's `field.bucket?.apply(value)`.

Query-time `handleQueryValue` is intentionally not ported — bulk
encoding only ever applies buckets to concrete property values.

Ref #389
Mirrors the existing EdgeCache encoding path (row key + qualifier +
value, per-direction) so EdgeGroup can be encoded the same way once
BulkEdgeEncoder wires it in. Encodes the full V3-compatible EdgeGroup
record bytes for a single edge: row key (hash|directedSrc|labelId|
EDGE_GROUP|direction|groupCode), qualifier (bucketed groupValues,
Order.DESC — matching EdgeGroupRecordMapper's GROUP_RECORD_ORDER),
and this edge's single contribution as a raw 8-byte long (1 for
COUNT, the valueField's value for SUM) — matching the raw `buffer.long`
V3 uses for its HBase Increment cell, not an OrderedBytes header.

encodeAllGroupEdges iterates each group's own directionType (not the
label's), matching V3 EdgeMutationBuilder.buildGroupRecords, and
skips the "__count__" sentinel group — it delegates to the native
EdgeCount query and never persists an EdgeGroup row, matching core's
EdgeMutationBuilder.groupNamesExcludedFromMutation (#396).

Ref #389
BulkEdgeEncoder.bulkEncodeAll only encoded EdgeState/EdgeIndex/
EdgeCache/EdgeCount from a BulkLoadEdge, so tables initialized via
bulk-load had no aggregation data until it accumulated incrementally
through the online write path. Wire the new group encoder methods
in for INDEXED and MULTI_EDGE labels, emitting one EDGE_GROUP_TYPE
row per (group, direction) — same "__count__" sentinel skip as
core's online mutation path.

Verified with:
- codec-java unit tests: COUNT/SUM group encoding, bucketed field
  qualifiers, "__count__" sentinel skip, groups-absent backward
  compatibility, and a MULTI_EDGE group encoding case.
- core's V2MultiEdgeBulkLoadTest: bulk-encoded group key/qualifier/
  value round-trips through V3's EdgeGroupRecordMapper decoder byte-
  for-byte, the same safety net already used for EdgeCount/EdgeCache.

Ref #389
No behavior change — googleJavaFormat/import-order fixups only.
@eazyhozy eazyhozy self-assigned this Jul 8, 2026
eazyhozy added 5 commits July 8, 2026 14:55
Per review feedback on #397: EncodedEdgeType declares EDGE_GROUP_TYPE
(-5) before EDGE_CACHE_TYPE (-6), but the constant declarations and
encoding blocks in AbstractEdgeEncoder/EdgeEncoder/both encoder
implementations had EdgeCache before EdgeGroup. Reorder them to
match the type-code order for a consistent read-through.

No behavior change — pure reordering.
encodeRawInt64 wrote the raw 8 bytes with no OrderedBytes header at
all, so "encode" was misleading next to encodeInt64/encodeInt32
(which do apply OrderedBytes headers). Rename to putRawInt64 to make
the plain-passthrough behavior clear, keeping the Int64 naming
consistent with encodeInt64/OrderedBytes.decodeInt64.

No behavior change.
core's EdgeMutationBuilder skips reserved group names via
groupNamesExcludedFromMutation, a Set<String>, rather than comparing
against a single sentinel string. Mirror that shape here with
GROUP_NAMES_EXCLUDED_FROM_ENCODING so both the INDEXED path
(encodeAllGroupEdges) and the MULTI_EDGE path (BulkEdgeEncoder's
manual loop) share one definition, and adding a future reserved name
only touches one place.

No behavior change — still skips exactly "__count__".
Only MILLISECOND and SECOND had apply() coverage. Add MICROSECOND
and NANOSECOND cases, all pinned to the same instant
(2026-06-11T00:00:00+09:00) via shared epoch constants so the four
tests are directly comparable.
Three gaps identified in review:

- Bucketed group fields were only tested on the INDEXED path
  (encodeAllGroupEdges). Add the same case for MULTI_EDGE, since
  BulkEdgeEncoder wires it in via a separate manual per-direction
  loop that could silently diverge.
- The INDEXED path's EdgeGroup bytes had no round-trip through V3's
  EdgeGroupRecordMapper decoder — only MULTI_EDGE did. Add the
  INDEXED equivalent to V2MultiEdgeBulkLoadTest so a divergence in
  either code path is caught.
- Group fields may reference the system properties
  "version"/"source"/"target" instead of an edge property name
  (shared resolveFieldValue switch with EdgeCache), but no group
  test exercised that branch. Add one case for "target" resolving to
  the direction-flipped directedTgt.
@eazyhozy
eazyhozy marked this pull request as ready for review July 13, 2026 08:20
@eazyhozy
eazyhozy requested a review from em3s as a code owner July 13, 2026 08:20
@dosubot dosubot Bot added enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 13, 2026
@eazyhozy
eazyhozy requested a review from zipdoki July 13, 2026 08:22
eazyhozy added 2 commits July 13, 2026 18:48
Per review feedback on #397: MULTI_EDGE's group-encoding block
hand-rolled its own filter+direction-fanout loop instead of reusing
EdgeEncoder's shared dispatch, unlike EdgeCache — which reuses
encodeAllCacheEdges per-direction via outEdge/inEdge. Add
EdgeEncoder.encodeGroupEdgesForDirection(dir, ...), sharing the same
sentinel-exclusion filter as encodeAllGroupEdges, and have
BulkEdgeEncoder call it once per direction with pre-built
outEdge/inEdge — mirroring the EdgeCache MULTI_EDGE branch shape.

Fixed a bug the hand-rolled loop didn't have but a naive refactor
introduced: a group's own directionType must stay independent of the
label's dirType (matching V3 EdgeMutationBuilder.buildGroupRecords),
so outEdge/inEdge are always built for MULTI_EDGE groups regardless
of label.getDirType() — unlike the label-dirType-gated indexed/cache
blocks above them. Added
testMultiEdgeGroupDirectionIsIndependentOfLabelDirType to cover this.

No behavior change to existing passing tests; all round-trip bytes
in V2MultiEdgeBulkLoadTest remain identical.
Per review feedback on #397: the EdgeGroup tests added in this PR
reused the pre-existing "gift.like_product_v1_20240402_132500" /
"Coffee10" fixture strings from the EdgeCache tests they were
patterned after. New test code shouldn't carry that naming forward,
so switch the group-only tests to generic names
("example.group_test_v1"/"example.group_test_indexed_v1", "Item10").
Bytes in V2MultiEdgeBulkLoadTest's round-trip tests were re-captured
against the new fixture.

Pre-existing EdgeState/EdgeIndex/EdgeCache/EdgeCount tests that
predate this PR are left untouched — out of scope here.

No behavior change.
@em3s

em3s commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Is this ready for review? @eazyhozy

As with the previous EdgeCache work, please verify that EdgeGroup works correctly in the internal bulkload path and share the test results.

#309 (comment)

The javadoc comment edited in 18bd341 wasn't re-run through
spotlessApply, so CI's spotlessJavaCheck failed on line-wrap
placement. No behavior change.
@eazyhozy

Copy link
Copy Markdown
Member Author

@em3s To verify the bulk-load path end-to-end without relying on the internal pipeline, I'd like to add a test in core that simulates the pipeline's aggregation step: encode several edges via BulkEdgeEncoder, group-by (row key, qualifier) + sum their per-edge contributions, and assert the result matches what the online path (EdgeMutationBuilder) produces for the same edges.

This would sit alongside the existing V2MultiEdgeBulkLoadTest and EdgeMutationBuilderTest in core. Does this address the verification concern?

@em3s

em3s commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

That's a great approach and worth adding.

However, to be completely confident, we still need to see it work end-to-end. Please run the internal pipeline test and share the results as well.

@eazyhozy

eazyhozy and others added 2 commits July 21, 2026 10:48
Simulate the external bulk-load pipeline's aggregation step in-process:
encode several edges via BulkEdgeEncoder (V2), decode the EdgeGroup rows
through V3's EdgeGroupRecordMapper, group-by (row key, qualifier) and sum
each edge's per-cell contribution, then assert the result matches what the
online path (EdgeMutationBuilder) produces for the same edges.

The single-edge byte-for-byte round-trip is already covered by
V2MultiEdgeBulkLoadTest; this adds the multi-edge group-by-and-sum semantics.
Edges are chosen so several land in the same group bucket, exercising the
sum rather than a trivial one-contribution-per-cell case.

Adds codec-java as a test-only dependency of core (no cycle: codec-java has
no dependency on core).
Exclude derived date formatting fields from Java serialization and
rebuild them after deserialization so Bucket.Date remains usable.

Tested: BucketTests
Tested: :codec-java:spotlessCheck

🤖 Generated with Codex (gpt-5.5)

Co-Authored-By: Codex <[email protected]>
# Conflicts:
#	codec-java/src/main/java/com/kakao/actionbase/v2/core/metadata/Group.java
@eazyhozy

Copy link
Copy Markdown
Member Author

@em3s Ran the end-to-end test on the internal pipeline — confirmed that EdgeGroup data is generated correctly through the bulk-load path.

@eazyhozy

Copy link
Copy Markdown
Member Author

@em3s Follow-up with the full-scale end-to-end result. The earlier verification I posted was from a run that turned out to be incomplete: the bulk pipeline's encode step was writing the per-edge EdgeGroup contributions to HFiles without the group-by-and-sum aggregation, so same-bucket cells collapsed instead of accumulating. That aggregation is the pipeline's responsibility by design (as covered in V2BulkLoadAggregationTest), and after adding it on the pipeline side (group by row key + qualifier, sum contributions), the full end-to-end run passed: aggregated counts are correct across both whole-period and time-bucketed groups, verified against sampled anchor edges including events from 8 years back. Removing the duplicate rows also cut the bulk-loaded HBase row count by ~63%. No codec-java changes were needed — the encoder contract here (one contribution per edge, COUNT=1 / SUM=valueField, matching the online mutation path) held up as-is.

@em3s

em3s commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Good job! Noted that the internal tests have passed. @eazyhozy

Please merge after a final check. @zipdoki

@em3s
em3s removed their request for review July 27, 2026 23:43
@em3s
em3s removed the request for review from zipdoki July 27, 2026 23:43
@zipdoki

zipdoki commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Optimistic merge.

@zipdoki
zipdoki merged commit f03180d into main Jul 28, 2026
2 checks passed
@zipdoki
zipdoki deleted the feat/bulk-load-edge-group branch July 28, 2026 02:03
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.

Encode EdgeGroup records in the bulk-load path (BulkEdgeEncoder)

3 participants