-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into split-types-from-co…
…de-on-kbn-ui-shared-deps-src
- Loading branch information
Showing
152 changed files
with
2,952 additions
and
781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/plugins/data/common/search/expressions/utils/filters_adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Filter } from '@kbn/es-query'; | ||
import { ExpressionValueFilter } from 'src/plugins/expressions/common'; | ||
|
||
function getGroupFromFilter(filter: Filter) { | ||
const { meta } = filter; | ||
const { group } = meta ?? {}; | ||
return group; | ||
} | ||
|
||
function range(filter: Filter): ExpressionValueFilter { | ||
const { query } = filter; | ||
const { range: rangeQuery } = query ?? {}; | ||
const column = Object.keys(rangeQuery)[0]; | ||
const { gte: from, lte: to } = rangeQuery[column] ?? {}; | ||
return { | ||
filterGroup: getGroupFromFilter(filter), | ||
from, | ||
to, | ||
column, | ||
type: 'filter', | ||
filterType: 'time', | ||
and: [], | ||
}; | ||
} | ||
|
||
function luceneQueryString(filter: Filter): ExpressionValueFilter { | ||
const { query } = filter; | ||
const { query_string: queryString } = query ?? {}; | ||
const { query: queryValue } = queryString; | ||
|
||
return { | ||
filterGroup: getGroupFromFilter(filter), | ||
query: queryValue, | ||
type: 'filter', | ||
filterType: 'luceneQueryString', | ||
and: [], | ||
}; | ||
} | ||
|
||
function term(filter: Filter): ExpressionValueFilter { | ||
const { query } = filter; | ||
const { term: termQuery } = query ?? {}; | ||
const column = Object.keys(termQuery)[0]; | ||
const { value } = termQuery[column] ?? {}; | ||
|
||
return { | ||
filterGroup: getGroupFromFilter(filter), | ||
column, | ||
value, | ||
type: 'filter', | ||
filterType: 'exactly', | ||
and: [], | ||
}; | ||
} | ||
|
||
const adapters = { range, term, luceneQueryString }; | ||
|
||
export function adaptToExpressionValueFilter(filter: Filter): ExpressionValueFilter { | ||
const { query = {} } = filter; | ||
const filterType = Object.keys(query)[0] as keyof typeof adapters; | ||
const adapt = adapters[filterType]; | ||
if (!adapt || typeof adapt !== 'function') { | ||
throw new Error(`Unknown filter type: ${filterType}`); | ||
} | ||
return adapt(filter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
*/ | ||
|
||
export * from './function_wrapper'; | ||
export { adaptToExpressionValueFilter } from './filters_adapter'; |
1 change: 1 addition & 0 deletions
1
src/plugins/expressions/common/executor/__snapshots__/executor.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.