Early return in tlcsv ValidateStructure#659
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Improves GTFS CSV structure validation performance by avoiding full-file scans during Reader.ValidateStructure, while preserving the existing empty-file/required-file semantics, and adds a regression test to ensure header-only vs. data-row behavior remains correct.
Changes:
- Update
Reader.ValidateStructureto read only the header and first data row (viaReadRowsIter) instead of scanning all rows. - Add
TestValidateStructure_RequiresDataRowto pin the “header-only is empty” vs. “has at least one data row” distinction.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tlcsv/reader.go | Switches structure validation to early-exit after confirming a header and first data row, avoiding costly full scans. |
| tlcsv/validate_structure_test.go | Adds a focused test ensuring header-only required files still error, while header+data does not. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reader.ValidateStructureonly needs each file's header and whether it contains at least one data row, but it previously read every row of every file to determine that — on stop_times.txt or shapes.txt that means scanning tens of millions of rows for nothing. It now reads the header and the first data row viaReadRowsIterand stops, leaving the rest of structure validation (empty-file handling, required-column and duplicate-column checks, the conditional stops.txt handling for flex feeds) unchanged.Behavior preserved
FileRequiredError, and optional files (such as stops.txt in a flex feed) are skipped without error.Test plan
TestValidateStructure_RequiresDataRowpins the header-vs-data-row distinction: a header-only required file reportsFileRequiredError, while the same file with one data row validates.tlcsvstructure-validation tests (flex stops.txt conditionals, required-header-only) still pass, confirming the early return produces the same results as the previous full scan.