Skip to content
This repository was archived by the owner on Dec 10, 2021. It is now read-only.

feat(core): add applied_time_extras to QueryObject#809

Merged
villebro merged 2 commits intoapache-superset:masterfrom
preset-io:villebro/applied-time-extras
Oct 19, 2020
Merged

feat(core): add applied_time_extras to QueryObject#809
villebro merged 2 commits intoapache-superset:masterfrom
preset-io:villebro/applied-time-extras

Conversation

@villebro
Copy link
Contributor

@villebro villebro commented Oct 16, 2020

🏆 Enhancements
Add applied_time_extras to QueryObject to be able to identify which filters have been set/overridden by extra_filters. Please see apache/superset#11325 for additional context.

@villebro villebro requested a review from suddjian October 16, 2020 13:46
@villebro villebro requested a review from a team as a code owner October 16, 2020 13:46
@vercel
Copy link

vercel bot commented Oct 16, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/superset/superset-ui/57hllvjrw
✅ Preview: https://superset-ui-git-villebro-applied-time-extras.superset.vercel.app

@codecov
Copy link

codecov bot commented Oct 16, 2020

Codecov Report

Merging #809 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #809   +/-   ##
=======================================
  Coverage   25.57%   25.57%           
=======================================
  Files         359      359           
  Lines        7949     7949           
  Branches     1056     1055    -1     
=======================================
  Hits         2033     2033           
  Misses       5796     5796           
  Partials      120      120           
Impacted Files Coverage Δ
...ckages/superset-ui-core/src/query/extractExtras.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 298b59f...4127393. Read the comment docs.

Copy link
Contributor

@pkdotson pkdotson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@villebro
Copy link
Contributor Author

Thanks @pkdotson !

Copy link
Contributor

@ktmud ktmud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of naming suggestions. I'm also not fully getting what is this used for. Can you also add more context on how is this going to be used in superset-frontend code (maybe a linked PR?) and what are we constrained with if we don't do this?

const queryField = reservedColumnsToQueryField[filter.col];
partialQueryObject[queryField] = filter.val;
// @ts-ignore
partialQueryObject.applied_time_extras[filter.col] = filter.val;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of ts-ignore, can use type assertion somewhere to make the typings compatible?

      partialQueryObject.applied_time_extras[filter.col as QueryObjectAppliedTimeExtraKey] = filter.val;

where?: string;
}>;

export type QueryObjectAppliedTimeExtraKey =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to something more generic such as TimeColumnConfigKey? Also, maybe put this into Time.ts ?

applied_time_extras: {},
};

const reservedColumnsToQueryField: Record<string, keyof QueryObject> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this could be Record<QueryObjectAppliedTimeExtraKey, keyof QueryObject> or Record<TimeColumnConfigKey, keyof QueryObject>.

};

export type QueryObject = {
/** Extra filters that have been applied to the query object */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't seem to indicate how is this is different from extra.

@villebro
Copy link
Contributor Author

Thanks for comments @ktmud , I'll add some more context to make this clearer and do the suggested code improvements. This is something that is needed to be able to complete the p0 filter indicator feature (filter indicators will otherwise not work with the chart data endpoint). I envision this and other related structures, namely how ad-hoc filters are transformed into simple filters + static wheres and havings will need to change soon when we start working on native filter components. Therefore I was hoping to make this slightly simpler so that we don't have to do a much more comprehensive refactor of this code up front.

| '__granularity';

export type QueryObjectAppliedTimeExtras = {
QueryObjectAppliedTimeExtraKey?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this type is doing what you think it's doing

@suddjian
Copy link
Member

I'm not sure what applied_extra_filters is meant to be used for. Is it a mapping to column names?

Comment on lines +8 to +12
const { extras = {}, filters = [] } = formData;
const partialQueryObject: Partial<QueryObject> = {
filters: formData.filters || [],
extras: formData.extras || {},
filters,
extras,
applied_time_extras,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bycatch: change to use destructuring here.

Comment on lines -31 to +36
partialQueryObject.extras = {
druid_time_origin: formData.druid_time_origin,
};
extras.druid_time_origin = formData.druid_time_origin;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bycatch: better to add to the object than discard the original one.

Comment on lines -37 to +40
partialQueryObject.extras = {
...partialQueryObject.extras,
time_grain_sqla: partialQueryObject.time_grain_sqla || formData.time_grain_sqla,
};
extras.time_grain_sqla = partialQueryObject.time_grain_sqla || formData.time_grain_sqla;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@villebro
Copy link
Contributor Author

@suddjian and @ktmud thanks for your comments, I did my best to address them. I added a link to the incubator-superset PR, which implements these changes for the new chart data endpoint (also implements the same for the legacy endpoint).

Copy link
Member

@suddjian suddjian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@ktmud ktmud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@villebro villebro merged commit fbea70c into apache-superset:master Oct 19, 2020
@villebro villebro deleted the villebro/applied-time-extras branch October 19, 2020 17:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants