Skip to content

Commit

Permalink
updating adhoc metric filtering (apache#5105)
Browse files Browse the repository at this point in the history
(cherry picked from commit cc0942a)
  • Loading branch information
Gabe Lyons authored and John Bodley committed Jun 1, 2018
1 parent b811851 commit 373c0fb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ describe('MetricsControl', () => {

expect(!!wrapper.instance().selectFilterOption(
{
metric_name: 'a_metric',
optionName: 'a_metric',
metric_name: 'avg__metric',
optionName: 'avg__metric',
expression: 'AVG(metric)',
},
'a',
Expand All @@ -238,14 +238,27 @@ describe('MetricsControl', () => {

expect(!!wrapper.instance().selectFilterOption(
{
metric_name: 'a_metric',
optionName: 'a_metric',
metric_name: 'avg__metric',
optionName: 'avg__metric',
expression: 'AVG(metric)',
},
'a',
)).to.be.false;
});

it('includes custom made simple saved metrics', () => {
const { wrapper } = setup();

expect(!!wrapper.instance().selectFilterOption(
{
metric_name: 'my_fancy_sum_metric',
optionName: 'my_fancy_sum_metric',
expression: 'SUM(value)',
},
'sum',
)).to.be.true;
});

it('excludes auto generated metrics', () => {
const { wrapper } = setup();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import savedMetricType from '../../propTypes/savedMetricType';
import adhocMetricType from '../../propTypes/adhocMetricType';
import {
AGGREGATES,
sqlaAutoGeneratedMetricRegex,
sqlaAutoGeneratedMetricNameRegex,
druidAutoGeneratedMetricRegex,
} from '../../constants';

Expand Down Expand Up @@ -210,7 +210,7 @@ export default class MetricsControl extends React.PureComponent {
if (this.props.datasourceType === 'druid') {
return druidAutoGeneratedMetricRegex.test(savedMetric.verbose_name);
}
return sqlaAutoGeneratedMetricRegex.test(savedMetric.expression);
return sqlaAutoGeneratedMetricNameRegex.test(savedMetric.metric_name);
}

selectFilterOption(option, filterValue) {
Expand Down
1 change: 1 addition & 0 deletions superset/assets/src/explore/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export const HAVING_OPERATORS = [
];
export const MULTI_OPERATORS = [OPERATORS.in, OPERATORS['not in']];

export const sqlaAutoGeneratedMetricNameRegex = /^(sum|min|max|avg|count|count_distinct)__.*$/i;
export const sqlaAutoGeneratedMetricRegex = /^(LONG|DOUBLE|FLOAT)?(SUM|AVG|MAX|MIN|COUNT)\([A-Z0-9_."]*\)$/i;
export const druidAutoGeneratedMetricRegex = /^(LONG|DOUBLE|FLOAT)?(SUM|MAX|MIN|COUNT)\([A-Z0-9_."]*\)$/i;

0 comments on commit 373c0fb

Please sign in to comment.