Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/inline-rollup-value-limit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/common-utils': patch
---

fix: inline the value limit in the KV rollup filter query so filter values load
when the rollup table is Distributed. #2643 brought back the bound `Int32`
parameter that #2474 had removed.
18 changes: 18 additions & 0 deletions packages/common-utils/src/__tests__/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,24 @@ describe('Metadata', () => {
expect(Object.values(params)).not.toContain('SeverityText');
});

// A bound Int32 parameter reaches the aggregate as `_CAST(20, 'Int32')`,
// which fails over Distributed tables (ClickHouse #71887, see #2163).
it('inlines the rollup value limit as a literal', async () => {
setupDefaultLogsSchema();

await metadata.getAllKeyValues({
...baseArgs,
keyExpressions: ['ServiceName'],
maxValuesPerKey: 7,
});

const mvCall = (mockClickhouseClient.query as jest.Mock).mock.calls.find(
(c: any[]) => (c[0].query as string).includes('Key IN ('),
)![0];
expect(mvCall.query).toContain('groupUniqArray(7)(Value)');
expect(mvCall.query).not.toMatch(/groupUniqArray\(\{/);
});

it('keeps the KV rollup MV query parameter count independent of the number of keys', async () => {
const { doMVsAggregateSpy } = setupDefaultLogsSchema();
doMVsAggregateSpy.mockResolvedValue(true);
Expand Down
2 changes: 1 addition & 1 deletion packages/common-utils/src/core/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ export class Metadata {
// time filter (and notEmpty) to the last branch only.
const sql = chSql`
SELECT * FROM (
SELECT ColumnIdentifier, Key, groupUniqArray(${{ Int32: maxValuesPerKey }})(Value) as Values
SELECT ColumnIdentifier, Key, groupUniqArray(${{ UNSAFE_RAW_SQL: inlineNonNegativeInt(maxValuesPerKey, 'maxValuesPerKey') }})(Value) as Values
FROM ${tableExpr({ database: databaseName, table: mvName })}
WHERE (${concatChSql(' OR ', branch)})
AND ${timeFilter}
Expand Down
Loading