Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: blankstate metrics columns #20755

Merged
merged 106 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
6fc435d
add POC ExploreMixin
hughhhh Jun 6, 2022
632ce21
Working POC
hughhhh Jun 6, 2022
6f22618
Created/tested query dataset dropdown
lyndsiWilliams Jun 7, 2022
236c489
Add isValidDatasourceType to @superset-ui/core and hide query dropdown
lyndsiWilliams Jun 8, 2022
24261d1
fix merge conflicts
hughhhh Jun 8, 2022
bd3b6a9
Visual updates to explore datasource panel
lyndsiWilliams Jun 8, 2022
64f4181
Temporarily make Query icon visible
lyndsiWilliams Jun 8, 2022
7c07534
Remove Query icon visibility
lyndsiWilliams Jun 8, 2022
6fab57f
Removed isValidDatasourceType check
lyndsiWilliams Jun 8, 2022
3a46152
Added Query preview Modal from DatasourceControl if the data source t…
eric-briscoe Jun 8, 2022
613d78a
> fix integration point with frontend
hughhhh Jun 8, 2022
e076f13
Merge branch 'master' of https://github.com/preset-io/superset into c…
hughhhh Jun 13, 2022
31dfdd2
Adjusts conditional logic approach to be extensible for additional ty…
eric-briscoe Jun 13, 2022
bbb91e0
Merge branch 'chart-power-query' into lyndsi/dataset-panel-updates
eric-briscoe Jun 13, 2022
8513cc5
Merge branch 'lyndsi/dataset-panel-updates' into ericbriscoe/sc-41493…
eric-briscoe Jun 13, 2022
cd54603
refactor
hughhhh Jun 14, 2022
a173cfa
Merge branch 'master' of https://github.com/preset-io/superset into c…
hughhhh Jun 15, 2022
0295818
Merge pull request #218 from preset-io/ericbriscoe/sc-41493/query-pre…
eric-briscoe Jun 15, 2022
de20276
set field for sql
hughhhh Jun 15, 2022
bd7db0d
Fixes issue where Missing query parameters error was showing in datas…
eric-briscoe Jun 16, 2022
e344197
add query_language
hughhhh Jun 16, 2022
9c5bc48
fix ds main_dttm
hughhhh Jun 17, 2022
b6fbc33
Fixes issue where menu.tsx was blocking access to redux debugging for…
eric-briscoe Jun 17, 2022
6af2961
Fixes issue where database id was not available to save query as data…
eric-briscoe Jun 17, 2022
12546f5
Merge branch 'master' into chart-power-query
eric-briscoe Jun 17, 2022
ff59846
Merge branch 'master' into chart-power-query
hughhhh Jun 21, 2022
bdbf2d1
oops
hughhhh Jun 21, 2022
559e1a2
fix pre-commit to 50 errors now
hughhhh Jun 21, 2022
890be43
fix circuliar dep
hughhhh Jun 21, 2022
4b833be
Disables showing Metrics section in DatasourcePanel when Query is the…
eric-briscoe Jun 21, 2022
4254b7e
adds condition to use query.columns if query.results is not present e…
eric-briscoe Jun 22, 2022
4710b3d
down to 26 now
hughhhh Jun 22, 2022
017bde6
patch for pre-commit
hughhhh Jun 24, 2022
075c5d8
one more pre-commit
hughhhh Jun 24, 2022
d73504c
added explore_json error
AAfghahi Jun 24, 2022
74ae38c
added error messages
AAfghahi Jun 24, 2022
ea49535
add for metrics
pkdotson Jun 27, 2022
3f5bea4
add text for columns
pkdotson Jun 27, 2022
07ee508
add model open/close method
pkdotson Jun 27, 2022
3ab4526
add propogation and methods
pkdotson Jun 28, 2022
d5d8aaa
change link to span
pkdotson Jun 28, 2022
91cd5c4
lint fix
pkdotson Jun 28, 2022
97ee4eb
Fixes frontend lint and TypeScript errors unit test fixes will be nex…
eric-briscoe Jun 28, 2022
276bc28
Aditional TypeScript error fix
eric-briscoe Jun 28, 2022
a8ff273
Fixes unit test failure
eric-briscoe Jun 28, 2022
ddf2c8d
fix some types
pkdotson Jun 28, 2022
044945b
added frontend piece
AAfghahi Jun 28, 2022
a9fb857
fix type
pkdotson Jun 28, 2022
8d8a868
Merge branch master
eric-briscoe Jun 28, 2022
7ace7a4
Fixes bad import caused by merge from master and removes duplicate sh…
eric-briscoe Jun 28, 2022
e436582
Fixes for DartasourceControl Test Suite
eric-briscoe Jun 28, 2022
76c3505
Fix lint error
eric-briscoe Jun 28, 2022
3370439
Fixes unit test issues due to array instead of a component being pass…
eric-briscoe Jun 29, 2022
d1866e8
merged main branch
AAfghahi Jun 29, 2022
18b6fa1
Merge pull request #223 from preset-io/arash/error_messages
AAfghahi Jun 29, 2022
a7ded35
Fixes unit test failure for DatasourceControl and simplifies getDatas…
eric-briscoe Jun 30, 2022
c65c225
Merge branch 'master' into chart-power-query
eric-briscoe Jun 30, 2022
54e4023
fix ts
pkdotson Jun 30, 2022
232d6dc
pylint
AAfghahi Jun 29, 2022
aa2756e
core_test fix
AAfghahi Jul 5, 2022
ebdfcf0
Merge pull request #225 from preset-io/arash/pylint_errors
hughhhh Jul 5, 2022
a52acd9
Merge branch 'master' into chart-power-query
eric-briscoe Jul 5, 2022
3653e40
Fixes line error post merge from master
eric-briscoe Jul 5, 2022
c0ab26b
merge master
hughhhh Jul 6, 2022
655fddf
fixed from master
hughhhh Jul 6, 2022
f752655
fixed from master
hughhhh Jul 6, 2022
c478add
Merge branch 'chart-power-query' of ssh://github.com/preset-io/supers…
eric-briscoe Jul 6, 2022
5e32c24
Fixes issue where Overwrite dataset does not work due to userid error
eric-briscoe Jul 6, 2022
6707808
Resolves TypeScript errors with changes made for SPA merging in and c…
eric-briscoe Jul 6, 2022
b28d79c
fix: top right panel view query functionality
hughhhh Jul 7, 2022
c619618
Merge branch 'master' of https://github.com/preset-io/superset into c…
hughhhh Jul 7, 2022
fa85488
remove unneeded code from core.py
hughhhh Jul 7, 2022
a09d781
working samples endpoint for query
hughhhh Jul 7, 2022
076e4fd
add owner check
hughhhh Jul 8, 2022
c5ca22d
update FE for it
hughhhh Jul 8, 2022
a35038d
handle columns are dict vs object
hughhhh Jul 8, 2022
661bb9e
fix exceptions
hughhhh Jul 8, 2022
b476b70
fix fe lint
hughhhh Jul 8, 2022
56fcdc9
fix test
hughhhh Jul 8, 2022
551ddc8
Merge pull request #233 from preset-io/chart-power-query-samples
hughhhh Jul 8, 2022
6e5443a
add tab_name to payload
hughhhh Jul 8, 2022
97ac731
Enables use of tab name from Query
eric-briscoe Jul 8, 2022
664773a
fix merge conflicts
hughhhh Jul 11, 2022
a073313
fix cypress test
hughhhh Jul 11, 2022
f717e18
save columns on execution
hughhhh Jul 11, 2022
16ea687
fix frontend build test
hughhhh Jul 11, 2022
3f6fa0a
remove parathesis around columns
hughhhh Jul 11, 2022
88a51b4
changing column types
AAfghahi Jul 11, 2022
a105ca6
fixing samples that has literal_columns
AAfghahi Jul 11, 2022
9e09af2
address comments
hughhhh Jul 11, 2022
69777d3
add changes
pkdotson Jul 12, 2022
6334e21
Merge branch 'chart-power-query' of https://github.com/preset-io/supe…
pkdotson Jul 12, 2022
8394881
fix path
pkdotson Jul 14, 2022
996f8d3
Merge branch 'master' of https://github.com/preset-io/superset into f…
pkdotson Jul 18, 2022
e9aaa1f
fix merge
pkdotson Jul 18, 2022
3db3d10
fix types
pkdotson Jul 19, 2022
0cf7000
remove console
pkdotson Jul 19, 2022
85177aa
add type
pkdotson Jul 21, 2022
79836f0
fix linting
hughhhh Jul 24, 2022
6073777
update to enum
hughhhh Jul 24, 2022
dc74d2b
Merge branch 'master' of https://github.com/preset-io/superset into f…
hughhhh Jul 25, 2022
bee3795
fix test
hughhhh Jul 25, 2022
b626843
remove explore from buttons
hughhhh Jul 26, 2022
9aac370
fix logic
hughhhh Jul 26, 2022
c0853cf
fix logic
hughhhh Jul 26, 2022
69009be
oops
hughhhh Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
hughhhh authored Jun 14, 2022
commit cd54603a143644e405a8039dada31b53f069cc10
56 changes: 31 additions & 25 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@
get_template_processor,
)
from superset.sql_parse import (
has_table_query,
extract_table_references,
has_table_query,
ParsedQuery,
sanitize_clause,
Table as TableName,
)

from superset.utils import core as utils

VIRTUAL_TABLE_ALIAS = "virtual_table"
Expand Down Expand Up @@ -587,9 +586,15 @@ def clone_model(
from sqlalchemy.sql.elements import ColumnElement, Label, literal_column

from superset.exceptions import QueryObjectValidationError
from superset.superset_typing import AdhocMetric, Metric, OrderBy, QueryObjectDict
from superset.superset_typing import (
AdhocMetric,
FilterValue,
FilterValues,
Metric,
OrderBy,
QueryObjectDict,
)
from superset.utils import core as utils
from superset.superset_typing import FilterValue, FilterValues, QueryObjectDict


# todo(hugh): centralize where this code lives
Expand Down Expand Up @@ -624,10 +629,6 @@ class ExploreMixin:
"MAX": sa.func.MAX,
}

@property
def data(self):
return {"foo": "bar"}

@property
def owners_data(self):
return []
Expand All @@ -650,7 +651,7 @@ def cache_timeout(self):

@property
def column_names(self):
return [col.get('column_name') for col in self.columns]
return [col.get("column_name") for col in self.columns]

@property
def offset(self):
Expand Down Expand Up @@ -688,7 +689,7 @@ def make_sqla_column_compatible(
sqla_col = sqla_col.label(label)
sqla_col.key = label_expected
return sqla_col

def mutate_query_from_config(self, sql: str) -> str:
"""Apply config's SQL_QUERY_MUTATOR

Expand Down Expand Up @@ -802,7 +803,7 @@ def exc_query(self, qry: Any) -> QueryResult:
query_str_ext = self.get_query_str_extended(qry)
sql = query_str_ext.sql

print('*****' * 5)
print("*****" * 5)

# sql = "select count(*) from flights"
status = QueryStatus.SUCCESS
Expand Down Expand Up @@ -973,7 +974,9 @@ def filter_values_handler( # pylint: disable=too-many-arguments
target_generic_type: utils.GenericDataType,
target_native_type: Optional[str] = None,
is_list_target: bool = False,
db_engine_spec: Optional[Type["BaseEngineSpec"]] = None, # fix(hughhh): Optional[Type[BaseEngineSpec]]
db_engine_spec: Optional[
Type["BaseEngineSpec"]
] = None, # fix(hughhh): Optional[Type[BaseEngineSpec]]
db_extra: Optional[Dict[str, Any]] = None,
) -> Optional[FilterValues]:
if values is None:
Expand Down Expand Up @@ -1061,7 +1064,9 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
"time_column": granularity,
"time_grain": time_grain,
"to_dttm": to_dttm.isoformat() if to_dttm else None,
"table_columns": [col.get('column_name') for col in self.columns], # [col.column_name for col in self.columns],
"table_columns": [
col.get("column_name") for col in self.columns
], # [col.column_name for col in self.columns],
"filter": filter,
}
columns = columns or []
Expand All @@ -1078,7 +1083,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
applied_template_filters: List[str] = []
template_kwargs["removed_filters"] = removed_filters
template_kwargs["applied_filters"] = applied_template_filters
template_processor = None # self.get_template_processor(**template_kwargs)
template_processor = None # self.get_template_processor(**template_kwargs)
db_engine_spec = self.db_engine_spec
prequeries: List[str] = []
orderby = orderby or []
Expand All @@ -1090,7 +1095,8 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
granularity = self.main_dttm_col

columns_by_name: Dict[str, TableColumn] = {
col.get('column_name'): col for col in self.columns # col.column_name: col for col in self.columns
col.get("column_name"): col
for col in self.columns # col.column_name: col for col in self.columns
}

metrics_by_name: Dict[str, SqlMetric] = {m.metric_name: m for m in self.metrics}
Expand Down Expand Up @@ -1184,7 +1190,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
# dedup columns while preserving order
columns = groupby or columns
for selected in columns:
if isinstance(selected, str):
if isinstance(selected, str):
# if groupby field/expr equals granularity field/expr
if selected == granularity:
table_col = columns_by_name[selected]
Expand Down Expand Up @@ -1224,9 +1230,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
self.schema,
)
if isinstance(columns_by_name[selected], dict):
select_exprs.append(
literal_column(f"({selected})")
)
select_exprs.append(literal_column(f"({selected})"))
else:
select_exprs.append(
columns_by_name[selected].get_sqla_col()
Expand Down Expand Up @@ -1258,7 +1262,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
db_engine_spec.time_secondary_columns
and self.main_dttm_col in self.dttm_cols
and self.main_dttm_col != dttm_col.column_name
):
):
pass
# todo(hughhh): fix time filter
# time_filters.append(
Expand Down Expand Up @@ -1323,12 +1327,12 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
time_grain=filter_grain, template_processor=template_processor
)
elif col_obj and isinstance(col_obj, dict):
sqla_col = sa.column(col_obj.get('column_name'))
sqla_col = sa.column(col_obj.get("column_name"))
elif col_obj:
sqla_col = col_obj.get_sqla_col()

if col_obj and isinstance(col_obj, dict):
col_type = col_obj.get('type')
col_type = col_obj.get("type")
else:
col_type = col_obj.type if col_obj else None
col_spec = db_engine_spec.get_column_spec(
Expand All @@ -1343,7 +1347,9 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
if col_obj and isinstance(col_obj, dict):
col_advanced_data_type = ""
else:
col_advanced_data_type = col_obj.advanced_data_type if col_obj else ""
col_advanced_data_type = (
col_obj.advanced_data_type if col_obj else ""
)

if col_spec and not col_advanced_data_type:
target_generic_type = col_spec.generic_type
Expand Down Expand Up @@ -1438,7 +1444,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
raise QueryObjectValidationError(
_("Invalid filter operation type: %(op)s", op=op)
)
# todo(hugh): fix this
# todo(hugh): fix this
# where_clause_and += self.get_sqla_row_level_filters(template_processor)
if extras:
where = extras.get("where")
Expand Down
21 changes: 17 additions & 4 deletions superset/models/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
from superset.models.tags import QueryUpdater
from superset.sql_parse import CtasMethod, ParsedQuery, Table
from superset.sqllab.limiting_factor import LimitingFactor
from superset.superset_typing import ResultSetColumnType
from superset.utils.core import QueryStatus, user_label

from superset.superset_typing import ResultSetColumnType

class Query(Model, ExtraJSONMixin, ExploreMixin):
"""ORM model for SQL query
Expand Down Expand Up @@ -173,6 +173,7 @@ def sql_tables(self) -> List[Table]:
def columns(self) -> List[ResultSetColumnType]:
# todo(hughhh): move this logic into a base class
from superset.utils.core import GenericDataType

bool_types = ("BOOL",)
num_types = (
"DOUBLE",
Expand All @@ -188,10 +189,10 @@ def columns(self) -> List[ResultSetColumnType]:
)
date_types = ("DATE", "TIME")
str_types = ("VARCHAR", "STRING", "CHAR")
columns = []
columns = []
for col in self.extra.get("columns", []):
computed_column = {**col}
col_type = col.get('type')
col_type = col.get("type")

if col_type and any(map(lambda t: t in col_type.upper(), str_types)):
computed_column["type_generic"] = GenericDataType.STRING
Expand All @@ -202,11 +203,23 @@ def columns(self) -> List[ResultSetColumnType]:
if col_type and any(map(lambda t: t in col_type.upper(), date_types)):
computed_column["type_generic"] = GenericDataType.TEMPORAL

computed_column["column_name"] = col.get('name')
computed_column["column_name"] = col.get("name")
computed_column["groupby"] = True
columns.append(computed_column)
return columns

@property
def data(self) -> Dict[str, Any]:
return {
"columns": self.columns,
"metrics": [],
"id": self.id,
"type": self.type,
"name": self.sql,
"owners": self.owners_data,
"database": {"id": self.database_id, "backend": self.database.backend},
}

def raise_for_access(self) -> None:
"""
Raise an exception if the user cannot access the resource.
Expand Down
17 changes: 2 additions & 15 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ def explore(
# Handle SIP-68 Models or explore view
# API will always use /explore/<datasource_type>/<int:datasource_id>/ to query
# new models to power any viz in explore
datasource_id = request.args.get('datasource_id', datasource_id)
datasource_type = request.args.get('datasource_type', datasource_type)
datasource_id = request.args.get("datasource_id", datasource_id)
datasource_type = request.args.get("datasource_type", datasource_type)

if datasource_id and datasource_type:
# 1. Query datasource object by type and id
Expand Down Expand Up @@ -869,19 +869,6 @@ def explore(
except (SupersetException, SQLAlchemyError):
datasource_data = dummy_datasource_data

columns: List[Dict[str, Any]] = []
if datasource:
datasource_data["owners"] = datasource.owners_data
if isinstance(datasource, Query):
# todo(hughhh): set is_dttm + name -> column_name
# datasource_data["data"] = datasource.data
# move all this logic into the class for the property data
datasource_data["columns"] = datasource.columns
datasource_data["metrics"] = datasource.extra.get("metrics", [])
datasource_data["id"] = datasource_id
datasource_data["type"] = datasource_type
datasource_data["name"] = datasource.sql

bootstrap_data = {
"can_add": slice_add_perm,
"can_download": slice_download_perm,
Expand Down