Skip to content

Commit

Permalink
Merge pull request apache#45 from john-bodley/john-bodley-cerry-pick-…
Browse files Browse the repository at this point in the history
…5060-5062

[cherry-picks] Picking cherries
  • Loading branch information
john-bodley authored May 23, 2018
2 parents 75d57a3 + de73731 commit 5dbdcfe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion superset/assets/visualizations/markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function markupWidget(slice, payload) {
<iframe id="${iframeId}"
frameborder="0"
height="${iframeHeight}"
sandbox="allow-same-origin allow-scripts allow-top-navigation allow-popups">
sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation">
</iframe>
`);

Expand Down
7 changes: 5 additions & 2 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,12 @@ def get_quoter(self):
return self.get_dialect().identifier_preparer.quote

def get_df(self, sql, schema):
sql = sql.strip().strip(';')
sqls = [x.strip() for x in sql.strip().strip(';').split(';')]
eng = self.get_sqla_engine(schema=schema)
df = pd.read_sql_query(sql, eng)
for i in range(len(sqls) - 1):
eng.execute(sqls[i])

df = pd.read_sql_query(sqls[-1], eng)

def needs_conversion(df_series):
if df_series.empty:
Expand Down
20 changes: 17 additions & 3 deletions tests/model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from __future__ import print_function
from __future__ import unicode_literals

import unittest

from sqlalchemy.engine.url import make_url

from superset import db
from superset.models.core import Database
from .base_tests import SupersetTestCase


class DatabaseModelTestCase(unittest.TestCase):
class DatabaseModelTestCase(SupersetTestCase):

def test_database_schema_presto(self):
sqlalchemy_uri = 'presto://presto.airbnb.io:8080/hive/default'
Expand Down Expand Up @@ -73,3 +73,17 @@ def test_database_impersonate_user(self):
model.impersonate_user = False
user_name = make_url(model.get_sqla_engine(user_name=example_user).url).username
self.assertNotEquals(example_user, user_name)

def test_single_statement(self):
main_db = self.get_main_database(db.session)

if main_db.backend == 'mysql':
df = main_db.get_df('SELECT 1', None)
self.assertEquals(df.iat[0, 0], 1)

def test_multi_statement(self):
main_db = self.get_main_database(db.session)

if main_db.backend == 'mysql':
df = main_db.get_df('USE superset; SELECT 1', None)
self.assertEquals(df.iat[0, 0], 1)

0 comments on commit 5dbdcfe

Please sign in to comment.