From 98df3b437c5eef727b2443197218bce1a6e4aed7 Mon Sep 17 00:00:00 2001 From: Bing Li Date: Tue, 14 Jan 2025 13:53:31 -0800 Subject: [PATCH 1/4] support empty sql query when dataframe ast is presented --- src/snowflake/connector/cursor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snowflake/connector/cursor.py b/src/snowflake/connector/cursor.py index 5ff7a15e5..6fd5ea5ed 100644 --- a/src/snowflake/connector/cursor.py +++ b/src/snowflake/connector/cursor.py @@ -930,7 +930,7 @@ def execute( if _do_reset: self.reset() command = command.strip(" \t\n\r") if command else None - if not command: + if not command and not _dataframe_ast: logger.warning("execute: no query is given to execute") return None logger.debug("query: [%s]", self._format_query_for_log(command)) From 8aa51bfc4bc5e756a2c784fa09d0083c8291e9a6 Mon Sep 17 00:00:00 2001 From: Bing Li Date: Wed, 15 Jan 2025 15:34:47 -0800 Subject: [PATCH 2/4] update cursor --- src/snowflake/connector/cursor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snowflake/connector/cursor.py b/src/snowflake/connector/cursor.py index 6fd5ea5ed..42b64668f 100644 --- a/src/snowflake/connector/cursor.py +++ b/src/snowflake/connector/cursor.py @@ -929,7 +929,7 @@ def execute( if _do_reset: self.reset() - command = command.strip(" \t\n\r") if command else None + command = command.strip(" \t\n\r") if command else "" if not command and not _dataframe_ast: logger.warning("execute: no query is given to execute") return None From daf9581a3e21636cdbc848ec67ff900ac838fbf9 Mon Sep 17 00:00:00 2001 From: Bing Li Date: Wed, 15 Jan 2025 16:25:09 -0800 Subject: [PATCH 3/4] log ast --- src/snowflake/connector/cursor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/snowflake/connector/cursor.py b/src/snowflake/connector/cursor.py index 42b64668f..1c93ce98f 100644 --- a/src/snowflake/connector/cursor.py +++ b/src/snowflake/connector/cursor.py @@ -933,7 +933,10 @@ def execute( if not command and not _dataframe_ast: logger.warning("execute: no query is given to execute") return None - logger.debug("query: [%s]", self._format_query_for_log(command)) + if command: + logger.debug("query: [%s]", self._format_query_for_log(command)) + if _dataframe_ast: + logger.debug("dataframe ast: [%s]", _dataframe_ast) _statement_params = _statement_params or dict() # If we need to add another parameter, please consider introducing a dict for all extra params From 284c59da54a0600aef0cd86b33f03ede51af2dc6 Mon Sep 17 00:00:00 2001 From: Bing Li Date: Wed, 15 Jan 2025 16:29:45 -0800 Subject: [PATCH 4/4] log ast --- src/snowflake/connector/cursor.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/snowflake/connector/cursor.py b/src/snowflake/connector/cursor.py index 1c93ce98f..b403b8a3e 100644 --- a/src/snowflake/connector/cursor.py +++ b/src/snowflake/connector/cursor.py @@ -930,14 +930,14 @@ def execute( if _do_reset: self.reset() command = command.strip(" \t\n\r") if command else "" - if not command and not _dataframe_ast: - logger.warning("execute: no query is given to execute") - return None - if command: - logger.debug("query: [%s]", self._format_query_for_log(command)) - if _dataframe_ast: - logger.debug("dataframe ast: [%s]", _dataframe_ast) + if not command: + if _dataframe_ast: + logger.debug("dataframe ast: [%s]", _dataframe_ast) + else: + logger.warning("execute: no query is given to execute") + return None + logger.debug("query: [%s]", self._format_query_for_log(command)) _statement_params = _statement_params or dict() # If we need to add another parameter, please consider introducing a dict for all extra params # See discussion in https://github.com/snowflakedb/snowflake-connector-python/pull/1524#discussion_r1174061775