Skip to content

Commit

Permalink
[CALCITE-4760] RelBuilder creation fails with error 'No suitable driv…
Browse files Browse the repository at this point in the history
…er 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.
  • Loading branch information
julianhyde committed Sep 4, 2021
1 parent 8c46299 commit 48d4cfa
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/src/main/java/org/apache/calcite/tools/Frameworks.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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;
Expand All @@ -42,21 +43,27 @@
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() {
}

Expand Down Expand Up @@ -174,8 +181,10 @@ public static <R> R withPrepare(FrameworkConfig config,
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);
Expand Down

0 comments on commit 48d4cfa

Please sign in to comment.