You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2021/09/04 00:30:21 UTC

[calcite] 01/01: [CALCITE-4760] RelBuilder creation fails with error 'No suitable driver found for jdbc:calcite:' in shaded Calcite

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

jhyde pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit 48d4cfadd4f521716a7e9a03175e52cd3972e737
Author: Julian Hyde <jh...@apache.org>
AuthorDate: Wed Sep 1 15:48:40 2021 -0700

    [CALCITE-4760] RelBuilder creation fails with error 'No suitable driver found for jdbc:calcite:' in shaded Calcite
    
    This commit does not add tests; it's not easy to reproduce
    issues caused by jar-packaging/shading.
---
 core/src/main/java/org/apache/calcite/tools/Frameworks.java | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/tools/Frameworks.java b/core/src/main/java/org/apache/calcite/tools/Frameworks.java
index 977cbd4..8ffba39 100644
--- a/core/src/main/java/org/apache/calcite/tools/Frameworks.java
+++ b/core/src/main/java/org/apache/calcite/tools/Frameworks.java
@@ -18,6 +18,7 @@ package org.apache.calcite.tools;
 
 import org.apache.calcite.config.CalciteConnectionProperty;
 import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.jdbc.Driver;
 import org.apache.calcite.materialize.SqlStatisticProvider;
 import org.apache.calcite.plan.Context;
 import org.apache.calcite.plan.Contexts;
@@ -42,21 +43,27 @@ import org.apache.calcite.sql2rel.StandardConvertletTable;
 import org.apache.calcite.statistic.QuerySqlStatisticProvider;
 import org.apache.calcite.util.Util;
 
+import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableList;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.util.List;
 import java.util.Objects;
 import java.util.Properties;
+import java.util.function.Supplier;
 
 /**
  * Tools for invoking Calcite functionality without initializing a container /
  * server first.
  */
 public class Frameworks {
+
+  /** Caches an instance of the JDBC driver. */
+  private static final Supplier<Driver> DRIVER_SUPPLIER =
+      Suppliers.memoize(Driver::new);
+
   private Frameworks() {
   }
 
@@ -174,8 +181,10 @@ public class Frameworks {
         info.setProperty(CalciteConnectionProperty.TYPE_SYSTEM.camelName(),
             config.getTypeSystem().getClass().getName());
       }
+      // Connect via a Driver instance. Don't use DriverManager because driver
+      // auto-loading can get broken by shading and jar-repacking.
       Connection connection =
-          DriverManager.getConnection("jdbc:calcite:", info);
+          DRIVER_SUPPLIER.get().connect("jdbc:calcite:", info);
       final CalciteServerStatement statement =
           connection.createStatement()
               .unwrap(CalciteServerStatement.class);