@@ -272,23 +272,32 @@ export function transformGreptimeDBLogs(sqlResponse: GreptimeResponse, query: CH
272
272
const labelColumnIndices : Record < string , number > = { } ;
273
273
const contextColumnIndices : Record < string , number > = { } ;
274
274
275
- columnSchemas . forEach ( ( schema , index ) => {
276
- const lowerCaseName = schema . name . toLowerCase ( ) ;
277
- if ( lowerCaseName === 'ts' || lowerCaseName === 'timestamp' ) {
278
- timestampColumnIndex = index ;
279
- } else if ( lowerCaseName === 'body' || lowerCaseName === 'message' ) {
280
- bodyColumnIndex = index ;
281
- } else if ( lowerCaseName === 'severity' || lowerCaseName === 'level' ) {
282
- severityColumnIndex = index ;
283
- } else if ( lowerCaseName === 'id' ) {
284
- idColumnIndex = index ;
285
- } else if ( contextColumns . includes ( schema . name ) ) {
286
- contextColumnIndices [ schema . name ] = index ;
287
- } else {
288
- // Consider other columns as potential labels
289
- labelColumnIndices [ schema . name ] = index ;
290
- }
291
- } ) ;
275
+
276
+ if ( 'builderOptions' in query ) {
277
+ const timeColumn = query . builderOptions ?. columns ?. find ( c => c . hint === 'time' )
278
+ const timeColumnName = timeColumn ?. alias || timeColumn ?. name
279
+ const bodyColumn = query . builderOptions ?. columns ?. find ( c => c . hint === 'log_message' )
280
+ const bodyColumnName = bodyColumn ?. alias || bodyColumn ?. name
281
+ const severityColumn = query . builderOptions ?. columns ?. find ( c => c . hint === 'log_level' )
282
+ const severityColumnName = severityColumn ?. alias || severityColumn ?. name
283
+
284
+ columnSchemas . forEach ( ( schema , index ) => {
285
+ const lowerCaseName = schema . name . toLowerCase ( ) ;
286
+ if ( lowerCaseName === timeColumnName ) {
287
+ timestampColumnIndex = index ;
288
+ } else if ( lowerCaseName === bodyColumnName ) {
289
+ bodyColumnIndex = index ;
290
+ } else if ( lowerCaseName === severityColumnName ) {
291
+ severityColumnIndex = index ;
292
+ } else if ( contextColumns . includes ( schema . name ) ) {
293
+ contextColumnIndices [ schema . name ] = index ;
294
+ } else {
295
+ // Consider other columns as potential labels
296
+ labelColumnIndices [ schema . name ] = index ;
297
+ }
298
+ } ) ;
299
+ }
300
+
292
301
293
302
// if (timestampColumnIndex === -1 || bodyColumnIndex === -1) {
294
303
// console.error('Timestamp or body column not found in GreptimeDB response.');
0 commit comments