mirror of
https://github.com/apache/superset.git
synced 2026-04-23 01:55:09 +00:00
including auto generated avg metrics in druid (#4718)
This commit is contained in:
@@ -74,13 +74,8 @@ function getDefaultAggregateForColumn(column) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const autoGeneratedMetricRegex = /^(LONG|DOUBLE|FLOAT)?(SUM|AVG|MAX|MIN|COUNT)\([A-Z_][A-Z0-9_]*\)$/i;
|
||||
function isAutoGeneratedMetric(savedMetric) {
|
||||
return (
|
||||
autoGeneratedMetricRegex.test(savedMetric.expression) ||
|
||||
autoGeneratedMetricRegex.test(savedMetric.verbose_name)
|
||||
);
|
||||
}
|
||||
const sqlaAutoGeneratedMetricRegex = /^(LONG|DOUBLE|FLOAT)?(SUM|AVG|MAX|MIN|COUNT)\([A-Z_][A-Z0-9_]*\)$/i;
|
||||
const druidAutoGeneratedMetricRegex = /^(LONG|DOUBLE|FLOAT)?(SUM|MAX|MIN|COUNT)\([A-Z_][A-Z0-9_]*\)$/i;
|
||||
|
||||
export default class MetricsControl extends React.PureComponent {
|
||||
constructor(props) {
|
||||
@@ -90,6 +85,7 @@ export default class MetricsControl extends React.PureComponent {
|
||||
this.checkIfAggregateInInput = this.checkIfAggregateInInput.bind(this);
|
||||
this.optionsForSelect = this.optionsForSelect.bind(this);
|
||||
this.selectFilterOption = this.selectFilterOption.bind(this);
|
||||
this.isAutoGeneratedMetric = this.isAutoGeneratedMetric.bind(this);
|
||||
this.optionRenderer = VirtualizedRendererWrap(option => (
|
||||
<MetricDefinitionOption option={option} />
|
||||
), { ignoreAutogeneratedMetrics: true });
|
||||
@@ -209,6 +205,13 @@ export default class MetricsControl extends React.PureComponent {
|
||||
});
|
||||
}
|
||||
|
||||
isAutoGeneratedMetric(savedMetric) {
|
||||
if (this.props.datasourceType === 'druid') {
|
||||
return druidAutoGeneratedMetricRegex.test(savedMetric.verbose_name);
|
||||
}
|
||||
return sqlaAutoGeneratedMetricRegex.test(savedMetric.expression);
|
||||
}
|
||||
|
||||
selectFilterOption(option, filterValue) {
|
||||
if (this.state.aggregateInInput) {
|
||||
let endIndex = filterValue.length;
|
||||
@@ -220,7 +223,7 @@ export default class MetricsControl extends React.PureComponent {
|
||||
(option.column_name.toLowerCase().indexOf(valueAfterAggregate.toLowerCase()) >= 0);
|
||||
}
|
||||
return option.optionName &&
|
||||
(!option.metric_name || !isAutoGeneratedMetric(option)) &&
|
||||
(!option.metric_name || !this.isAutoGeneratedMetric(option)) &&
|
||||
(option.optionName.toLowerCase().indexOf(filterValue.toLowerCase()) >= 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user