Skip to content

Support bzip2 and xz compressed inputs in LLM file analysis - #70302

Open
guan404ming wants to merge 3 commits into
apache:mainfrom
guan404ming:common-ai-file-analysis-compression
Open

Support bzip2 and xz compressed inputs in LLM file analysis#70302
guan404ming wants to merge 3 commits into
apache:mainfrom
guan404ming:common-ai-file-analysis-compression

Conversation

@guan404ming

Copy link
Copy Markdown
Member

Why

  • LLMFileAnalysisOperator only accepted gzip, so archived logs and exports stored as .log.xz or .csv.bz2 were rejected outright.
  • The path suffixes were already recognised, but any codec other than gzip was refused, forcing users to decompress in a separate task.

How

  • Accept bzip2 and xz alongside gzip for .log, .json, and .csv inputs, using the standard library only.
  • Replace the hardcoded gzip branch with a codec lookup, so all supported codecs share one read path.
  • Keep snappy and zstd rejected, and keep compression unsupported for Parquet, Avro, image, and PDF inputs.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.8)

Generated-by: Claude Code (Opus 4.8) following the guidelines

@guan404ming
guan404ming force-pushed the common-ai-file-analysis-compression branch from 45bb2b6 to 3ed4e00 Compare July 28, 2026 22:07
import io
import json
import logging
import lzma

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_bz2 and _lzma are optional CPython extensions, so on an interpreter built without them (the classic pyenv source build without liblzma-dev) this import now takes down the whole module, and with it LLMFileAnalysisOperator and @task.llm_file_analysis, even for the plain and gzip inputs that worked before this PR. Since detect_file_format already keys off _DECOMPRESSORS membership, registering bzip2/xz under try/except ImportError would degrade those builds to the existing "Compression ... is not supported" error instead (pandas guards these two imports the same way).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed. Imports now guarded; missing codecs fall back to the unsupported-compression error.

path = tmp_path / filename
path.write_bytes(b"content")

with pytest.raises(LLMFileAnalysisUnsupportedFormatError, match="not supported for"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This match can't tell the two rejection branches apart: the codec-level message ("Compression 'bzip2' is not supported for file analysis.") contains the same substring, so the new sample.avro.bz2 and sample.png.xz cases would still pass if bzip2/xz support were reverted. Something like match=r"not supported for '\w+' file analysis" pins them to the format-combination branch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, tightened the match to pin the format-combination branch.

``.csv.gz``.
- Gzip is not supported for ``.parquet``, ``.avro``, image, or PDF inputs.
- ``gzip``, ``bzip2``, and ``xz`` compressed text inputs are supported for
``.log``, ``.json``, and ``.csv`` (``.log.gz``, ``.csv.bz2``, ``.json.xz``, ...).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code also accepts compressed .txt here (_COMPRESSION_SUPPORTED_FORMATS includes txt, and test_detect_file_format covers notes.txt.gz), so .txt belongs in this list. The Text-like bullet above is missing .txt too since #70431 didn't touch this page, may as well fix both while you're here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, added .txt to both lists.

@guan404ming
guan404ming requested a review from kaxil August 4, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants