-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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(sqllab): Replace autocomplete logic by a hook #24677
fix(sqllab): Replace autocomplete logic by a hook #24677
Conversation
Codecov Report
@@ Coverage Diff @@
## master #24677 +/- ##
==========================================
- Coverage 69.03% 68.96% -0.08%
==========================================
Files 1908 1903 -5
Lines 74197 73947 -250
Branches 8186 8174 -12
==========================================
- Hits 51219 50994 -225
+ Misses 20857 20843 -14
+ Partials 2121 2110 -11
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 13 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@sadpandajoe can you help us test this? |
/testenv up |
@john-bodley Ephemeral environment creation is currently limited to committers. |
/testenv up |
Yeah I can probably either later today or tomorrow. We should take a look at writing an e2e test for this. |
@michael-s-molina Ephemeral environment spinning up at http://52.13.18.69:8080. Credentials are |
@michael-s-molina looks like when I try to log into the ephemeral I'm stuck in an infinite log in state. |
@eschutho were you able to resolve this issue? |
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.
Thanks for the PR @justinpark. Left some first-pass comments.
}); | ||
|
||
test('returns column keywords among selected tables', async () => { | ||
const expectDbId = 1; |
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.
Could you extract the constants that are reusable by the tests?
// skipFetch is used to prevent re-evaluating memoized keywords | ||
// due to updated api results by skip flag | ||
const skipFetch = hasFetchedKeywords && skip; | ||
const { data: schemaOptions } = useSchemas({ |
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.
We should pass the onError
callback and deal with errors when fetching schemas and tables.
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.
The schema error handling already covered at DatabaseSelector
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.
I'm not sure if I understood. I'm assuming this hook is independent of the DatabaseSelector
. It's calling useSchemas
from src/hooks/apiResources
which might fail right? If I use this hook in another component, shouldn't the exception be handled?
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.
You're right. This hook is independent of the DatabaseSelector. However, it shared the query data from DatabaseSelector by using shared useSchemas/useTables
hooks. If this hook also add the error handler (which shows the error toast), the same error message pops up twice because that error handler is already implemented in DatabaseSelect
which is used in the left sidebar layout.
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.
Why the error handler in DatabaseSelector
? There's a benefit of covering all error situations in that component such like new dataset left menu refactor doesn't need to add extra error handling logic for that integration.
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.
To minimize the confusion, let me change useQuery
over useQueryState
which means only sharing the query data without triggering fetches. It will only useQuery for database_functions since it's the only item that requires fetch for additional autocomplete data
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.
As we discussed offline, let's improve the error handling in a follow-up PR as it may require a more detailed context.
}), | ||
}); | ||
|
||
const { data: functionNames, isError } = useDatabaseFunctionsQuery( |
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.
It would be good if these hooks follow the same pattern for error handling. Tables and Schemas have an onError
callback. Could you make useDatabaseFunctionsQuery
follow the same pattern?
{ skip: skipFetch || !dbId }, | ||
); | ||
|
||
useEffect(() => { |
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.
We need to account for all resources when handling errors (tables, schemas).
|
||
hasFetchedKeywords.current = !skip; | ||
|
||
return skip ? EMPTY_LIST : keywords; |
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.
Can you move the skip
check to the beginning of the function to avoid everything else in case it should return an empty list?
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.
It will violate the rule of hooks then.
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.
🤦🏼♂️
@justinpark Given the PR description, is it fair to change the PR title from |
8c41dde
to
230a5aa
Compare
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.
LGTM
Ephemeral environment shutdown and build artifacts deleted. |
(cherry picked from commit 7750517)
SUMMARY
Following-up #24611, this commit adds specs for autocomplete regression by refactoring the logic into a dedicate hook.
In addition to the refactoring, this commit also fixes the unnecessary iterations for generating autocomplete items.
This performance improvement enables the autocomplete with a large-size metadata set.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
After: (able to interact with autocomplete in a large set)
after--autocomplete-perf.mov
Before: (impossible to interact with autocomplete in a large set)
before--autocomplete-perf.mov
TESTING INSTRUCTIONS
Go to SQL lab and enable autocomplete
ADDITIONAL INFORMATION