-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[python/hotfix] Fix zstd manifest decompression error on Python 3.6 #6982
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
Merged
+126
−28
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0a78244
fix fastavro read java avro issue
ec958f7
fastavro compatible with zstd for py36 hack
d25855b
fix code format
401ff26
fix
2d35e76
fix code format
002acfb
fix CI for py36
c79e64a
fix CI for py36
8765b7c
add fastavro_py36_compat.py
bc17843
fix CI
fe07e07
clean code
36cd060
clean code
2d3a43e
remove extra case
515ab4d
fix
415f087
fix
823cf80
fix
21e4b86
fix format
3a2bdda
revert fix
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 |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ | |
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.condition.DisabledIfSystemProperty; | ||
| import org.junit.jupiter.api.condition.EnabledIfSystemProperty; | ||
|
|
||
| import java.nio.file.Files; | ||
|
|
@@ -260,19 +261,9 @@ public void testJavaWriteReadPkTableLance() throws Exception { | |
|
|
||
| @Test | ||
| @EnabledIfSystemProperty(named = "run.e2e.tests", matches = "true") | ||
| @DisabledIfSystemProperty(named = "python.version", matches = "3.6") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why disable for 3.6?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
py36 does not have pylance dependency |
||
| public void testReadPkTableLance() throws Exception { | ||
| try { | ||
| // Known issue: Reading Python-written Lance files in Java causes JVM crash due to | ||
| // missing Tokio runtime. The error is: | ||
| // "there is no reactor running, must be called from the context of a Tokio 1.x runtime" | ||
| // | ||
| // This is a limitation of lance-core Java bindings. The Rust native library requires | ||
| // Tokio runtime for certain operations when reading files written by Python (which may | ||
| // use different encoding formats). Java-written files can be read successfully because | ||
| // they use synchronous APIs that don't require Tokio. | ||
| // | ||
| // Workaround: Try to "warm up" Tokio runtime by reading a Java-written file first. | ||
| // This may initialize the Tokio runtime if it's created on first use. | ||
| try { | ||
| Identifier warmupIdentifier = identifier("mixed_test_pk_tablej_lance"); | ||
| try { | ||
|
|
||
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
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
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,77 @@ | ||
| ################################################################################ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| ################################################################################ | ||
|
|
||
| """ | ||
| Provides compatibility patches for fastavro on Python 3.6, | ||
| specifically for handling zstd-compressed Avro files. | ||
|
|
||
| The main issue addressed is: | ||
| - On Python 3.6, fastavro's zstd decompression may fail with: | ||
| "zstd.ZstdError: could not determine content size in frame header" | ||
|
|
||
| This module patches fastavro's zstd handling to use a more compatible | ||
| decompression method that works on Python 3.6. | ||
| """ | ||
|
|
||
| import sys | ||
|
|
||
| _patch_applied = False | ||
|
|
||
|
|
||
| def _apply_zstd_patch(): | ||
| global _patch_applied | ||
| if _patch_applied or sys.version_info[:2] != (3, 6): | ||
| return | ||
|
|
||
| try: | ||
| import fastavro._read as fastavro_read | ||
| import zstandard as zstd | ||
| from io import BytesIO | ||
| except (ImportError, AttributeError): | ||
| return | ||
|
|
||
| def _fixed_zstandard_read_block(decoder): | ||
| from fastavro._read import read_long | ||
|
|
||
| length = read_long(decoder) | ||
|
|
||
| if hasattr(decoder, 'read_fixed'): | ||
| data = decoder.read_fixed(length) | ||
| elif hasattr(decoder, 'read'): | ||
| data = decoder.read(length) | ||
| else: | ||
| from fastavro._read import read_fixed | ||
| data = read_fixed(decoder, length) | ||
|
|
||
| decompressor = zstd.ZstdDecompressor() | ||
| with decompressor.stream_reader(BytesIO(data)) as reader: | ||
| decompressed = reader.read() | ||
| return BytesIO(decompressed) | ||
|
|
||
| if hasattr(fastavro_read, 'BLOCK_READERS'): | ||
| block_readers = fastavro_read.BLOCK_READERS | ||
| block_readers['zstandard'] = _fixed_zstandard_read_block | ||
| block_readers['zstd'] = _fixed_zstandard_read_block | ||
| _patch_applied = True | ||
|
|
||
|
|
||
| if sys.version_info[:2] == (3, 6): | ||
| try: | ||
| _apply_zstd_patch() | ||
| except ImportError: | ||
| pass |
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
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.
Why disable for 3.6?
Uh oh!
There was an error while loading. Please reload this page.
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.
compatible issue in pk table for py36, will create another PR to fix it.