Add docstrings and typing to db_engine_specs and sql_parse (#8058)

* 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
This commit is contained in:
Ville Brofeldt
2019-08-22 06:29:32 +03:00
committed by GitHub
parent 40776bd547
commit fb51632e18
21 changed files with 496 additions and 194 deletions

View File

@@ -15,6 +15,11 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=C,R,W
from datetime import datetime
from typing import List, Optional, Tuple
from sqlalchemy.dialects.postgresql.base import PGInspector
from superset.db_engine_specs.base import BaseEngineSpec, LimitMethod
@@ -36,7 +41,7 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
}
@classmethod
def fetch_data(cls, cursor, limit):
def fetch_data(cls, cursor, limit: int) -> List[Tuple]:
if not cursor.description:
return []
if cls.limit_method == LimitMethod.FETCH_MANY:
@@ -44,11 +49,11 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
return cursor.fetchall()
@classmethod
def epoch_to_dttm(cls):
def epoch_to_dttm(cls) -> str:
return "(timestamp 'epoch' + {col} * interval '1 second')"
@classmethod
def convert_dttm(cls, target_type, dttm):
def convert_dttm(cls, target_type: str, dttm: datetime) -> str:
return "'{}'".format(dttm.strftime("%Y-%m-%d %H:%M:%S"))
@@ -58,7 +63,9 @@ class PostgresEngineSpec(PostgresBaseEngineSpec):
try_remove_schema_from_table_name = False
@classmethod
def get_table_names(cls, inspector, schema):
def get_table_names(
cls, inspector: PGInspector, schema: Optional[str]
) -> List[str]:
"""Need to consider foreign tables for PostgreSQL"""
tables = inspector.get_table_names(schema)
tables.extend(inspector.get_foreign_table_names(schema))