mirror of https://github.com/apache/superset.git
Revert "[get_df] Adding support for multi-statement SQL" (#5078)
This commit is contained in:
parent
1aaa73b548
commit
3207116535
|
@ -690,13 +690,9 @@ class Database(Model, AuditMixinNullable, ImportMixin):
|
||||||
return self.get_dialect().identifier_preparer.quote
|
return self.get_dialect().identifier_preparer.quote
|
||||||
|
|
||||||
def get_df(self, sql, schema):
|
def get_df(self, sql, schema):
|
||||||
sqls = [x.strip() for x in sql.strip().strip(';').split(';')]
|
sql = sql.strip().strip(';')
|
||||||
eng = self.get_sqla_engine(schema=schema)
|
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):
|
def needs_conversion(df_series):
|
||||||
if df_series.empty:
|
if df_series.empty:
|
||||||
|
|
|
@ -106,20 +106,6 @@ class DatabaseModelTestCase(SupersetTestCase):
|
||||||
self.assertEquals(d.get('P1D').function, 'DATE({col})')
|
self.assertEquals(d.get('P1D').function, 'DATE({col})')
|
||||||
self.assertEquals(d.get('Time Column').function, '{col}')
|
self.assertEquals(d.get('Time Column').function, '{col}')
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
class SqlaTableModelTestCase(SupersetTestCase):
|
class SqlaTableModelTestCase(SupersetTestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue