mirror of
https://github.com/apache/superset.git
synced 2024-09-06 22:07:34 -04:00
fix: enable several pylint rules partially in db_engines_specs module (#11000)
* Enabled mssql * Enabling pylint rules in `mysql.py` from `db_engine_specs`: - added variable to shorten line and enable `line-too-long` - `import-error` seems not prompting anymore - specified exception instead broad-except * Refactored too long line in `oracle.py` from `db_engine_specs`. Enabled too-long-line pylint rule. * Changed fstring into string `pinot.py` to reenable `f-string-without-interpolation` rule. * Enabled `unused-import` rule and changed line to adjust to correct number of characters in `db_engine_specs/postgres.py`. * Enabled unused-import pylint check in `db_engine_specs/presto.py` * Enabled unused-import pylint check in `db_engine_specs/snowflake.py` * Enabled unused-import pylint check in `db_engine_specs/sqlite.py`
This commit is contained in:
parent
fb6f14c469
commit
af1e8e8839
@ -25,7 +25,7 @@ from superset.db_engine_specs.base import BaseEngineSpec, LimitMethod
|
|||||||
from superset.utils import core as utils
|
from superset.utils import core as utils
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from superset.models.core import Database # pylint: disable=unused-import
|
from superset.models.core import Database
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -62,9 +62,11 @@ class MssqlEngineSpec(BaseEngineSpec):
|
|||||||
if tt == utils.TemporalType.DATE:
|
if tt == utils.TemporalType.DATE:
|
||||||
return f"CONVERT(DATE, '{dttm.date().isoformat()}', 23)"
|
return f"CONVERT(DATE, '{dttm.date().isoformat()}', 23)"
|
||||||
if tt == utils.TemporalType.DATETIME:
|
if tt == utils.TemporalType.DATETIME:
|
||||||
return f"""CONVERT(DATETIME, '{dttm.isoformat(timespec="milliseconds")}', 126)""" # pylint: disable=line-too-long
|
datetime_formatted = dttm.isoformat(timespec="milliseconds")
|
||||||
|
return f"""CONVERT(DATETIME, '{datetime_formatted}', 126)"""
|
||||||
if tt == utils.TemporalType.SMALLDATETIME:
|
if tt == utils.TemporalType.SMALLDATETIME:
|
||||||
return f"""CONVERT(SMALLDATETIME, '{dttm.isoformat(sep=" ", timespec="seconds")}', 20)""" # pylint: disable=line-too-long
|
datetime_formatted = dttm.isoformat(sep=" ", timespec="seconds")
|
||||||
|
return f"""CONVERT(SMALLDATETIME, '{datetime_formatted}', 20)"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -56,7 +56,8 @@ class MySQLEngineSpec(BaseEngineSpec):
|
|||||||
if tt == utils.TemporalType.DATE:
|
if tt == utils.TemporalType.DATE:
|
||||||
return f"STR_TO_DATE('{dttm.date().isoformat()}', '%Y-%m-%d')"
|
return f"STR_TO_DATE('{dttm.date().isoformat()}', '%Y-%m-%d')"
|
||||||
if tt == utils.TemporalType.DATETIME:
|
if tt == utils.TemporalType.DATETIME:
|
||||||
return f"""STR_TO_DATE('{dttm.isoformat(sep=" ", timespec="microseconds")}', '%Y-%m-%d %H:%i:%s.%f')""" # pylint: disable=line-too-long
|
datetime_formatted = dttm.isoformat(sep=" ", timespec="microseconds")
|
||||||
|
return f"""STR_TO_DATE('{datetime_formatted}', '%Y-%m-%d %H:%i:%s.%f')"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -70,7 +71,7 @@ class MySQLEngineSpec(BaseEngineSpec):
|
|||||||
def get_datatype(cls, type_code: Any) -> Optional[str]:
|
def get_datatype(cls, type_code: Any) -> Optional[str]:
|
||||||
if not cls.type_code_map:
|
if not cls.type_code_map:
|
||||||
# only import and store if needed at least once
|
# only import and store if needed at least once
|
||||||
import MySQLdb # pylint: disable=import-error
|
import MySQLdb
|
||||||
|
|
||||||
ft = MySQLdb.constants.FIELD_TYPE
|
ft = MySQLdb.constants.FIELD_TYPE
|
||||||
cls.type_code_map = {
|
cls.type_code_map = {
|
||||||
@ -94,6 +95,6 @@ class MySQLEngineSpec(BaseEngineSpec):
|
|||||||
try:
|
try:
|
||||||
if isinstance(ex.args, tuple) and len(ex.args) > 1:
|
if isinstance(ex.args, tuple) and len(ex.args) > 1:
|
||||||
message = ex.args[1]
|
message = ex.args[1]
|
||||||
except Exception: # pylint: disable=broad-except
|
except (AttributeError, KeyError):
|
||||||
pass
|
pass
|
||||||
return message
|
return message
|
||||||
|
@ -46,9 +46,11 @@ class OracleEngineSpec(BaseEngineSpec):
|
|||||||
if tt == utils.TemporalType.DATE:
|
if tt == utils.TemporalType.DATE:
|
||||||
return f"TO_DATE('{dttm.date().isoformat()}', 'YYYY-MM-DD')"
|
return f"TO_DATE('{dttm.date().isoformat()}', 'YYYY-MM-DD')"
|
||||||
if tt == utils.TemporalType.DATETIME:
|
if tt == utils.TemporalType.DATETIME:
|
||||||
return f"""TO_DATE('{dttm.isoformat(timespec="seconds")}', 'YYYY-MM-DD"T"HH24:MI:SS')""" # pylint: disable=line-too-long
|
datetime_formatted = dttm.isoformat(timespec="seconds")
|
||||||
|
return f"""TO_DATE('{datetime_formatted}', 'YYYY-MM-DD"T"HH24:MI:SS')"""
|
||||||
if tt == utils.TemporalType.TIMESTAMP:
|
if tt == utils.TemporalType.TIMESTAMP:
|
||||||
return f"""TO_TIMESTAMP('{dttm.isoformat(timespec="microseconds")}', 'YYYY-MM-DD"T"HH24:MI:SS.ff6')""" # pylint: disable=line-too-long
|
return f"""TO_TIMESTAMP('{dttm
|
||||||
|
.isoformat(timespec="microseconds")}', 'YYYY-MM-DD"T"HH24:MI:SS.ff6')"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -85,9 +85,7 @@ class PinotEngineSpec(BaseEngineSpec): # pylint: disable=abstract-method
|
|||||||
if not granularity:
|
if not granularity:
|
||||||
raise NotImplementedError("No pinot grain spec for " + str(time_grain))
|
raise NotImplementedError("No pinot grain spec for " + str(time_grain))
|
||||||
else:
|
else:
|
||||||
return TimestampExpression(
|
return TimestampExpression("{{col}}", col)
|
||||||
f"{{col}}", col # pylint: disable=f-string-without-interpolation
|
|
||||||
)
|
|
||||||
# In pinot the output is a string since there is no timestamp column like pg
|
# In pinot the output is a string since there is no timestamp column like pg
|
||||||
time_expr = f"DATETIMECONVERT({{col}}, '{tf}', '{tf}', '{granularity}')"
|
time_expr = f"DATETIMECONVERT({{col}}, '{tf}', '{tf}', '{granularity}')"
|
||||||
return TimestampExpression(time_expr, col)
|
return TimestampExpression(time_expr, col)
|
||||||
|
@ -24,7 +24,6 @@ from superset.db_engine_specs.base import BaseEngineSpec
|
|||||||
from superset.utils import core as utils
|
from superset.utils import core as utils
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
# pylint: disable=unused-import
|
|
||||||
from superset.models.core import Database # pragma: no cover
|
from superset.models.core import Database # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
@ -86,5 +85,6 @@ class PostgresEngineSpec(PostgresBaseEngineSpec):
|
|||||||
if tt == utils.TemporalType.DATE:
|
if tt == utils.TemporalType.DATE:
|
||||||
return f"TO_DATE('{dttm.date().isoformat()}', 'YYYY-MM-DD')"
|
return f"TO_DATE('{dttm.date().isoformat()}', 'YYYY-MM-DD')"
|
||||||
if tt == utils.TemporalType.TIMESTAMP:
|
if tt == utils.TemporalType.TIMESTAMP:
|
||||||
return f"""TO_TIMESTAMP('{dttm.isoformat(sep=" ", timespec="microseconds")}', 'YYYY-MM-DD HH24:MI:SS.US')""" # pylint: disable=line-too-long
|
dttm_formatted = dttm.isoformat(sep=" ", timespec="microseconds")
|
||||||
|
return f"""TO_TIMESTAMP('{dttm_formatted}', 'YYYY-MM-DD HH24:MI:SS.US')"""
|
||||||
return None
|
return None
|
||||||
|
@ -53,7 +53,7 @@ from superset.utils import core as utils
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
# prevent circular imports
|
# prevent circular imports
|
||||||
from superset.models.core import Database # pylint: disable=unused-import
|
from superset.models.core import Database
|
||||||
|
|
||||||
QueryStatus = utils.QueryStatus
|
QueryStatus = utils.QueryStatus
|
||||||
config = app.config
|
config = app.config
|
||||||
|
@ -25,7 +25,7 @@ from superset.db_engine_specs.postgres import PostgresBaseEngineSpec
|
|||||||
from superset.utils import core as utils
|
from superset.utils import core as utils
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from superset.models.core import Database # pylint: disable=unused-import
|
from superset.models.core import Database
|
||||||
|
|
||||||
|
|
||||||
class SnowflakeEngineSpec(PostgresBaseEngineSpec):
|
class SnowflakeEngineSpec(PostgresBaseEngineSpec):
|
||||||
|
@ -24,7 +24,7 @@ from superset.utils import core as utils
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
# prevent circular imports
|
# prevent circular imports
|
||||||
from superset.models.core import Database # pylint: disable=unused-import
|
from superset.models.core import Database
|
||||||
|
|
||||||
|
|
||||||
class SqliteEngineSpec(BaseEngineSpec):
|
class SqliteEngineSpec(BaseEngineSpec):
|
||||||
|
Loading…
Reference in New Issue
Block a user