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

fix(dashboard): native filters do not preserve bigint #24413

Closed
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
14 changes: 14 additions & 0 deletions superset-frontend/src/filters/components/Select/buildQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,18 @@ describe('Select buildQuery', () => {
const [query] = queryContext.queries;
expect(query.filters).toEqual([{ col: 'my_col', op: '>=', val: 123 }]);
});

it('should add big numeric search parameter to query filter', () => {
const queryContext = buildQuery(formData, {
ownState: {
search: '123436775936632786',
coltypeMap: { my_col: GenericDataType.NUMERIC },
},
});
expect(queryContext.queries.length).toEqual(1);
const [query] = queryContext.queries;
expect(query.filters).toEqual([
{ col: 'my_col', op: '>=', val: '123436775936632786' },
]);
});
});
21 changes: 15 additions & 6 deletions superset-frontend/src/filters/components/Select/buildQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,21 @@ const buildQuery: BuildQuery<PluginFilterSelectQueryFormData> = (
coltypeMap[label] === GenericDataType.NUMERIC &&
!Number.isNaN(Number(search))
) {
// for numeric columns we apply a >= where clause
extraFilters.push({
col: column,
op: '>=',
val: Number(search),
});
if (search === `${Number(search)}`) {
// for numeric columns we apply a >= where clause
extraFilters.push({
col: column,
op: '>=',
val: Number(search),
Copy link
Member

Choose a reason for hiding this comment

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

@justinpark do you know what additional value using Number(...) provides? This is how the backend handles the filtering logic which casts strings to numbers and thus maybe it's ok for the backend to handle both cases, i.e., we could remove lines 54–60.

We could include a comment of the form,

// for numeric columns the backend casts the search string to the appropriate type—preventing JavaScript overflow. Additionally we use the fairly crude(and insufficient)  >= operator as a proxy for detecting whether the search string is contained within the column given there is no trivial way of dynamically casting the the column type.

});
} else {
// for big number case
extraFilters.push({
col: column,
op: '>=',
val: search,
});
}
}
});
}
Expand Down