Skip to content

Commit

Permalink
[Lens] Fix unformatted timeseries functions (#92498) (#92645)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
Wylie Conlon and kibanamachine authored Feb 24, 2021
1 parent 398ef2a commit 68184ed
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,55 @@ describe('IndexPattern Data Source', () => {
`);
});

it('should put column formatters after calculated columns', async () => {
const queryBaseState: IndexPatternBaseState = {
currentIndexPatternId: '1',
layers: {
first: {
indexPatternId: '1',
columnOrder: ['bucket', 'metric', 'calculated'],
columns: {
bucket: {
label: 'Date',
dataType: 'date',
isBucketed: true,
operationType: 'date_histogram',
sourceField: 'timestamp',
params: {
interval: 'auto',
},
},
metric: {
label: 'Count of records',
dataType: 'number',
isBucketed: false,
sourceField: 'Records',
operationType: 'count',
timeScale: 'h',
},
calculated: {
label: 'Moving average of bytes',
dataType: 'number',
isBucketed: false,
operationType: 'moving_average',
references: ['metric'],
params: {
window: 5,
},
},
},
},
},
};

const state = enrichBaseState(queryBaseState);

const ast = indexPatternDatasource.toExpression(state, 'first') as Ast;
const formatIndex = ast.chain.findIndex((fn) => fn.function === 'lens_format_column');
const calculationIndex = ast.chain.findIndex((fn) => fn.function === 'moving_average');
expect(calculationIndex).toBeLessThan(formatIndex);
});

it('should rename the output from esaggs when using flat query', () => {
const queryBaseState: IndexPatternBaseState = {
currentIndexPatternId: '1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ function getExpressionForLayer(
idMap: [JSON.stringify(idMap)],
},
},
...formatterOverrides,
...expressions,
...formatterOverrides,
...timeScaleFunctions,
],
};
Expand Down
37 changes: 37 additions & 0 deletions x-pack/test/functional/apps/lens/smokescreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import expect from '@kbn/expect';
import { range } from 'lodash';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
Expand Down Expand Up @@ -439,6 +440,42 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await find.allByCssSelector('.echLegendItem')).to.have.length(2);
});

it('should allow formatting on references', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisType('lens');
await PageObjects.lens.goToTimeRange();
await PageObjects.lens.switchToVisualization('lnsDatatable');

await PageObjects.lens.configureDimension({
dimension: 'lnsDatatable_column > lns-empty-dimension',
operation: 'date_histogram',
field: '@timestamp',
});
await PageObjects.lens.configureDimension({
dimension: 'lnsDatatable_metrics > lns-empty-dimension',
operation: 'moving_average',
keepOpen: true,
});
await PageObjects.lens.configureReference({
operation: 'sum',
field: 'bytes',
});
await PageObjects.lens.editDimensionFormat('Number');
await PageObjects.lens.closeDimensionEditor();

const values = await Promise.all(
range(0, 6).map((index) => PageObjects.lens.getDatatableCellText(index, 1))
);
expect(values).to.eql([
'-',
'222,420.00',
'702,050.00',
'1,879,613.33',
'3,482,256.25',
'4,359,953.00',
]);
});

/**
* The edge cases are:
*
Expand Down

0 comments on commit 68184ed

Please sign in to comment.