-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Allow users to estimate query cost before executing it #8172
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
29a376b
WIP
betodealmeida d7ff8e0
Basic functionality working
betodealmeida 465d054
Enable per DB
betodealmeida e3a3680
Show error message
betodealmeida 7428efc
Small improvements
betodealmeida 70c09e9
Fix lint
betodealmeida d80e6be
Address comments
betodealmeida 4ec832d
Address comments
betodealmeida 14e23c7
Remove logging, fix exception
betodealmeida 5e3118a
Fix tests
betodealmeida dbe09b0
Bump FAB requirements
betodealmeida 5566ef8
Merge branch 'master' into VIZ-726
betodealmeida 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
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
108 changes: 108 additions & 0 deletions
108
superset/assets/src/SqlLab/components/EstimateQueryCostButton.jsx
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,108 @@ | ||
| /** | ||
| * 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 React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { Table } from 'reactable-arc'; | ||
| import { Alert } from 'react-bootstrap'; | ||
| import { t } from '@superset-ui/translation'; | ||
|
|
||
| import Button from '../../components/Button'; | ||
| import Loading from '../../components/Loading'; | ||
| import ModalTrigger from '../../components/ModalTrigger'; | ||
|
|
||
| const propTypes = { | ||
| dbId: PropTypes.number.isRequired, | ||
| schema: PropTypes.string.isRequired, | ||
| sql: PropTypes.string.isRequired, | ||
| getEstimate: PropTypes.func.isRequired, | ||
| queryCostEstimate: PropTypes.Object, | ||
| selectedText: PropTypes.string, | ||
| tooltip: PropTypes.string, | ||
| disabled: PropTypes.bool, | ||
| }; | ||
| const defaultProps = { | ||
| queryCostEstimate: [], | ||
| tooltip: '', | ||
| disabled: false, | ||
| }; | ||
|
|
||
| class EstimateQueryCostButton extends React.PureComponent { | ||
| constructor(props) { | ||
| super(props); | ||
| this.queryCostModal = React.createRef(); | ||
| this.onClick = this.onClick.bind(this); | ||
| this.renderModalBody = this.renderModalBody.bind(this); | ||
| } | ||
|
|
||
| onClick() { | ||
| this.props.getEstimate(); | ||
| } | ||
|
|
||
| renderModalBody() { | ||
| if (this.props.queryCostEstimate.error !== null) { | ||
| return ( | ||
| <Alert key="query-estimate-error" bsStyle="danger"> | ||
| {this.props.queryCostEstimate.error} | ||
| </Alert> | ||
| ); | ||
| } else if (this.props.queryCostEstimate.completed) { | ||
| return ( | ||
| <Table | ||
| className="table cost-estimate" | ||
| data={this.props.queryCostEstimate.cost} | ||
| /> | ||
| ); | ||
| } | ||
| return <Loading position="normal" />; | ||
| } | ||
|
|
||
| render() { | ||
| const { disabled, selectedText, tooltip } = this.props; | ||
| const btnText = selectedText | ||
| ? t('Estimate Selected Query Cost') | ||
| : t('Estimate Query Cost'); | ||
| return ( | ||
| <span className="EstimateQueryCostButton"> | ||
| <ModalTrigger | ||
| ref={this.queryCostModal} | ||
| modalTitle={t('Query Cost Estimate')} | ||
| modalBody={this.renderModalBody()} | ||
| triggerNode={ | ||
| <Button | ||
| bsStyle="warning" | ||
| bsSize="small" | ||
| onClick={this.onClick} | ||
| key="query-estimate-btn" | ||
| tooltip={tooltip} | ||
| disabled={disabled} | ||
| > | ||
| <i className="fa fa-clock-o" /> {btnText} | ||
| </Button> | ||
| } | ||
| bsSize="medium" | ||
| /> | ||
| </span> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| EstimateQueryCostButton.propTypes = propTypes; | ||
| EstimateQueryCostButton.defaultProps = defaultProps; | ||
|
|
||
| export default EstimateQueryCostButton; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -435,3 +435,7 @@ a.Link { | |
| .SouthPane .tab-content button.fetch { | ||
| margin-top: 10px; | ||
| } | ||
|
|
||
| .cost-estimate { | ||
| font-size: 12px; | ||
| } | ||
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
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.