mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
Fix broken dedup and remove redundant db_spec logic (#5467)
* Fix broken dedup and remove redundant db_spec logic * Add test case
This commit is contained in:
committed by
Maxime Beauchemin
parent
971e9f0993
commit
a165aec822
@@ -70,12 +70,11 @@ class SupersetDataFrame(object):
|
||||
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:
|
||||
|
||||
@@ -321,15 +321,6 @@ class BaseEngineSpec(object):
|
||||
"""
|
||||
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)
|
||||
@@ -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'
|
||||
@@ -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'
|
||||
@@ -440,10 +423,6 @@ class OracleEngineSpec(PostgresBaseEngineSpec):
|
||||
"""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'
|
||||
|
||||
@@ -113,3 +113,15 @@ class SupersetDataFrameTestCase(SupersetTestCase):
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
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'])
|
||||
|
||||
Reference in New Issue
Block a user