From notifications-return-40861-archive-asf-public=cust-asf.ponee.io@superset.apache.org Thu May 14 12:12:52 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 87BC8180621 for ; Thu, 14 May 2020 14:12:52 +0200 (CEST) Received: (qmail 58811 invoked by uid 500); 14 May 2020 12:12:52 -0000 Mailing-List: contact notifications-help@superset.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@superset.apache.org Delivered-To: mailing list notifications@superset.apache.org Received: (qmail 58802 invoked by uid 99); 14 May 2020 12:12:51 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 May 2020 12:12:51 +0000 From: =?utf-8?q?GitBox?= To: notifications@superset.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bincubator-superset=5D_villebro_commented_on_a_chan?= =?utf-8?q?ge_in_pull_request_=239752=3A_fix=28mssql=29=3A_reverts_=239644_a?= =?utf-8?q?nd_displays_a_better_error_msg?= Message-ID: <158945837186.19379.16278032337164817724.asfpy@gitbox.apache.org> Date: Thu, 14 May 2020 12:12:51 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit References: In-Reply-To: villebro commented on a change in pull request #9752: URL: https://github.com/apache/incubator-superset/pull/9752#discussion_r425084363 ########## File path: superset/db_engine_specs/mssql.py ########## @@ -85,6 +84,10 @@ def get_sqla_column_type(cls, type_: str) -> Optional[TypeEngine]: return None @classmethod - def apply_limit_to_sql(cls, sql: str, limit: int, database: "Database") -> str: - new_sql = ParsedQuery(sql).set_alias() - return super().apply_limit_to_sql(new_sql, limit, database) + def extract_error_message(cls, ex: Exception) -> str: + if str(ex).startswith("(8155"): + return ( + f"{cls.engine} error: All your SQL functions need to " + "have alias on MSSQL. For example: SELECT COUNT(*) AS C1 FROM TABLE1" Review comment: ```suggestion "have an alias on MSSQL. For example: SELECT COUNT(*) AS C1 FROM TABLE1" ``` ########## File path: superset/db_engine_specs/mssql.py ########## @@ -85,6 +84,10 @@ def get_sqla_column_type(cls, type_: str) -> Optional[TypeEngine]: return None @classmethod - def apply_limit_to_sql(cls, sql: str, limit: int, database: "Database") -> str: - new_sql = ParsedQuery(sql).set_alias() - return super().apply_limit_to_sql(new_sql, limit, database) + def extract_error_message(cls, ex: Exception) -> str: + if str(ex).startswith("(8155"): Review comment: ```suggestion if str(ex).startswith("(8155,"): ``` You never know if they introduce `^\(8155\d+,`.. ########## File path: tests/db_engine_specs/mssql_tests.py ########## @@ -97,64 +94,28 @@ def test_convert_dttm(self): for actual, expected in test_cases: self.assertEqual(actual, expected) - def test_apply_limit(self): - def compile_sqla_query(qry: Select, schema: Optional[str] = None) -> str: - return str( - qry.compile( - dialect=mssql.dialect(), compile_kwargs={"literal_binds": True} - ) - ) - - database = Database( - database_name="mssql_test", - sqlalchemy_uri="mssql+pymssql://sa:Password_123@localhost:1433/msdb", + def test_extract_error_message(self): + test_mssql_exception = Exception( + "(8155, b\"No column name was specified for column 1 of 'inner_qry'." + "DB-Lib error message 20018, severity 16:\\nGeneral SQL Server error: " + 'Check messages from the SQL Server\\n")' ) - db.session.add(database) - db.session.commit() - - with mock.patch.object(database, "compile_sqla_query", new=compile_sqla_query): - test_sql = "SELECT COUNT(*) FROM FOO_TABLE" - - limited_sql = MssqlEngineSpec.apply_limit_to_sql(test_sql, 1000, database) - - expected_sql = ( - "SELECT TOP 1000 * \n" - "FROM (SELECT COUNT(*) AS COUNT_1 FROM FOO_TABLE) AS inner_qry" - ) - self.assertEqual(expected_sql, limited_sql) - - test_sql = "SELECT COUNT(*), SUM(id) FROM FOO_TABLE" - limited_sql = MssqlEngineSpec.apply_limit_to_sql(test_sql, 1000, database) - - expected_sql = ( - "SELECT TOP 1000 * \n" - "FROM (SELECT COUNT(*) AS COUNT_1, SUM(id) AS SUM_2 FROM FOO_TABLE) " - "AS inner_qry" - ) - self.assertEqual(expected_sql, limited_sql) - - test_sql = "SELECT COUNT(*), FOO_COL1 FROM FOO_TABLE GROUP BY FOO_COL1" - limited_sql = MssqlEngineSpec.apply_limit_to_sql(test_sql, 1000, database) - - expected_sql = ( - "SELECT TOP 1000 * \n" - "FROM (SELECT COUNT(*) AS COUNT_1, " - "FOO_COL1 FROM FOO_TABLE GROUP BY FOO_COL1)" - " AS inner_qry" - ) - self.assertEqual(expected_sql, limited_sql) - - test_sql = "SELECT COUNT(*), COUNT(*) FROM FOO_TABLE" - limited_sql = MssqlEngineSpec.apply_limit_to_sql(test_sql, 1000, database) - expected_sql = ( - "SELECT TOP 1000 * \n" - "FROM (SELECT COUNT(*) AS COUNT_1, COUNT(*) AS COUNT_2 FROM FOO_TABLE)" - " AS inner_qry" - ) - self.assertEqual(expected_sql, limited_sql) + error_message = MssqlEngineSpec.extract_error_message(test_mssql_exception) + expected_message = ( + "mssql error: All your SQL functions need to " + "have alias on MSSQL. For example: SELECT COUNT(*) AS C1 FROM TABLE1" Review comment: ```suggestion "have an alias on MSSQL. For example: SELECT COUNT(*) AS C1 FROM TABLE1" ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org For additional commands, e-mail: notifications-help@superset.apache.org