@@ -4,6 +4,7 @@ import { ClickHouseClient } from '@clickhouse/client';
44import { convertCHDataTypeToJSType , JSDataType } from '@/clickhouse' ;
55import { ClickhouseClient as HdxClickhouseClient } from '@/clickhouse/node' ;
66import { Metadata , MetadataCache } from '@/core/metadata' ;
7+ import { renderMetricExemplarsChartConfig } from '@/core/renderChartConfig' ;
78import { convertToCategoricalChartConfig } from '@/core/utils' ;
89import {
910 ChartConfigWithOptDateRange ,
@@ -2786,6 +2787,50 @@ describe('queryChartConfig Integration Tests', () => {
27862787 ) . rejects . toThrow ( ) ;
27872788 } ) ;
27882789 } ) ;
2790+ // HIST_TABLE mirrors the seed schema, where Exemplars.TimeUnix is
2791+ // Array(DateTime). toUnixTimestamp64Milli only accepts DateTime64, so the
2792+ // scan must cast it; this runs the generated SQL against that column type.
2793+ it ( 'reads exemplars from an Array(DateTime) Exemplars.TimeUnix column' , async ( ) => {
2794+ const traceId = '0af7651916cd43dd8448eb211c80319c' ;
2795+ await client . insert ( {
2796+ table : `${ DATABASE } .${ HIST_TABLE } ` ,
2797+ values : [
2798+ {
2799+ ...histRow ( 'exemplar.latency' , insertTs ( 1 ) , 'svc-a' , [ 3 , 1 ] , [ 1 ] ) ,
2800+ 'Exemplars.FilteredAttributes' : [ { } ] ,
2801+ 'Exemplars.TimeUnix' : [ insertTs ( 1 ) ] ,
2802+ 'Exemplars.Value' : [ 2.5 ] ,
2803+ 'Exemplars.SpanId' : [ 'b7ad6b7169203331' ] ,
2804+ 'Exemplars.TraceId' : [ traceId ] ,
2805+ } ,
2806+ ] ,
2807+ format : 'JSONEachRow' ,
2808+ } ) ;
2809+
2810+ const exemplarSql = await renderMetricExemplarsChartConfig (
2811+ baseConfig ( { select : [ histQuantileSelect ( 'exemplar.latency' , 0.99 ) ] } ) ,
2812+ metadata ,
2813+ ) ;
2814+ expect ( exemplarSql ) . not . toBeNull ( ) ;
2815+
2816+ const resp = await hdxClient . query ( {
2817+ query : exemplarSql ! . sql ,
2818+ query_params : exemplarSql ! . params ,
2819+ format : 'JSON' ,
2820+ } ) ;
2821+ const { data } = await resp . json < {
2822+ timestamp : string ;
2823+ value : number ;
2824+ traceId : string ;
2825+ } > ( ) ;
2826+
2827+ expect ( data ) . toHaveLength ( 1 ) ;
2828+ expect ( Number ( data [ 0 ] . timestamp ) ) . toBe (
2829+ Date . parse ( `${ insertTs ( 1 ) . replace ( ' ' , 'T' ) } Z` ) ,
2830+ ) ;
2831+ expect ( data [ 0 ] . value ) . toBe ( 2.5 ) ;
2832+ expect ( data [ 0 ] . traceId ) . toBe ( traceId ) ;
2833+ } ) ;
27892834 } ) ;
27902835
27912836 // Formulas on event (log/trace) sources compile inline in the single-scan
0 commit comments