From dc364d9628361a727aa19523adb3ce27c12485e2 Mon Sep 17 00:00:00 2001 From: DnlRKorn <6885702+DnlRKorn@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:39:05 -0400 Subject: [PATCH 1/2] Update sql_implementation.py to include sqlachemy output in debug logging. The current logging scheme directly prints the query as rendered by str(q); the following is the output from logging.info(f"ECA query: {q}") in function _equivalent_class_relationships. INFO:root:ECA query: SELECT statements.subject AS statements_subject, statements.predicate AS statements_predicate, statements.object AS statements_object FROM statements WHERE statements.predicate = ? AND statements.object IN (__[POSTCOMPILE_object_1]) AND statements.object IN (SELECT class_node.id FROM class_node) With this change, when running at logging level DEBUG, anytime a query is executed sqlachemy will also writes it's logging output, which is the following: INFO:sqlalchemy.engine.Engine:SELECT statements.subject AS statements_subject, statements.predicate AS statements_predicate, statements.object AS statements_object FROM statements WHERE statements.predicate = ? AND statements.object IN (?) AND statements.object IN (SELECT class_node.id FROM class_node) INFO:sqlalchemy.engine.Engine:[generated in 0.00023s] ('owl:equivalentClass', 'MONDO:0000550') In the Sqlalchemy logging, the ambiguous term "(__[POSTCOMPILE_object_1])" isn't stated and instead replaced with a query parameter, and the query parameters are outputted on a second line. --- src/oaklib/implementations/sqldb/sql_implementation.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/oaklib/implementations/sqldb/sql_implementation.py b/src/oaklib/implementations/sqldb/sql_implementation.py index acdaa9dfd..6006c2820 100644 --- a/src/oaklib/implementations/sqldb/sql_implementation.py +++ b/src/oaklib/implementations/sqldb/sql_implementation.py @@ -364,6 +364,11 @@ def __post_init__(self): locator = f"sqlite:///{path}" logging.info(f"Locator, post-processed: {locator}") self.engine = create_engine(locator) + + if(logging.root.level <= logging.DEBUG): + #If oaklib is running at DEBUG level logging; record all queries from sqlachemy on execution. + #This line is equivalent to create_engine(locator,echo=True) + logging.getLogger('sqlalchemy.engine.Engine').setLevel(logging.INFO) @property def session(self): From d42a4cd0a6d38bc8e447b04aee40f525dcb72413 Mon Sep 17 00:00:00 2001 From: DnlRKorn <6885702+DnlRKorn@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:14:25 -0400 Subject: [PATCH 2/2] Update sql_implementation.py Corrected lint errors --- src/oaklib/implementations/sqldb/sql_implementation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/oaklib/implementations/sqldb/sql_implementation.py b/src/oaklib/implementations/sqldb/sql_implementation.py index 6006c2820..3b839c5c0 100644 --- a/src/oaklib/implementations/sqldb/sql_implementation.py +++ b/src/oaklib/implementations/sqldb/sql_implementation.py @@ -364,8 +364,8 @@ def __post_init__(self): locator = f"sqlite:///{path}" logging.info(f"Locator, post-processed: {locator}") self.engine = create_engine(locator) - - if(logging.root.level <= logging.DEBUG): + + if(logging.root.level <= logging.DEBUG): #If oaklib is running at DEBUG level logging; record all queries from sqlachemy on execution. #This line is equivalent to create_engine(locator,echo=True) logging.getLogger('sqlalchemy.engine.Engine').setLevel(logging.INFO)