Repository navigation
Conversation
A CSV file is read as text; each integer, number, boolean, date, timestamp and time column is converted from it, and a type check counts the values that do not convert. A bad value no longer stops the run with a conversion error, and is missing for the other checks of its column. Integers must be whole numbers, and dates, timestamps and times must be in their declared format (ISO 8601 without one). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 tasks done
This branch has not been deployed
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.
Fixes #1721.
Problem
On a CSV file, DuckDB converts each column to the type its
logicalTypedeclares while it reads the file. The first value that does not convert, saytwoin anintegercolumn, stops the run withConversion Error: CSV Error on Line: 3, and every other check comes back without a result. A decimal in anintegercolumn passes unnoticed, becauseCAST('2.50' AS BIGINT)rounds to 3. A date in another format thanlogicalTypeOptions.formatdeclares either stops the run or passes.What this changes
{model}__raw__view. The typed table is then built from that text withTRY_CAST, so a bad value becomes NULL instead of stopping the read.integer,number,boolean,date,timestampandtimecolumn gets afield_typecheck, "Check that field quantity has type integer". It is aninvalid_countcheck on the raw view, so it counts every bad value, and--include-failed-samplesshows the values and their keys.integeris strict: the text must be a whole number (^[+-]?[0-9]+$), so2.50and2.00fail.date,timestampandtimewithlogicalTypeOptions.formatmust be in that format and must exist (31/02/2024fails). The JavaDateTimeFormatterpattern is mapped to astrptimeformat in the newcsv_values.py. A pattern that cannot be mapped (for exampleXXX, which writesZfor UTC) gives a warning instead of a false failure. Without a format, ISO 8601 applies, as before.requiredcolumn also reports it as missing.Tests
tests/test_test_local_csv_types.py: 26 tests, covering a bad value of each type failing only its own column's check, every bad value counted, empty values, a bad value being missing for the other checks (alsorequired), failed samples and diagnostics, ISO 8601 and declared date formats, the warning for a pattern that cannot be mapped, and the pattern mapping itself.test_test_metadata_only.pyandtest_test_dimension_filter.pyare updated for the new check, which is skipped with--metadata-onlyand belongs to the conformity dimension.uv run pytest: all pass.uv run ruff checkandruff format: clean.Docs
The data-types table in
reference/local.md, thelogicalTypeOptions.formatbullet inschema.md, and the notes on CSV types in the s3, azure, gcs, index,testing/local.mdandtesting/xml.mdpages. CHANGELOG entry under Fixed.Known limit
--filterdoes not narrow the type check: it counts the whole file, because the raw view has no typed columns to filter on.uv run pytest)uv run ruff check --fix && uv run ruff format)🤖 Generated with Claude Code