Skip to content
Closed
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
12 changes: 9 additions & 3 deletions superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,15 +1237,21 @@ def query(self, query_obj):

# Reordering columns
cols = []
groupby = query_obj.get('groupby') or []
columns = query_obj.get('columns') or []
metrics = query_obj.get('metrics') or []
if DTTM_ALIAS in df.columns:
cols += [DTTM_ALIAS]
cols += query_obj.get('groupby') or []
cols += query_obj.get('columns') or []
cols += query_obj.get('metrics') or []
cols += groupby
Copy link
Contributor

@xrmx xrmx Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cols = [DTTM_ALIAS] + groupby + columns + metrics

may be a bit cheaper and cleaner

cols += columns
cols += metrics

cols = [col for col in cols if col in df.columns]
df = df[cols]

for col in groupby + columns:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible for some of these columns to not be in df.columns given the list comprehension at line 1249?

df[col] = df[col].astype('str')

time_offset = DruidDatasource.time_offset(query_obj['granularity'])

def increment_timestamp(ts):
Expand Down
5 changes: 4 additions & 1 deletion tests/druid_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __reduce__(self):
'timestamp': '2012-01-01T00:00:00.000Z',
'event': {
'dim1': 'Canada',
'dim2': 0,
'metric1': 12345678,
},
},
Expand All @@ -63,6 +64,7 @@ def __reduce__(self):
'timestamp': '2012-01-01T00:00:00.000Z',
'event': {
'dim1': 'USA',
'dim2': 'false',
'metric1': 12345678 / 2,
},
},
Expand Down Expand Up @@ -152,7 +154,7 @@ def test_client(self, PyDruid):
'row_limit': 5000,
'include_search': 'false',
'metrics': ['count'],
'groupby': ['dim1', 'dim2d'],
'groupby': ['dim1', 'dim2'],
'force': 'true',
}
# two groupby
Expand All @@ -162,6 +164,7 @@ def test_client(self, PyDruid):
)
resp = self.get_json_resp(url)
self.assertEqual('Canada', resp['data']['records'][0]['dim1'])
self.assertEqual('0', resp['data']['records'][0]['dim2'])

def test_druid_sync_from_config(self):
CLUSTER_NAME = 'new_druid'
Expand Down