Skip to content

Commit

Permalink
first pass at removing native Druid nosql
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi committed Jun 9, 2022
1 parent 07b4a71 commit 4ef250e
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 131 deletions.
17 changes: 0 additions & 17 deletions superset-frontend/src/components/Datasource/DatasourceEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,6 @@ class DatasourceEditor extends React.PureComponent {
}),
},
errors: [],
isDruid:
props.datasource.type === 'druid' ||
props.datasource.datasource_type === 'druid',
isSqla:
props.datasource.datasource_type === 'table' ||
props.datasource.type === 'table',
Expand Down Expand Up @@ -1079,20 +1076,6 @@ class DatasourceEditor extends React.PureComponent {
/>
</>
)}
{this.state.isDruid && (
<Field
fieldKey="json"
label={t('JSON')}
description={
<div>
{t('The JSON metric or post aggregation definition.')}
</div>
}
control={
<TextAreaControl language="json" offerEditInModal={false} />
}
/>
)}
</div>
)}
{this.state.datasourceType === DATASOURCE_TYPES.physical.key && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ const isTimeSection = (section: ControlPanelSectionConfig): boolean =>
sections.legacyTimeseriesTime.label === section.label);

const hasTimeColumn = (datasource: Dataset): boolean =>
datasource?.columns?.some(c => c.is_dttm) ||
datasource.type === DatasourceType.Druid;

datasource?.columns?.some(c => c.is_dttm);
const sectionsToExpand = (
sections: ControlPanelSectionConfig[],
datasource: Dataset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,8 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => {
// via datasource saved metric
if (filterOptions.saved_metric_name) {
return new AdhocFilter({
expressionType:
datasource.type === 'druid'
? EXPRESSION_TYPES.SIMPLE
: EXPRESSION_TYPES.SQL,
subject:
datasource.type === 'druid'
? filterOptions.saved_metric_name
: getMetricExpression(filterOptions.saved_metric_name),
expressionType: EXPRESSION_TYPES.SQL,
subject: getMetricExpression(filterOptions.saved_metric_name),
operator:
OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
operatorId: Operators.GREATER_THAN,
Expand All @@ -240,14 +234,8 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => {
// has a custom label, meaning it's custom column
if (filterOptions.label) {
return new AdhocFilter({
expressionType:
datasource.type === 'druid'
? EXPRESSION_TYPES.SIMPLE
: EXPRESSION_TYPES.SQL,
subject:
datasource.type === 'druid'
? filterOptions.label
: new AdhocMetric(option).translateToSql(),
expressionType: EXPRESSION_TYPES.SQL,
subject: new AdhocMetric(option).translateToSql(),
operator:
OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
operatorId: Operators.GREATER_THAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,8 @@ class AdhocFilterControl extends React.Component {
// via datasource saved metric
if (option.saved_metric_name) {
return new AdhocFilter({
expressionType:
this.props.datasource.type === 'druid'
? EXPRESSION_TYPES.SIMPLE
: EXPRESSION_TYPES.SQL,
subject:
this.props.datasource.type === 'druid'
? option.saved_metric_name
: this.getMetricExpression(option.saved_metric_name),
expressionType: EXPRESSION_TYPES.SQL,
subject: this.getMetricExpression(option.saved_metric_name),
operator:
OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
comparator: 0,
Expand All @@ -258,14 +252,8 @@ class AdhocFilterControl extends React.Component {
// has a custom label, meaning it's custom column
if (option.label) {
return new AdhocFilter({
expressionType:
this.props.datasource.type === 'druid'
? EXPRESSION_TYPES.SIMPLE
: EXPRESSION_TYPES.SQL,
subject:
this.props.datasource.type === 'druid'
? option.label
: new AdhocMetric(option).translateToSql(),
expressionType: EXPRESSION_TYPES.SQL,
subject: new AdhocMetric(option).translateToSql(),
operator:
OPERATOR_ENUM_TO_OPERATOR_TYPE[Operators.GREATER_THAN].operation,
comparator: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import Button from 'src/components/Button';
import { Tooltip } from 'src/components/Tooltip';
import { styled, t } from '@superset-ui/core';

import ErrorBoundary from 'src/components/ErrorBoundary';
Expand Down Expand Up @@ -227,20 +226,7 @@ export default class AdhocFilterEditPopover extends React.Component {
<Tabs.TabPane
className="adhoc-filter-edit-tab"
key={EXPRESSION_TYPES.SQL}
tab={
datasource?.type === 'druid' ? (
<Tooltip
title={t(
'Custom SQL ad-hoc filters are not available for the native Druid connector',
)}
>
{t('Custom SQL')}
</Tooltip>
) : (
t('Custom SQL')
)
}
disabled={datasource?.type === 'druid'}
tab={t('Custom SQL')}
>
<ErrorBoundary>
<AdhocFilterEditPopoverSqlTabContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,6 @@ describe('AdhocFilterEditPopoverSimpleTabContent', () => {
expect(isOperatorRelevant(Operators.LIKE, 'value')).toBe(true);
});

it('will filter operators for druid datasources', () => {
const { props } = setup({ datasource: { type: 'druid' } });
const { isOperatorRelevant } = useSimpleTabFilterProps(props);
expect(isOperatorRelevant(Operators.REGEX, 'value')).toBe(true);
expect(isOperatorRelevant(Operators.LIKE, 'value')).toBe(false);
});

it('will show LATEST PARTITION operator', () => {
const { props } = setup({
datasource: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { t, SupersetClient, SupersetTheme, styled } from '@superset-ui/core';
import {
Operators,
OPERATORS_OPTIONS,
TABLE_ONLY_OPERATORS,
DRUID_ONLY_OPERATORS,
HAVING_OPERATORS,
MULTI_OPERATORS,
Expand Down Expand Up @@ -141,8 +140,6 @@ export const useSimpleTabFilterProps = (props: Props) => {
);
}
return !(
(props.datasource.type === 'druid' &&
TABLE_ONLY_OPERATORS.indexOf(operator) >= 0) ||
(props.datasource.type === 'table' &&
DRUID_ONLY_OPERATORS.indexOf(operator) >= 0) ||
(props.adhocFilter.clause === CLAUSES.HAVING &&
Expand Down Expand Up @@ -316,23 +313,13 @@ const AdhocFilterEditPopoverSimpleTabContent: React.FC<Props> = props => {
placeholder: '',
};

if (props.datasource.type === 'druid') {
subjectSelectProps.placeholder = t(
'%s column(s) and metric(s)',
columns.length,
);
} else {
// we cannot support simple ad-hoc filters for metrics because we don't know what type
// the value should be cast to (without knowing the output type of the aggregate, which
// becomes a rather complicated problem)
subjectSelectProps.placeholder =
props.adhocFilter.clause === CLAUSES.WHERE
? t('%s column(s)', columns.length)
: t('To filter on a metric, use Custom SQL tab.');
columns = props.options.filter(
option => 'column_name' in option && option.column_name,
);
}
subjectSelectProps.placeholder =
props.adhocFilter.clause === CLAUSES.WHERE
? t('%s column(s)', columns.length)
: t('To filter on a metric, use Custom SQL tab.');
columns = props.options.filter(
option => 'column_name' in option && option.column_name,
);

const operatorSelectProps = {
placeholder: t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,6 @@ test('Should render correct elements for SQL', () => {
expect(screen.getByRole('tabpanel', { name: 'Saved' })).toBeVisible();
});

test('Should render correct elements for native Druid', () => {
const props = { ...createProps(), datasource: { type: 'druid' } };
render(<AdhocMetricEditPopover {...props} />);
expect(screen.getByRole('tab', { name: 'Custom SQL' })).toHaveAttribute(
'aria-disabled',
'true',
);
expect(screen.getByRole('tab', { name: 'Simple' })).toBeEnabled();
expect(screen.getByRole('tab', { name: 'Saved' })).toBeEnabled();
expect(screen.getByRole('tabpanel', { name: 'Saved' })).toBeVisible();
});

test('Should render correct elements for allow ad-hoc metrics', () => {
const props = {
...createProps(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,6 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
autoFocus: true,
};

if (
this.props.datasource?.type === 'druid' &&
aggregateSelectProps.options
) {
aggregateSelectProps.options = aggregateSelectProps.options.filter(
aggregate => aggregate !== 'AVG',
);
}

const stateIsValid = adhocMetric.isValid() || savedMetric?.metric_name;
const hasUnsavedChanges =
!adhocMetric.equals(propsAdhocMetric) ||
Expand Down Expand Up @@ -431,18 +422,11 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
<Tabs.TabPane
key={EXPRESSION_TYPES.SQL}
tab={
extra.disallow_adhoc_metrics ||
this.props.datasource?.type === 'druid' ? (
extra.disallow_adhoc_metrics ? (
<Tooltip
title={
this.props.datasource?.type === 'druid'
? t(
'Custom SQL ad-hoc metrics are not available for the native Druid connector',
)
: t(
'Custom SQL ad-hoc metrics are not enabled for this dataset',
)
}
title={t(
'Custom SQL ad-hoc metrics are not enabled for this dataset',
)}
>
{t('Custom SQL')}
</Tooltip>
Expand All @@ -451,10 +435,7 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
)
}
data-test="adhoc-metric-edit-tab#custom"
disabled={
extra.disallow_adhoc_metrics ||
this.props.datasource?.type === 'druid'
}
disabled={extra.disallow_adhoc_metrics}
>
<SQLEditor
data-test="sql-editor"
Expand Down
1 change: 1 addition & 0 deletions superset/charts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ class ChartDataExtrasSchema(Schema):
having_druid = fields.List(
fields.Nested(ChartDataFilterSchema),
description="HAVING filters to be added to legacy Druid datasource queries.",
deprecated=True,
)
time_grain_sqla = fields.String(
description="To what level of granularity should the temporal column be "
Expand Down
3 changes: 3 additions & 0 deletions superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,8 @@ def get_time_filter_status(
)

if ExtraFiltersTimeColumnType.TIME_ORIGIN in applied_time_extras:
# This seems like it is to do with the druid time series, which I think we
# are still keeping mentions of.
if datasource.type == "druid":
applied.append({"column": ExtraFiltersTimeColumnType.TIME_ORIGIN})
else:
Expand All @@ -1748,6 +1750,7 @@ def get_time_filter_status(
)

if ExtraFiltersTimeColumnType.GRANULARITY in applied_time_extras:
# Same here
if datasource.type == "druid":
applied.append({"column": ExtraFiltersTimeColumnType.GRANULARITY})
else:
Expand Down
1 change: 0 additions & 1 deletion superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ def query_obj(self) -> QueryObjectDict: # pylint: disable=too-many-locals
extras = {
"druid_time_origin": self.form_data.get("druid_time_origin", ""),
"having": self.form_data.get("having", ""),
"having_druid": self.form_data.get("having_filters", []),
"time_grain_sqla": self.form_data.get("time_grain_sqla"),
"where": self.form_data.get("where", ""),
}
Expand Down

0 comments on commit 4ef250e

Please sign in to comment.