Skip to content

Commit

Permalink
chore: removing Druid from front- and back- end (#20338)
Browse files Browse the repository at this point in the history
* first pass at removing native Druid nosql

* removing having_druid

* addressing comments, linting

* fixed all tests

* addressing comments

* redirected to ui-core TimeGranularity type

* query form metric linting

* fixed broken chart type

* implementing feedback
  • Loading branch information
AAfghahi committed Jul 8, 2022
1 parent 9856d88 commit 0ce0c6e
Show file tree
Hide file tree
Showing 47 changed files with 65 additions and 454 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const TIME_FILTER_LABELS = {
time_range: t('Time Range'),
granularity_sqla: t('Time Column'),
time_grain_sqla: t('Time Grain'),
druid_time_origin: t('Origin'),
granularity: t('Time Granularity'),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const legacyTimeseriesTime: ControlPanelSectionConfig = {
...baseTimeSection,
controlSetRows: [
['granularity'],
['druid_time_origin'],
['granularity_sqla'],
['time_grain_sqla'],
['time_range'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,6 @@ const columnsControl: typeof groupByControl = {
description: t('One or many columns to pivot as columns'),
};

const druid_time_origin: SharedControlConfig<'SelectControl'> = {
type: 'SelectControl',
freeForm: true,
label: TIME_FILTER_LABELS.druid_time_origin,
choices: [
['', 'default'],
['now', 'now'],
],
default: null,
description: t(
'Defines the origin where time buckets start, ' +
'accepts natural dates as in `now`, `sunday` or `1970-01-01`',
),
};

const granularity: SharedControlConfig<'SelectControl'> = {
type: 'SelectControl',
freeForm: true,
Expand Down Expand Up @@ -569,7 +554,6 @@ const sharedControls = {
secondary_metric: enableExploreDnd ? dnd_secondary_metric : secondary_metric,
groupby: enableExploreDnd ? dndGroupByControl : groupByControl,
columns: enableExploreDnd ? dndColumnsControl : columnsControl,
druid_time_origin,
granularity,
granularity_sqla: enableExploreDnd ? dnd_granularity_sqla : granularity_sqla,
time_grain_sqla,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
/* eslint-disable camelcase */
import {
AdhocFilter,
QueryFieldAliases,
QueryFormColumn,
QueryFormData,
QueryObject,
QueryObjectFilterClause,
isPhysicalColumn,
isAdhocColumn,
} from './types';
import {
QueryFieldAliases,
QueryFormColumn,
QueryFormData,
} from './types/QueryFormData';
import processFilters from './processFilters';
import extractExtras from './extractExtras';
import extractQueryFields from './extractQueryFields';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
export const DTTM_ALIAS = '__timestamp';

export const EXTRA_FORM_DATA_OVERRIDE_EXTRA_KEYS: (keyof ExtraFormDataOverrideExtras)[] =
['druid_time_origin', 'relative_start', 'relative_end', 'time_grain_sqla'];
['relative_start', 'relative_end', 'time_grain_sqla'];

export const EXTRA_FORM_DATA_APPEND_KEYS: (keyof ExtraFormDataAppend)[] = [
'adhoc_filters',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*/

/* eslint-disable camelcase */
import { TimeGranularity, QueryFormData } from '@superset-ui/core';
import {
AppliedTimeExtras,
isDruidFormData,
QueryFormData,
QueryObjectExtras,
QueryObjectFilterClause,
TimeColumnConfigKey,
Expand All @@ -30,8 +29,7 @@ import {
type ExtraFilterQueryField = {
time_range?: string;
granularity_sqla?: string;
time_grain_sqla?: string;
druid_time_origin?: string;
time_grain_sqla?: TimeGranularity;
granularity?: string;
};

Expand All @@ -58,36 +56,28 @@ export default function extractExtras(formData: QueryFormData): ExtractedExtra {
__time_range: 'time_range',
__time_col: 'granularity_sqla',
__time_grain: 'time_grain_sqla',
__time_origin: 'druid_time_origin',
__granularity: 'granularity',
};

(formData.extra_filters || []).forEach(filter => {
if (filter.col in reservedColumnsToQueryField) {
const key = filter.col as TimeColumnConfigKey;
const queryField = reservedColumnsToQueryField[key];
extract[queryField] = filter.val as string;
extract[queryField] = filter.val as TimeGranularity;
applied_time_extras[key] = filter.val as string;
} else {
filters.push(filter);
}
});

// map to undeprecated names and remove deprecated fields
if (isDruidFormData(formData) && !extract.druid_time_origin) {
extras.druid_time_origin = formData.druid_time_origin;
delete extract.druid_time_origin;
} else {
// SQL
extras.time_grain_sqla =
extract.time_grain_sqla || formData.time_grain_sqla;
extract.granularity =
extract.granularity_sqla ||
formData.granularity ||
formData.granularity_sqla;
delete extract.granularity_sqla;
delete extract.time_grain_sqla;
}
// SQL
extras.time_grain_sqla = extract.time_grain_sqla || formData.time_grain_sqla;
extract.granularity =
extract.granularity_sqla ||
formData.granularity ||
formData.granularity_sqla;
delete extract.granularity_sqla;
delete extract.time_grain_sqla;

return extract;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
/* eslint-disable no-underscore-dangle */

import { QueryFormData } from './types';
import { QueryFormData } from '@superset-ui/core';
import { TimeGranularity } from '../time-format';

export default function extractTimegrain(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { isAdhocMetricSimple, isSavedMetric, QueryFormMetric } from './types';
import { QueryFormMetric, isSavedMetric, isAdhocMetricSimple } from './types';

export default function getMetricLabel(metric: QueryFormMetric): string {
if (isSavedMetric(metric)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export default function processFilters(

// some filter-related fields need to go in `extras`
extras.having = freeformHaving.map(sanitizeClause).join(' AND ');
extras.having_druid = simpleHaving;
extras.where = freeformWhere.map(sanitizeClause).join(' AND ');

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export type Filter = {
adhoc_filters?: AdhocFilter[];
granularity_sqla?: string;
granularity?: string;
druid_time_origin?: string;
time_grain_sqla?: string;
time_range?: string;
requiredFirst?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export type PostProcessingPivot = _PostProcessingPivot | DefaultPostProcessing;
interface _PostProcessingProphet {
operation: 'prophet';
options: {
time_grain: TimeGranularity;
time_grain: TimeGranularity | undefined;
periods: number;
confidence_interval: number;
yearly_seasonality?: boolean | number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export type QueryObjectFilterClause = {

export type QueryObjectExtras = Partial<{
/** HAVING condition for Druid */
having_druid?: string;
druid_time_origin?: string;
/** HAVING condition for SQLAlchemy */
having?: string;
relative_start?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ export type ExtraFormDataAppend = {
* filter clauses can't be overridden */
export type ExtraFormDataOverrideExtras = Pick<
QueryObjectExtras,
'druid_time_origin' | 'relative_start' | 'relative_end' | 'time_grain_sqla'
'relative_start' | 'relative_end' | 'time_grain_sqla'
>;

/** These parameters override those already present in the form data/query object */
export type ExtraFormDataOverrideRegular = Partial<
Pick<SqlaFormData, 'granularity_sqla'>
> &
Partial<Pick<DruidFormData, 'granularity'>> &
Partial<Pick<SqlaFormData, 'granularity'>> &
Partial<Pick<BaseFormData, 'time_range'>> &
Partial<Pick<QueryObject, 'time_column' | 'time_grain'>>;

Expand Down Expand Up @@ -194,30 +194,16 @@ export interface SqlaFormData extends BaseFormData {
/**
* Name of the Time Column. Time column is optional.
*/
granularity?: string;
granularity_sqla?: string;
time_grain_sqla?: TimeGranularity;
having?: string;
}

/**
* Form data for Druid datasources.
*/
export interface DruidFormData extends BaseFormData {
granularity?: string;
having_druid?: string;
druid_time_origin?: string;
}

export type QueryFormData = DruidFormData | SqlaFormData;
export type QueryFormData = SqlaFormData;

//---------------------------------------------------
// Type guards
//---------------------------------------------------

export function isDruidFormData(
formData: QueryFormData,
): formData is DruidFormData {
return 'granularity' in formData;
}

export default {};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export type TimeColumnConfigKey =
| '__time_col'
| '__time_grain'
| '__time_range'
| '__time_origin'
| '__granularity';

export type AppliedTimeExtras = Partial<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@

/* eslint sort-keys: 'off' */
/** The form data defined here is based on default visualizations packaged with Apache Superset */
import { TimeGranularity } from '@superset-ui/core';

export const bigNumberFormData = {
datasource: '3__table',
viz_type: 'big_number',
slice_id: 54,
granularity_sqla: 'ds',
time_grain_sqla: 'P1D',
time_grain_sqla: TimeGranularity.DAY,
time_range: '100 years ago : now',
metric: 'sum__num',
adhoc_filters: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
import { TimeGranularity } from '@superset-ui/core';
import extractExtras from '../../src/query/extractExtras';

describe('extractExtras', () => {
const baseQueryFormData = {
datasource: '1__table',
granularity_sqla: 'ds',
time_grain_sqla: 'PT1M',
time_grain_sqla: TimeGranularity.MINUTE,
viz_type: 'my_viz',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('processFilters', () => {
}),
).toEqual(
expect.objectContaining({
extras: { having: '', having_druid: [], where: '' },
extras: { having: '', where: '' },
filters: [],
}),
);
Expand Down Expand Up @@ -59,7 +59,6 @@ describe('processFilters', () => {
).toEqual({
extras: {
having: '',
having_druid: [],
where: '',
},
filters: [
Expand Down Expand Up @@ -89,7 +88,6 @@ describe('processFilters', () => {
filters: [],
extras: {
having: '',
having_druid: [],
where: '(1 = 1)',
},
});
Expand All @@ -115,20 +113,6 @@ describe('processFilters', () => {
operator: '==',
comparator: 'almond',
},
{
expressionType: 'SIMPLE',
clause: 'HAVING',
subject: 'sweetness',
operator: '>',
comparator: '0',
},
{
expressionType: 'SIMPLE',
clause: 'HAVING',
subject: 'sweetness',
operator: '<=',
comparator: '50',
},
{
expressionType: 'SQL',
clause: 'WHERE',
Expand All @@ -154,18 +138,6 @@ describe('processFilters', () => {
).toEqual({
extras: {
having: '(ice = 25 OR ice = 50) AND (waitTime <= 180 -- comment\n)',
having_druid: [
{
col: 'sweetness',
op: '>',
val: '0',
},
{
col: 'sweetness',
op: '<=',
val: '50',
},
],
where: "(tea = 'jasmine') AND (cup = 'large' -- comment\n)",
},
filters: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ test('should compile query object A', () => {
filters: [],
extras: {
having: '',
having_druid: [],
time_grain_sqla: 'P1W',
where: "(foo in ('a', 'b'))",
},
Expand Down Expand Up @@ -158,7 +157,6 @@ test('should compile query object B', () => {
filters: [],
extras: {
having: '',
having_druid: [],
time_grain_sqla: 'P1W',
where: "(name in ('c', 'd'))",
},
Expand Down Expand Up @@ -282,7 +280,6 @@ test('should compile query objects with x-axis', () => {
filters: [],
extras: {
having: '',
having_druid: [],
time_grain_sqla: 'P1W',
where: "(foo in ('a', 'b'))",
},
Expand Down

0 comments on commit 0ce0c6e

Please sign in to comment.