You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/01/30 19:42:42 UTC

[GitHub] betodealmeida commented on a change in pull request #6719: Adding support for Pinot

betodealmeida commented on a change in pull request #6719: Adding support for Pinot
URL: https://github.com/apache/incubator-superset/pull/6719#discussion_r252409364
 
 

 ##########
 File path: superset/connectors/sqla/models.py
 ##########
 @@ -804,10 +837,24 @@ def query(self, query_obj):
                 df = df.rename(index=str, columns=self.mutated_labels)
         except Exception as e:
             status = utils.QueryStatus.FAILED
-            logging.exception(e)
+            logging.exception(f'Query {sql} on schema {self.schema} failed')
             error_message = (
                 self.database.db_engine_spec.extract_error_message(e))
 
+        labels_expected = query_str_ext.labels_expected
+        if df is not None and \
+                not df.empty and \
+                not self.database.db_engine_spec.db_respects_given_column_labels and \
+                labels_expected is not None:
+            if len(df.columns) != len(labels_expected):
+                error_message = (f'For {sql}, df.columns: {df.columns}' +
+                                 f' differs from {labels_expected}')
+                status = utils.QueryStatus.FAILED
+            else:
+                logging.info(f'For query {sql}, renaming the df.columns from'
+                             f' {df.columns} to {labels_expected}')
+                df.columns = labels_expected
+
 
 Review comment:
   I think that the logic belongs in the DB API driver instead of Superset — it would also benefit other tools that use the driver.
   
   I wrote a Google Spreadsheets connector that has the same problem, since the SQL API supported is very crude and doesn't accept aliases. Maybe you can reuse the helper function I created? It's based on `moz-sql-parser` instead of `sqlparse`:
   
   https://github.com/betodealmeida/gsheets-db-api/blob/master/gsheetsdb/query.py#L93

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org