mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
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:
@@ -15,9 +15,12 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# pylint: disable=C,R,W
|
||||
from datetime import datetime
|
||||
import re
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from sqlalchemy.types import String, UnicodeText
|
||||
from sqlalchemy.engine.interfaces import Dialect
|
||||
from sqlalchemy.types import String, TypeEngine, UnicodeText
|
||||
|
||||
from superset.db_engine_specs.base import BaseEngineSpec, LimitMethod
|
||||
|
||||
@@ -45,12 +48,12 @@ class MssqlEngineSpec(BaseEngineSpec):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def convert_dttm(cls, target_type, dttm):
|
||||
def convert_dttm(cls, target_type: str, dttm: datetime) -> str:
|
||||
return "CONVERT(DATETIME, '{}', 126)".format(dttm.isoformat())
|
||||
|
||||
@classmethod
|
||||
def fetch_data(cls, cursor, limit):
|
||||
data = super(MssqlEngineSpec, cls).fetch_data(cursor, limit)
|
||||
def fetch_data(cls, cursor, limit: int) -> List[Tuple]:
|
||||
data = super().fetch_data(cursor, limit)
|
||||
if data and type(data[0]).__name__ == "Row":
|
||||
data = [[elem for elem in r] for r in data]
|
||||
return data
|
||||
@@ -61,14 +64,16 @@ class MssqlEngineSpec(BaseEngineSpec):
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def get_sqla_column_type(cls, type_):
|
||||
def get_sqla_column_type(cls, type_: str) -> Optional[TypeEngine]:
|
||||
for sqla_type, regex in cls.column_types:
|
||||
if regex.match(type_):
|
||||
return sqla_type
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def column_datatype_to_string(cls, sqla_column_type, dialect):
|
||||
def column_datatype_to_string(
|
||||
cls, sqla_column_type: TypeEngine, dialect: Dialect
|
||||
) -> str:
|
||||
datatype = super().column_datatype_to_string(sqla_column_type, dialect)
|
||||
# MSSQL returns long overflowing datatype
|
||||
# as in 'VARCHAR(255) COLLATE SQL_LATIN1_GENERAL_CP1_CI_AS'
|
||||
|
||||
Reference in New Issue
Block a user