2019-09-17 20:57:53 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
import { DatasourceSuggestion } from '../types';
|
2019-09-17 20:57:53 +02:00
|
|
|
import { generateId } from '../id_generator';
|
2019-10-09 21:20:55 +02:00
|
|
|
import { IndexPatternPrivateState } from './types';
|
|
|
|
import {
|
|
|
|
getDatasourceSuggestionsForField,
|
|
|
|
getDatasourceSuggestionsFromCurrentState,
|
2020-10-06 10:15:41 +02:00
|
|
|
getDatasourceSuggestionsForVisualizeField,
|
2019-10-09 21:20:55 +02:00
|
|
|
} from './indexpattern_suggestions';
|
2020-11-10 19:45:46 +01:00
|
|
|
import { documentField } from './document_field';
|
2020-11-10 14:31:04 +01:00
|
|
|
import { getFieldByNameFactory } from './pure_helpers';
|
2019-09-17 20:57:53 +02:00
|
|
|
|
|
|
|
jest.mock('./loader');
|
|
|
|
jest.mock('../id_generator');
|
|
|
|
|
2020-11-10 14:31:04 +01:00
|
|
|
const fieldsOne = [
|
|
|
|
{
|
|
|
|
name: 'timestamp',
|
|
|
|
displayName: 'timestampLabel',
|
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'start_date',
|
|
|
|
displayName: 'start_date',
|
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'bytes',
|
|
|
|
displayName: 'bytes',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'memory',
|
|
|
|
displayName: 'memory',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'source',
|
|
|
|
displayName: 'source',
|
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'dest',
|
|
|
|
displayName: 'dest',
|
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
2020-11-10 19:45:46 +01:00
|
|
|
documentField,
|
2020-11-10 14:31:04 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
const fieldsTwo = [
|
|
|
|
{
|
|
|
|
name: 'timestamp',
|
|
|
|
displayName: 'timestampLabel',
|
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
aggregationRestrictions: {
|
|
|
|
date_histogram: {
|
|
|
|
agg: 'date_histogram',
|
|
|
|
fixed_interval: '1d',
|
|
|
|
delay: '7d',
|
|
|
|
time_zone: 'UTC',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-11-10 14:31:04 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'bytes',
|
|
|
|
displayName: 'bytes',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
aggregationRestrictions: {
|
|
|
|
// Ignored in the UI
|
|
|
|
histogram: {
|
|
|
|
agg: 'histogram',
|
|
|
|
interval: 1000,
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-11-10 14:31:04 +01:00
|
|
|
avg: {
|
|
|
|
agg: 'avg',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-11-10 14:31:04 +01:00
|
|
|
max: {
|
|
|
|
agg: 'max',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-11-10 14:31:04 +01:00
|
|
|
min: {
|
|
|
|
agg: 'min',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-11-10 14:31:04 +01:00
|
|
|
sum: {
|
|
|
|
agg: 'sum',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'source',
|
|
|
|
displayName: 'source',
|
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
aggregationRestrictions: {
|
|
|
|
terms: {
|
|
|
|
agg: 'terms',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-11-10 14:31:04 +01:00
|
|
|
},
|
|
|
|
},
|
2020-11-10 19:45:46 +01:00
|
|
|
documentField,
|
2020-11-10 14:31:04 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
const expectedIndexPatterns = {
|
|
|
|
1: {
|
|
|
|
id: '1',
|
|
|
|
title: 'my-fake-index-pattern',
|
|
|
|
timeFieldName: 'timestamp',
|
|
|
|
hasRestrictions: false,
|
|
|
|
fields: fieldsOne,
|
|
|
|
getFieldByName: getFieldByNameFactory(fieldsOne),
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
2: {
|
|
|
|
id: '2',
|
|
|
|
title: 'my-fake-restricted-pattern',
|
2020-08-26 09:09:40 +02:00
|
|
|
hasRestrictions: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
timeFieldName: 'timestamp',
|
2020-11-10 14:31:04 +01:00
|
|
|
fields: fieldsTwo,
|
|
|
|
getFieldByName: getFieldByNameFactory(fieldsTwo),
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
function testInitialState(): IndexPatternPrivateState {
|
|
|
|
return {
|
|
|
|
currentIndexPatternId: '1',
|
|
|
|
indexPatternRefs: [],
|
2019-10-14 18:46:33 +02:00
|
|
|
existingFields: {},
|
2019-10-09 21:20:55 +02:00
|
|
|
indexPatterns: expectedIndexPatterns,
|
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
indexPatternId: '1',
|
|
|
|
columnOrder: ['col1'],
|
|
|
|
columns: {
|
|
|
|
col1: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
|
|
|
|
// Private
|
|
|
|
operationType: 'terms',
|
2020-10-01 13:39:10 +02:00
|
|
|
sourceField: 'dest',
|
2019-10-09 21:20:55 +02:00
|
|
|
params: {
|
|
|
|
size: 5,
|
|
|
|
orderBy: { type: 'alphabetical' },
|
|
|
|
orderDirection: 'asc',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
},
|
2020-07-01 10:08:37 +02:00
|
|
|
isFirstExistenceFetch: false,
|
2019-10-09 21:20:55 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('IndexPattern Data Source suggestions', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
let count = 0;
|
|
|
|
jest.resetAllMocks();
|
|
|
|
(generateId as jest.Mock).mockImplementation(() => `id${++count}`);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
describe('#getDatasourceSuggestionsForField', () => {
|
2019-09-17 20:57:53 +02:00
|
|
|
describe('with no layer', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
function stateWithoutLayer() {
|
|
|
|
return {
|
|
|
|
...testInitialState(),
|
2019-09-17 20:57:53 +02:00
|
|
|
layers: {},
|
2019-10-09 21:20:55 +02:00
|
|
|
};
|
|
|
|
}
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-11-17 10:11:44 +01:00
|
|
|
it('should apply a bucketed aggregation for a string field, using metric for sorting', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(stateWithoutLayer(), '1', {
|
|
|
|
name: 'source',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'source',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
2019-10-09 21:20:55 +02:00
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnOrder: ['id3', 'id2'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-11-17 10:11:44 +01:00
|
|
|
id3: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'terms',
|
|
|
|
sourceField: 'source',
|
2020-11-17 10:11:44 +01:00
|
|
|
params: expect.objectContaining({
|
|
|
|
size: 5,
|
|
|
|
orderBy: { columnId: 'id2', type: 'column' },
|
|
|
|
}),
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
2020-11-17 10:11:44 +01:00
|
|
|
id2: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'count',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: [
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id3',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id2',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
],
|
2019-10-09 21:20:55 +02:00
|
|
|
layerId: 'id1',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should apply a bucketed aggregation for a date field', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(stateWithoutLayer(), '1', {
|
|
|
|
name: 'timestamp',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'timestampLabel',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnOrder: ['id3', 'id2'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-11-17 10:11:44 +01:00
|
|
|
id3: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'date_histogram',
|
|
|
|
sourceField: 'timestamp',
|
|
|
|
}),
|
2020-11-17 10:11:44 +01:00
|
|
|
id2: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'count',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: [
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id3',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id2',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
],
|
2019-10-09 21:20:55 +02:00
|
|
|
layerId: 'id1',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should select a metric for a number field', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(stateWithoutLayer(), '1', {
|
|
|
|
name: 'bytes',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'bytes',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: expect.objectContaining({
|
2020-11-10 19:45:46 +01:00
|
|
|
columnOrder: ['id3', 'id2'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-11-10 19:45:46 +01:00
|
|
|
id3: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'date_histogram',
|
|
|
|
sourceField: 'timestamp',
|
|
|
|
}),
|
2020-11-10 19:45:46 +01:00
|
|
|
id2: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'bytes',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: [
|
|
|
|
expect.objectContaining({
|
2020-11-10 19:45:46 +01:00
|
|
|
columnId: 'id3',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2020-11-10 19:45:46 +01:00
|
|
|
columnId: 'id2',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
],
|
2019-10-09 21:20:55 +02:00
|
|
|
layerId: 'id1',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-09-25 16:58:46 +02:00
|
|
|
it('should make a metric suggestion for a number field if there is no time field', async () => {
|
2019-09-17 20:57:53 +02:00
|
|
|
const state: IndexPatternPrivateState = {
|
2019-10-09 21:20:55 +02:00
|
|
|
indexPatternRefs: [],
|
2019-10-14 18:46:33 +02:00
|
|
|
existingFields: {},
|
2019-09-17 20:57:53 +02:00
|
|
|
currentIndexPatternId: '1',
|
2020-07-01 10:08:37 +02:00
|
|
|
isFirstExistenceFetch: false,
|
2019-09-17 20:57:53 +02:00
|
|
|
indexPatterns: {
|
|
|
|
1: {
|
|
|
|
id: '1',
|
|
|
|
title: 'no timefield',
|
2020-08-26 09:09:40 +02:00
|
|
|
hasRestrictions: false,
|
2019-09-17 20:57:53 +02:00
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: 'bytes',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'bytes',
|
2019-09-17 20:57:53 +02:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
],
|
2020-11-10 14:31:04 +01:00
|
|
|
getFieldByName: getFieldByNameFactory([
|
|
|
|
{
|
|
|
|
name: 'bytes',
|
|
|
|
displayName: 'bytes',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
]),
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
indexPatternId: '1',
|
|
|
|
columnOrder: [],
|
|
|
|
columns: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(state, '1', {
|
|
|
|
name: 'bytes',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'bytes',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-25 16:58:46 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
first: expect.objectContaining({
|
2019-10-09 21:20:55 +02:00
|
|
|
columnOrder: ['id1'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'bytes',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
2019-09-25 16:58:46 +02:00
|
|
|
})
|
|
|
|
);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with a previous empty layer', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
function stateWithEmptyLayer() {
|
|
|
|
const state = testInitialState();
|
|
|
|
return {
|
|
|
|
...state,
|
2019-09-17 20:57:53 +02:00
|
|
|
layers: {
|
|
|
|
previousLayer: {
|
|
|
|
indexPatternId: '1',
|
|
|
|
columns: {},
|
|
|
|
columnOrder: [],
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
};
|
|
|
|
}
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-11-17 10:11:44 +01:00
|
|
|
it('should apply a bucketed aggregation for a string field, using metric for sorting', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(stateWithEmptyLayer(), '1', {
|
|
|
|
name: 'source',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'source',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
previousLayer: expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnOrder: ['id2', 'id1'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-11-17 10:11:44 +01:00
|
|
|
id2: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'terms',
|
|
|
|
sourceField: 'source',
|
2020-11-17 10:11:44 +01:00
|
|
|
params: expect.objectContaining({
|
|
|
|
size: 5,
|
|
|
|
orderBy: { columnId: 'id1', type: 'column' },
|
|
|
|
}),
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
2020-11-17 10:11:44 +01:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'count',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: [
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id2',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id1',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
layerId: 'previousLayer',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should apply a bucketed aggregation for a date field', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(stateWithEmptyLayer(), '1', {
|
|
|
|
name: 'timestamp',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'timestampLabel',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
previousLayer: expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnOrder: ['id2', 'id1'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-11-17 10:11:44 +01:00
|
|
|
id2: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'date_histogram',
|
|
|
|
sourceField: 'timestamp',
|
|
|
|
}),
|
2020-11-17 10:11:44 +01:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'count',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: [
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id2',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id1',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
layerId: 'previousLayer',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should select a metric for a number field', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(stateWithEmptyLayer(), '1', {
|
|
|
|
name: 'bytes',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'bytes',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
previousLayer: expect.objectContaining({
|
2020-11-10 19:45:46 +01:00
|
|
|
columnOrder: ['id2', 'id1'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-11-10 19:45:46 +01:00
|
|
|
id2: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'date_histogram',
|
|
|
|
sourceField: 'timestamp',
|
|
|
|
}),
|
2020-11-10 19:45:46 +01:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'bytes',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: [
|
|
|
|
expect.objectContaining({
|
2020-11-10 19:45:46 +01:00
|
|
|
columnId: 'id2',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2020-11-10 19:45:46 +01:00
|
|
|
columnId: 'id1',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
layerId: 'previousLayer',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-09-25 16:58:46 +02:00
|
|
|
it('should make a metric suggestion for a number field if there is no time field', async () => {
|
2019-09-17 20:57:53 +02:00
|
|
|
const state: IndexPatternPrivateState = {
|
2019-10-09 21:20:55 +02:00
|
|
|
indexPatternRefs: [],
|
2019-10-14 18:46:33 +02:00
|
|
|
existingFields: {},
|
2019-09-17 20:57:53 +02:00
|
|
|
currentIndexPatternId: '1',
|
2020-07-01 10:08:37 +02:00
|
|
|
isFirstExistenceFetch: false,
|
2019-09-17 20:57:53 +02:00
|
|
|
indexPatterns: {
|
|
|
|
1: {
|
|
|
|
id: '1',
|
|
|
|
title: 'no timefield',
|
2020-08-26 09:09:40 +02:00
|
|
|
hasRestrictions: false,
|
2019-09-17 20:57:53 +02:00
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: 'bytes',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'bytes',
|
2019-09-17 20:57:53 +02:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
],
|
2020-11-10 14:31:04 +01:00
|
|
|
|
|
|
|
getFieldByName: getFieldByNameFactory([
|
|
|
|
{
|
|
|
|
name: 'bytes',
|
|
|
|
displayName: 'bytes',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
]),
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
layers: {
|
|
|
|
previousLayer: {
|
|
|
|
indexPatternId: '1',
|
|
|
|
columnOrder: [],
|
|
|
|
columns: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(state, '1', {
|
|
|
|
name: 'bytes',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'bytes',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-25 16:58:46 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
previousLayer: expect.objectContaining({
|
2019-10-09 21:20:55 +02:00
|
|
|
columnOrder: ['id1'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'bytes',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
2019-09-25 16:58:46 +02:00
|
|
|
})
|
|
|
|
);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
2019-10-30 00:05:03 +01:00
|
|
|
|
|
|
|
it('creates a new layer and replaces layer if no match is found', () => {
|
|
|
|
const suggestions = getDatasourceSuggestionsForField(stateWithEmptyLayer(), '2', {
|
|
|
|
name: 'source',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'source',
|
2019-10-30 00:05:03 +01:00
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(suggestions).toContainEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
previousLayer: expect.objectContaining({
|
|
|
|
indexPatternId: '1',
|
|
|
|
}),
|
|
|
|
id1: expect.objectContaining({
|
|
|
|
indexPatternId: '2',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: expect.arrayContaining([]),
|
|
|
|
layerId: 'id1',
|
|
|
|
},
|
|
|
|
keptLayerIds: ['previousLayer'],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestions).toContainEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
id1: expect.objectContaining({
|
|
|
|
indexPatternId: '2',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: false,
|
|
|
|
columns: expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
columnId: expect.any(String),
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
layerId: 'id1',
|
|
|
|
},
|
|
|
|
keptLayerIds: [],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('suggesting extensions to non-empty tables', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
function stateWithNonEmptyTables(): IndexPatternPrivateState {
|
|
|
|
const state = testInitialState();
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
return {
|
|
|
|
...state,
|
2019-09-17 20:57:53 +02:00
|
|
|
currentIndexPatternId: '1',
|
|
|
|
layers: {
|
|
|
|
previousLayer: {
|
|
|
|
indexPatternId: '2',
|
|
|
|
columns: {},
|
|
|
|
columnOrder: [],
|
|
|
|
},
|
|
|
|
currentLayer: {
|
|
|
|
indexPatternId: '1',
|
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
cola: {
|
2019-09-17 20:57:53 +02:00
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
sourceField: 'source',
|
|
|
|
label: 'values of source',
|
|
|
|
operationType: 'terms',
|
|
|
|
params: {
|
2019-10-09 21:20:55 +02:00
|
|
|
orderBy: { type: 'column', columnId: 'colb' },
|
2019-09-17 20:57:53 +02:00
|
|
|
orderDirection: 'asc',
|
|
|
|
size: 5,
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
colb: {
|
2019-09-17 20:57:53 +02:00
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
sourceField: 'bytes',
|
|
|
|
label: 'Avg of bytes',
|
|
|
|
operationType: 'avg',
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
columnOrder: ['cola', 'colb'],
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
};
|
|
|
|
}
|
2019-09-17 20:57:53 +02:00
|
|
|
|
|
|
|
it('replaces an existing date histogram column on date field', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = stateWithNonEmptyTables();
|
|
|
|
const suggestions = getDatasourceSuggestionsForField(
|
2019-09-17 20:57:53 +02:00
|
|
|
{
|
|
|
|
...initialState,
|
|
|
|
layers: {
|
|
|
|
previousLayer: initialState.layers.previousLayer,
|
|
|
|
currentLayer: {
|
|
|
|
...initialState.layers.currentLayer,
|
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
cola: {
|
2019-09-17 20:57:53 +02:00
|
|
|
dataType: 'date',
|
|
|
|
isBucketed: true,
|
|
|
|
sourceField: 'timestamp',
|
|
|
|
label: 'date histogram of timestamp',
|
|
|
|
operationType: 'date_histogram',
|
|
|
|
params: {
|
|
|
|
interval: 'w',
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
colb: {
|
2019-09-17 20:57:53 +02:00
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
sourceField: 'bytes',
|
|
|
|
label: 'Avg of bytes',
|
|
|
|
operationType: 'avg',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
'1',
|
2019-09-17 20:57:53 +02:00
|
|
|
{
|
2019-10-09 21:20:55 +02:00
|
|
|
name: 'start_date',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'start_date',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
previousLayer: initialState.layers.previousLayer,
|
|
|
|
currentLayer: expect.objectContaining({
|
2020-11-10 19:45:46 +01:00
|
|
|
columnOrder: ['cola', 'colb'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-11-10 19:45:46 +01:00
|
|
|
cola: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'date_histogram',
|
|
|
|
sourceField: 'start_date',
|
|
|
|
}),
|
2019-10-09 21:20:55 +02:00
|
|
|
colb: initialState.layers.currentLayer.columns.colb,
|
2019-09-26 15:56:30 +02:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
2019-09-17 20:57:53 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('puts a date histogram column after the last bucket column on date field', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = stateWithNonEmptyTables();
|
|
|
|
const suggestions = getDatasourceSuggestionsForField(initialState, '1', {
|
|
|
|
name: 'timestamp',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'timestampLabel',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
previousLayer: initialState.layers.previousLayer,
|
|
|
|
currentLayer: expect.objectContaining({
|
2019-10-09 21:20:55 +02:00
|
|
|
columnOrder: ['cola', 'id1', 'colb'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
|
|
|
...initialState.layers.currentLayer.columns,
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'date_histogram',
|
|
|
|
sourceField: 'timestamp',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'extended',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: [
|
|
|
|
expect.objectContaining({
|
2019-10-09 21:20:55 +02:00
|
|
|
columnId: 'cola',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2019-10-09 21:20:55 +02:00
|
|
|
columnId: 'id1',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2019-10-09 21:20:55 +02:00
|
|
|
columnId: 'colb',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
layerId: 'currentLayer',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not use the same field for bucketing multiple times', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(stateWithNonEmptyTables(), '1', {
|
|
|
|
name: 'source',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'source',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-10-15 23:44:08 +02:00
|
|
|
expect(suggestions).toHaveLength(1);
|
|
|
|
// Check that the suggestion is a single metric
|
|
|
|
expect(suggestions[0].table.columns).toHaveLength(1);
|
|
|
|
expect(suggestions[0].table.columns[0].operation.isBucketed).toBeFalsy();
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2020-04-30 04:03:41 +02:00
|
|
|
it('appends a terms column with default size on string field', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = stateWithNonEmptyTables();
|
|
|
|
const suggestions = getDatasourceSuggestionsForField(initialState, '1', {
|
|
|
|
name: 'dest',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'dest',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
previousLayer: initialState.layers.previousLayer,
|
|
|
|
currentLayer: expect.objectContaining({
|
2020-03-23 22:11:09 +01:00
|
|
|
columnOrder: ['cola', 'id1', 'colb'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
|
|
|
...initialState.layers.currentLayer.columns,
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'terms',
|
|
|
|
sourceField: 'dest',
|
2020-04-30 04:03:41 +02:00
|
|
|
params: expect.objectContaining({ size: 3 }),
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
2019-09-17 20:57:53 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-11-10 19:45:46 +01:00
|
|
|
it('suggests both replacing and adding metric if only one other metric is set', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = stateWithNonEmptyTables();
|
|
|
|
const suggestions = getDatasourceSuggestionsForField(initialState, '1', {
|
|
|
|
name: 'memory',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'memory',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2020-03-23 22:11:09 +01:00
|
|
|
expect(suggestions).toContainEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: expect.objectContaining({
|
|
|
|
currentLayer: expect.objectContaining({
|
2020-04-10 18:29:26 +02:00
|
|
|
columnOrder: ['cola', 'colb'],
|
2020-03-23 22:11:09 +01:00
|
|
|
columns: {
|
|
|
|
cola: initialState.layers.currentLayer.columns.cola,
|
2020-04-10 18:29:26 +02:00
|
|
|
colb: expect.objectContaining({
|
2020-03-23 22:11:09 +01:00
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'memory',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
);
|
2020-11-10 19:45:46 +01:00
|
|
|
|
|
|
|
expect(suggestions).toContainEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: expect.objectContaining({
|
|
|
|
currentLayer: expect.objectContaining({
|
|
|
|
columnOrder: ['cola', 'colb', 'id1'],
|
|
|
|
columns: {
|
|
|
|
cola: initialState.layers.currentLayer.columns.cola,
|
|
|
|
colb: initialState.layers.currentLayer.columns.colb,
|
|
|
|
id1: expect.objectContaining({
|
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'memory',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
);
|
2020-03-23 22:11:09 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('adds a metric column on a number field if no other metrics set', () => {
|
|
|
|
const initialState = stateWithNonEmptyTables();
|
|
|
|
const modifiedState: IndexPatternPrivateState = {
|
|
|
|
...initialState,
|
|
|
|
layers: {
|
|
|
|
...initialState.layers,
|
|
|
|
currentLayer: {
|
|
|
|
...initialState.layers.currentLayer,
|
|
|
|
columns: {
|
|
|
|
cola: initialState.layers.currentLayer.columns.cola,
|
|
|
|
},
|
|
|
|
columnOrder: ['cola'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const suggestions = getDatasourceSuggestionsForField(modifiedState, '1', {
|
|
|
|
name: 'memory',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'memory',
|
2020-03-23 22:11:09 +01:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
2020-03-23 22:11:09 +01:00
|
|
|
previousLayer: modifiedState.layers.previousLayer,
|
2019-09-26 15:56:30 +02:00
|
|
|
currentLayer: expect.objectContaining({
|
2020-03-23 22:11:09 +01:00
|
|
|
columnOrder: ['cola', 'id1'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-03-23 22:11:09 +01:00
|
|
|
...modifiedState.layers.currentLayer.columns,
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'memory',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
2019-09-17 20:57:53 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-11-10 19:45:46 +01:00
|
|
|
it('skips duplicates when the field is already in use', () => {
|
|
|
|
const initialState = stateWithNonEmptyTables();
|
|
|
|
const suggestions = getDatasourceSuggestionsForField(initialState, '1', {
|
|
|
|
name: 'bytes',
|
|
|
|
displayName: 'bytes',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(suggestions).not.toContain(expect.objectContaining({ changeType: 'extended' }));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('skips duplicates when the document-specific field is already in use', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = stateWithNonEmptyTables();
|
2020-03-23 22:11:09 +01:00
|
|
|
const modifiedState: IndexPatternPrivateState = {
|
|
|
|
...initialState,
|
|
|
|
layers: {
|
|
|
|
...initialState.layers,
|
|
|
|
currentLayer: {
|
|
|
|
...initialState.layers.currentLayer,
|
|
|
|
columns: {
|
|
|
|
...initialState.layers.currentLayer.columns,
|
2020-11-10 19:45:46 +01:00
|
|
|
colb: {
|
|
|
|
label: 'Count of records',
|
|
|
|
dataType: 'document',
|
2020-03-23 22:11:09 +01:00
|
|
|
isBucketed: false,
|
2020-11-10 19:45:46 +01:00
|
|
|
|
|
|
|
operationType: 'count',
|
|
|
|
sourceField: 'Records',
|
2020-03-23 22:11:09 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-11-10 19:45:46 +01:00
|
|
|
const suggestions = getDatasourceSuggestionsForField(modifiedState, '1', documentField);
|
|
|
|
expect(suggestions).not.toContain(expect.objectContaining({ changeType: 'extended' }));
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('finding the layer that is using the current index pattern', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
function stateWithCurrentIndexPattern(): IndexPatternPrivateState {
|
|
|
|
const state = testInitialState();
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
return {
|
|
|
|
...state,
|
2019-09-17 20:57:53 +02:00
|
|
|
currentIndexPatternId: '1',
|
|
|
|
layers: {
|
|
|
|
previousLayer: {
|
|
|
|
indexPatternId: '1',
|
|
|
|
columns: {},
|
|
|
|
columnOrder: [],
|
|
|
|
},
|
|
|
|
currentLayer: {
|
|
|
|
indexPatternId: '2',
|
|
|
|
columns: {},
|
|
|
|
columnOrder: [],
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
};
|
|
|
|
}
|
2019-09-17 20:57:53 +02:00
|
|
|
|
|
|
|
it('suggests on the layer that matches by indexPatternId', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = stateWithCurrentIndexPattern();
|
|
|
|
const suggestions = getDatasourceSuggestionsForField(initialState, '2', {
|
|
|
|
name: 'timestamp',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'timestampLabel',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
aggregationRestrictions: {
|
|
|
|
date_histogram: {
|
|
|
|
agg: 'date_histogram',
|
|
|
|
fixed_interval: '1d',
|
|
|
|
delay: '7d',
|
|
|
|
time_zone: 'UTC',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
previousLayer: initialState.layers.previousLayer,
|
|
|
|
currentLayer: expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnOrder: ['id2', 'id1'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-11-17 10:11:44 +01:00
|
|
|
id2: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'date_histogram',
|
|
|
|
sourceField: 'timestamp',
|
|
|
|
}),
|
2020-11-17 10:11:44 +01:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'count',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: [
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id2',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id1',
|
2019-09-26 15:56:30 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
layerId: 'currentLayer',
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('suggests on the layer with the fewest columns that matches by indexPatternId', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = stateWithCurrentIndexPattern();
|
|
|
|
const suggestions = getDatasourceSuggestionsForField(initialState, '1', {
|
|
|
|
name: 'timestamp',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'timestampLabel',
|
2019-10-09 21:20:55 +02:00
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2019-09-26 15:56:30 +02:00
|
|
|
expect(suggestions).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
currentLayer: initialState.layers.currentLayer,
|
|
|
|
previousLayer: expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnOrder: ['id2', 'id1'],
|
2019-09-26 15:56:30 +02:00
|
|
|
columns: {
|
2020-11-17 10:11:44 +01:00
|
|
|
id2: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'date_histogram',
|
|
|
|
sourceField: 'timestamp',
|
|
|
|
}),
|
2020-11-17 10:11:44 +01:00
|
|
|
id1: expect.objectContaining({
|
2019-09-26 15:56:30 +02:00
|
|
|
operationType: 'count',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
2019-09-17 20:57:53 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-10-06 10:15:41 +02:00
|
|
|
describe('#getDatasourceSuggestionsForVisualizeField', () => {
|
|
|
|
describe('with no layer', () => {
|
|
|
|
function stateWithoutLayer() {
|
|
|
|
return {
|
|
|
|
...testInitialState(),
|
|
|
|
layers: {},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should return an empty array if the field does not exist', () => {
|
|
|
|
const suggestions = getDatasourceSuggestionsForVisualizeField(
|
|
|
|
stateWithoutLayer(),
|
|
|
|
'1',
|
|
|
|
'field_not_exist'
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestions).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should apply a bucketed aggregation for a string field', () => {
|
|
|
|
const suggestions = getDatasourceSuggestionsForVisualizeField(
|
|
|
|
stateWithoutLayer(),
|
|
|
|
'1',
|
|
|
|
'source'
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(suggestions).toContainEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
state: expect.objectContaining({
|
|
|
|
layers: {
|
|
|
|
id1: expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnOrder: ['id3', 'id2'],
|
2020-10-06 10:15:41 +02:00
|
|
|
columns: {
|
2020-11-17 10:11:44 +01:00
|
|
|
id3: expect.objectContaining({
|
2020-10-06 10:15:41 +02:00
|
|
|
operationType: 'terms',
|
|
|
|
sourceField: 'source',
|
|
|
|
params: expect.objectContaining({ size: 5 }),
|
|
|
|
}),
|
2020-11-17 10:11:44 +01:00
|
|
|
id2: expect.objectContaining({
|
2020-10-06 10:15:41 +02:00
|
|
|
operationType: 'count',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
table: {
|
|
|
|
changeType: 'initial',
|
|
|
|
label: undefined,
|
|
|
|
isMultiRow: true,
|
|
|
|
columns: [
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id3',
|
2020-10-06 10:15:41 +02:00
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
2020-11-17 10:11:44 +01:00
|
|
|
columnId: 'id2',
|
2020-10-06 10:15:41 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
layerId: 'id1',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
|
|
|
|
describe('#getDatasourceSuggestionsFromCurrentState', () => {
|
|
|
|
it('returns no suggestions if there are no columns', () => {
|
|
|
|
expect(
|
2019-10-09 21:20:55 +02:00
|
|
|
getDatasourceSuggestionsFromCurrentState({
|
2020-07-01 10:08:37 +02:00
|
|
|
isFirstExistenceFetch: false,
|
2019-10-09 21:20:55 +02:00
|
|
|
indexPatternRefs: [],
|
2019-10-14 18:46:33 +02:00
|
|
|
existingFields: {},
|
2019-09-17 20:57:53 +02:00
|
|
|
indexPatterns: expectedIndexPatterns,
|
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
indexPatternId: '1',
|
|
|
|
columnOrder: [],
|
|
|
|
columns: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
currentIndexPatternId: '1',
|
|
|
|
})
|
|
|
|
).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a single suggestion containing the current columns for each layer', async () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = testInitialState();
|
|
|
|
const state: IndexPatternPrivateState = {
|
|
|
|
...initialState,
|
2019-09-17 20:57:53 +02:00
|
|
|
layers: {
|
2019-10-09 21:20:55 +02:00
|
|
|
...initialState.layers,
|
2019-09-17 20:57:53 +02:00
|
|
|
second: {
|
2019-10-09 21:20:55 +02:00
|
|
|
...initialState.layers.first,
|
|
|
|
columnOrder: ['cola'],
|
2019-09-17 20:57:53 +02:00
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
cola: {
|
2019-09-17 20:57:53 +02:00
|
|
|
label: 'My Op 2',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
|
|
|
|
// Private
|
|
|
|
operationType: 'terms',
|
2020-10-01 13:39:10 +02:00
|
|
|
sourceField: 'dest',
|
2019-09-17 20:57:53 +02:00
|
|
|
params: {
|
|
|
|
size: 5,
|
|
|
|
orderBy: { type: 'alphabetical' },
|
|
|
|
orderDirection: 'asc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const result = getDatasourceSuggestionsFromCurrentState(state);
|
2019-10-30 00:05:03 +01:00
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
expect(result).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
2019-10-30 00:05:03 +01:00
|
|
|
table: expect.objectContaining({
|
2019-09-17 20:57:53 +02:00
|
|
|
isMultiRow: true,
|
|
|
|
changeType: 'unchanged',
|
|
|
|
label: undefined,
|
2019-10-30 00:05:03 +01:00
|
|
|
layerId: 'first',
|
|
|
|
}),
|
|
|
|
keptLayerIds: ['first', 'second'],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(result).toContainEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
table: {
|
|
|
|
isMultiRow: true,
|
|
|
|
changeType: 'layers',
|
|
|
|
label: 'Show only layer 1',
|
2019-09-17 20:57:53 +02:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
columnId: 'col1',
|
|
|
|
operation: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
scale: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
layerId: 'first',
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(result).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
|
|
|
table: {
|
|
|
|
isMultiRow: true,
|
2019-10-30 00:05:03 +01:00
|
|
|
changeType: 'layers',
|
|
|
|
label: 'Show only layer 2',
|
2019-09-17 20:57:53 +02:00
|
|
|
columns: [
|
|
|
|
{
|
2019-10-09 21:20:55 +02:00
|
|
|
columnId: 'cola',
|
2019-09-17 20:57:53 +02:00
|
|
|
operation: {
|
|
|
|
label: 'My Op 2',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
scale: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
layerId: 'second',
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
})
|
|
|
|
);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a metric over time for single metric tables', async () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = testInitialState();
|
|
|
|
const state: IndexPatternPrivateState = {
|
|
|
|
...initialState,
|
2019-09-17 20:57:53 +02:00
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
indexPatternId: '1',
|
2019-10-09 21:20:55 +02:00
|
|
|
columnOrder: ['cola'],
|
2019-09-17 20:57:53 +02:00
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
cola: {
|
2019-09-17 20:57:53 +02:00
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'bytes',
|
|
|
|
scale: 'ratio',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(getDatasourceSuggestionsFromCurrentState(state)).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
|
|
|
table: {
|
|
|
|
isMultiRow: true,
|
|
|
|
changeType: 'extended',
|
|
|
|
label: 'Over time',
|
|
|
|
columns: [
|
|
|
|
{
|
2019-10-09 21:20:55 +02:00
|
|
|
columnId: 'id1',
|
2019-09-17 20:57:53 +02:00
|
|
|
operation: {
|
2020-08-21 11:33:42 +02:00
|
|
|
label: 'timestampLabel',
|
2019-09-17 20:57:53 +02:00
|
|
|
dataType: 'date',
|
|
|
|
isBucketed: true,
|
|
|
|
scale: 'interval',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-10-09 21:20:55 +02:00
|
|
|
columnId: 'cola',
|
2019-09-17 20:57:53 +02:00
|
|
|
operation: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
scale: 'ratio',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
layerId: 'first',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds date histogram over default time field for tables without time dimension', async () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = testInitialState();
|
|
|
|
const state: IndexPatternPrivateState = {
|
|
|
|
...initialState,
|
2019-09-17 20:57:53 +02:00
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
indexPatternId: '1',
|
2019-10-09 21:20:55 +02:00
|
|
|
columnOrder: ['cola', 'colb'],
|
2019-09-17 20:57:53 +02:00
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
cola: {
|
2019-09-17 20:57:53 +02:00
|
|
|
label: 'My Terms',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
operationType: 'terms',
|
|
|
|
sourceField: 'source',
|
|
|
|
scale: 'ordinal',
|
|
|
|
params: {
|
|
|
|
orderBy: { type: 'alphabetical' },
|
|
|
|
orderDirection: 'asc',
|
|
|
|
size: 5,
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
colb: {
|
2019-09-17 20:57:53 +02:00
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'bytes',
|
|
|
|
scale: 'ratio',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(getDatasourceSuggestionsFromCurrentState(state)).toContainEqual(
|
2019-09-17 20:57:53 +02:00
|
|
|
expect.objectContaining({
|
|
|
|
table: {
|
|
|
|
isMultiRow: true,
|
|
|
|
changeType: 'extended',
|
|
|
|
label: 'Over time',
|
|
|
|
columns: [
|
|
|
|
{
|
2019-10-09 21:20:55 +02:00
|
|
|
columnId: 'cola',
|
2019-09-17 20:57:53 +02:00
|
|
|
operation: {
|
|
|
|
label: 'My Terms',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
scale: 'ordinal',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-10-09 21:20:55 +02:00
|
|
|
columnId: 'id1',
|
2019-09-17 20:57:53 +02:00
|
|
|
operation: {
|
2020-08-21 11:33:42 +02:00
|
|
|
label: 'timestampLabel',
|
2019-09-17 20:57:53 +02:00
|
|
|
dataType: 'date',
|
|
|
|
isBucketed: true,
|
|
|
|
scale: 'interval',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-10-09 21:20:55 +02:00
|
|
|
columnId: 'colb',
|
2019-09-17 20:57:53 +02:00
|
|
|
operation: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
scale: 'ratio',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
layerId: 'first',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-10-19 14:45:48 +02:00
|
|
|
it('does not create an over time suggestion if tables with numeric buckets with time dimension', async () => {
|
|
|
|
const initialState = testInitialState();
|
|
|
|
const state: IndexPatternPrivateState = {
|
|
|
|
...initialState,
|
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
indexPatternId: '1',
|
|
|
|
columnOrder: ['colb', 'cola'],
|
|
|
|
columns: {
|
|
|
|
cola: {
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
sourceField: 'dest',
|
|
|
|
label: 'Unique count of dest',
|
|
|
|
operationType: 'cardinality',
|
|
|
|
},
|
|
|
|
colb: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: true,
|
|
|
|
operationType: 'range',
|
|
|
|
sourceField: 'bytes',
|
|
|
|
scale: 'interval',
|
|
|
|
params: {
|
|
|
|
type: 'histogram',
|
|
|
|
maxBars: 100,
|
|
|
|
ranges: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getDatasourceSuggestionsFromCurrentState(state)).not.toContainEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
table: {
|
|
|
|
isMultiRow: true,
|
|
|
|
label: 'Over time',
|
|
|
|
layerId: 'first',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds date histogram over default time field for custom range intervals', async () => {
|
|
|
|
const initialState = testInitialState();
|
|
|
|
const state: IndexPatternPrivateState = {
|
|
|
|
...initialState,
|
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
indexPatternId: '1',
|
|
|
|
columnOrder: ['colb', 'cola'],
|
|
|
|
columns: {
|
|
|
|
cola: {
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
sourceField: 'dest',
|
|
|
|
label: 'Unique count of dest',
|
|
|
|
operationType: 'cardinality',
|
|
|
|
},
|
|
|
|
colb: {
|
|
|
|
label: 'My Custom Range',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
operationType: 'range',
|
|
|
|
sourceField: 'bytes',
|
|
|
|
scale: 'ordinal',
|
|
|
|
params: {
|
|
|
|
type: 'range',
|
|
|
|
maxBars: 100,
|
|
|
|
ranges: [{ from: 1, to: 2, label: '' }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(getDatasourceSuggestionsFromCurrentState(state)).toContainEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
table: {
|
|
|
|
changeType: 'extended',
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
columnId: 'colb',
|
|
|
|
operation: {
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
label: 'My Custom Range',
|
|
|
|
scale: 'ordinal',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
columnId: 'id1',
|
|
|
|
operation: {
|
|
|
|
dataType: 'date',
|
|
|
|
isBucketed: true,
|
|
|
|
label: 'timestampLabel',
|
|
|
|
scale: 'interval',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
columnId: 'cola',
|
|
|
|
operation: {
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
label: 'Unique count of dest',
|
|
|
|
scale: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
isMultiRow: true,
|
|
|
|
label: 'Over time',
|
|
|
|
layerId: 'first',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
it('does not create an over time suggestion if there is no default time field', async () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = testInitialState();
|
|
|
|
const state: IndexPatternPrivateState = {
|
|
|
|
...initialState,
|
2019-09-17 20:57:53 +02:00
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
indexPatternId: '1',
|
2019-10-09 21:20:55 +02:00
|
|
|
columnOrder: ['id1'],
|
2019-09-17 20:57:53 +02:00
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: {
|
2019-09-17 20:57:53 +02:00
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'bytes',
|
|
|
|
scale: 'ratio',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
};
|
|
|
|
const suggestions = getDatasourceSuggestionsFromCurrentState({
|
2019-09-17 20:57:53 +02:00
|
|
|
...state,
|
|
|
|
indexPatterns: { 1: { ...state.indexPatterns['1'], timeFieldName: undefined } },
|
|
|
|
});
|
2020-05-22 09:08:58 +02:00
|
|
|
suggestions.forEach((suggestion) => expect(suggestion.table.columns.length).toBe(1));
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns simplified versions of table with more than 2 columns', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = testInitialState();
|
2020-11-10 14:31:04 +01:00
|
|
|
const fields = [
|
|
|
|
{
|
|
|
|
name: 'field1',
|
|
|
|
displayName: 'field1',
|
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'field2',
|
|
|
|
displayName: 'field2',
|
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'field3',
|
|
|
|
displayName: 'field3Label',
|
|
|
|
type: 'string',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'field4',
|
|
|
|
displayName: 'field4',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'field5',
|
|
|
|
displayName: 'field5',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
];
|
2019-09-17 20:57:53 +02:00
|
|
|
const state: IndexPatternPrivateState = {
|
2019-10-09 21:20:55 +02:00
|
|
|
indexPatternRefs: [],
|
2019-10-14 18:46:33 +02:00
|
|
|
existingFields: {},
|
2019-09-17 20:57:53 +02:00
|
|
|
currentIndexPatternId: '1',
|
|
|
|
indexPatterns: {
|
|
|
|
1: {
|
|
|
|
id: '1',
|
|
|
|
title: 'my-fake-index-pattern',
|
2020-08-26 09:09:40 +02:00
|
|
|
hasRestrictions: false,
|
2020-11-10 14:31:04 +01:00
|
|
|
fields,
|
|
|
|
getFieldByName: getFieldByNameFactory(fields),
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
2020-07-01 10:08:37 +02:00
|
|
|
isFirstExistenceFetch: false,
|
2019-09-17 20:57:53 +02:00
|
|
|
layers: {
|
|
|
|
first: {
|
2019-10-09 21:20:55 +02:00
|
|
|
...initialState.layers.first,
|
2019-09-17 20:57:53 +02:00
|
|
|
columns: {
|
|
|
|
col1: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
|
|
|
|
operationType: 'terms',
|
|
|
|
sourceField: 'field1',
|
|
|
|
params: {
|
|
|
|
size: 5,
|
|
|
|
orderBy: { type: 'alphabetical' },
|
|
|
|
orderDirection: 'asc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
col2: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
|
|
|
|
operationType: 'terms',
|
|
|
|
sourceField: 'field2',
|
|
|
|
params: {
|
|
|
|
size: 5,
|
|
|
|
orderBy: { type: 'alphabetical' },
|
|
|
|
orderDirection: 'asc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
col3: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
|
|
|
|
operationType: 'terms',
|
|
|
|
sourceField: 'field3',
|
|
|
|
params: {
|
|
|
|
size: 5,
|
|
|
|
orderBy: { type: 'alphabetical' },
|
|
|
|
orderDirection: 'asc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
col4: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
|
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'field4',
|
|
|
|
},
|
|
|
|
col5: {
|
|
|
|
label: 'My Op',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
|
|
|
|
operationType: 'min',
|
|
|
|
sourceField: 'field5',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
columnOrder: ['col1', 'col2', 'col3', 'col4', 'col5'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsFromCurrentState(state);
|
2019-09-17 20:57:53 +02:00
|
|
|
// 1 bucket col, 2 metric cols
|
|
|
|
isTableWithBucketColumns(suggestions[0], ['col1', 'col4', 'col5'], 1);
|
|
|
|
|
|
|
|
// 1 bucket col, 1 metric col
|
|
|
|
isTableWithBucketColumns(suggestions[1], ['col1', 'col4'], 1);
|
|
|
|
|
|
|
|
// 2 bucket cols, 2 metric cols
|
|
|
|
isTableWithBucketColumns(suggestions[2], ['col1', 'col2', 'col4', 'col5'], 2);
|
|
|
|
|
|
|
|
// 2 bucket cols, 1 metric col
|
|
|
|
isTableWithBucketColumns(suggestions[3], ['col1', 'col2', 'col4'], 2);
|
|
|
|
|
|
|
|
// 3 bucket cols, 2 metric cols
|
|
|
|
isTableWithBucketColumns(suggestions[4], ['col1', 'col2', 'col3', 'col4', 'col5'], 3);
|
|
|
|
|
|
|
|
// 3 bucket cols, 1 metric col
|
|
|
|
isTableWithBucketColumns(suggestions[5], ['col1', 'col2', 'col3', 'col4'], 3);
|
|
|
|
|
|
|
|
// first metric col
|
|
|
|
isTableWithMetricColumns(suggestions[6], ['col4']);
|
|
|
|
|
|
|
|
// second metric col
|
|
|
|
isTableWithMetricColumns(suggestions[7], ['col5']);
|
|
|
|
|
|
|
|
expect(suggestions.length).toBe(8);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns an only metric version of a given table', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = testInitialState();
|
2019-09-17 20:57:53 +02:00
|
|
|
const state: IndexPatternPrivateState = {
|
2019-10-09 21:20:55 +02:00
|
|
|
indexPatternRefs: [],
|
2019-10-14 18:46:33 +02:00
|
|
|
existingFields: {},
|
2019-09-17 20:57:53 +02:00
|
|
|
currentIndexPatternId: '1',
|
|
|
|
indexPatterns: {
|
|
|
|
1: {
|
|
|
|
id: '1',
|
|
|
|
title: 'my-fake-index-pattern',
|
2020-08-26 09:09:40 +02:00
|
|
|
hasRestrictions: false,
|
2019-09-17 20:57:53 +02:00
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: 'field1',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'field1',
|
2019-09-17 20:57:53 +02:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'field2',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'field2',
|
2019-09-17 20:57:53 +02:00
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
],
|
2020-11-10 14:31:04 +01:00
|
|
|
|
|
|
|
getFieldByName: getFieldByNameFactory([
|
|
|
|
{
|
|
|
|
name: 'field1',
|
|
|
|
displayName: 'field1',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'field2',
|
|
|
|
displayName: 'field2',
|
|
|
|
type: 'date',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
]),
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
2020-07-01 10:08:37 +02:00
|
|
|
isFirstExistenceFetch: false,
|
2019-09-17 20:57:53 +02:00
|
|
|
layers: {
|
|
|
|
first: {
|
2019-10-09 21:20:55 +02:00
|
|
|
...initialState.layers.first,
|
2019-09-17 20:57:53 +02:00
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: {
|
2019-09-17 20:57:53 +02:00
|
|
|
label: 'Date histogram',
|
|
|
|
dataType: 'date',
|
|
|
|
isBucketed: true,
|
|
|
|
|
|
|
|
operationType: 'date_histogram',
|
|
|
|
sourceField: 'field2',
|
|
|
|
params: {
|
|
|
|
interval: 'd',
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
id2: {
|
2019-09-17 20:57:53 +02:00
|
|
|
label: 'Average of field1',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
|
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'field1',
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
columnOrder: ['id1', 'id2'],
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsFromCurrentState(state);
|
2019-09-17 20:57:53 +02:00
|
|
|
expect(suggestions[1].table.columns[0].operation.label).toBe('Average of field1');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns an alternative metric for an only-metric table', () => {
|
2019-10-09 21:20:55 +02:00
|
|
|
const initialState = testInitialState();
|
2019-09-17 20:57:53 +02:00
|
|
|
const state: IndexPatternPrivateState = {
|
2019-10-09 21:20:55 +02:00
|
|
|
indexPatternRefs: [],
|
2019-10-14 18:46:33 +02:00
|
|
|
existingFields: {},
|
2019-09-17 20:57:53 +02:00
|
|
|
currentIndexPatternId: '1',
|
|
|
|
indexPatterns: {
|
|
|
|
1: {
|
|
|
|
id: '1',
|
|
|
|
title: 'my-fake-index-pattern',
|
2020-08-26 09:09:40 +02:00
|
|
|
hasRestrictions: false,
|
2019-09-17 20:57:53 +02:00
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: 'field1',
|
2020-08-21 11:33:42 +02:00
|
|
|
displayName: 'field1',
|
2019-09-17 20:57:53 +02:00
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
],
|
2020-11-10 14:31:04 +01:00
|
|
|
getFieldByName: getFieldByNameFactory([
|
|
|
|
{
|
|
|
|
name: 'field1',
|
|
|
|
displayName: 'field1',
|
|
|
|
type: 'number',
|
|
|
|
aggregatable: true,
|
|
|
|
searchable: true,
|
|
|
|
},
|
|
|
|
]),
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
2020-07-01 10:08:37 +02:00
|
|
|
isFirstExistenceFetch: false,
|
2019-09-17 20:57:53 +02:00
|
|
|
layers: {
|
|
|
|
first: {
|
2019-10-09 21:20:55 +02:00
|
|
|
...initialState.layers.first,
|
2019-09-17 20:57:53 +02:00
|
|
|
columns: {
|
2019-10-09 21:20:55 +02:00
|
|
|
id1: {
|
2019-09-17 20:57:53 +02:00
|
|
|
label: 'Average of field1',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
|
|
|
|
operationType: 'avg',
|
|
|
|
sourceField: 'field1',
|
|
|
|
},
|
|
|
|
},
|
2019-10-09 21:20:55 +02:00
|
|
|
columnOrder: ['id1'],
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-10-09 21:20:55 +02:00
|
|
|
const suggestions = getDatasourceSuggestionsFromCurrentState(state);
|
2019-09-17 20:57:53 +02:00
|
|
|
expect(suggestions[0].table.columns.length).toBe(1);
|
|
|
|
expect(suggestions[0].table.columns[0].operation.label).toBe('Sum of field1');
|
|
|
|
});
|
2020-04-30 16:52:10 +02:00
|
|
|
|
|
|
|
it('contains a reordering suggestion when there are exactly 2 buckets', () => {
|
|
|
|
const initialState = testInitialState();
|
|
|
|
const state: IndexPatternPrivateState = {
|
|
|
|
indexPatternRefs: [],
|
|
|
|
existingFields: {},
|
|
|
|
currentIndexPatternId: '1',
|
|
|
|
indexPatterns: expectedIndexPatterns,
|
2020-07-01 10:08:37 +02:00
|
|
|
isFirstExistenceFetch: false,
|
2020-04-30 16:52:10 +02:00
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
...initialState.layers.first,
|
|
|
|
columns: {
|
|
|
|
id1: {
|
|
|
|
label: 'Date histogram',
|
|
|
|
dataType: 'date',
|
|
|
|
isBucketed: true,
|
|
|
|
|
|
|
|
operationType: 'date_histogram',
|
2020-10-01 13:39:10 +02:00
|
|
|
sourceField: 'timestamp',
|
2020-04-30 16:52:10 +02:00
|
|
|
params: {
|
|
|
|
interval: 'd',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
id2: {
|
|
|
|
label: 'Top 5',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
|
|
|
|
operationType: 'terms',
|
2020-10-01 13:39:10 +02:00
|
|
|
sourceField: 'dest',
|
2020-04-30 16:52:10 +02:00
|
|
|
params: { size: 5, orderBy: { type: 'alphabetical' }, orderDirection: 'asc' },
|
|
|
|
},
|
|
|
|
id3: {
|
|
|
|
label: 'Average of field1',
|
|
|
|
dataType: 'number',
|
|
|
|
isBucketed: false,
|
|
|
|
|
|
|
|
operationType: 'avg',
|
2020-10-01 13:39:10 +02:00
|
|
|
sourceField: 'bytes',
|
2020-04-30 16:52:10 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
columnOrder: ['id1', 'id2', 'id3'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const suggestions = getDatasourceSuggestionsFromCurrentState(state);
|
|
|
|
expect(suggestions).toContainEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
table: expect.objectContaining({
|
|
|
|
changeType: 'reorder',
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2020-10-01 13:39:10 +02:00
|
|
|
|
|
|
|
it('does not generate suggestions if invalid fields are referenced', () => {
|
|
|
|
const initialState = testInitialState();
|
|
|
|
const state: IndexPatternPrivateState = {
|
|
|
|
indexPatternRefs: [],
|
|
|
|
existingFields: {},
|
|
|
|
currentIndexPatternId: '1',
|
|
|
|
indexPatterns: expectedIndexPatterns,
|
|
|
|
isFirstExistenceFetch: false,
|
|
|
|
layers: {
|
|
|
|
first: {
|
|
|
|
...initialState.layers.first,
|
|
|
|
columns: {
|
|
|
|
...initialState.layers.first.columns,
|
|
|
|
col2: {
|
|
|
|
label: 'Top 5',
|
|
|
|
dataType: 'string',
|
|
|
|
isBucketed: true,
|
|
|
|
|
|
|
|
operationType: 'terms',
|
|
|
|
sourceField: 'nonExistingField',
|
|
|
|
params: { size: 5, orderBy: { type: 'alphabetical' }, orderDirection: 'asc' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
columnOrder: ['col1', 'col2'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const suggestions = getDatasourceSuggestionsFromCurrentState(state);
|
|
|
|
expect(suggestions).toEqual([]);
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function isTableWithBucketColumns(
|
|
|
|
suggestion: DatasourceSuggestion<IndexPatternPrivateState>,
|
|
|
|
columnIds: string[],
|
|
|
|
numBuckets: number
|
|
|
|
) {
|
2020-05-22 09:08:58 +02:00
|
|
|
expect(suggestion.table.columns.map((column) => column.columnId)).toEqual(columnIds);
|
2019-09-17 20:57:53 +02:00
|
|
|
expect(
|
2020-05-22 09:08:58 +02:00
|
|
|
suggestion.table.columns.slice(0, numBuckets).every((column) => column.operation.isBucketed)
|
2019-09-17 20:57:53 +02:00
|
|
|
).toBeTruthy();
|
|
|
|
}
|
|
|
|
|
|
|
|
function isTableWithMetricColumns(
|
|
|
|
suggestion: DatasourceSuggestion<IndexPatternPrivateState>,
|
|
|
|
columnIds: string[]
|
|
|
|
) {
|
|
|
|
expect(suggestion.table.isMultiRow).toEqual(false);
|
2020-05-22 09:08:58 +02:00
|
|
|
expect(suggestion.table.columns.map((column) => column.columnId)).toEqual(columnIds);
|
|
|
|
expect(suggestion.table.columns.every((column) => !column.operation.isBucketed)).toBeTruthy();
|
2019-09-17 20:57:53 +02:00
|
|
|
}
|