mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DataFrame: Add optional unique row id definition as frame.meta.uniqueRowIdFields (#80428)
* Define an unique id for a row in dataframe * Update comment * Rename attribute * Add comment about plugin sdk * Fix comment
This commit is contained in:
parent
5800e40fba
commit
5b122a25b3
@ -13,5 +13,6 @@ export {
|
||||
isTimeSeriesFrame,
|
||||
isTimeSeriesFrames,
|
||||
isTimeSeriesField,
|
||||
getRowUniqueId,
|
||||
} from './utils';
|
||||
export { StreamingDataFrame, StreamingFrameAction, type StreamingFrameOptions, closestIdx } from './StreamingDataFrame';
|
||||
|
@ -86,3 +86,15 @@ export function anySeriesWithTimeField(data: DataFrame[]) {
|
||||
export function hasTimeField(data: DataFrame): boolean {
|
||||
return data.fields.some((field) => field.type === FieldType.time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get row id based on the meta.uniqueRowIdFields attribute.
|
||||
* @param dataFrame
|
||||
* @param rowIndex
|
||||
*/
|
||||
export function getRowUniqueId(dataFrame: DataFrame, rowIndex: number) {
|
||||
if (dataFrame.meta?.uniqueRowIdFields === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return dataFrame.meta.uniqueRowIdFields.map((fieldIndex) => dataFrame.fields[fieldIndex].values[rowIndex]).join('-');
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ export const preferredVisualizationTypes = [
|
||||
export type PreferredVisualisationType = (typeof preferredVisualizationTypes)[number];
|
||||
|
||||
/**
|
||||
* Should be kept in sync with https://github.com/grafana/grafana-plugin-sdk-go/blob/main/data/frame_meta.go
|
||||
* @public
|
||||
*/
|
||||
export interface QueryResultMeta {
|
||||
@ -107,6 +108,14 @@ export interface QueryResultMeta {
|
||||
limit?: number; // used by log models and loki
|
||||
json?: boolean; // used to keep track of old json doc values
|
||||
instant?: boolean;
|
||||
|
||||
/**
|
||||
* Array of field indices which values create a unique id for each row. Ideally this should be globally unique ID
|
||||
* but that isn't guarantied. Should help with keeping track and deduplicating rows in visualizations, especially
|
||||
* with streaming data with frequent updates.
|
||||
* Example: TraceID in Tempo, table name + primary key in SQL
|
||||
*/
|
||||
uniqueRowIdFields?: number[];
|
||||
}
|
||||
|
||||
export interface QueryResultMetaStat extends FieldConfig {
|
||||
|
Loading…
Reference in New Issue
Block a user