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(sqllab): Replace autocomplete logic by a hook #24677

Conversation

justinpark
Copy link
Member

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

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@justinpark
Copy link
Member Author

cc: @sadpandajoe @EugeneTorap

@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Merging #24677 (e29cfce) into master (1473d97) will decrease coverage by 0.08%.
The diff coverage is 80.52%.

❗ Current head e29cfce differs from pull request most recent head 3ebebf2. Consider uploading reports for the commit 3ebebf2 to get more accurate results

@@            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     
Flag Coverage Δ
javascript 55.77% <70.63%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...src/components/ColumnTypeLabel/ColumnTypeLabel.tsx 100.00% <ø> (ø)
...d/packages/superset-ui-chart-controls/src/index.ts 100.00% <ø> (ø)
...-chart-controls/src/sections/advancedAnalytics.tsx 14.28% <ø> (ø)
...rset-ui-chart-controls/src/sections/chartTitle.tsx 100.00% <ø> (ø)
...legacy-plugin-chart-partition/src/controlPanel.tsx 25.00% <ø> (ø)
...gins/legacy-plugin-chart-rose/src/controlPanel.tsx 50.00% <ø> (ø)
...gins/legacy-preset-chart-nvd3/src/NVD3Controls.tsx 100.00% <ø> (ø)
.../BigNumber/BigNumberWithTrendline/controlPanel.tsx 16.66% <ø> (ø)
...s/plugin-chart-echarts/src/Funnel/controlPanel.tsx 66.66% <ø> (ø)
...ns/plugin-chart-echarts/src/Gauge/controlPanel.tsx 66.66% <ø> (ø)
... and 90 more

... and 13 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@john-bodley
Copy link
Member

@sadpandajoe can you help us test this?

@john-bodley
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@john-bodley Ephemeral environment creation is currently limited to committers.

@michael-s-molina
Copy link
Member

/testenv up

@sadpandajoe
Copy link
Member

@sadpandajoe can you help us test this?

Yeah I can probably either later today or tomorrow. We should take a look at writing an e2e test for this.

@github-actions
Copy link
Contributor

@michael-s-molina Ephemeral environment spinning up at http://52.13.18.69:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@sadpandajoe
Copy link
Member

@michael-s-molina looks like when I try to log into the ephemeral I'm stuck in an infinite log in state.

@michael-s-molina
Copy link
Member

@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?

@justinpark justinpark added the v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch label Jul 18, 2023
Copy link
Member

@michael-s-molina michael-s-molina left a 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;
Copy link
Member

@michael-s-molina michael-s-molina Jul 19, 2023

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({
Copy link
Member

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.

Copy link
Member Author

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

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 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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member

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(
Copy link
Member

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(() => {
Copy link
Member

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;
Copy link
Member

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?

Copy link
Member Author

@justinpark justinpark Jul 20, 2023

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.

Copy link
Member

Choose a reason for hiding this comment

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

🤦🏼‍♂️

@michael-s-molina
Copy link
Member

@justinpark Given the PR description, is it fair to change the PR title from refactor: to fix:?

@justinpark justinpark changed the title refactor(sqllab): Replace autocomplete logic by a hook fix(sqllab): Replace autocomplete logic by a hook Jul 20, 2023
@justinpark justinpark force-pushed the refactor--sqllab-autocomplete-by-useKeywords branch from 8c41dde to 230a5aa Compare July 21, 2023 23:09
Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM

@justinpark justinpark merged commit 7750517 into apache:master Jul 26, 2023
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

@mistercrunch mistercrunch added 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 2024
vinothkumar66 pushed a commit to vinothkumar66/superset that referenced this pull request Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XL v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch 🍒 3.0.0 🍒 3.0.1 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants