@@ -76,7 +76,7 @@ import {
7676 useRenderedSqlChartConfig ,
7777} from '@/hooks/useChartConfig' ;
7878import { useCsvExport } from '@/hooks/useCsvExport' ;
79- import { useTableMetadata } from '@/hooks/useMetadata' ;
79+ import { useColumns , useTableMetadata } from '@/hooks/useMetadata' ;
8080import useOffsetPaginatedQuery from '@/hooks/useOffsetPaginatedQuery' ;
8181import { useGroupedPatterns } from '@/hooks/usePatterns' ;
8282import useRowWhere , {
@@ -1374,14 +1374,15 @@ export const RawLogTable = memo(
13741374 } ,
13751375) ;
13761376
1377- export function appendSelectWithPrimaryAndPartitionKey (
1377+ export function appendSelectWithAdditionalKeys (
13781378 select : SelectList ,
13791379 primaryKeys : string ,
13801380 partitionKey : string ,
1381+ extraKeys : string [ ] ,
13811382) : { select : SelectList ; additionalKeysLength : number } {
13821383 const partitionKeyArr = extractColumnReferencesFromKey ( partitionKey ) ;
13831384 const primaryKeyArr = extractColumnReferencesFromKey ( primaryKeys ) ;
1384- const allKeys = new Set ( [ ...partitionKeyArr , ...primaryKeyArr ] ) ;
1385+ const allKeys = new Set ( [ ...partitionKeyArr , ...primaryKeyArr , ... extraKeys ] ) ;
13851386 if ( typeof select === 'string' ) {
13861387 const selectSplit = splitAndTrimWithBracket ( select ) ;
13871388 const selectColumns = new Set ( selectSplit ) ;
@@ -1407,7 +1408,12 @@ function getSelectLength(select: SelectList): number {
14071408 }
14081409}
14091410
1410- export function useConfigWithPrimaryAndPartitionKey (
1411+ // Column name used to disambiguate rows with identical visible column values.
1412+ // This is a MATERIALIZED column (random UInt16) added to otel_logs to ensure
1413+ // the WHERE clause generated for row detail queries uniquely identifies a row.
1414+ const HDX_ID_COLUMN = '__hdx_id' ;
1415+
1416+ export function useConfigWithAdditionalSelect (
14111417 config : BuilderChartConfigWithDateRange ,
14121418) {
14131419 const { data : tableMetadata } = useTableMetadata ( {
@@ -1416,6 +1422,12 @@ export function useConfigWithPrimaryAndPartitionKey(
14161422 connectionId : config . connection ,
14171423 } ) ;
14181424
1425+ const { data : columns } = useColumns ( {
1426+ databaseName : config . from . databaseName ,
1427+ tableName : config . from . tableName ,
1428+ connectionId : config . connection ,
1429+ } ) ;
1430+
14191431 const primaryKey = tableMetadata ?. primary_key ;
14201432 const partitionKey = tableMetadata ?. partition_key ;
14211433
@@ -1424,14 +1436,17 @@ export function useConfigWithPrimaryAndPartitionKey(
14241436 return undefined ;
14251437 }
14261438
1427- const { select, additionalKeysLength } =
1428- appendSelectWithPrimaryAndPartitionKey (
1429- config . select ,
1430- primaryKey ,
1431- partitionKey ,
1432- ) ;
1439+ const hasHdxIdColumn =
1440+ columns ?. some ( c => c . name === HDX_ID_COLUMN ) ?? false ;
1441+
1442+ const { select, additionalKeysLength } = appendSelectWithAdditionalKeys (
1443+ config . select ,
1444+ primaryKey ,
1445+ partitionKey ,
1446+ hasHdxIdColumn ? [ HDX_ID_COLUMN ] : [ ] ,
1447+ ) ;
14331448 return { ...config , select, additionalKeysLength } ;
1434- } , [ primaryKey , partitionKey , config ] ) ;
1449+ } , [ primaryKey , partitionKey , config , columns ] ) ;
14351450
14361451 return mergedConfig ;
14371452}
@@ -1564,7 +1579,7 @@ function DBSqlRowTableComponent({
15641579 return base ;
15651580 } , [ me , config , orderByArray ] ) ;
15661581
1567- const mergedConfig = useConfigWithPrimaryAndPartitionKey ( mergedConfigObj ) ;
1582+ const mergedConfig = useConfigWithAdditionalSelect ( mergedConfigObj ) ;
15681583
15691584 const { data, fetchNextPage, hasNextPage, isFetching, isError, error } =
15701585 useOffsetPaginatedQuery ( mergedConfig ?? config , {
0 commit comments