Skip to content

Commit

Permalink
Add docstrings and typing to db_engine_specs and sql_parse (apache#8058)
Browse files Browse the repository at this point in the history
* Add typing to db_engine_specs

* Add more type annotations and docstrings

* Add docstrings and typing to sql_parse and db_engine_specs

* Refine select_star

* Fix execute and add more docstrings

* Revert kwargs change from execute

* Remove redundant or

* Align view and table getter schema types

* Fix return type of latest_partition

* Remove some typing from presto

* Improve docstring for __extract_from_token
  • Loading branch information
villebro authored Aug 22, 2019
1 parent 40776bd commit fb51632
Show file tree
Hide file tree
Showing 21 changed files with 496 additions and 194 deletions.
13 changes: 8 additions & 5 deletions superset/db_engine_specs/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=C,R,W
from datetime import datetime

from superset.db_engine_specs.base import BaseEngineSpec


Expand All @@ -38,7 +40,7 @@ class AthenaEngineSpec(BaseEngineSpec):
}

@classmethod
def convert_dttm(cls, target_type, dttm):
def convert_dttm(cls, target_type: str, dttm: datetime) -> str:
tt = target_type.upper()
if tt == "DATE":
return "from_iso8601_date('{}')".format(dttm.isoformat()[:10])
Expand All @@ -47,14 +49,15 @@ def convert_dttm(cls, target_type, dttm):
return "CAST ('{}' AS TIMESTAMP)".format(dttm.strftime("%Y-%m-%d %H:%M:%S"))

@classmethod
def epoch_to_dttm(cls):
def epoch_to_dttm(cls) -> str:
return "from_unixtime({col})"

@staticmethod
def mutate_label(label):
def _mutate_label(label: str) -> str:
"""
Athena only supports lowercase column names and aliases.
:param str label: Original label which might include uppercase letters
:return: String that is supported by the database
:param label: Expected expression label
:return: Conditionally mutated label
"""
return label.lower()
Loading

0 comments on commit fb51632

Please sign in to comment.