Handling bigquery dialect when previewing data (#5655)
* Handling bigquery dialect when previewing data * review comments * lint
This commit is contained in:
parent
2d23ae1065
commit
0fbda33c68
|
|
@ -311,6 +311,10 @@ class BaseEngineSpec(object):
|
|||
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,
|
||||
|
|
@ -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"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue