Skip to content

Allow zero-size string types |S0 and <U0 in Npy format - #101179

Merged
Algunenano merged 1 commit into
ClickHouse:masterfrom
Algunenano:npy-allow-zero-size-string
Apr 2, 2026
Merged

Algunenano merged 1 commit into
ClickHouse:masterfrom
Algunenano:npy-allow-zero-size-string

Conversation

@Algunenano

@Algunenano Algunenano commented Mar 30, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #100625. The blanket element_size == 0 rejection was incorrect:
np.ndarray(shape=(3,), dtype='|S0') produces a valid .npy file with
zero-length string elements and zero data bytes, and NumPy loads it back fine.

Two fixes:

  • Remove the element_size == 0 rejection; guard the overflow division instead.
  • Fix readRow to use a row counter instead of relying solely on eof().
    For zero-size elements the data section is empty, so EOF is reached
    immediately despite rows remaining. This caused SELECT count() (which
    uses countRows from shape metadata) and SELECT * (which uses readRow)
    to disagree.

Closes #101133

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not for changelog — the regression was introduced in #100625 which has not been included in any release.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.521

`np.ndarray(shape=(3,), dtype='|S0')` produces a valid `.npy` file with
zero-length string elements and zero data bytes. The blanket rejection of
`element_size == 0` was incorrect for these types.

Guard the overflow division by `element_size` instead of rejecting zero
outright. Also fix `readRow` to use a row counter instead of relying
solely on `eof()` — for zero-size elements the data section is empty, so
EOF is reached immediately despite rows remaining.

Fixes ClickHouse#101133

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [31ea671]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_llvm_coverage, 2/5) failure
test_overcommit_tracker/test.py::test_user_overcommit FAIL cidb, issue ISSUE EXISTS
Stress test (amd_debug) failure
Logical error: '!subranges.empty()' (STID: 2508-423f) FAIL cidb IGNORED
Stress test (arm_msan) failure
Logical error: '!subranges.empty()' (STID: 2508-3d1e) FAIL cidb IGNORED
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-1bfa) FAIL cidb IGNORED

AI Review

Summary

This PR updates Npy input handling to allow zero-size NumPy string types (|S0, <U0) and fixes row production for such files by tracking rows explicitly instead of relying only on eof. The change is focused, test coverage was extended for zero-size string/unicode and multidimensional cases, and I did not find correctness, safety, or performance regressions in the modified paths.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Mar 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.20% +0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.70% 76.70% +0.00%

Changed lines: 78.95% (15/19) · Uncovered code

Full report · Diff report

@yariks5s yariks5s self-assigned this Mar 31, 2026
@Algunenano
Algunenano added this pull request to the merge queue Apr 2, 2026
Merged via the queue into ClickHouse:master with commit 990b6a7 Apr 2, 2026
156 of 160 checks passed
@Algunenano
Algunenano deleted the npy-allow-zero-size-string branch April 2, 2026 10:50
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

element_size == 0 check rejects valid |S0 and <U0 NumPy types

3 participants