Skip to content

Commit

Permalink
Handling bigquery dialect when previewing data (apache#5655)
Browse files Browse the repository at this point in the history
* Handling bigquery dialect when previewing data

* review comments

* lint
  • Loading branch information
sumedhsakdeo authored and mistercrunch committed Aug 21, 2018
1 parent 32759b2 commit d0fa279
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ def where_latest_partition(
cls, table_name, schema, database, qry, columns=None):
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,
Expand All @@ -321,7 +325,7 @@ def select_star(cls, my_db, table_name, engine, schema=None, limit=100,
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)
Expand Down Expand Up @@ -1410,6 +1414,19 @@ def fetch_data(cls, cursor, limit):
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"""
Expand Down

0 comments on commit d0fa279

Please sign in to comment.