-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lens esql generation #196049
base: main
Are you sure you want to change the base?
lens esql generation #196049
Changes from 96 commits
6a56775
02b4ce9
ca29b48
6f2d487
3e33117
cd2908e
31620f7
e181929
5c12195
6428efc
a097d5d
9854348
1c310e8
8733660
1ed9574
7ae6eb7
5d2b96d
8c3258b
f07ab43
e1e57b8
3dcccc5
2cc02b9
1f0e333
744fce4
f50288f
eb97bfa
047b62f
2e4e915
22a25a4
b99c96e
788921a
3d19a0c
9e3bf36
ca50dbb
219d137
e964d8e
7f5b0d4
1f0b622
f7e45b6
f83b14c
c5ce419
7ccff61
e40f3c7
d14e60e
2d9721c
a33acf9
1282dff
dd8b573
a66aac5
49994ca
71aeea7
5fe3d49
a00d274
a121f52
4bec564
6797280
faa4507
68a170f
2df80d1
2af476a
b34215b
6e3059b
93cd513
b0449bb
a64c6df
1355380
df614ab
4374d61
a1fd88d
c2e19cb
f8db55c
f683a80
c17eb1c
2ab401d
a603866
9d8b116
cb25122
1772aa7
ed49cd9
003a98c
a4adfa7
9bc39cd
1102f5e
b30c3ce
87e7f7b
fc03c86
b5bb6f4
3dfd811
9fae536
fadb2f8
895a92d
7dfebfc
45f221d
c9f594c
6933945
cfeaa80
2a44aaa
d0d76e8
c780d9f
aa58127
8766331
317c93b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,17 @@ import { | |
type AggregateQuery, | ||
} from '@kbn/es-query'; | ||
import { appendWhereClauseToESQLQuery } from '@kbn/esql-utils'; | ||
import { | ||
buildSimpleExistFilter, | ||
buildSimpleNumberRangeFilter, | ||
} from '@kbn/es-query/src/filters/build_filters'; | ||
import { getIndexPatterns, getSearchService } from '../../services'; | ||
import { AggConfigSerialized } from '../../../common/search/aggs'; | ||
import { mapAndFlattenFilters } from '../../query'; | ||
|
||
interface ValueClickDataContext { | ||
data: Array<{ | ||
table: Pick<Datatable, 'rows' | 'columns'>; | ||
table: Pick<Datatable, 'rows' | 'columns' | 'meta'>; | ||
column: number; | ||
row: number; | ||
value: any; | ||
|
@@ -129,6 +133,69 @@ export const createFilter = async ( | |
return filter; | ||
}; | ||
|
||
export const createFilterESQL = async ( | ||
table: Pick<Datatable, 'rows' | 'columns'>, | ||
columnIndex: number, | ||
rowIndex: number | ||
) => { | ||
if ( | ||
!table || | ||
!table.columns || | ||
!table.columns[columnIndex] || | ||
!table.columns[columnIndex].meta || | ||
!table.columns[columnIndex].meta.sourceParams?.sourceField || | ||
table.columns[columnIndex].meta.sourceParams?.sourceField === '___records___' | ||
ppisljar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) { | ||
return; | ||
} | ||
const column = table.columns[columnIndex]; | ||
const { indexPattern, sourceField, operationType, interval } = table.columns[columnIndex].meta | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be nice to have a type guard here |
||
.sourceParams as { | ||
indexPattern: string; | ||
sourceField: string; | ||
operationType: string; | ||
interval: number; | ||
}; | ||
|
||
const value = rowIndex > -1 ? table.rows[rowIndex][column.id] : null; | ||
if (value === null || value === undefined) { | ||
ppisljar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
|
||
const filters: Filter[] = []; | ||
|
||
if (operationType === 'date_histogram') { | ||
filters.push( | ||
buildSimpleNumberRangeFilter( | ||
sourceField, | ||
{ | ||
gte: value, | ||
lt: value + interval, | ||
format: 'strict_date_optional_time', | ||
}, | ||
indexPattern, | ||
value | ||
) | ||
); | ||
} else if (operationType === 'histogram') { | ||
filters.push( | ||
buildSimpleNumberRangeFilter( | ||
sourceField, | ||
{ | ||
gte: value, | ||
lt: value + interval, | ||
}, | ||
indexPattern, | ||
value | ||
) | ||
); | ||
ppisljar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
filters.push(buildSimpleExistFilter(sourceField, indexPattern)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean we're always going to create either a range or an exists filter when clicking on a value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is what is currently supported, on aggconfigs we also do ip range filters, ip prefix, terms and multiterms filters, but this is not yet supported on esql level at the moment (or by this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you let me know how to get into a situation in this PR where something other than an exists filter should be created? I can't seem to set up any Lens configurations that actually send the ES|QL query instead of the aggs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I think you wont find any Lukas, I was also trying to test this scenario There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lukas go to advanced settings and set time zone to UTC |
||
} | ||
|
||
return filters; | ||
}; | ||
|
||
/** @public */ | ||
export const createFiltersFromValueClickAction = async ({ | ||
data, | ||
|
@@ -141,7 +208,10 @@ export const createFiltersFromValueClickAction = async ({ | |
.filter((point) => point) | ||
.map(async (val) => { | ||
const { table, column, row } = val; | ||
const filter: Filter[] = (await createFilter(table, column, row)) || []; | ||
const filter = | ||
table.meta?.type === 'es_ql' | ||
? await createFilterESQL(table, column, row) | ||
ppisljar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: (await createFilter(table, column, row)) || []; | ||
if (filter) { | ||
filter.forEach((f) => { | ||
if (negate) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clicking on a metric with count(*) creates a wrong filter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in c9f594c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed now, the click is not enabled if the metric is showing count of records
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be enabled here though right?
I am clicking the metric but I dont get a filter