Files
dolt/integration-tests
David Dansby 4adaa52628 refactor(diff): prevent empty table hdrs when filtering data-only diffs
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
2025-11-10 17:08:12 -08:00
..