-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VisBuilder] Fixes pipeline aggs (#3137)
* fixes pipeline aggs in visbuilder Signed-off-by: Ashwin P Chandran <[email protected]> * adds changelog Signed-off-by: Ashwin P Chandran <[email protected]> * Adds unit tests Signed-off-by: Ashwin P Chandran <[email protected]> * fixes pipeline aggs in visbuilder Signed-off-by: Ashwin P Chandran <[email protected]> * adds changelog Signed-off-by: Ashwin P Chandran <[email protected]> * Adds unit tests Signed-off-by: Ashwin P Chandran <[email protected]> * fixes unit tests Signed-off-by: Ashwin P Chandran <[email protected]> Signed-off-by: Ashwin P Chandran <[email protected]>
- Loading branch information
Showing
21 changed files
with
437 additions
and
113 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
24 changes: 24 additions & 0 deletions
24
src/plugins/vis_builder/public/application/utils/state_management/handlers/editor_state.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,24 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { setEditorState } from '../metadata_slice'; | ||
import { RootState, Store } from '../store'; | ||
|
||
export const handlerEditorState = (store: Store, state: RootState, previousState: RootState) => { | ||
const { metadata, ...renderState } = state; | ||
const { metadata: prevMetadata, ...prevRenderState } = previousState; | ||
|
||
// Need to make sure the editorStates are in the clean states(not the initial states) to indicate the viz finished loading | ||
// Because when loading a saved viz from saved object, the previousStore will differ from | ||
// the currentStore even tho there is no changes applied ( aggParams will | ||
// first be empty, and it then will change to not empty once the viz finished loading) | ||
if ( | ||
prevMetadata.editor.state === 'clean' && | ||
metadata.editor.state === 'clean' && | ||
JSON.stringify(renderState) !== JSON.stringify(prevRenderState) | ||
) { | ||
store.dispatch(setEditorState({ state: 'dirty' })); | ||
} | ||
}; |
67 changes: 67 additions & 0 deletions
67
src/plugins/vis_builder/public/application/utils/state_management/handlers/parent_aggs.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,67 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { findLast } from 'lodash'; | ||
import { BUCKET_TYPES, IMetricAggType, search } from '../../../../../../data/public'; | ||
import { VisBuilderServices } from '../../../../types'; | ||
import { RootState, Store } from '../store'; | ||
import { setAggParamValue } from '../visualization_slice'; | ||
|
||
/** | ||
* Parent pipeline aggs when combined with histogram aggs need `min_doc_count` to be set appropriately to avoid an error | ||
* on opensearch engine https://opensearch.org/docs/2.4/opensearch/pipeline-agg/#parent-aggregations | ||
*/ | ||
export const handlerParentAggs = async ( | ||
store: Store, | ||
state: RootState, | ||
services: VisBuilderServices | ||
) => { | ||
const { | ||
visualization: { activeVisualization, indexPattern = '' }, | ||
} = state; | ||
|
||
const { | ||
data: { | ||
indexPatterns, | ||
search: { aggs: aggService }, | ||
}, | ||
} = services; | ||
|
||
if (!activeVisualization) return state; | ||
|
||
const aggConfigs = aggService.createAggConfigs( | ||
await indexPatterns.get(indexPattern), | ||
activeVisualization.aggConfigParams | ||
); | ||
|
||
// Pipeline aggs should have a valid bucket agg | ||
const metricAggs = aggConfigs.aggs.filter((agg) => agg.schema === 'metric'); | ||
const lastParentPipelineAgg = findLast( | ||
metricAggs, | ||
({ type }: { type: IMetricAggType }) => type.subtype === search.aggs.parentPipelineType | ||
); | ||
const lastBucket = findLast(aggConfigs.aggs, (agg) => agg.type.type === 'buckets'); | ||
|
||
aggConfigs.aggs.forEach((agg) => { | ||
const isLastBucket = lastBucket?.id === agg.id; | ||
// When a Parent Pipeline agg is selected and this agg is the last bucket. | ||
const isLastBucketAgg = isLastBucket && lastParentPipelineAgg && agg.type; | ||
|
||
if ( | ||
isLastBucketAgg && | ||
([BUCKET_TYPES.DATE_HISTOGRAM, BUCKET_TYPES.HISTOGRAM] as any).includes(agg.type.name) | ||
) { | ||
store.dispatch( | ||
setAggParamValue({ | ||
aggId: agg.id, | ||
paramName: 'min_doc_count', | ||
// "histogram" agg has an editor for "min_doc_count" param, which accepts boolean | ||
// "date_histogram" agg doesn't have an editor for "min_doc_count" param, it should be set as a numeric value | ||
value: agg.type.name === 'histogram' ? true : 0, | ||
}) | ||
); | ||
} | ||
}); | ||
}; |
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
Oops, something went wrong.