Skip to content

[WIP] [SIP-6] Remove backend logic of tablevis.#6667

Closed
conglei wants to merge 47 commits into
apache:feature--embeddable-charts-pilotfrom
conglei:conglei_table
Closed

[WIP] [SIP-6] Remove backend logic of tablevis.#6667
conglei wants to merge 47 commits into
apache:feature--embeddable-charts-pilotfrom
conglei:conglei_table

Conversation

@conglei
Copy link
Copy Markdown
Contributor

@conglei conglei commented Jan 11, 2019

This PR is to move the backend logic of TableVis to frontend.

  • move get_data to frontend.

  • add more query object fields in frontend.

  • move 'query_object' to frontend.

@xtinec

@conglei conglei changed the title [SIP6]Added get_data for tablevis [SIP6][WIP] Remove backend logic of tablevis. Jan 11, 2019
if (formData.viz_type === 'word_cloud' && !forceExplore) {
directory = '/api/v1/query/';
if (formData.viz_type === 'word_cloud' ||
formData.viz_type === 'table' &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps worthwhile defining an array of viz_types to "whitelist" for the query endpoint and checking that the viz_type from form_data is in that array (since we'll be adding new ones soon)?

@kristw kristw added #refine and removed #refine labels Jan 16, 2019
@kristw kristw changed the title [SIP6][WIP] Remove backend logic of tablevis. [WIP] [SIP-6] Remove backend logic of tablevis. Jan 16, 2019
Comment thread superset/views/api.py
@handle_api_exception
@has_access_api
@expose('/v1/query', methods=['POST'])
@expose('/v1/query/', methods=['POST'])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, I thought we decided to drop the / to avoid calling the endpoint with /v1/query/?slice_id..., no?

Comment thread superset/views/api.py
@handle_api_exception
@has_access_api
@expose('/v1/form_data', methods=['GET'])
@expose('/v1/form_data/', methods=['GET'])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto


if query_obj and not is_loaded:
try:
print(query_obj)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove?

}

export enum MetricsKey {
METRICS = 'metrics',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. So when the keys are either metrics or percent_metrics, the values are always arrays?

groupby?: string[];
columns?: string[];
all_columns?: string[];
limit?: string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this be number instead of string?

columns?: string[];
all_columns?: string[];
limit?: string;
row_limit: string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto. Should this be number?

} & BaseFormData;

type FormData = SqlaFormData | DruidFormData;
type FormData = BaseFormData & SqlaFormData & DruidFormData;
Copy link
Copy Markdown
Contributor

@xtinec xtinec Jan 17, 2019

Choose a reason for hiding this comment

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

Why &? Shouldn't a data source be either SqlAlchemy or Druid? 🤔 Also either type will "inherit" the command fields from BaseFormData. It seems the type of FormData should stay the same as before, no?

granularity: string;
groupby?: string[];
metrics?: Metric[];
groupby: string[];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not all of these fields are required as this interface should accommodate all query objects (e.g. groupby is optional in the query object for word cloud). I think a good way to type this is to match a given field with whether it is required in the api signature on the server side.

// specific viz, which is a subtype of the generic formData shared among all viz types.
export default function buildQueryObject<T extends FormData>(formData: T): QueryObject {
const extras = {
druid_time_origin: formData.druid_time_origin || '',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are all these fields in extras required?

import { FormData as GenericFormData } from 'src/query';
import { RawMetric } from 'src/query/Metric';

// FormData specific to the wordcloud viz
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

table viz?

all_columns: string[];
percent_metrics: RawMetric[];
include_time: boolean;
order_by_cols: any[];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we type this without any?

this.metrics = [];
for (const key of Object.keys(MetricKey)) {
const metric = formData[MetricKey[key] as MetricKey];
let metric = formData[MetricKey[key] as MetricKey];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would recommend using const unless we're reassigning metric.

static convertMetric(metric: RawMetric) {
if (!metric) {
return null;
} if (typeof metric === 'string') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

else if?

}
}
for (const key of Object.keys(MetricsKey)) {
let metrics = formData[MetricsKey[key] as MetricsKey];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would recommend using const here instead of let as well.


export default function buildQuery(formData: FormData) {
// Set the single QueryObject's groupby field with series in formData
return buildQueryContext(formData, (baseQueryObject) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Haven't reviewed the new buildQuery for table view. Can take another pass after we address the type related comments above.

@@ -1,3 +1,55 @@
const DTTM_ALIAS = '__timestamp';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we port this file to TypeScript? 🙂

@xtinec xtinec force-pushed the feature--embeddable-charts-pilot branch from c9c6ff1 to f59594b Compare February 5, 2019 00:46
@stale
Copy link
Copy Markdown

stale Bot commented Apr 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the inactive Inactive for >= 30 days label Apr 10, 2019
@stale stale Bot closed this Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inactive Inactive for >= 30 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants