Home > Back-end >  Strange behavior in terminal output using snowflake-connector together with simple-ddl-parser
Strange behavior in terminal output using snowflake-connector together with simple-ddl-parser

Time:09-28

does anybody have an idea what is happening? I'm not so advanced in coding to understand the reason behind the following behavior:

I have a short python script connecting to Snowflake and getting a DDL definition from some table. Having the DDL I want to parse it using simple-ddl-parser.

import snowflake.connector
from simple_ddl_parser import DDLParser

ctx = snowflake.connector.connect(
    user='xxx',
    account='xxx', 
    warehouse='xxx', 
    database='xxx',       
    schema ='xxx',
    role = 'xxx',
    authenticator="externalbrowser")        

cs = ctx.cursor()

try:
    cs.execute("select get_ddl('table', 'xxx');")
    ddl = cs.fetchone()
    # print(ddl[0])
    result = DDLParser(ddl[0]).run()
finally:
    cs.close()
    
ctx.close()

When I'm commenting out the line result = DDLParser(ddl[0]).run() and simply printing out the ddl on the screen everything is working fine. In terminal I'm getting the information that my browser will open etc. (because of externalbrowser authentication) and I can see the DDL.

However when I'm starting to use the DDLParser to parse the DDL I'm getting a lot of information from snowflake-connector. It looks like some debug info or all the details about connection etc.:

Initiating login request with your identity provider. A browser window should have opened for you to complete the login. If you can't see it, check existing browser windows, or your OS settings. Press CTRL C to abort and try again...
connection.py: 557:closed
telemetry.py: 151:Closing telemetry client.
telemetry.py: 116:Sending 1 logs to telemetry. Data is {'logs': [{'message': {'type': 'client_time_consume_first_result', 'source': 'PythonConnector', 'query_id': '01a7449c-0c03-a272-0000-ce55d70a2ffe', 'value': 493}, 'timestamp': '1664357536706'}]}.
network.py:1147:Session status for SessionPool 'xxx', SessionPool 1/1 active sessions
network.py: 827:remaining request timeout: 5, retry cnt: 1
network.py: 808:Request guid: 8524f554-bc67-4209-af13-d87249a7fae6
network.py:1006:socket timeout: 60
connectionpool.py: 456:https://xxx:443 "POST /telemetry/send?request_guid=8524f554-bc67-4209-af13-d87249a7fae6 HTTP/1.1" 200 86
network.py:1032:SUCCESS
network.py:1152:Session status for SessionPool 'xxx', SessionPool 0/1 active sessions
network.py: 715:ret[code] = None, after post request
telemetry.py: 140:Successfully uploading metrics to telemetry.
connection.py: 560:No async queries seem to be running, deleting session
network.py:1147:Session status for SessionPool 'xxx', SessionPool 1/1 active sessions
network.py: 827:remaining request timeout: 5, retry cnt: 1
network.py: 808:Request guid: 33d96b5f-f8db-4fbc-b88f-54a5c330615c
network.py:1006:socket timeout: 60
connectionpool.py: 456:https://xxx:443 "POST /session?delete=true&request_guid=33d96b5f-f8db-4fbc-b88f-54a5c330615c HTTP/1.1" 200 76
network.py:1032:SUCCESS
network.py:1152:Session status for SessionPool 'xxx', SessionPool 0/1 active sessions
network.py: 715:ret[code] = None, after post request
connection.py: 571:Session is closed
connection.py: 548:Rest object has been destroyed, cannot close session
   _api.py: 172:Attempting to acquire lock 1617266024480 on C:\Users\xxx\AppData\Local\Snowflake\Caches\ocsp_cache.lock
   _api.py: 176:Lock 1617266024480 acquired on C:\Users\xxx\AppData\Local\Snowflake\Caches\ocsp_cache.lock
   _api.py: 209:Attempting to release lock 1617266024480 on C:\Users\xxx\AppData\Local\Snowflake\Caches\ocsp_cache.lock
   _api.py: 212:Lock 1617266024480 released on C:\Users\xxx\AppData\Local\Snowflake\Caches\ocsp_cache.lock

I'm getting my DDL successfully parsed but why I'm getting all this additional information displayed on the screen?

Is snowflake-connector and simple-ddl-parser somehow interfering with each other? Is it possible that some variables or functions are named the same or something in the simple-ddl-parser code is switching on some debug info from snowflake-connector? I have no idea... but I don't want to see this "debug" info on my screen but want to use simple-ddl-parser.

I will be happy to get any feedback! Thx!

CodePudding user response:

Thank you @Sergiu!

Your solution is working! So again to understand... if I'm using multiple python packages in my code and one of them is changing the logging level to e.g. DEBUG, I will get debug info from all of my other packages as well? So this one setting is impacting the logging behavior in my whole code? Interesting.

I have found the way how to change the logging level for my whole program independent from the settings in a particular package (put it at the beginning of your code):

import logging

logging.basicConfig(level=logging.CRITICAL)

Ps. I'm using another function from simple-ddl-parser (below), but it seems it's not using any parameters as log_level. I will ask the creator if it would be a good idea to add this feature there also and for now I will add above code to my program (I think WARNING level is also sufficient).

from simple_ddl_parser import parse_from_file

result = parse_from_file('tests/sql/test_one_statement.sql')
print(result)

CodePudding user response:

The DDLParser has default log level set to DEBUG as I can see here.

You can set the DDLParser logging to CRITICAL and these messages won't appear on the screen anymore.

So, in your existing script add:

import logging
...
result = DDLParser(ddl[0], log_level=logging.CRITICAL).run()

See more information here.

  • Related