Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ describe('IndexPatternDimensionPanel', () => {
columns: {
col1: {
operationId: 'op1',
label: 'Value of timestamp',
label: 'Date Histogram of timestamp',
dataType: 'date',
isBucketed: false,
isBucketed: true,

// Private
operationType: 'value',
operationType: 'date_histogram',
sourceField: 'timestamp',
},
},
Expand Down Expand Up @@ -169,17 +169,14 @@ describe('IndexPatternDimensionPanel', () => {
);

expect(
wrapper.find('[data-test-subj="lns-indexPatternDimension-value"]').prop('color')
wrapper.find('[data-test-subj="lns-indexPatternDimension-date_histogram"]').prop('color')
).toEqual('primary');
expect(
wrapper.find('[data-test-subj="lns-indexPatternDimension-value"]').prop('isDisabled')
wrapper.find('[data-test-subj="lns-indexPatternDimension-date_histogram"]').prop('isDisabled')
).toEqual(false);
expect(
wrapper.find('[data-test-subj="lns-indexPatternDimension-terms"]').prop('isDisabled')
).toEqual(true);
expect(
wrapper.find('[data-test-subj="lns-indexPatternDimension-date_histogram"]').prop('isDisabled')
).toEqual(false);
expect(
wrapper.find('[data-test-subj="lns-indexPatternDimension-sum"]').prop('isDisabled')
).toEqual(true);
Expand Down Expand Up @@ -271,11 +268,6 @@ describe('IndexPatternDimensionPanel', () => {
...state.columns,
col2: expect.objectContaining({
operationId: firstField.value,
label: 'Value of bytes',
dataType: 'number',
isBucketed: false,
operationType: 'value',
sourceField: 'bytes',
}),
},
columnOrder: ['col1', 'col2'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ describe('IndexPattern Data Source', () => {
operationId: 'op1',
label: 'My Op',
dataType: 'string',
isBucketed: false,
isBucketed: true,

// Private
operationType: 'value',
operationType: 'terms',
sourceField: 'op',
},
},
Expand Down Expand Up @@ -208,39 +208,6 @@ describe('IndexPattern Data Source', () => {
expect(indexPatternDatasource.toExpression(state)).toEqual(null);
});

it('should generate an expression for a values query', async () => {
const queryPersistedState: IndexPatternPersistedState = {
currentIndexPatternId: '1',
columnOrder: ['col1', 'col2'],
columns: {
col1: {
operationId: 'op1',
label: 'My Op',
dataType: 'string',
isBucketed: false,

// Private
operationType: 'value',
sourceField: 'source',
},
col2: {
operationId: 'op2',
label: 'My Op 2',
dataType: 'number',
isBucketed: false,

// Private
operationType: 'value',
sourceField: 'bytes',
},
},
};
const state = await indexPatternDatasource.initialize(queryPersistedState);
expect(indexPatternDatasource.toExpression(state)).toMatchInlineSnapshot(
`"esdocs index=\\"my-fake-index-pattern\\" fields=\\"source, bytes\\" sort=\\"source, DESC\\" | lens_rename_columns idMap='{\\"source\\":\\"col1\\",\\"bytes\\":\\"col2\\"}'"`
);
});

it('should generate an expression for an aggregated query', async () => {
const queryPersistedState: IndexPatternPersistedState = {
currentIndexPatternId: '1',
Expand Down Expand Up @@ -303,7 +270,7 @@ describe('IndexPattern Data Source', () => {
id: 'op1',
label: 'My Op',
dataType: 'string',
isBucketed: false,
isBucketed: true,
} as Operation);
});
});
Expand Down
10 changes: 1 addition & 9 deletions x-pack/plugins/lens/public/indexpattern_plugin/indexpattern.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@ import { ChildDragDropProvider, DragDrop } from '../drag_drop';
import { toExpression } from './to_expression';
import { IndexPatternDimensionPanel } from './dimension_panel';

export type OperationType =
| 'value'
| 'terms'
| 'date_histogram'
| 'sum'
| 'avg'
| 'min'
| 'max'
| 'count';
export type OperationType = 'terms' | 'date_histogram' | 'sum' | 'avg' | 'min' | 'max' | 'count';

export interface IndexPatternColumn {
// Public
Expand Down
44 changes: 16 additions & 28 deletions x-pack/plugins/lens/public/indexpattern_plugin/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('getOperationTypesForField', () => {
aggregatable: true,
searchable: true,
})
).toEqual(expect.arrayContaining(['value', 'terms']));
).toEqual(expect.arrayContaining(['terms']));
});

it('should return operations on numbers', () => {
Expand All @@ -56,7 +56,7 @@ describe('getOperationTypesForField', () => {
aggregatable: true,
searchable: true,
})
).toEqual(expect.arrayContaining(['value', 'avg', 'sum', 'min', 'max']));
).toEqual(expect.arrayContaining(['avg', 'sum', 'min', 'max']));
});

it('should return operations on dates', () => {
Expand All @@ -67,7 +67,7 @@ describe('getOperationTypesForField', () => {
aggregatable: true,
searchable: true,
})
).toEqual(expect.arrayContaining(['value', 'date_histogram']));
).toEqual(expect.arrayContaining(['date_histogram']));
});

it('should return no operations on unknown types', () => {
Expand Down Expand Up @@ -149,12 +149,12 @@ describe('getOperationTypesForField', () => {
columns: {
col1: {
operationId: 'op1',
label: 'Value of timestamp',
label: 'Date Histogram of timestamp',
dataType: 'date',
isBucketed: false,
isBucketed: true,

// Private
operationType: 'value',
operationType: 'date_histogram',
sourceField: 'timestamp',
},
},
Expand All @@ -172,10 +172,6 @@ describe('getOperationTypesForField', () => {

expect(columns.map(col => [col.sourceField, col.operationType])).toMatchInlineSnapshot(`
Array [
Array [
"bytes",
"value",
],
Array [
"bytes",
"sum",
Expand All @@ -196,18 +192,10 @@ Array [
"documents",
"count",
],
Array [
"source",
"value",
],
Array [
"source",
"terms",
],
Array [
"timestamp",
"value",
],
Array [
"timestamp",
"date_histogram",
Expand All @@ -228,12 +216,12 @@ describe('getColumnOrder', () => {
getColumnOrder({
col1: {
operationId: 'op1',
label: 'Value of timestamp',
dataType: 'string',
isBucketed: false,
label: 'Date Histogram of timestamp',
dataType: 'date',
isBucketed: true,

// Private
operationType: 'value',
operationType: 'date_histogram',
sourceField: 'timestamp',
},
})
Expand All @@ -250,8 +238,8 @@ describe('getColumnOrder', () => {
isBucketed: true,

// Private
operationType: 'value',
sourceField: 'timestamp',
operationType: 'terms',
sourceField: 'category',
},
col2: {
operationId: 'op2',
Expand All @@ -260,7 +248,7 @@ describe('getColumnOrder', () => {
isBucketed: false,

// Private
operationType: 'value',
operationType: 'avg',
sourceField: 'bytes',
},
col3: {
Expand All @@ -287,8 +275,8 @@ describe('getColumnOrder', () => {
isBucketed: true,

// Private
operationType: 'value',
sourceField: 'timestamp',
operationType: 'terms',
sourceField: 'category',
suggestedOrder: 2,
},
col2: {
Expand All @@ -298,7 +286,7 @@ describe('getColumnOrder', () => {
isBucketed: false,

// Private
operationType: 'value',
operationType: 'avg',
sourceField: 'bytes',
suggestedOrder: 0,
},
Expand Down
22 changes: 5 additions & 17 deletions x-pack/plugins/lens/public/indexpattern_plugin/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
} from './indexpattern';

export function getOperations(): OperationType[] {
return ['value', 'terms', 'date_histogram', 'sum', 'avg', 'min', 'max', 'count'];
// Raw value is not listed in the MVP
return ['terms', 'date_histogram', 'sum', 'avg', 'min', 'max', 'count'];
}

export function getOperationDisplay(): Record<
Expand All @@ -27,17 +28,6 @@ export function getOperationDisplay(): Record<
}
> {
return {
value: {
type: 'value',
displayName: i18n.translate('xpack.lens.indexPattern.value', {
defaultMessage: 'Value',
}),
ofName: name =>
i18n.translate('xpack.lens.indexPattern.valueOf', {
defaultMessage: 'Value of {name}',
values: { name },
}),
},
terms: {
type: 'terms',
displayName: i18n.translate('xpack.lens.indexPattern.terms', {
Expand Down Expand Up @@ -132,19 +122,17 @@ export function getOperationTypesForField({

switch (type) {
case 'date':
return ['value', 'date_histogram'];
return ['date_histogram'];
case 'number':
return ['value', 'sum', 'avg', 'min', 'max'];
return ['sum', 'avg', 'min', 'max'];
case 'string':
return ['value', 'terms'];
return ['terms'];
}
return [];
}

export function getOperationResultType({ type }: IndexPatternField, op: OperationType): DataType {
switch (op) {
case 'value':
return type as DataType;
case 'avg':
case 'min':
case 'max':
Expand Down
16 changes: 1 addition & 15 deletions x-pack/plugins/lens/public/indexpattern_plugin/to_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,9 @@ export function toExpression(state: IndexPatternPrivateState) {
return null;
}

const fieldNames = state.columnOrder.map(col => state.columns[col].sourceField);
const sortedColumns = state.columnOrder.map(col => state.columns[col]);

const indexName = state.indexPatterns[state.currentIndexPatternId].title;

if (sortedColumns.every(({ operationType }) => operationType === 'value')) {
const idMap = fieldNames.reduce(
(currentIdMap, fieldName, index) => ({
...currentIdMap,
[fieldName]: state.columnOrder[index],
}),
{} as Record<string, string>
);
return `esdocs index="${indexName}" fields="${fieldNames.join(', ')}" sort="${
fieldNames[0]
}, DESC" | lens_rename_columns idMap='${JSON.stringify(idMap)}'`;
} else if (sortedColumns.length) {
if (sortedColumns.length) {
const firstMetric = sortedColumns.findIndex(({ isBucketed }) => !isBucketed);
const aggs = sortedColumns.map((col, index) => {
if (col.operationType === 'date_histogram') {
Expand Down