Skip to content

Commit

Permalink
[Discover] Remove field popover stats for ES|QL mode (elastic#198948)
Browse files Browse the repository at this point in the history
- Related to elastic#197538

## Summary

This PR removes the support of showing stats in the field popover in
ES|QL mode as this UX will be revisited in the future to provide better
results.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
2 people authored and CAWilson94 committed Nov 8, 2024
1 parent f838340 commit 8a7db5e
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 776 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,14 @@ describe('UnifiedFieldList FieldStats', () => {

expect(wrapper.text()).toBe('Summarymin29674max36821994Calculated from 5000 sample records.');
});

it('should not request field stats for ES|QL query', async () => {
const wrapper = await mountComponent(
<FieldStats {...defaultProps} query={{ esql: 'from logs* | limit 10' }} />
);

expect(loadFieldStats).toHaveBeenCalledTimes(0);

expect(wrapper.text()).toBe('Analysis is not available for this field.');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
canProvideNumberSummaryForField,
} from '../../utils/can_provide_stats';
import { loadFieldStats } from '../../services/field_stats';
import { loadFieldStatsTextBased } from '../../services/field_stats_text_based';
import type { AddFieldFilterHandler } from '../../types';
import {
FieldTopValues,
Expand Down Expand Up @@ -136,7 +135,7 @@ const FieldStatsComponent: React.FC<FieldStatsProps> = ({
const [dataView, changeDataView] = useState<DataView | null>(null);
const abortControllerRef = useRef<AbortController | null>(null);
const isCanceledRef = useRef<boolean>(false);
const isTextBased = !!query && isOfAggregateQueryType(query);
const isEsqlQuery = !!query && isOfAggregateQueryType(query);

const setState: typeof changeState = useCallback(
(nextState) => {
Expand Down Expand Up @@ -178,6 +177,12 @@ const FieldStatsComponent: React.FC<FieldStatsProps> = ({

setDataView(loadedDataView);

if (isEsqlQuery) {
// Not supported yet for ES|QL queries
// Previous implementation was removed in https://github.com/elastic/kibana/pull/198948/
return;
}

if (state.isLoading) {
return;
}
Expand All @@ -187,32 +192,17 @@ const FieldStatsComponent: React.FC<FieldStatsProps> = ({
abortControllerRef.current?.abort();
abortControllerRef.current = new AbortController();

const results = isTextBased
? await loadFieldStatsTextBased({
services: { data },
dataView: loadedDataView,
field,
fromDate,
toDate,
baseQuery: query,
abortController: abortControllerRef.current,
})
: await loadFieldStats({
services: { data },
dataView: loadedDataView,
field,
fromDate,
toDate,
dslQuery:
dslQuery ??
buildEsQuery(
loadedDataView,
query ?? [],
filters ?? [],
getEsQueryConfig(uiSettings)
),
abortController: abortControllerRef.current,
});
const results = await loadFieldStats({
services: { data },
dataView: loadedDataView,
field,
fromDate,
toDate,
dslQuery:
dslQuery ??
buildEsQuery(loadedDataView, query ?? [], filters ?? [], getEsQueryConfig(uiSettings)),
abortController: abortControllerRef.current,
});

abortControllerRef.current = null;

Expand Down Expand Up @@ -297,7 +287,7 @@ const FieldStatsComponent: React.FC<FieldStatsProps> = ({
let title = <></>;

function combineWithTitleAndFooter(el: React.ReactElement) {
const countsElement = getCountsElement(state, services, isTextBased, dataTestSubject);
const countsElement = getCountsElement(state, services, isEsqlQuery, dataTestSubject);

return (
<>
Expand All @@ -319,7 +309,7 @@ const FieldStatsComponent: React.FC<FieldStatsProps> = ({
);
}

if (!canProvideStatsForField(field, isTextBased)) {
if (!canProvideStatsForField(field, isEsqlQuery)) {
const messageNoAnalysis = (
<FieldSummaryMessage
message={i18n.translate('unifiedFieldList.fieldStats.notAvailableForThisFieldDescription', {
Expand All @@ -336,7 +326,7 @@ const FieldStatsComponent: React.FC<FieldStatsProps> = ({
: messageNoAnalysis;
}

if (canProvideNumberSummaryForField(field, isTextBased) && isNumberSummaryValid(numberSummary)) {
if (canProvideNumberSummaryForField(field, isEsqlQuery) && isNumberSummaryValid(numberSummary)) {
title = (
<EuiTitle size="xxxs">
<h6>
Expand Down Expand Up @@ -563,21 +553,19 @@ const FieldStatsComponent: React.FC<FieldStatsProps> = ({
function getCountsElement(
state: FieldStatsState,
services: FieldStatsServices,
isTextBased: boolean,
isEsqlQuery: boolean,
dataTestSubject: string
): JSX.Element {
const dataTestSubjDocsCount = 'unifiedFieldStats-statsFooter-docsCount';
const { fieldFormats } = services;
const { totalDocuments, sampledValues, sampledDocuments, topValues } = state;
const { totalDocuments, sampledDocuments } = state;

if (!totalDocuments) {
if (!totalDocuments || isEsqlQuery) {
return <></>;
}

let labelElement;

if (isTextBased) {
labelElement = topValues?.areExamples ? (
const labelElement =
sampledDocuments && sampledDocuments < totalDocuments ? (
<FormattedMessage
id="unifiedFieldList.fieldStats.calculatedFromSampleRecordsLabel"
defaultMessage="Calculated from {sampledDocumentsFormatted} sample {sampledDocuments, plural, one {record} other {records}}."
Expand All @@ -594,54 +582,20 @@ function getCountsElement(
/>
) : (
<FormattedMessage
id="unifiedFieldList.fieldStats.calculatedFromSampleValuesLabel"
defaultMessage="Calculated from {sampledValuesFormatted} sample {sampledValues, plural, one {value} other {values}}."
id="unifiedFieldList.fieldStats.calculatedFromTotalRecordsLabel"
defaultMessage="Calculated from {totalDocumentsFormatted} {totalDocuments, plural, one {record} other {records}}."
values={{
sampledValues,
sampledValuesFormatted: (
totalDocuments,
totalDocumentsFormatted: (
<strong data-test-subj={dataTestSubjDocsCount}>
{fieldFormats
.getDefaultInstance(KBN_FIELD_TYPES.NUMBER, [ES_FIELD_TYPES.INTEGER])
.convert(sampledValues)}
.convert(totalDocuments)}
</strong>
),
}}
/>
);
} else {
labelElement =
sampledDocuments && sampledDocuments < totalDocuments ? (
<FormattedMessage
id="unifiedFieldList.fieldStats.calculatedFromSampleRecordsLabel"
defaultMessage="Calculated from {sampledDocumentsFormatted} sample {sampledDocuments, plural, one {record} other {records}}."
values={{
sampledDocuments,
sampledDocumentsFormatted: (
<strong data-test-subj={dataTestSubjDocsCount}>
{fieldFormats
.getDefaultInstance(KBN_FIELD_TYPES.NUMBER, [ES_FIELD_TYPES.INTEGER])
.convert(sampledDocuments)}
</strong>
),
}}
/>
) : (
<FormattedMessage
id="unifiedFieldList.fieldStats.calculatedFromTotalRecordsLabel"
defaultMessage="Calculated from {totalDocumentsFormatted} {totalDocuments, plural, one {record} other {records}}."
values={{
totalDocuments,
totalDocumentsFormatted: (
<strong data-test-subj={dataTestSubjDocsCount}>
{fieldFormats
.getDefaultInstance(KBN_FIELD_TYPES.NUMBER, [ES_FIELD_TYPES.INTEGER])
.convert(totalDocuments)}
</strong>
),
}}
/>
);
}

return (
<EuiText color="subdued" size="xs" data-test-subj={`${dataTestSubject}-statsFooter`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {
UnifiedFieldListSidebarContainerStateService,
AddFieldFilterHandler,
} from '../../types';
import { canProvideStatsForFieldTextBased } from '../../utils/can_provide_stats';
import { canProvideStatsForEsqlField } from '../../utils/can_provide_stats';

interface GetCommonFieldItemButtonPropsParams {
stateService: UnifiedFieldListSidebarContainerStateService;
Expand Down Expand Up @@ -405,7 +405,7 @@ function UnifiedFieldListItemComponent({
/>
)}
renderContent={
(searchMode === 'text-based' && canProvideStatsForFieldTextBased(field)) ||
(searchMode === 'text-based' && canProvideStatsForEsqlField(field)) ||
searchMode === 'documents'
? renderPopover
: undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('fieldExamplesCalculator', function () {
values: getFieldValues(hits, dataView.fields.getByName('extension')!, dataView),
field: dataView.fields.getByName('extension')!,
count: 3,
isTextBased: false,
isEsqlQuery: false,
};
});

Expand Down Expand Up @@ -286,33 +286,19 @@ describe('fieldExamplesCalculator', function () {
expect(getFieldExampleBuckets(params).sampledValues).toBe(5);
});

it('works for text-based', function () {
const result = getFieldExampleBuckets({
values: [['a'], ['b'], ['a'], ['a']],
field: { name: 'message', type: 'string', esTypes: ['text'] } as DataViewField,
isTextBased: true,
});
expect(result).toMatchInlineSnapshot(`
Object {
"buckets": Array [
Object {
"count": 3,
"key": "a",
},
Object {
"count": 1,
"key": "b",
},
],
"sampledDocuments": 4,
"sampledValues": 4,
}
`);
it('should not work for ES|QL', function () {
expect(() =>
getFieldExampleBuckets({
values: [['a'], ['b'], ['a'], ['a']],
field: { name: 'message', type: 'string', esTypes: ['text'] } as DataViewField,
isEsqlQuery: true,
})
).toThrowError();
expect(() =>
getFieldExampleBuckets({
values: [['a'], ['b'], ['a'], ['a']],
field: { name: 'message', type: 'string', esTypes: ['keyword'] } as DataViewField,
isTextBased: true,
isEsqlQuery: true,
})
).toThrowError();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export interface FieldValueCountsParams {
values: FieldHitValue[];
field: DataViewField;
count?: number;
isTextBased: boolean;
isEsqlQuery: boolean;
}

export function getFieldExampleBuckets(params: FieldValueCountsParams, formatter?: FieldFormat) {
params = defaults(params, {
count: DEFAULT_SIMPLE_EXAMPLES_SIZE,
});

if (!canProvideExamplesForField(params.field, params.isTextBased)) {
if (!canProvideExamplesForField(params.field, params.isEsqlQuery)) {
throw new Error(
`Analysis is not available this field type: "${params.field.type}". Field name: "${params.field.name}"`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export async function getSimpleExamples(
values: getFieldValues(simpleExamplesResult.hits.hits, field, dataView),
field,
count: DEFAULT_SIMPLE_EXAMPLES_SIZE,
isTextBased: false,
isEsqlQuery: false,
},
formatter
);
Expand Down
Loading

0 comments on commit 8a7db5e

Please sign in to comment.