Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(native-filters): Fetch only the required dataset fields #23303

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Column, JsonObject } from '@superset-ui/core';
import userEvent from '@testing-library/user-event';
import { ColumnSelect } from './ColumnSelect';

fetchMock.get('glob:*/api/v1/dataset/123', {
fetchMock.get('glob:*/api/v1/dataset/123?*', {
body: {
result: {
columns: [
Expand All @@ -35,7 +35,7 @@ fetchMock.get('glob:*/api/v1/dataset/123', {
},
},
});
fetchMock.get('glob:*/api/v1/dataset/456', {
fetchMock.get('glob:*/api/v1/dataset/456?*', {
body: {
result: {
columns: [
Expand All @@ -47,7 +47,7 @@ fetchMock.get('glob:*/api/v1/dataset/456', {
},
});

fetchMock.get('glob:*/api/v1/dataset/789', { status: 404 });
fetchMock.get('glob:*/api/v1/dataset/789?*', { status: 404 });

const createProps = (extraProps: JsonObject = {}) => ({
filterId: 'filterId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import React, { useCallback, useState, useMemo, useEffect } from 'react';
import rison from 'rison';
import { Column, ensureIsArray, t, useChangeEffect } from '@superset-ui/core';
import { Select, FormInstance } from 'src/components';
import { useToasts } from 'src/components/MessageToasts/withToasts';
Expand Down Expand Up @@ -85,7 +86,13 @@ export function ColumnSelect({
}
if (datasetId != null) {
cachedSupersetGet({
endpoint: `/api/v1/dataset/${datasetId}`,
endpoint: `/api/v1/dataset/${datasetId}?q=${rison.encode({
Copy link
Member

Choose a reason for hiding this comment

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

The columns state is later used to get currentColumn which is then passed to the filterValues function. If you check filterValues references, you will see that is_dttm and type_generic attributes are also used.

columns: [
'columns.column_name',
'columns.is_dttm',
'columns.type_generic',
Comment on lines +92 to +93
Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100 % sure on this (more like 90 %), but I feel like is_dttm is no longer necessary, and type_generic === GenericDataType.TEMPORAL should always be true for any col that has is_dttm === true, and is the preferred way of checking for temporal columns in the frontend. So if we want to reduce payload size, this is kind of a low hanging fruit.

Copy link
Member Author

Choose a reason for hiding this comment

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

@villebro thanks for the review. If your hypothesis is correct then it seems like a follow up PR would be to deprecate the is_dttm column everywhere.

],
})}`,
}).then(
({ json: { result } }) => {
const lookupValue = Array.isArray(value) ? value : [value];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import React, {
useMemo,
useState,
} from 'react';
import rison from 'rison';
import { PluginFilterSelectCustomizeProps } from 'src/filters/components/Select/types';
import { useSelector } from 'react-redux';
import { getChartDataRequest } from 'src/components/Chart/chartAction';
Expand Down Expand Up @@ -654,7 +655,28 @@ const FiltersConfigForm = (
useEffect(() => {
if (datasetId) {
cachedSupersetGet({
endpoint: `/api/v1/dataset/${datasetId}`,
endpoint: `/api/v1/dataset/${datasetId}?q=${rison.encode({
columns: [
Copy link
Member

Choose a reason for hiding this comment

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

I found other attributes that need to be queried when analyzing the following files:

database.id
datasource_name
schema
is_sqllab_view

columns.type

columns.is_dttm
columns.name
main_dttm_col

return !!datasource && 'results' in datasource && 'sql' in datasource;

results
sql

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-s-molina it seem like results isn't an attribute returned per here.

Copy link
Member

Choose a reason for hiding this comment

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

@john-bodley You're right. Given that results is not listed in show_select_columns, I'm assuming that it's populated elsewhere and you projections won't affect this behavior. Tagging @zhaoyongjie and @villebro in case they know something different.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, I think this is needed in the Explore control panel only, hence shouldn't affect dashboards/native filters.

'columns.column_name',
'columns.expression',
'columns.filterable',
'columns.is_dttm',
'columns.type',
'columns.verbose_name',
'database.id',
'database.database_name',
Copy link
Member Author

Choose a reason for hiding this comment

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

It's somewhat weird how FAB doesn't barf when you give it invalid columns.

'datasource_type',
'filter_select_enabled',
'id',
'is_sqllab_view',
'main_dttm_col',
'metrics.metric_name',
'metrics.verbose_name',
'schema',
'sql',
'table_name',
],
})}`,
})
.then((response: JsonResponse) => {
setMetrics(response.json?.result?.metrics);
Expand Down