Skip to content

Commit

Permalink
Move more Presto nested types behind feature flag (apache#8075)
Browse files Browse the repository at this point in the history
* Move more stuff behind ff

* Fix unit tests

* Fix more tests

* Fix lint
  • Loading branch information
betodealmeida authored and Grace Guo committed Aug 20, 2019
1 parent d872511 commit aae9b56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions superset/db_engine_specs/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from typing import List, Set, Tuple
from urllib import parse

from sqlalchemy import Column, literal_column, types
from sqlalchemy import Column, literal_column
from sqlalchemy.engine.base import Engine
from sqlalchemy.engine.reflection import Inspector
from sqlalchemy.engine.result import RowProxy
Expand Down Expand Up @@ -231,7 +231,9 @@ def get_columns(
for column in columns:
try:
# parse column if it is a row or array
if "array" in column.Type or "row" in column.Type:
if is_feature_enabled("PRESTO_EXPAND_DATA") and (
"array" in column.Type or "row" in column.Type
):
structural_column_index = len(result)
cls._parse_structural_column(column.Column, column.Type, result)
result[structural_column_index]["nullable"] = getattr(
Expand All @@ -247,7 +249,7 @@ def get_columns(
column.Type, column.Column
)
)
column_type = types.NullType
column_type = "OTHER"
column_info = cls._create_column_info(column.Column, column_type)
column_info["nullable"] = getattr(column, "Null", True)
column_info["default"] = None
Expand Down Expand Up @@ -352,7 +354,7 @@ def select_star(
to an array's contents.
"""
presto_cols = cols
if show_cols:
if is_feature_enabled("PRESTO_EXPAND_DATA") and show_cols:
dot_regex = r"\.(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"
presto_cols = [
col for col in presto_cols if not re.search(dot_regex, col["name"])
Expand Down
18 changes: 18 additions & 0 deletions tests/db_engine_specs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,25 @@ def test_presto_get_column(self):
expected_results = [("column_name", "BOOLEAN")]
self.verify_presto_column(presto_column, expected_results)

@mock.patch.dict(
"superset._feature_flags", {"PRESTO_EXPAND_DATA": True}, clear=True
)
def test_presto_get_simple_row_column(self):
presto_column = ("column_name", "row(nested_obj double)", "")
expected_results = [("column_name", "ROW"), ("column_name.nested_obj", "FLOAT")]
self.verify_presto_column(presto_column, expected_results)

@mock.patch.dict(
"superset._feature_flags", {"PRESTO_EXPAND_DATA": True}, clear=True
)
def test_presto_get_simple_row_column_with_name_containing_whitespace(self):
presto_column = ("column name", "row(nested_obj double)", "")
expected_results = [("column name", "ROW"), ("column name.nested_obj", "FLOAT")]
self.verify_presto_column(presto_column, expected_results)

@mock.patch.dict(
"superset._feature_flags", {"PRESTO_EXPAND_DATA": True}, clear=True
)
def test_presto_get_simple_row_column_with_tricky_nested_field_name(self):
presto_column = ("column_name", 'row("Field Name(Tricky, Name)" double)', "")
expected_results = [
Expand All @@ -378,11 +387,17 @@ def test_presto_get_simple_row_column_with_tricky_nested_field_name(self):
]
self.verify_presto_column(presto_column, expected_results)

@mock.patch.dict(
"superset._feature_flags", {"PRESTO_EXPAND_DATA": True}, clear=True
)
def test_presto_get_simple_array_column(self):
presto_column = ("column_name", "array(double)", "")
expected_results = [("column_name", "ARRAY")]
self.verify_presto_column(presto_column, expected_results)

@mock.patch.dict(
"superset._feature_flags", {"PRESTO_EXPAND_DATA": True}, clear=True
)
def test_presto_get_row_within_array_within_row_column(self):
presto_column = (
"column_name",
Expand All @@ -397,6 +412,9 @@ def test_presto_get_row_within_array_within_row_column(self):
]
self.verify_presto_column(presto_column, expected_results)

@mock.patch.dict(
"superset._feature_flags", {"PRESTO_EXPAND_DATA": True}, clear=True
)
def test_presto_get_array_within_row_within_array_column(self):
presto_column = (
"column_name",
Expand Down

0 comments on commit aae9b56

Please sign in to comment.