Repository navigation
fix(native-filters): populate granularity_sqla from datasource main_dttm_col for time-range parent cascade #39894
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
Open
jtjenkins
wants to merge
8
commits into
apache:master
Choose a base branch
from
jtjenkins:fix/native-filter-granularity-sqla-cascade
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+340
−6
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b50b04
fix(native-filters): populate granularity_sqla from datasource main_d…
jtjenkins b582c8a
fix(native-filters): deduplicate in-flight fetchDatasourceMetadata re…
jtjenkins 010f053
test(native-filters): pin granularity cascade + dedup, drop any cast
jtjenkins 3c99fa2
fix(native-filters): handle metadata fetch rejection, drop any from t…
jtjenkins 022c541
Merge remote-tracking branch 'apache/master' into fix/native-filter-g…
jtjenkins 9130ab3
fix(native-filters): share in-flight metadata promise across callers
jtjenkins daf1158
Merge master into fix/native-filter-granularity-sqla-cascade
rusackas c5fb4cc
Merge branch 'master' into fix/native-filter-granularity-sqla-cascade
DamianPendrak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
superset-frontend/src/dashboard/actions/datasources.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| import { JsonObject, SupersetClient } from '@superset-ui/core'; | ||
| import { Datasource, DatasourcesState, RootState } from 'src/dashboard/types'; | ||
| import { | ||
| DatasourcesAction, | ||
| fetchDatasourceMetadata, | ||
| setDatasource, | ||
| } from './datasources'; | ||
|
|
||
| const KEY = '7__table'; | ||
|
|
||
| type ClientResponse = Awaited<ReturnType<typeof SupersetClient.get>>; | ||
|
|
||
| // Minimal typed stand-ins so the tests avoid `any` while exercising the thunk. | ||
| const datasource = (json: JsonObject = { uid: KEY, main_dttm_col: 'ds' }) => | ||
| json as unknown as Datasource; | ||
|
|
||
| const jsonResponse = (json: JsonObject): ClientResponse => | ||
| ({ json }) as unknown as ClientResponse; | ||
|
|
||
| const buildGetState = | ||
| (datasources: DatasourcesState = {}) => | ||
| () => | ||
| ({ datasources }) as unknown as RootState; | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| test('fetchDatasourceMetadata uses the cached datasource without a network call', () => { | ||
| const getSpy = jest.spyOn(SupersetClient, 'get'); | ||
| const dispatch = jest.fn(); | ||
| const cached = datasource(); | ||
|
|
||
| fetchDatasourceMetadata(KEY)(dispatch, buildGetState({ [KEY]: cached })); | ||
|
|
||
| expect(getSpy).not.toHaveBeenCalled(); | ||
| expect(dispatch).toHaveBeenCalledWith(setDatasource(cached, KEY)); | ||
| }); | ||
|
|
||
| test('fetchDatasourceMetadata fetches and caches an uncached datasource', async () => { | ||
| const json = { uid: KEY, main_dttm_col: 'ds' }; | ||
| const getSpy = jest | ||
| .spyOn(SupersetClient, 'get') | ||
| .mockResolvedValue(jsonResponse(json)); | ||
| const dispatch = jest.fn(); | ||
|
|
||
| await fetchDatasourceMetadata(KEY)(dispatch, buildGetState()); | ||
|
|
||
| expect(getSpy).toHaveBeenCalledTimes(1); | ||
| expect(dispatch).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: DatasourcesAction.SetDatasource, | ||
| key: KEY, | ||
| datasource: json, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| test('fetchDatasourceMetadata deduplicates concurrent in-flight requests for the same key', async () => { | ||
| let resolveGet: (value: ClientResponse) => void = () => {}; | ||
| const getSpy = jest.spyOn(SupersetClient, 'get').mockReturnValue( | ||
| new Promise<ClientResponse>(resolve => { | ||
| resolveGet = resolve; | ||
| }), | ||
| ); | ||
| const dispatch = jest.fn(); | ||
| const getState = buildGetState(); | ||
|
|
||
| // Two filters using the same dataset mount and dispatch before the first | ||
| // request resolves and populates the cache. | ||
| fetchDatasourceMetadata(KEY)(dispatch, getState); | ||
| fetchDatasourceMetadata(KEY)(dispatch, getState); | ||
|
|
||
| expect(getSpy).toHaveBeenCalledTimes(1); | ||
|
|
||
| resolveGet(jsonResponse({ uid: KEY, main_dttm_col: 'ds' })); | ||
| await Promise.resolve(); | ||
| }); | ||
|
|
||
| test('fetchDatasourceMetadata clears the in-flight key after a failed request so it can retry', async () => { | ||
| const getSpy = jest | ||
| .spyOn(SupersetClient, 'get') | ||
| .mockRejectedValueOnce(new Error('boom')) | ||
| .mockResolvedValueOnce(jsonResponse({ uid: KEY })); | ||
| const dispatch = jest.fn(); | ||
| const getState = buildGetState(); | ||
|
|
||
| await expect( | ||
| fetchDatasourceMetadata(KEY)(dispatch, getState), | ||
| ).rejects.toThrow('boom'); | ||
|
|
||
| // The failed key is no longer in flight, so a subsequent dispatch retries. | ||
| await fetchDatasourceMetadata(KEY)(dispatch, getState); | ||
|
|
||
| expect(getSpy).toHaveBeenCalledTimes(2); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.