This is an automated email from the ASF dual-hosted git repository.

snazy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new 7fa497cd6 JDBC: Log SQL statements at debug level (#2221)
7fa497cd6 is described below

commit 7fa497cd63fd862026ff38d54cc2e17011cbb5b5
Author: Robert Stupp <sn...@snazy.de>
AuthorDate: Mon Aug 4 09:24:01 2025 +0200

    JDBC: Log SQL statements at debug level (#2221)
---
 .../relational/jdbc/DatasourceOperations.java           | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git 
a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java
 
b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java
index f5afbc04d..346cd3f1c 100644
--- 
a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java
+++ 
b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java
@@ -38,6 +38,7 @@ import java.util.Objects;
 import java.util.Random;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
+import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import javax.sql.DataSource;
 import org.apache.polaris.core.persistence.EntityAlreadyExistsException;
@@ -151,6 +152,7 @@ public class DatasourceOperations {
       throws SQLException {
     withRetries(
         () -> {
+          logQuery(query);
           try (Connection connection = borrowConnection();
               PreparedStatement statement = 
connection.prepareStatement(query.sql())) {
             List<Object> params = query.parameters();
@@ -176,6 +178,7 @@ public class DatasourceOperations {
   public int executeUpdate(QueryGenerator.PreparedQuery preparedQuery) throws 
SQLException {
     return withRetries(
         () -> {
+          logQuery(preparedQuery);
           try (Connection connection = borrowConnection();
               PreparedStatement statement = 
connection.prepareStatement(preparedQuery.sql())) {
             List<Object> params = preparedQuery.parameters();
@@ -226,6 +229,7 @@ public class DatasourceOperations {
 
   public Integer execute(Connection connection, QueryGenerator.PreparedQuery 
preparedQuery)
       throws SQLException {
+    logQuery(preparedQuery);
     try (PreparedStatement statement = 
connection.prepareStatement(preparedQuery.sql())) {
       List<Object> params = preparedQuery.parameters();
       for (int i = 0; i < params.size(); i++) {
@@ -334,4 +338,17 @@ public class DatasourceOperations {
   private Connection borrowConnection() throws SQLException {
     return datasource.getConnection();
   }
+
+  private static void logQuery(QueryGenerator.PreparedQuery query) {
+    LOGGER
+        .atDebug()
+        .addArgument(query.sql())
+        .addArgument(
+            () ->
+                query.parameters().stream()
+                    .map(o -> o != null ? o.toString() : "NULL")
+                    .collect(Collectors.joining("\n    ", "\n    ", "")))
+        .setMessage("query: {}{}")
+        .log();
+  }
 }

Reply via email to