Skip to content
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][Visualize] Enables histogram for histogram fields #131379

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
6 changes: 5 additions & 1 deletion src/plugins/data/common/search/aggs/buckets/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export const getHistogramBucketAgg = ({
{
name: 'field',
type: 'field',
filterFieldTypes: [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.NUMBER_RANGE],
filterFieldTypes: [
KBN_FIELD_TYPES.NUMBER,
KBN_FIELD_TYPES.NUMBER_RANGE,
KBN_FIELD_TYPES.HISTOGRAM,
],
},
{
/*
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/search/aggs/buckets/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const getRangeBucketAgg = ({ getFieldFormatsStart }: RangeBucketAggDepend
name: 'field',
type: 'field',
// number_range is not supported by Elasticsearch
filterFieldTypes: [KBN_FIELD_TYPES.NUMBER],
filterFieldTypes: [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.HISTOGRAM],
},
{
name: 'ranges',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function NumberIntervalParamEditor({
setValue,
}: AggParamEditorProps<string | undefined>) {
const field = agg.getField();
const fieldSupportsAuto = !field || field.type === 'number';
const fieldSupportsAuto = !field || field.type === 'number' || field.type === 'histogram';
const isAutoChecked = fieldSupportsAuto && isAutoInterval(value);
const base: number = get(editorConfig, 'interval.base') as number;
const min = base || 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,22 @@ describe('ranges', () => {
});
});

it('should return operation with the right type for histogram', () => {
expect(
rangeOperation.getPossibleOperationForField({
aggregatable: true,
searchable: true,
name: 'test',
displayName: 'test',
type: 'histogram',
})
).toEqual({
dataType: 'number',
isBucketed: true,
scale: 'interval',
});
});

it('should not return operation if field type is not number', () => {
expect(
rangeOperation.getPossibleOperationForField({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function getFieldDefaultFormat(indexPattern: IndexPattern, field: IndexPatternFi
return undefined;
}

const supportedTypes = ['number', 'histogram'];

export const rangeOperation: OperationDefinition<RangeIndexPatternColumn, 'field'> = {
type: 'range',
displayName: i18n.translate('xpack.lens.indexPattern.intervals', {
Expand All @@ -82,7 +84,7 @@ export const rangeOperation: OperationDefinition<RangeIndexPatternColumn, 'field
getInvalidFieldMessage(layer.columns[columnId] as FieldBasedIndexPatternColumn, indexPattern),
getPossibleOperationForField: ({ aggregationRestrictions, aggregatable, type }) => {
if (
type === 'number' &&
supportedTypes.includes(type) &&
aggregatable &&
(!aggregationRestrictions || aggregationRestrictions.range)
) {
Expand Down Expand Up @@ -121,7 +123,7 @@ export const rangeOperation: OperationDefinition<RangeIndexPatternColumn, 'field

return Boolean(
newField &&
newField.type === 'number' &&
supportedTypes.includes(newField.type) &&
newField.aggregatable &&
(!newField.aggregationRestrictions || newField.aggregationRestrictions.range)
);
Expand Down