You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2018/08/21 05:04:25 UTC

[incubator-superset] branch master updated: Handling bigquery dialect when previewing data (#5655)

This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 0fbda33  Handling bigquery dialect when previewing data (#5655)
0fbda33 is described below

commit 0fbda33c68762a690ab6a19a03e5b6046fbdeccf
Author: Sumedh Sakdeo <77...@users.noreply.github.com>
AuthorDate: Mon Aug 20 22:04:22 2018 -0700

    Handling bigquery dialect when previewing data (#5655)
    
    * Handling bigquery dialect when previewing data
    
    * review comments
    
    * lint
---
 superset/db_engine_specs.py | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index b4a0b3c..fe408ce 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -312,6 +312,10 @@ class BaseEngineSpec(object):
         return False
 
     @classmethod
+    def _get_fields(cls, cols):
+        return [sqla.column(c.get('name')) for c in cols]
+
+    @classmethod
     def select_star(cls, my_db, table_name, engine, schema=None, limit=100,
                     show_cols=False, indent=True, latest_partition=True,
                     cols=None):
@@ -321,7 +325,7 @@ class BaseEngineSpec(object):
             cols = my_db.get_columns(table_name, schema)
 
         if show_cols:
-            fields = [sqla.column(c.get('name')) for c in cols]
+            fields = cls._get_fields(cols)
         quote = engine.dialect.identifier_preparer.quote
         if schema:
             full_table_name = quote(schema) + '.' + quote(table_name)
@@ -1410,6 +1414,19 @@ class BQEngineSpec(BaseEngineSpec):
             data = [r.values() for r in data]
         return data
 
+    @classmethod
+    def _get_fields(cls, cols):
+        """
+        BigQuery dialect requires us to not use backtick in the fieldname which are
+        nested.
+        Using literal_column handles that issue.
+        http://docs.sqlalchemy.org/en/latest/core/tutorial.html#using-more-specific-text-with-table-literal-column-and-column
+        Also explicility specifying column names so we don't encounter duplicate
+        column names in the result.
+        """
+        return [sqla.literal_column(c.get('name')).label(c.get('name').replace('.', '__'))
+                for c in cols]
+
 
 class ImpalaEngineSpec(BaseEngineSpec):
     """Engine spec for Cloudera's Impala"""