Skip to content

Add arrayPartialAutocorrelation function - #102160

Draft
wenyuchen96 wants to merge 1 commit into
ClickHouse:masterfrom
wenyuchen96:feature/array-partial-autocorrelation
Draft

wenyuchen96 wants to merge 1 commit into
ClickHouse:masterfrom
wenyuchen96:feature/array-partial-autocorrelation

Conversation

@wenyuchen96

@wenyuchen96 wenyuchen96 commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Relates to #87209

Relates to: Add arrayAutocorrelation function #94776

Changelog category (leave one):

  • New Feature

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

Add function arrayPartialAutocorrelation(arr [, max_lag]) that computes the partial autocorrelation of a numeric array for each lag. Supports integer, float, and decimal array types.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Motivation: Following the addition of the Auto Correlation Function (ACF) in #94776, the Partial Autocorrelation Function (PACF) is the next essential component for in-database time-series analysis. While ACF shows the overall correlation with past lags, PACF isolates the direct correlation between a time series and its lagged values by removing the indirect effects of shorter lags.

This is a critical step for determining the order of Autoregressive (AR) models (like ARIMA) in predictive modeling. Implementing this natively in ClickHouse further eliminates the need to export large datasets to Python or R for standard forecasting and anomaly detection workflows.

Parameters: - arr: An array of numeric values (Array(Int*) or Array(Float*)). The function automatically casts integers to Float64 for high-precision calculation.

  • max_lag (optional): The maximum lag to compute the partial autocorrelation for.

Example use: SELECT arrayPartialAutocorrelation([10, 20, 30, 10, 20, 30]);


Workflow [PR]
Sync PR [sync-upstream/pr/102160]

@wenyuchen96 wenyuchen96 changed the title WIP: Add arrayPartialAutocorrelation function WIP: Add arrayPartialAutocorrelation function Apr 9, 2026
@wenyuchen96 wenyuchen96 changed the title WIP: Add arrayPartialAutocorrelation function Add arrayPartialAutocorrelation function Apr 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Dear @wenyuchen96, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Dear @wenyuchen96, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

pull Bot pushed a commit to Mattlk13/ClickHouse that referenced this pull request Aug 17, 2026
arrayAutocorrelation accepts Array(Nothing) deliberately, because [] has that
type and arrayAutocorrelation([]) returns []. Both of its ColumnNothing
branches guarded on the column type alone, when the correct condition is type
and emptiness: ColumnNothing keeps only a row count and holds no readable
elements, so a length-N Array(Nothing) like [arrayMax([])] is a structurally
valid ColumnArray with zero accessible elements, and this function has no way
to represent it.

The non-const branch reused the input offsets next to a fresh empty
ColumnFloat64, producing offsets=[1] with 0 elements. Since ClickHouse#112504 the
ColumnArray constructor rejects that:

  Logical error: 'offsets_column has data inconsistent with nested_column.
  Data size: 0, last offset: 1'

which is an exception in release builds and an abort in debug and sanitizer
builds. The const branch instead zeroed the offsets, so it silently returned []
for any input length.

Both branches now reject a non-empty Nothing column with ILLEGAL_COLUMN, using
the message already used for this condition in assumeNotNull and in
IFunction::defaultImplementationForNothing. The empty case is unchanged. No
value is synthesized, because Nothing holds no values and any number produced
would be invented.

Found by the AST fuzzer (STID 2632-416b). Before ClickHouse#112504 this was a silent
wrong result: 26.7.4.15 returns [0]. ClickHouse#112504 is the detector and is correct.

arrayPartialAutocorrelation in the open ClickHouse#102160 carries the same defect in both
places.

Co-Authored-By: Claude Fable 5 <[email protected]>
@abashkeev abashkeev added the comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... label Sep 4, 2026
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Nov 14, 2026
@clickhouse-gh clickhouse-gh Bot closed this Nov 14, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Nov 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [95baaf2]

Summary: ❌

job_name test_name status info comment
Style check FAIL
cpp FAIL cidb
Fast test FAIL
Build ClickHouse FAIL
Build (arm_tidy, 1/4) FAIL
Build ClickHouse FAIL cidb
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Nov 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... external Author is not a member of the ClickHouse organization pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants