Skip to content

Commit

Permalink
Add visualize advise for long query (#2879)
Browse files Browse the repository at this point in the history
in SqlLab view, if query takes over 45 seconds, we will show advise to store a summarized data set before user clicks on Visualize button.
This advise will not block Visualize button.

fixes #2733
  • Loading branch information
Grace Guo authored May 31, 2017
1 parent e300273 commit db052b1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
19 changes: 19 additions & 0 deletions superset/assets/javascripts/SqlLab/components/VisualizeModal.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global notify */
import moment from 'moment';
import React from 'react';
import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
Expand All @@ -11,6 +12,7 @@ import shortid from 'shortid';
import { getExploreUrl } from '../../explore/exploreUtils';
import * as actions from '../actions';
import { VISUALIZE_VALIDATION_ERRORS } from '../constants';
import { QUERY_TIMEOUT_THRESHOLD } from '../../constants';

const CHART_TYPES = [
{ value: 'dist_bar', label: 'Distribution - Bar Chart', requiresTime: false },
Expand Down Expand Up @@ -126,6 +128,22 @@ class VisualizeModal extends React.PureComponent {
dbId: this.props.query.dbId,
};
}
buildVisualizeAdvise() {
let advise;
const queryDuration = moment.duration(this.props.query.endDttm - this.props.query.startDttm);
if (Math.round(queryDuration.asMilliseconds()) > QUERY_TIMEOUT_THRESHOLD) {
advise = (
<Alert bsStyle="warning">
This query took {Math.round(queryDuration.asSeconds())} seconds to run,
and the explore view times out at {QUERY_TIMEOUT_THRESHOLD / 1000} seconds,
following this flow will most likely lead to your query timing out.
We recommend your summarize your data further before following that flow.
If activated you can use the <strong>CREATE TABLE AS</strong> feature
to store a summarized data set that you can then explore.
</Alert>);
}
return advise;
}
visualize() {
this.props.actions.createDatasource(this.buildVizOptions(), this)
.done(() => {
Expand Down Expand Up @@ -224,6 +242,7 @@ class VisualizeModal extends React.PureComponent {
</Modal.Header>
<Modal.Body>
{alerts}
{this.buildVisualizeAdvise()}
<div className="row">
<Col md={6}>
Chart Type
Expand Down
20 changes: 20 additions & 0 deletions superset/assets/spec/javascripts/sqllab/VisualizeModal_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ describe('VisualizeModal', () => {
});
});

it('should build visualize advise for long query', () => {
const longQuery = Object.assign({}, queries[0], { endDttm: 1476910666798 });
const props = {
show: true,
query: longQuery,
};
const longQueryWrapper = shallow(<VisualizeModal {...props} />, {
context: { store },
}).dive();
const alertWrapper = shallow(longQueryWrapper.instance().buildVisualizeAdvise());
expect(alertWrapper.hasClass('alert')).to.equal(true);
expect(alertWrapper.text()).to.contain(
'This query took 101 seconds to run, and the explore view times out at 45 seconds');
});

it('should not build visualize advise', () => {
const wrapper = getVisualizeModalWrapper();
expect(wrapper.instance().buildVisualizeAdvise()).to.be.a('undefined');
});

describe('visualize', () => {
const wrapper = getVisualizeModalWrapper();
const mockOptions = { attr: 'mockOptions' };
Expand Down

0 comments on commit db052b1

Please sign in to comment.