Skip to content

Commit

Permalink
Fix broken dedup and remove redundant db_spec logic (#5467)
Browse files Browse the repository at this point in the history
* Fix broken dedup and remove redundant db_spec logic

* Add test case
  • Loading branch information
villebro authored and mistercrunch committed Jul 23, 2018
1 parent 971e9f0 commit a165aec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
5 changes: 2 additions & 3 deletions superset/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ def __init__(self, data, cursor_description, db_engine_spec):
if cursor_description:
column_names = [col[0] for col in cursor_description]

self.column_names = dedup(
db_engine_spec.get_normalized_column_names(cursor_description))
self.column_names = dedup(column_names)

data = data or []
self.df = (
pd.DataFrame(list(data), columns=column_names).infer_objects())
pd.DataFrame(list(data), columns=self.column_names).infer_objects())

self._type_dict = {}
try:
Expand Down
21 changes: 0 additions & 21 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,6 @@ def get_configuration_for_impersonation(cls, uri, impersonate_user, username):
"""
return {}

@classmethod
def get_normalized_column_names(cls, cursor_description):
columns = cursor_description if cursor_description else []
return [cls.normalize_column_name(col[0]) for col in columns]

@staticmethod
def normalize_column_name(column_name):
return column_name

@staticmethod
def execute(cursor, query, async=False):
cursor.execute(query)
Expand Down Expand Up @@ -402,10 +393,6 @@ class SnowflakeEngineSpec(PostgresBaseEngineSpec):
Grain('year', _('year'), "DATE_TRUNC('YEAR', {col})", 'P1Y'),
)

@staticmethod
def normalize_column_name(column_name):
return column_name.lower()


class VerticaEngineSpec(PostgresBaseEngineSpec):
engine = 'vertica'
Expand All @@ -414,10 +401,6 @@ class VerticaEngineSpec(PostgresBaseEngineSpec):
class RedshiftEngineSpec(PostgresBaseEngineSpec):
engine = 'redshift'

@staticmethod
def normalize_column_name(column_name):
return column_name.lower()


class OracleEngineSpec(PostgresBaseEngineSpec):
engine = 'oracle'
Expand All @@ -440,10 +423,6 @@ def convert_dttm(cls, target_type, dttm):
"""TO_TIMESTAMP('{}', 'YYYY-MM-DD"T"HH24:MI:SS.ff6')"""
).format(dttm.isoformat())

@staticmethod
def normalize_column_name(column_name):
return column_name.lower()


class Db2EngineSpec(BaseEngineSpec):
engine = 'ibm_db_sa'
Expand Down
12 changes: 12 additions & 0 deletions tests/dataframe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,15 @@ def test_get_columns_type_inference(self):
},
],
)

def test_dedup_with_data(self):
data = [
('a', 1),
('a', 2),
]
cursor_descr = (
('a', 'string'),
('a', 'string'),
)
cdf = SupersetDataFrame(data, cursor_descr, BaseEngineSpec)
self.assertListEqual(cdf.column_names, ['a', 'a__1'])

0 comments on commit a165aec

Please sign in to comment.