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

[SQL Lab] Allow running multiple statements #6112

Merged
merged 5 commits into from
Dec 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions superset/assets/src/SqlLab/components/ResultSet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const defaultProps = {

const SEARCH_HEIGHT = 46;

const LOADING_STYLES = { position: 'relative', height: 50 };
const LOADING_STYLES = { position: 'relative', minHeight: 100 };

export default class ResultSet extends React.PureComponent {
constructor(props) {
Expand Down Expand Up @@ -231,11 +231,19 @@ export default class ResultSet extends React.PureComponent {
</Button>
);
}
const progressMsg = query && query.extra && query.extra.progress ? query.extra.progress : null;
return (
<div style={LOADING_STYLES}>
<div>
{!progressBar && <Loading position="normal" />}
</div>
<QueryStateLabel query={query} />
{!progressBar && <Loading />}
{progressBar}
<div>
{progressMsg && <Alert bsStyle="success">{progressMsg}</Alert>}
</div>
<div>
{progressBar}
</div>
<div>
{trackingUrl}
</div>
Expand Down
18 changes: 10 additions & 8 deletions superset/assets/src/SqlLab/main.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "../../stylesheets/less/cosmo/variables.less";
body {
overflow: hidden;
}
Expand Down Expand Up @@ -168,8 +169,8 @@ div.Workspace {
}

.Resizer {
background: #000;
opacity: .2;
background: @brand-primary;
opacity: 0.5;
z-index: 1;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
Expand All @@ -180,23 +181,24 @@ div.Workspace {
}

.Resizer:hover {
-webkit-transition: all 2s ease;
transition: all 2s ease;
-webkit-transition: all 0.3s ease;
transition: all 0.3s ease;
opacity: 0.3;
}

.Resizer.horizontal {
height: 10px;
margin: -5px 0;
border-top: 5px solid rgba(255, 255, 255, 0);
border-bottom: 5px solid rgba(255, 255, 255, 0);
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
cursor: row-resize;
width: 100%;
padding: 1px;
}

.Resizer.horizontal:hover {
border-top: 5px solid rgba(0, 0, 0, 0.5);
border-bottom: 5px solid rgba(0, 0, 0, 0.5);
border-top: 5px solid @brand-primary;
border-bottom: 5px solid @brand-primary;
}

.Resizer.vertical {
Expand Down
29 changes: 18 additions & 11 deletions superset/assets/src/components/Loading.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@ import PropTypes from 'prop-types';

const propTypes = {
size: PropTypes.number,
position: PropTypes.oneOf(['floating', 'normal']),
};
const defaultProps = {
size: 50,
position: 'floating',
};

export default function Loading({ size }) {
const FLOATING_STYLE = {
padding: 0,
margin: 0,
position: 'absolute',
left: '50%',
top: '50%',
transform: 'translate(-50%, -50%)',
};

export default function Loading({ size, position }) {
const style = position === 'floating' ? FLOATING_STYLE : {};
const styleWithWidth = {
...style,
size,
};
return (
<img
className="loading"
alt="Loading..."
src="/static/assets/images/loading.gif"
style={{
width: Math.min(size, 50),
// height is auto
padding: 0,
margin: 0,
position: 'absolute',
left: '50%',
top: '50%',
transform: 'translate(-50%, -50%)',
}}
style={styleWithWidth}
/>
);
}
Expand Down
6 changes: 3 additions & 3 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,18 @@ def apply_limit_to_sql(cls, sql, limit, database):
)
return database.compile_sqla_query(qry)
elif LimitMethod.FORCE_LIMIT:
parsed_query = sql_parse.SupersetQuery(sql)
parsed_query = sql_parse.ParsedQuery(sql)
sql = parsed_query.get_query_with_new_limit(limit)
return sql

@classmethod
def get_limit_from_sql(cls, sql):
parsed_query = sql_parse.SupersetQuery(sql)
parsed_query = sql_parse.ParsedQuery(sql)
return parsed_query.limit

@classmethod
def get_query_with_new_limit(cls, sql, limit):
parsed_query = sql_parse.SupersetQuery(sql)
parsed_query = sql_parse.ParsedQuery(sql)
return parsed_query.get_query_with_new_limit(limit)

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Add extra column to Query

Revision ID: 0b1f1ab473c0
Revises: 55e910a74826
Create Date: 2018-11-05 08:42:56.181012

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = '0b1f1ab473c0'
down_revision = '55e910a74826'


def upgrade():
op.add_column('query', sa.Column('extra_json', sa.Text(), nullable=True))


def downgrade():
op.drop_column('query', 'extra_json')
22 changes: 0 additions & 22 deletions superset/migrations/versions/a7ca4a272e0a_.py

This file was deleted.

18 changes: 18 additions & 0 deletions superset/migrations/versions/de021a1ca60d_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""empty message

Revision ID: de021a1ca60d
Revises: ('0b1f1ab473c0', 'cefabc8f7d38')
Create Date: 2018-12-18 22:45:55.783083

"""
# revision identifiers, used by Alembic.
revision = 'de021a1ca60d'
down_revision = ('0b1f1ab473c0', 'cefabc8f7d38', '3e1b21cd94a4')


def upgrade():
pass


def downgrade():
pass
20 changes: 20 additions & 0 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,23 @@ def __init__( # noqa
self.duration = duration
self.status = status
self.error_message = error_message


class ExtraJSONMixin:
"""Mixin to add an `extra` column (JSON) and utility methods"""
extra_json = sa.Column(sa.Text, default='{}')

@property
def extra(self):
try:
return json.loads(self.extra_json)
except Exception:
return {}

def set_extra_json(self, d):
self.extra_json = json.dumps(d)

def set_extra_json_key(self, key, value):
extra = self.extra
extra[key] = value
self.extra_json = json.dumps(extra)
10 changes: 7 additions & 3 deletions superset/models/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
from sqlalchemy.orm import backref, relationship

from superset import security_manager
from superset.models.helpers import AuditMixinNullable
from superset.models.helpers import AuditMixinNullable, ExtraJSONMixin
from superset.utils.core import QueryStatus, user_label


class Query(Model):
"""ORM model for SQL query"""
class Query(Model, ExtraJSONMixin):
"""ORM model for SQL query

Now that SQL Lab support multi-statement execution, an entry in this
table may represent multiple SQL statements executed sequentially"""

__tablename__ = 'query'
id = Column(Integer, primary_key=True)
Expand Down Expand Up @@ -105,6 +108,7 @@ def to_dict(self):
'limit_reached': self.limit_reached,
'resultsKey': self.results_key,
'trackingUrl': self.tracking_url,
'extra': self.extra,
}

@property
Expand Down
2 changes: 1 addition & 1 deletion superset/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def datasource_access_by_fullname(
database, table_name, schema=table_schema)

def rejected_datasources(self, sql, database, schema):
superset_query = sql_parse.SupersetQuery(sql)
superset_query = sql_parse.ParsedQuery(sql)
return [
t for t in superset_query.tables if not
self.datasource_access_by_fullname(database, t, schema)]
Expand Down
Loading