Add feature flag for Presto expand data (#8056)

* Add feature flag for Presto expand data

* Fix unit tests

* Fix black

* Revert temporary file change
This commit is contained in:
Beto Dealmeida 2019-08-15 20:10:05 -07:00 committed by GitHub
parent ef1d4a6aa1
commit 478d0969a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 1 deletions

View File

@ -1185,7 +1185,8 @@ You can enable or disable features with flag from ``superset_config.py``:
DEFAULT_FEATURE_FLAGS = {
'CLIENT_CACHE': False,
'ENABLE_EXPLORE_JSON_CSRF_PROTECTION': False
'ENABLE_EXPLORE_JSON_CSRF_PROTECTION': False,
'PRESTO_EXPAND_DATA': False,
}
Here is a list of flags and descriptions:
@ -1195,3 +1196,7 @@ Here is a list of flags and descriptions:
* For some security concerns, you may need to enforce CSRF protection on all query request to explore_json endpoint. In Superset, we use `flask-csrf <https://sjl.bitbucket.io/flask-csrf/>`_ add csrf protection for all POST requests, but this protection doesn't apply to GET method.
* When ENABLE_EXPLORE_JSON_CSRF_PROTECTION is set to true, your users cannot make GET request to explore_json. The default value for this feature False (current behavior), explore_json accepts both GET and POST request. See `PR 7935 <https://github.com/apache/incubator-superset/pull/7935>`_ for more details.
* PRESTO_EXPAND_DATA
* When this feature is enabled, nested types in Presto will be expanded into extra columns and/or arrays. This is experimental, and doesn't work with all nested types.

View File

@ -208,6 +208,7 @@ DEFAULT_FEATURE_FLAGS = {
# Experimental feature introducing a client (browser) cache
"CLIENT_CACHE": False,
"ENABLE_EXPLORE_JSON_CSRF_PROTECTION": False,
"PRESTO_EXPAND_DATA": False,
}
# A function that receives a dict of all feature flags

View File

@ -30,6 +30,7 @@ from sqlalchemy.engine.reflection import Inspector
from sqlalchemy.engine.result import RowProxy
from sqlalchemy.sql.expression import ColumnClause
from superset import is_feature_enabled
from superset.db_engine_specs.base import BaseEngineSpec
from superset.exceptions import SupersetTemplateException
from superset.models.sql_types.presto_sql_types import type_map as presto_type_map
@ -749,6 +750,9 @@ class PrestoEngineSpec(BaseEngineSpec):
:return: list of all columns(selected columns and their nested fields),
expanded data set, listed of nested fields
"""
if not is_feature_enabled("PRESTO_EXPAND_DATA"):
return columns, data, []
all_columns: List[dict] = []
# Get the list of all columns (selected fields and their nested fields)
for column in columns:

View File

@ -614,6 +614,9 @@ class DbEngineSpecsTestCase(SupersetTestCase):
}
self.assertEqual(array_col_hierarchy, expected_array_col_hierarchy)
@mock.patch.dict(
"superset._feature_flags", {"PRESTO_EXPAND_DATA": True}, clear=True
)
def test_presto_expand_data_with_simple_structural_columns(self):
cols = [
{"name": "row_column", "type": "ROW(NESTED_OBJ VARCHAR)"},
@ -644,6 +647,9 @@ class DbEngineSpecsTestCase(SupersetTestCase):
self.assertEqual(actual_data, expected_data)
self.assertEqual(actual_expanded_cols, expected_expanded_cols)
@mock.patch.dict(
"superset._feature_flags", {"PRESTO_EXPAND_DATA": True}, clear=True
)
def test_presto_expand_data_with_complex_row_columns(self):
cols = [
{
@ -684,6 +690,9 @@ class DbEngineSpecsTestCase(SupersetTestCase):
self.assertEqual(actual_data, expected_data)
self.assertEqual(actual_expanded_cols, expected_expanded_cols)
@mock.patch.dict(
"superset._feature_flags", {"PRESTO_EXPAND_DATA": True}, clear=True
)
def test_presto_expand_data_with_complex_array_columns(self):
cols = [
{"name": "int_column", "type": "BIGINT"},