mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-24 03:09:22 -06:00
Implement lazy table header initialization to fix a bug where empty table headers were printed when all rows were filtered out during data-only diffs. This occurred because BeginTable() was called before row filtering, causing headers to print even when no matching rows existed. The solution introduces a lazyRowWriter that delays the BeginTable() call until the first row is actually written. This wrapper is only used when: - A filter is active (added/modified/removed) - The diff is data-only (no schema changes or table renames) Implementation changes: - Add shouldUseLazyHeader() helper to determine when to use lazy initialization based on filter presence and diff type - Add lazyRowWriter type that wraps SqlRowDiffWriter and delays BeginTable() until first WriteRow() or WriteCombinedRow() call - Modify diffUserTable() to skip BeginTable when using lazy writer - Modify diffRows() to conditionally create lazyRowWriter vs normal rowWriter based on shouldUseLazyHeader() check - Add comprehensive unit tests for shouldUseLazyHeader logic and lazyRowWriter behavior (5 test functions, 8+ test cases) - Add mock implementations of diffWriter and SqlRowDiffWriter interfaces to enable testing without database dependencies - Fix BATS test assertions to match actual SQL output format (lowercase type names, MODIFY COLUMN vs DROP/ADD pattern) Test coverage: - TestShouldUseLazyHeader: validates lazy header logic conditions - TestLazyRowWriter_NoRowsWritten: verifies BeginTable not called when no rows written (core lazy behavior) - TestLazyRowWriter_RowsWritten: verifies BeginTable called on first write - TestLazyRowWriter_CombinedRowsWritten: tests combined row writes - TestLazyRowWriter_InitializedOnlyOnce: ensures BeginTable called exactly once Refs: #1430