-
Notifications
You must be signed in to change notification settings - Fork 18k
fix(sqllab): key overwrite-dataset options by id, not table name #42620
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
base: master
Are you sure you want to change the base?
Changes from all commits
8c10eae
01fdda5
eff9fae
c800f64
9ddff12
7e013dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,6 +195,37 @@ const updateDataset = async ({ | |
|
|
||
| const UNTITLED = t('Untitled Dataset'); | ||
|
|
||
| /** | ||
| * Datasets are unique by database, catalog, schema and table name, so a label | ||
| * built from anything less can be ambiguous — e.g. `examples.public.sales`. | ||
| */ | ||
| const qualifiedLabel = (dataset: { | ||
| database?: { database_name?: string }; | ||
| catalog?: string | null; | ||
| schema?: string | null; | ||
| table_name: string; | ||
| }) => | ||
| [ | ||
| dataset.database?.database_name, | ||
| dataset.catalog, | ||
| dataset.schema, | ||
| dataset.table_name, | ||
| ] | ||
| .filter(Boolean) | ||
| .join('.'); | ||
|
|
||
| /** | ||
| * Break a search typed against those labels into its parts. The trailing part | ||
| * is the table name, unless the user has just typed a separator. | ||
| */ | ||
| const parseQualifiedSearch = (input: string) => { | ||
| const parts = input.split('.').filter(Boolean); | ||
| return { | ||
| parts, | ||
| tableSearch: input.endsWith('.') ? '' : (parts[parts.length - 1] ?? ''), | ||
| }; | ||
| }; | ||
|
|
||
| // The filters param is only used to test jinja templates. | ||
| // Remove the special filters entry from the templateParams | ||
| // before saving the dataset. | ||
|
|
@@ -321,12 +352,18 @@ export const SaveDatasetModal = ({ | |
| }; | ||
|
|
||
| const loadDatasetOverwriteOptions = useCallback(async (input = '') => { | ||
| // Only the table part can be filtered server-side — `database` is a | ||
| // relationship the list endpoint cannot match on by name. Sending the | ||
| // whole search as a `table_name` filter matches nothing once the user | ||
| // types a separator; filterAutocompleteOption narrows the qualifiers. | ||
| const { tableSearch } = parseQualifiedSearch(input); | ||
|
|
||
| const queryParams = rison.encode({ | ||
| filters: [ | ||
| { | ||
| col: 'table_name', | ||
| opr: 'ct', | ||
| value: input, | ||
| value: tableSearch, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: When the input contains a separator, only the table-name suffix is sent to the API and qualifier filtering is deferred to the browser. The async select receives only the first API page, so if more than one page of editable datasets shares that table-name suffix, a matching database/schema dataset on a later page is never loaded and cannot be selected. Apply the qualifier filters server-side, or request and merge all relevant pages before client-side filtering. [logic error] Severity Level: Major
|
||
| }, | ||
| { | ||
| col: 'id', | ||
|
|
@@ -342,9 +379,18 @@ export const SaveDatasetModal = ({ | |
| endpoint: `/api/v1/dataset/?q=${queryParams}`, | ||
|
Comment on lines
361
to
379
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The loader ignores the Severity Level: Major
|
||
| }).then(response => ({ | ||
| data: response.json.result.map( | ||
| (r: { table_name: string; id: number; editors: Subject[] }) => ({ | ||
| value: r.table_name, | ||
| label: r.table_name, | ||
| (r: { | ||
| table_name: string; | ||
| id: number; | ||
| editors: Subject[]; | ||
| database?: { database_name?: string }; | ||
| catalog?: string | null; | ||
| schema?: string | null; | ||
| }) => ({ | ||
| // `id` is unique; `table_name` is not. Keying by the table name | ||
| // collapses same-named datasets onto a single Select key. | ||
| value: r.id, | ||
| label: qualifiedLabel(r), | ||
| datasetId: r.id, | ||
| editors: r.editors, | ||
| }), | ||
|
|
@@ -424,7 +470,14 @@ export const SaveDatasetModal = ({ | |
| const filterAutocompleteOption = ( | ||
| inputValue: string, | ||
| option: DatasetOverwriteOption, | ||
| ) => option.value.toLowerCase().includes(inputValue.toLowerCase()); | ||
| ) => { | ||
| const label = option.label.toLowerCase(); | ||
| // Position-independent: a dataset may or may not have a catalog, and a | ||
| // search skipping a part (`examples.sales`) should still match. | ||
| return parseQualifiedSearch(inputValue.toLowerCase()).parts.every(part => | ||
| label.includes(part), | ||
| ); | ||
|
Comment on lines
+477
to
+479
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The client-side filter treats every qualified-search component as an unordered substring, so a search such as Severity Level: Major
|
||
| }; | ||
|
|
||
| return ( | ||
| <Modal | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropping empty qualifier slots makes distinct datasets such as
(catalog=reporting, schema=null)and(catalog=null, schema=reporting)render the same label, so the overwrite picker cannot tell users which dataset they are selecting. Could this preserve the qualifier positions or label each component explicitly?