-
Notifications
You must be signed in to change notification settings - Fork 4
fix: treat Compression.NONE sentinel as uncompressed in COPY INTO formats #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
simozzy
wants to merge
1
commit into
databendlabs:main
Choose a base branch
from
PlaidCloud:upstream-pr/compression-none-sentinel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| from sqlalchemy.testing import fixtures, assert_raises_message | ||
| from sqlalchemy.testing.assertions import AssertsCompiledSQL | ||
|
|
||
| from databend_sqlalchemy import ( | ||
| CSVFormat, | ||
| TSVFormat, | ||
| NDJSONFormat, | ||
| ParquetFormat, | ||
| Compression, | ||
| ) | ||
|
|
||
|
|
||
| class CompileCopyFormatCompressionTest(fixtures.TestBase, AssertsCompiledSQL): | ||
|
|
||
| __only_on__ = "databend" | ||
|
|
||
| _FORMATS = [ | ||
| (CSVFormat, "CSV"), | ||
| (TSVFormat, "TSV"), | ||
| (NDJSONFormat, "NDJSON"), | ||
| (ParquetFormat, "PARQUET"), | ||
| ] | ||
|
|
||
| def test_no_compression_emits_no_option(self): | ||
| # ``None`` and the ``Compression.NONE`` sentinel both mean uncompressed. | ||
| # Regression: ``Compression.NONE`` is a truthy Enum member, so the old | ||
| # ``if compression:`` guard treated it as "a codec was set" — emitting a | ||
| # spurious ``COMPRESSION = NONE`` option and, for ParquetFormat, raising. | ||
| for fmt_cls, type_ in self._FORMATS: | ||
| expected = f"FILE_FORMAT = (TYPE = {type_})" | ||
| self.assert_compile(fmt_cls(), expected) | ||
| self.assert_compile(fmt_cls(compression=Compression.NONE), expected) | ||
|
|
||
| def test_explicit_codec_is_emitted(self): | ||
| for fmt_cls, type_, codec in [ | ||
| (CSVFormat, "CSV", Compression.GZIP), | ||
| (TSVFormat, "TSV", Compression.GZIP), | ||
| (NDJSONFormat, "NDJSON", Compression.GZIP), | ||
| (ParquetFormat, "PARQUET", Compression.ZSTD), | ||
| (ParquetFormat, "PARQUET", Compression.SNAPPY), | ||
| ]: | ||
| self.assert_compile( | ||
| fmt_cls(compression=codec), | ||
| f"FILE_FORMAT = (TYPE = {type_}, COMPRESSION = {codec.value})", | ||
| ) | ||
|
|
||
| def test_parquet_rejects_unsupported_codec(self): | ||
| # ParquetFormat still rejects codecs its writer can't use. | ||
| for codec in [Compression.GZIP, Compression.BZ2, Compression.ZIP]: | ||
| assert_raises_message( | ||
| TypeError, | ||
| "Compression should be None, ZStd, or Snappy.", | ||
| ParquetFormat, | ||
| compression=codec, | ||
| ) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When callers pass
ParquetFormat(compression=Compression.NONE), this condition now skips validation and emits noCOMPRESSIONoption. For Parquet, Databend only supportsZSTD/SNAPPYfor this option and the omitted-option default isZSTD, so a user asking for no compression silently gets ZSTD-compressed output instead of the previous clear rejection. KeepCompression.NONErejected for Parquet rather than treating it likeNone.Useful? React with 👍 / 👎.