Repository navigation
feat(files): read CSV in other encodings and skip leading lines - #185
Merged
Merged
Conversation
csv.encoding decodes files in cp1252, latin-1, UTF-16 or any Encoding Standard label, and a byte the encoding does not define fails the table with its file, line and byte. csv.skip_rows skips lines before the header. Snowflake's direct COPY passes both on as ENCODING and SKIP_HEADER, and an encoding it does not support fails plan.
Deploying sqlload with
|
| Latest commit: |
4b635aa
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9dde67a3.sqlload.pages.dev |
| Branch Preview URL: | https://feat-csv-encoding.sqlload.pages.dev |
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.
Files sources can now read CSV files in encodings other than UTF-8, and skip lines before the header.
What changes
csv.encoding(defaultutf-8) accepts:cp1252;latin-1and its other spellings (iso88591,iso-8859-1,cp819, …), read byte for byte as ISO-8859-1;ascii;utf-16leandutf-16be;windows-1250,iso-8859-15,shift_jis, …).plan.ascii) fails the table with the file, line and byte. A bad UTF-8 file fails the same way.csv.skip_rowsskips lines (ending at\nor\r\n) before the header. Quotes in skipped lines don't matter, and error line numbers count the skipped lines. A file whose lines end in a bare\rfails rather than being skipped whole.COPY: both settings now pass through asENCODINGandSKIP_HEADER = skip_rows + header. Snowflake reads latin-1, windows-1250–1256, iso-8859-2/5/6/7/15, koi8-r and utf-16le/be the way SQLLoad's reader does.ascii, East Asian encodings and other unmapped encodings failplanfor the direct route.Snowflake live check
One X-Small run used
copy_to_internal_stagewith synthetic files. The schema was dropped and the warehouse suspended afterwards. The loaded values were byte-identical to SQLLoad's own reader (compared withHEX_ENCODE) for:ISO88591reads it as U+0080, byte for byte);Known difference: Snowflake loads a byte cp1252 leaves undefined (0x81) as the control character U+0081, where SQLLoad's reader fails.
plancatches such a byte when it falls in the sampled rows. The docs say so.Tests
files_source/tests/test_read_text_files.rscovers each encoding, the error cases, skip_rows and its line numbers.test_direct_copies.rs, plus a test of the encoding mapping.make check,make test-unitandmake test-python(353 passed) all pass.The docs mark both settings "From 0.35.0 (not released yet)".