From 60bcb11ec6dbce3b75b495e2efc71ddb7c46a927 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Thu, 20 Apr 2023 17:28:48 +0000 Subject: [PATCH 1/4] refactor: holy shit I botched another commit lol --- superset/db_engine_specs/ocient.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/superset/db_engine_specs/ocient.py b/superset/db_engine_specs/ocient.py index 9c019b7be2741..229ab334d09e4 100644 --- a/superset/db_engine_specs/ocient.py +++ b/superset/db_engine_specs/ocient.py @@ -38,10 +38,6 @@ from superset.models.core import Database from superset.models.sql_lab import Query -# Ensure pyocient inherits Superset's logging level -superset_log_level = app.config["LOG_LEVEL"] -pyocient.logger.setLevel(superset_log_level) - # Regular expressions to catch custom errors From 2190ec82ed6774ff17aafde3615af3810de7cda2 Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Thu, 20 Apr 2023 17:31:46 +0000 Subject: [PATCH 2/4] fix: address warnings generated by pylint --- superset/db_engine_specs/ocient.py | 40 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/superset/db_engine_specs/ocient.py b/superset/db_engine_specs/ocient.py index 229ab334d09e4..c52a714c504a5 100644 --- a/superset/db_engine_specs/ocient.py +++ b/superset/db_engine_specs/ocient.py @@ -42,29 +42,31 @@ # Regular expressions to catch custom errors CONNECTION_INVALID_USERNAME_REGEX = re.compile( - "The referenced user does not exist \(User '(?P.*?)' not found\)" + r"The referenced user does not exist \(User '(?P.*?)' not found\)" ) CONNECTION_INVALID_PASSWORD_REGEX = re.compile( - "The userid/password combination was not valid \(Incorrect password for user\)" + r"The userid/password combination was not valid \(Incorrect password for user\)" ) CONNECTION_INVALID_HOSTNAME_REGEX = re.compile( r"Unable to connect to (?P.*?):(?P.*?):" ) CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile( - "No database named '(?P.*?)' exists" + r"No database named '(?P.*?)' exists" ) CONNECTION_INVALID_PORT_ERROR = re.compile("Port out of range 0-65535") INVALID_CONNECTION_STRING_REGEX = re.compile( - "An invalid connection string attribute was specified \(failed to decrypt cipher text\)" + r"An invalid connection string attribute was specified" + r" \(failed to decrypt cipher text\)" ) SYNTAX_ERROR_REGEX = re.compile( - r"There is a syntax error in your statement \((?P.*?) input '(?P.*?)' expecting {.*}" + r"There is a syntax error in your statement \((?P.*?)" + r" input '(?P.*?)' expecting {.*}" ) TABLE_DOES_NOT_EXIST_REGEX = re.compile( - "The referenced table or view '(?P.*?)' does not exist" + r"The referenced table or view '(?P
.*?)' does not exist" ) COLUMN_DOES_NOT_EXIST_REGEX = re.compile( - "The reference to column '(?P.*?)' is not valid" + r"The reference to column '(?P.*?)' is not valid" ) @@ -135,7 +137,7 @@ def _point_to_comma_delimited(point: "_STPoint") -> str: # Superset serializes temporal objects using a custom serializer # defined in superset/utils/core.py (#json_int_dttm_ser(...)). Other # are serialized by the default JSON encoder. -# +# # Need to try-catch here because pyocient may not be installed try: from pyocient import TypeCodes @@ -189,7 +191,8 @@ class OcientEngineSpec(BaseEngineSpec): ), CONNECTION_INVALID_PASSWORD_REGEX: ( __( - "The user/password combination is not valid (Incorrect password for user)." + "The user/password combination is not valid" + " (Incorrect password for user)." ), SupersetErrorType.CONNECTION_INVALID_PASSWORD_ERROR, {}, @@ -211,7 +214,8 @@ class OcientEngineSpec(BaseEngineSpec): ), INVALID_CONNECTION_STRING_REGEX: ( __( - "Invalid Connection String: Expecting String of the form 'ocient://user:pass@host:port/database'." + "Invalid Connection String: Expecting String of" + " the form 'ocient://user:pass@host:port/database'." ), SupersetErrorType.GENERIC_DB_ENGINE_ERROR, {}, @@ -252,11 +256,11 @@ def get_table_names( @classmethod def fetch_data( - cls, cursor: Any, lim: Optional[int] = None + cls, cursor: Any, limit: Optional[int] = None ) -> List[Tuple[Any, ...]]: try: rows: List[Tuple[Any, ...]] = super(OcientEngineSpec, cls).fetch_data( - cursor, lim + cursor, limit ) except Exception as exception: with OcientEngineSpec.query_id_mapping_lock: @@ -298,7 +302,7 @@ def identity(x: Any) -> Any: for row in rows ] return rows - + @classmethod def epoch_to_dttm(cls) -> str: return "DATEADD(S, {col}, '1970-01-01')" @@ -327,10 +331,10 @@ def cancel_query(cls, cursor: Any, query: Query, cancel_query_id: str) -> bool: with OcientEngineSpec.query_id_mapping_lock: if query.id in OcientEngineSpec.query_id_mapping: cursor.execute(f"CANCEL {OcientEngineSpec.query_id_mapping[query.id]}") - # Query has been cancelled, so we can safely remove the cursor from the cache + # Query has been cancelled, so we can safely remove the cursor from + # the cache del OcientEngineSpec.query_id_mapping[query.id] - return True - # If the query is not in the cache, it must have either been cancelled elsewhere or completed - else: - return False + # If the query is not in the cache, it must have either been cancelled + # elsewhere or completed + return False From f0f191e8363c0b98a2fcf475b9a21365b90b545e Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Thu, 20 Apr 2023 18:47:41 +0000 Subject: [PATCH 3/4] fix: fix custom errors matchers --- superset/db_engine_specs/ocient.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/superset/db_engine_specs/ocient.py b/superset/db_engine_specs/ocient.py index c52a714c504a5..f6f97a9576fbf 100644 --- a/superset/db_engine_specs/ocient.py +++ b/superset/db_engine_specs/ocient.py @@ -48,7 +48,7 @@ r"The userid/password combination was not valid \(Incorrect password for user\)" ) CONNECTION_INVALID_HOSTNAME_REGEX = re.compile( - r"Unable to connect to (?P.*?):(?P.*?):" + r"Unable to connect to (?P.*?):(?P.*?)" ) CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile( r"No database named '(?P.*?)' exists" @@ -60,7 +60,7 @@ ) SYNTAX_ERROR_REGEX = re.compile( r"There is a syntax error in your statement \((?P.*?)" - r" input '(?P.*?)' expecting {.*}" + r" input '(?P.*?)' expecting (?P.*?)\)" ) TABLE_DOES_NOT_EXIST_REGEX = re.compile( r"The referenced table or view '(?P
.*?)' does not exist" @@ -221,7 +221,7 @@ class OcientEngineSpec(BaseEngineSpec): {}, ), SYNTAX_ERROR_REGEX: ( - __('Syntax Error: %(qualifier)s input "%(input)s".'), + __('Syntax Error: %(qualifier)s input "%(input)s" expecting "%(expected)s'), SupersetErrorType.SYNTAX_ERROR, {}, ), From 9cc59c4e2f5b60c4b7efad5c2a0d50b9cecfbc8d Mon Sep 17 00:00:00 2001 From: Jordan Williams Date: Thu, 20 Apr 2023 18:48:03 +0000 Subject: [PATCH 4/4] test: fix broken unit tests --- .../unit_tests/db_engine_specs/test_ocient.py | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/tests/unit_tests/db_engine_specs/test_ocient.py b/tests/unit_tests/db_engine_specs/test_ocient.py index 0b8a7533be187..75acb68680db4 100644 --- a/tests/unit_tests/db_engine_specs/test_ocient.py +++ b/tests/unit_tests/db_engine_specs/test_ocient.py @@ -25,20 +25,6 @@ from superset.errors import ErrorLevel, SupersetError, SupersetErrorType -@pytest.mark.parametrize( - "actual,expected", - [ - ("DATE", "TO_DATE('2019-01-02')"), - ("DATETIME", "CAST('2019-01-02T03:04:05.678900' AS DATETIME)"), - ("TIMESTAMP", "TO_TIMESTAMP('2019-01-02T03:04:05.678900')"), - ], -) -def test_convert_dttm(actual: str, expected: str, dttm: datetime) -> None: - from superset.db_engine_specs.ocient import OcientEngineSpec - - assert OcientEngineSpec.convert_dttm(actual, dttm) == expected - - # (msg,expected) MARSHALED_OCIENT_ERRORS: List[Tuple[str, SupersetError]] = [ ( @@ -144,9 +130,9 @@ def test_convert_dttm(actual: str, expected: str, dttm: datetime) -> None: ), ), ( - "There is a syntax error in your statement (extraneous input 'foo bar baz' expecting ", + "There is a syntax error in your statement (extraneous input 'foo bar baz' expecting {, 'trace', 'using'})", SupersetError( - message='Extraneous input: "foo bar baz".', + message='Syntax Error: extraneous input "foo bar baz" expecting "{, \'trace\', \'using\'}', error_type=SupersetErrorType.SYNTAX_ERROR, level=ErrorLevel.ERROR, extra={ @@ -163,7 +149,7 @@ def test_convert_dttm(actual: str, expected: str, dttm: datetime) -> None: ( "There is a syntax error in your statement (mismatched input 'to' expecting {, 'trace', 'using'})", SupersetError( - message='Extraneous input: "foo bar baz".', + message='Syntax Error: mismatched input "to" expecting "{, \'trace\', \'using\'}', error_type=SupersetErrorType.SYNTAX_ERROR, level=ErrorLevel.ERROR, extra={