Skip to content

Commit 02e09c8

Browse files
committed
fix(app): keep __hdx_id as a tiebreaker when only one block column is persisted
1 parent 4502777 commit 02e09c8

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

‎packages/app/src/components/DBRowTable.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,12 +1634,13 @@ export function useConfigWithAdditionalSelect(
16341634
needsMergeTreeSettings ? mergeTreeSettings : undefined,
16351635
);
16361636

1637-
if (blockColumns.length > 0) {
1638-
extraKeys = blockColumns;
1639-
hasBothBlockColumns =
1640-
blockColumns.length === BLOCK_COLUMN_SETTINGS.length;
1641-
} else if (columns?.some(c => c.name === '__hdx_id')) {
1642-
extraKeys = ['__hdx_id'];
1637+
hasBothBlockColumns =
1638+
blockColumns.length === BLOCK_COLUMN_SETTINGS.length;
1639+
extraKeys = [...blockColumns];
1640+
// Without a unique block pair, the full-row lookup takes every
1641+
// tiebreaker it can get.
1642+
if (!hasBothBlockColumns && columns?.some(c => c.name === '__hdx_id')) {
1643+
extraKeys.push('__hdx_id');
16431644
}
16441645
}
16451646

‎packages/app/src/components/__tests__/DBRowTable.test.tsx‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,40 @@ describe('useConfigWithAdditionalSelect', () => {
10431043
expect(result.current?.rowKeyColumns).toBeUndefined();
10441044
});
10451045

1046+
it('keeps __hdx_id alongside a lone block column in the full-row lookup', () => {
1047+
mockMetadata({
1048+
engineFull:
1049+
'MergeTree ORDER BY Timestamp SETTINGS enable_block_offset_column = 1',
1050+
columns: [{ name: '__hdx_id', type: 'String' }],
1051+
});
1052+
1053+
const { result } = renderHook(() =>
1054+
useConfigWithAdditionalSelect(config, 'source-id'),
1055+
);
1056+
1057+
expect(result.current?.select).toBe(
1058+
'Timestamp,ServiceName,Body,toDate(Timestamp),toStartOfFiveMinutes(Timestamp),_block_offset,__hdx_id',
1059+
);
1060+
expect(result.current?.rowKeyColumns).toBeUndefined();
1061+
});
1062+
1063+
it('does not add __hdx_id when both block columns are persisted', () => {
1064+
mockMetadata({
1065+
engineFull:
1066+
'MergeTree ORDER BY Timestamp SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1',
1067+
columns: [{ name: '__hdx_id', type: 'String' }],
1068+
});
1069+
1070+
const { result } = renderHook(() =>
1071+
useConfigWithAdditionalSelect(config, 'source-id'),
1072+
);
1073+
1074+
expect(result.current?.select).toBe(
1075+
'Timestamp,ServiceName,Body,toDate(Timestamp),toStartOfFiveMinutes(Timestamp),_block_number,_block_offset',
1076+
);
1077+
expect(result.current?.rowKeyColumns?.has('__hdx_id')).toBe(false);
1078+
});
1079+
10461080
it('falls back to __hdx_id and the full row when no block column is persisted', () => {
10471081
mockMetadata({
10481082
engineFull:

0 commit comments

Comments
 (0)