mirror of https://github.com/apache/superset.git
Minor improvments
This commit is contained in:
parent
e1e298044e
commit
d419279d70
|
@ -265,8 +265,9 @@ class Table(Model, Queryable, AuditMixin):
|
||||||
try:
|
try:
|
||||||
table = self.database.get_table(self.table_name)
|
table = self.database.get_table(self.table_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
flash(str(e))
|
||||||
flash(
|
flash(
|
||||||
"Table doesn't see to exist in the specified database, "
|
"Table doesn't seem to exist in the specified database, "
|
||||||
"couldn't fetch column information", "danger")
|
"couldn't fetch column information", "danger")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -275,6 +276,10 @@ class Table(Model, Queryable, AuditMixin):
|
||||||
metrics = []
|
metrics = []
|
||||||
any_date_col = None
|
any_date_col = None
|
||||||
for col in table.columns:
|
for col in table.columns:
|
||||||
|
try:
|
||||||
|
datatype = str(col.type)
|
||||||
|
except Exception as e:
|
||||||
|
datatype = "UNKNOWN"
|
||||||
dbcol = (
|
dbcol = (
|
||||||
db.session
|
db.session
|
||||||
.query(TC)
|
.query(TC)
|
||||||
|
@ -285,15 +290,16 @@ class Table(Model, Queryable, AuditMixin):
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
if not dbcol:
|
if not dbcol:
|
||||||
dbcol = TableColumn(column_name=col.name)
|
dbcol = TableColumn(column_name=col.name)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
str(col.type).startswith('VARCHAR') or
|
str(datatype).startswith('VARCHAR') or
|
||||||
str(col.type).startswith('STRING')):
|
str(datatype).startswith('STRING')):
|
||||||
dbcol.groupby = True
|
dbcol.groupby = True
|
||||||
dbcol.filterable = True
|
dbcol.filterable = True
|
||||||
db.session.merge(self)
|
db.session.merge(self)
|
||||||
self.columns.append(dbcol)
|
self.columns.append(dbcol)
|
||||||
|
|
||||||
if not any_date_col and 'date' in str(col.type).lower():
|
if not any_date_col and 'date' in datatype.lower():
|
||||||
any_date_col = dbcol
|
any_date_col = dbcol
|
||||||
|
|
||||||
if dbcol.sum:
|
if dbcol.sum:
|
||||||
|
@ -324,7 +330,7 @@ class Table(Model, Queryable, AuditMixin):
|
||||||
metric_type='count_distinct',
|
metric_type='count_distinct',
|
||||||
expression="COUNT(DISTINCT {})".format(dbcol.column_name)
|
expression="COUNT(DISTINCT {})".format(dbcol.column_name)
|
||||||
))
|
))
|
||||||
dbcol.type = str(col.type)
|
dbcol.type = datatype
|
||||||
db.session.merge(self)
|
db.session.merge(self)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -509,13 +515,14 @@ class Datasource(Model, AuditMixin, Queryable):
|
||||||
#session.commit()
|
#session.commit()
|
||||||
|
|
||||||
def query(
|
def query(
|
||||||
self, groupby, metrics,
|
self, groupby, metrics,
|
||||||
granularity,
|
granularity,
|
||||||
from_dttm, to_dttm,
|
from_dttm, to_dttm,
|
||||||
limit_spec=None,
|
limit_spec=None,
|
||||||
filter=None,
|
filter=None,
|
||||||
is_timeseries=True,
|
is_timeseries=True,
|
||||||
timeseries_limit=15, row_limit=None):
|
timeseries_limit=None,
|
||||||
|
row_limit=None):
|
||||||
qry_start_dttm = datetime.now()
|
qry_start_dttm = datetime.now()
|
||||||
|
|
||||||
query_str = ""
|
query_str = ""
|
||||||
|
@ -565,7 +572,7 @@ class Datasource(Model, AuditMixin, Queryable):
|
||||||
|
|
||||||
client = self.cluster.get_pydruid_client()
|
client = self.cluster.get_pydruid_client()
|
||||||
orig_filters = filters
|
orig_filters = filters
|
||||||
if timeseries_limit:
|
if timeseries_limit and is_timeseries:
|
||||||
# Limit on the number of timeseries, doing a two-phases query
|
# Limit on the number of timeseries, doing a two-phases query
|
||||||
pre_qry = deepcopy(qry)
|
pre_qry = deepcopy(qry)
|
||||||
pre_qry['granularity'] = "all"
|
pre_qry['granularity'] = "all"
|
||||||
|
@ -605,7 +612,15 @@ class Datasource(Model, AuditMixin, Queryable):
|
||||||
Filter.build_filter(ff),
|
Filter.build_filter(ff),
|
||||||
Filter.build_filter(orig_filters)])
|
Filter.build_filter(orig_filters)])
|
||||||
qry['limit_spec'] = None
|
qry['limit_spec'] = None
|
||||||
|
if row_limit:
|
||||||
|
qry['limit_spec'] = {
|
||||||
|
"type": "default",
|
||||||
|
"limit": row_limit,
|
||||||
|
"columns": [{
|
||||||
|
"dimension": metrics[0] if metrics else self.metrics[0],
|
||||||
|
"direction": "descending",
|
||||||
|
}],
|
||||||
|
}
|
||||||
client.groupby(**qry)
|
client.groupby(**qry)
|
||||||
query_str += json.dumps(client.query_dict, indent=2)
|
query_str += json.dumps(client.query_dict, indent=2)
|
||||||
df = client.export_pandas()
|
df = client.export_pandas()
|
||||||
|
|
|
@ -93,7 +93,7 @@ form input.form-control {
|
||||||
<h3>{{ viz.verbose_name }}
|
<h3>{{ viz.verbose_name }}
|
||||||
{% if results %}
|
{% if results %}
|
||||||
<span class="label label-success">
|
<span class="label label-success">
|
||||||
{{ "{0:0.2f}".format(results.duration.total_seconds()) }} s
|
{{ "{0:0.4f}".format(results.duration.total_seconds()) }} s
|
||||||
</span>
|
</span>
|
||||||
<span class="label label-info btn"
|
<span class="label label-info btn"
|
||||||
data-toggle="modal" data-target="#query_modal">query</span>
|
data-toggle="modal" data-target="#query_modal">query</span>
|
||||||
|
|
10
app/viz.py
10
app/viz.py
|
@ -120,8 +120,7 @@ class BaseViz(object):
|
||||||
if granularity != "all":
|
if granularity != "all":
|
||||||
granularity = utils.parse_human_timedelta(
|
granularity = utils.parse_human_timedelta(
|
||||||
granularity).total_seconds() * 1000
|
granularity).total_seconds() * 1000
|
||||||
limit = int(
|
limit = int(args.get("limit", 0))
|
||||||
args.get("limit", config.ROW_LIMIT))
|
|
||||||
row_limit = int(
|
row_limit = int(
|
||||||
args.get("row_limit", config.ROW_LIMIT))
|
args.get("row_limit", config.ROW_LIMIT))
|
||||||
since = args.get("since", "1 year ago")
|
since = args.get("since", "1 year ago")
|
||||||
|
@ -137,6 +136,7 @@ class BaseViz(object):
|
||||||
'granularity': granularity,
|
'granularity': granularity,
|
||||||
'from_dttm': from_dttm,
|
'from_dttm': from_dttm,
|
||||||
'to_dttm': to_dttm,
|
'to_dttm': to_dttm,
|
||||||
|
'is_timeseries': True,
|
||||||
'groupby': groupby,
|
'groupby': groupby,
|
||||||
'metrics': metrics,
|
'metrics': metrics,
|
||||||
'row_limit': row_limit,
|
'row_limit': row_limit,
|
||||||
|
@ -161,6 +161,12 @@ class TableViz(BaseViz):
|
||||||
verbose_name = "Table View"
|
verbose_name = "Table View"
|
||||||
template = 'panoramix/viz_table.html'
|
template = 'panoramix/viz_table.html'
|
||||||
|
|
||||||
|
def query_obj(self):
|
||||||
|
d = super(TableViz, self).query_obj()
|
||||||
|
d['is_timeseries'] = False
|
||||||
|
d['timeseries_limit'] = None
|
||||||
|
return d
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
if self.error_msg:
|
if self.error_msg:
|
||||||
return super(TableViz, self).render(error_msg=self.error_msg)
|
return super(TableViz, self).render(error_msg=self.error_msg)
|
||||||
|
|
Loading…
Reference in New Issue