Repository navigation
Encode EdgeGroup records in the bulk-load path (BulkEdgeEncoder) - #397
Conversation
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.
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.
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.
|
Is this ready for review? @eazyhozy As with the previous |
The javadoc comment edited in 18bd341 wasn't re-run through spotlessApply, so CI's spotlessJavaCheck failed on line-wrap placement. No behavior change.
|
@em3s To verify the bulk-load path end-to-end without relying on the internal pipeline, I'd like to add a test in This would sit alongside the existing |
|
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. |
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
|
@em3s Ran the end-to-end test on the internal pipeline — confirmed that EdgeGroup data is generated correctly through the bulk-load path. |
|
@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. |
|
Optimistic merge. |
Summary
The bulk-load encoding path (
BulkEdgeEncoder.bulkEncodeAllincodec-java) only encoded EdgeState/EdgeIndex/EdgeCache/EdgeCount from aBulkLoadEdge. 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 intoBulkEdgeEncoder, so bulk-loaded edges emit EdgeGroup records too.Closes #389
Changes
metadata/Bucket.java(new): ports V3'sdatebucket — epoch value → formatted string — used to bucket group fields (e.g. daily aggregation). Query-timehandleQueryValueis intentionally not ported; bulk encoding only ever applies buckets to concrete property values.metadata/Group.java:Group.Fieldgains an optionalbucketand anapplyBuckethelper.code/EdgeEncoder.java/code/AbstractEdgeEncoder.java/code/BytesKeyValueEdgeEncoder.java/code/StringKeyFieldValueEdgeEncoder.java: newencodeGroupEdge/encodeAllGroupEdgesmethods 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 (bucketedgroupValues,Order.DESC, matchingEdgeGroupRecordMapper'sGROUP_RECORD_ORDER), and this edge's single contribution as a raw 8-byte long (1for COUNT, thevalueField's value for SUM) — matching the rawbuffer.longV3 uses for its HBaseIncrementcell, not anOrderedBytesheader.code/BulkEdgeEncoder.java: wires EdgeGroup encoding intobulkEncodeAllfor INDEXED and MULTI_EDGE labels, one row per(group, direction), iterating each group's owndirectionType(not the label's) — matching V3EdgeMutationBuilder.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.BulkEdgeEncoderTests,MultiEdgeBulkEdgeEncoderTests,BucketTests(codec-java), andV2MultiEdgeBulkLoadTest(core) — the bulk-encoded group key/qualifier/value round-trips through V3'sEdgeGroupRecordMapperdecoder byte-for-byte, the same safety net already used for EdgeCount/EdgeCache.Out of scope
Consuming these
EDGE_GROUP_TYPErecords 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