Repository navigation
Closed
[Feature Request]: Enhance data branch diff with fallback, delta output, and summary statistics#23751
Feature
Copy link
Labels
ai-heavyAI打辅助,核心逻辑靠人kind/featurepriority/p0Critical feature that should be implemented in this version
Milestone
Description
Is there an existing issue for the same feature request?
- I have checked the existing issues.
Is your feature request related to a problem?
Currently data branch diff has limitations that make it less flexible than Git's diff:
- Only works with branched tables: Requires LCA (Lowest Common Ancestor) relationship, cannot compare arbitrary tables
- Limited output modes: Only supports full output and
output count, lacks incremental change tracking - No detailed statistics:
output countonly returns total rows, not breakdown of changes
Describe the feature you'd like
1. Fallback to EXCEPT for non-branched tables
Current behavior:
-- Only works if t2 was created from t1
data branch create table t2 from t1{snapshot="sp1"};
data branch diff t2 against t1; -- ✅ Works (has LCA)
-- Fails if no branch relationship
data branch diff t3 against t4; -- ❌ Error: no LCAProposed behavior:
-- Automatically fallback to EXCEPT-like behavior
data branch diff t3 against t4; -- ✅ Works (uses set difference)2. Delta output mode
Proposed syntax:
data branch diff t1 against t2 output delta;Expected result:
operation | a | b
----------|---|---
+ | 3 | 3 -- Added in t1
- | 4 | 4 -- Deleted from t1 (exists in t2)
Similar to Git's +/- notation for added/removed lines.
3. Summary statistics output
Proposed syntax:
data branch diff t1 against t2 output summary;Expected result:
metric | count
----------|------
added | 10
deleted | 5
modified | 3
unchanged | 100
Provides quick overview without scanning all rows.
Describe implementation you've considered
Fallback mechanism
- Check if tables have LCA relationship
- If no LCA: use EXCEPT-based comparison
- Maintain same output format for consistency
Delta output
- Add
operationcolumn:+(added),-(deleted),~(modified) - Use primary key to match rows for modification detection
- If no PK: treat as add/delete only
Summary statistics
- Leverage existing diff computation
- Aggregate results into statistics
- Minimal performance overhead (single pass)
Documentation, Adoption, Use Case, Migration Strategy
Use Cases
- Data validation: Compare staging vs production tables without branch relationship
- Change tracking: Quickly see what changed between snapshots
- Monitoring: Track data drift with summary statistics
- Debugging: Identify specific rows added/deleted with delta output
Adoption
- Backward compatible: existing queries work unchanged
- New output modes are opt-in via
outputclause - Fallback behavior is transparent to users
Metadata
Metadata
Assignees
Labels
ai-heavyAI打辅助,核心逻辑靠人kind/featurepriority/p0Critical feature that should be implemented in this version
Activity
gouhongshen commentedon Mar 2, 2026
Sync note:
gouhongshen commentedon Mar 2, 2026
Clarification with current implemented
OUTPUT SUMMARYformat:data branch diff <target> against <base> output summary;returns 3 columns and 3 rows:Columns:
metric<target table expr>(BIGINT count)<base table expr>(BIGINT count)Rows (fixed metric values):
INSERTEDDELETEDUPDATEDEquivalent shape:
So the spec for
output summaryshould match this current shape.feat: add COLUMNS projection to data branch diff
feat: add COLUMNS projection to data branch diff
to 3.0: fix: avoid duplicate rows in data branch diff replay (#24141)
Ariznawlll commentedon Sep 18, 2026
测试版本
main4ff27bb9b35c43c1b0961bb9a01bf8fc0b6a2171780ef933f2479aa1679faf13d08850ce6c8f7c2f原问题验证
围绕
DATA BRANCH DIFF的 fallback、OUTPUT DELTA/LIMIT和OUTPUT SUMMARY执行原语法与结果验证。OUTPUT DELTA与OUTPUT LIMIT按研发说明采用同一行为;OUTPUT SUMMARY固定返回INSERTED、DELETED、UPDATED三行,以及 metric、target count、base count 三列。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
-count=3执行通过。1250/1250通过,补充集39/39通过。回归测试
72ff591183d0f24bc2401e77ea5803ac56ec8d39。test/distributed/cases/git4data/branch/diff/与test/distributed/cases/git4data/branch/merge/,覆盖 diff/merge 的输出与边界用例。测试证据
测试结论
测试通过。