-
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
[ES|QL] Hide field statistics tab and Dashboard when ES|QL is in use, disable Index data visualizer for MATCH and QSRT functions #197538
Changes from 11 commits
f5fa6c6
8736c72
b35e69c
2957796
aff1b6f
a6145ce
ae086fc
1f9cef4
38d47b9
fafcc26
db63c8b
b2b7222
7321cf5
4215c9c
347e1ec
989a523
2dd74e9
3ec8263
cd06f88
2c4f740
0dfc116
881e57b
7ea2efb
b3c356e
bafff15
a8cd5be
6b7ee45
dc99c68
9d4f0f1
eabc053
62c5496
5ccbdf7
47f6210
ed826d0
5cf259a
2f2b2fb
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
import type { AggregateQuery, Query } from '@kbn/es-query'; | ||
import { Walker } from '@kbn/esql-ast'; | ||
import { parse } from '@kbn/esql-ast'; | ||
import { isOfAggregateQueryType } from '@kbn/es-query'; | ||
|
||
/** | ||
* Check if the query contains any of the function names being passed in | ||
* @param query | ||
* @param functions list of function names to check for | ||
* @returns | ||
*/ | ||
export const queryContainsFunction = ( | ||
query: AggregateQuery | Query | { [key: string]: any } | undefined | null, | ||
functions: string[] | ||
): boolean => { | ||
if (query && isOfAggregateQueryType(query)) { | ||
const { root } = parse(query.esql); | ||
return functions.some((f) => Walker.hasFunction(root, f)); | ||
} | ||
return false; | ||
}; | ||
|
||
const UNSAMPLABLE_FUNCTIONS = ['match', 'qstr']; | ||
/** | ||
* Check if the query contains any function that cannot be used after LIMIT clause | ||
* @param query | ||
* @returns | ||
*/ | ||
export const queryCannotBeSampled = ( | ||
query: AggregateQuery | Query | { [key: string]: any } | undefined | null | ||
): boolean => { | ||
return queryContainsFunction(query, UNSAMPLABLE_FUNCTIONS); | ||
}; |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -53,6 +53,10 @@ import { | |||
import { FieldSummaryMessage } from './field_summary_message'; | ||||
import { FieldNumberSummary, isNumberSummaryValid } from './field_number_summary'; | ||||
import { ErrorBoundary } from '../error_boundary'; | ||||
import { | ||||
FIELD_DATA_LABEL, | ||||
getReasonIfFieldStatsUnavailableForQuery, | ||||
} from '../../utils/get_warning_message'; | ||||
|
||||
export interface FieldStatsState { | ||||
isLoading: boolean; | ||||
|
@@ -187,6 +191,18 @@ const FieldStatsComponent: React.FC<FieldStatsProps> = ({ | |||
abortControllerRef.current?.abort(); | ||||
abortControllerRef.current = new AbortController(); | ||||
|
||||
/** | ||||
* If the ES|QL query is unsupported, we can exit early | ||||
*/ | ||||
const unsupportedReasonForQuery = isTextBased | ||||
? getReasonIfFieldStatsUnavailableForQuery(query, FIELD_DATA_LABEL) | ||||
: undefined; | ||||
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 file is quite large already. Let's move this logic to Line 56 in b628770
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. I ended up refactoring it to |
||||
|
||||
if (unsupportedReasonForQuery) { | ||||
setState((s) => ({ ...s, isLoading: false })); | ||||
return; | ||||
} | ||||
|
||||
const results = isTextBased | ||||
? await loadFieldStatsTextBased({ | ||||
services: { data }, | ||||
|
@@ -336,6 +352,20 @@ const FieldStatsComponent: React.FC<FieldStatsProps> = ({ | |||
: messageNoAnalysis; | ||||
} | ||||
|
||||
const unsupportedReasonForQuery = getReasonIfFieldStatsUnavailableForQuery( | ||||
query, | ||||
FIELD_DATA_LABEL | ||||
); | ||||
if (unsupportedReasonForQuery) { | ||||
const messageUnsupportedReason = <FieldSummaryMessage message={unsupportedReasonForQuery} />; | ||||
|
||||
return overrideMissingContent | ||||
? overrideMissingContent({ | ||||
reason: 'unsupported', | ||||
element: messageUnsupportedReason, | ||||
}) | ||||
: messageUnsupportedReason; | ||||
} | ||||
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. QQ: should we also skip the request to ES in this case? 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. Yes! Definitely. Thanks for catching that. I'll make the change. 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. Thanks! |
||||
if (canProvideNumberSummaryForField(field, isTextBased) && isNumberSummaryValid(numberSummary)) { | ||||
title = ( | ||||
<EuiTitle size="xxxs"> | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
import type { AggregateQuery, Query } from '@kbn/es-query'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { queryCannotBeSampled } from '@kbn/esql-utils'; | ||
|
||
const FIELD_STATISTICS_LABEL = i18n.translate('unifiedFieldList.fieldStats.fieldStatisticsLabel', { | ||
defaultMessage: `Field statistics are`, | ||
}); | ||
|
||
export const FIELD_DATA_LABEL = i18n.translate('unifiedFieldList.fieldStats.fieldDataLabel', { | ||
defaultMessage: `Field data is`, | ||
}); | ||
|
||
export const getReasonIfFieldStatsUnavailableForQuery = ( | ||
query?: AggregateQuery | Query | { [key: string]: any }, | ||
label: string = FIELD_STATISTICS_LABEL | ||
): string | undefined => { | ||
if (queryCannotBeSampled(query)) { | ||
return i18n.translate('unifiedFieldList.fieldStats.notAvailableForMatchESQLQueryDescription', { | ||
defaultMessage: `{label} not supported for ES|QL queries with 'MATCH' or 'QSTR' functions.`, | ||
values: { label }, | ||
}); | ||
} | ||
}; | ||
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 would not work for all translations. I think we better define 2 full messages (without concatenation). 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. Updated here |
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.
Can we add some unit tests?
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.
Updated here
b2b7222
(#197538)