Add arrayPermutations, arrayPartialPermutations, and arrayCombinations#101135
Add arrayPermutations, arrayPartialPermutations, and arrayCombinations#101135ArtemovMichael wants to merge 4 commits intoClickHouse:masterfrom
Conversation
|
Workflow [PR], commit [f7a323b] Summary: ❌
AI ReviewSummaryThis PR adds three new array combinatorics SQL functions: Missing context
Findings💡 Nits
ClickHouse Rules
Final Verdict
|
| factory.registerFunction<FunctionArrayCombinations>(combinations_documentation); | ||
| } | ||
|
|
||
| } // namespace DB |
There was a problem hiding this comment.
Style check fails on this line (Found unnecessary namespace comments). Please remove the trailing namespace comment to keep CI green:
} // namespace DBbecomes
}| return true; | ||
| } | ||
|
|
||
| /// Returns true if P(n, k) / C(n, k) fits into count_limit and writes it to result. |
There was a problem hiding this comment.
Typo in comment: P(n, k) / C(n, k) reads as division, but the function handles either partial permutations or combinations depending on the template mode. Please reword to avoid confusion, e.g. P(n, k) or C(n, k).
LLVM Coverage Report
Changed lines: 98.34% (356/362) · Uncovered code |
Closes #43175
Changelog category:
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added new array combinatorics functions:
arrayPermutations,arrayPartialPermutations, andarrayCombinations. These functions generate permutations and combinations by element indexes (so equal values may produce duplicate rows), validate argumentk, and enforce result-size limits viafunction_range_max_elements_in_block.Documentation entry for user-facing changes
Motivation:
Parameters:
arrayPermutations(arr):arr: source array, returns all full permutations.arrayPartialPermutations(arr, k):arr: source array.k: selection length, must be non-negative and not exceed array length.arrayCombinations(arr, k):arr: source array.k: combination length, must be non-negative and not exceed array length.function_range_max_elements_in_block.Example use:
SELECT arrayPermutations([1, 2, 3]);SELECT arrayPartialPermutations([1, 2, 3], 2);SELECT arrayCombinations([1, 2, 3], 2);