You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by vo...@apache.org on 2021/02/01 06:41:14 UTC
[drill] branch master updated: DRILL-7850: Unable to load
DrillConnectionImpl class from JDBC driver
This is an automated email from the ASF dual-hosted git repository.
volodymyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git
The following commit(s) were added to refs/heads/master by this push:
new abf044f DRILL-7850: Unable to load DrillConnectionImpl class from JDBC driver
abf044f is described below
commit abf044fa9232af89be2bf8e5dc68784c66d3b79b
Author: Volodymyr Vysotskyi <vv...@gmail.com>
AuthorDate: Tue Jan 26 23:45:34 2021 +0200
DRILL-7850: Unable to load DrillConnectionImpl class from JDBC driver
---
.../drill/exec/util/StoragePluginTestUtils.java | 12 +---
.../drill/jdbc/impl/DrillConnectionImpl.java | 70 +---------------------
.../java/org/apache/drill/jdbc/JdbcTestBase.java | 36 +++++++----
.../drill/jdbc/impl/DrillConnectionUtils.java | 27 +++++++++
.../org/apache/drill/jdbc/test/TestJdbcQuery.java | 2 +-
5 files changed, 58 insertions(+), 89 deletions(-)
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/StoragePluginTestUtils.java b/exec/java-exec/src/test/java/org/apache/drill/exec/util/StoragePluginTestUtils.java
similarity index 85%
rename from exec/java-exec/src/main/java/org/apache/drill/exec/util/StoragePluginTestUtils.java
rename to exec/java-exec/src/test/java/org/apache/drill/exec/util/StoragePluginTestUtils.java
index ace8ed0..35b7b31 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/util/StoragePluginTestUtils.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/util/StoragePluginTestUtils.java
@@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-import org.apache.drill.exec.store.SchemaFactory;
import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableList;
import org.apache.drill.common.logical.FormatPluginConfig;
import org.apache.drill.exec.store.StoragePluginRegistry;
@@ -34,9 +33,7 @@ import org.apache.drill.exec.store.easy.sequencefile.SequenceFileFormatConfig;
import org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig;
/**
- * Utility methods to speed up tests. Some of the production code currently
- * calls this method when the production code is executed as part of the test
- * runs. That's the reason why this code has to be in production module.
+ * Utility methods to speed up tests.
*/
public class StoragePluginTestUtils {
public static final String CP_PLUGIN_NAME = "cp";
@@ -46,13 +43,6 @@ public class StoragePluginTestUtils {
public static final String ROOT_SCHEMA = "root";
public static final String DFS_TMP_SCHEMA = DFS_PLUGIN_NAME + "." + TMP_SCHEMA;
- public static final String DFS_DEFAULT_SCHEMA = DFS_PLUGIN_NAME + "." + SchemaFactory.DEFAULT_WS_NAME;
- public static final String DFS_ROOT_SCHEMA = DFS_PLUGIN_NAME + "." + ROOT_SCHEMA;
-
- public static final String UNIT_TEST_PROP_PREFIX = "drillJDBCUnitTests";
- public static final String UNIT_TEST_DFS_TMP_PROP = UNIT_TEST_PROP_PREFIX + "." + DFS_TMP_SCHEMA;
- public static final String UNIT_TEST_DFS_DEFAULT_PROP = UNIT_TEST_PROP_PREFIX + "." + DFS_DEFAULT_SCHEMA;
- public static final String UNIT_TEST_DFS_ROOT_PROP = UNIT_TEST_PROP_PREFIX + "." + DFS_ROOT_SCHEMA;
/**
* Update the workspace locations for a plugin.
diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java
index 59b28ae..714a3ec 100644
--- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java
+++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java
@@ -17,7 +17,6 @@
*/
package org.apache.drill.jdbc.impl;
-import java.io.File;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
@@ -59,8 +58,6 @@ import org.apache.drill.exec.proto.UserProtos;
import org.apache.drill.exec.rpc.RpcException;
import org.apache.drill.exec.server.Drillbit;
import org.apache.drill.exec.server.RemoteServiceSet;
-import org.apache.drill.exec.store.SchemaFactory;
-import org.apache.drill.exec.store.StoragePluginRegistry;
import org.apache.drill.jdbc.AlreadyClosedSqlException;
import org.apache.drill.jdbc.DrillConnection;
import org.apache.drill.jdbc.DrillConnectionConfig;
@@ -71,15 +68,6 @@ import org.slf4j.Logger;
import org.apache.drill.shaded.guava.com.google.common.base.Throwables;
import org.slf4j.LoggerFactory;
-import static org.apache.drill.exec.util.StoragePluginTestUtils.DFS_PLUGIN_NAME;
-import static org.apache.drill.exec.util.StoragePluginTestUtils.ROOT_SCHEMA;
-import static org.apache.drill.exec.util.StoragePluginTestUtils.TMP_SCHEMA;
-import static org.apache.drill.exec.util.StoragePluginTestUtils.UNIT_TEST_DFS_DEFAULT_PROP;
-import static org.apache.drill.exec.util.StoragePluginTestUtils.UNIT_TEST_DFS_ROOT_PROP;
-import static org.apache.drill.exec.util.StoragePluginTestUtils.UNIT_TEST_DFS_TMP_PROP;
-import static org.apache.drill.exec.util.StoragePluginTestUtils.UNIT_TEST_PROP_PREFIX;
-import static org.apache.drill.exec.util.StoragePluginTestUtils.updateSchemaLocation;
-
/**
* Drill's implementation of {@link java.sql.Connection}.
*/
@@ -147,8 +135,6 @@ public class DrillConnectionImpl extends AvaticaConnection implements DrillConne
bit = null;
}
- makeTmpSchemaLocationsUnique(bit.getContext().getStorage(), info);
-
this.client = new DrillClient(dConfig, set.getCoordinator());
} else if(config.isDirect()) {
final DrillConfig dConfig = DrillConfig.forClient();
@@ -231,13 +217,7 @@ public class DrillConnectionImpl extends AvaticaConnection implements DrillConne
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
- checkOpen();
- if (!autoCommit) {
- throw new SQLFeatureNotSupportedException(
- "Can't turn off auto-committing; transactions are not supported. "
- + "(Drill is not transactional.)" );
- }
- assert getAutoCommit() : "getAutoCommit() = " + getAutoCommit();
+ this.checkOpen();
}
@Override
@@ -662,51 +642,7 @@ public class DrillConnectionImpl extends AvaticaConnection implements DrillConne
closeOrWarn(serviceSet, "Exception while closing service set.", logger);
}
- // TODO(DRILL-xxxx): Eliminate this test-specific hack from production code.
- // If we're not going to have tests themselves explicitly handle making names
- // unique, then at least move this logic into a test base class, and have it
- // go through DrillConnection.getClient().
- /**
- * Test only code to make JDBC tests run concurrently. If the property <i>drillJDBCUnitTests</i> is set to
- * <i>true</i> in connection properties:
- * - Update dfs.tmp workspace location with a temp directory. This temp is for exclusive use for test jvm.
- * - Update dfs.tmp workspace to immutable, so that test writer don't try to create views in dfs.tmp
- * @param pluginRegistry
- */
- private static void makeTmpSchemaLocationsUnique(StoragePluginRegistry pluginRegistry, Properties props) {
- try {
- if (props != null && "true".equalsIgnoreCase(props.getProperty(UNIT_TEST_PROP_PREFIX))) {
- final String logMessage = "The {} property was not configured";
-
- final String dfsTmpPath = props.getProperty(UNIT_TEST_DFS_TMP_PROP);
- final String dfsRootPath = props.getProperty(UNIT_TEST_DFS_ROOT_PROP);
- final String dfsDefaultPath = props.getProperty(UNIT_TEST_DFS_DEFAULT_PROP);
-
- if (dfsTmpPath == null) {
- logger.warn(logMessage, UNIT_TEST_DFS_TMP_PROP);
- } else {
- updateSchemaLocation(DFS_PLUGIN_NAME, pluginRegistry, new File(dfsTmpPath), TMP_SCHEMA);
- }
-
- if (dfsRootPath == null) {
- logger.warn(logMessage, UNIT_TEST_DFS_ROOT_PROP);
- } else {
- updateSchemaLocation(DFS_PLUGIN_NAME, pluginRegistry, new File(dfsRootPath), ROOT_SCHEMA);
- }
-
- if (dfsDefaultPath == null) {
- logger.warn(logMessage, UNIT_TEST_DFS_DEFAULT_PROP);
- } else {
- updateSchemaLocation(DFS_PLUGIN_NAME, pluginRegistry, new File(dfsDefaultPath), SchemaFactory.DEFAULT_WS_NAME);
- }
- }
- } catch(Throwable e) {
- // Reason for catching Throwable is to capture NoSuchMethodError etc which depend on certain classed to be
- // present in classpath which may not be available when just using the standalone JDBC. This is unlikely to
- // happen, but just a safeguard to avoid failing user applications.
- logger.warn("Failed to update tmp schema locations. This step is purely for testing purpose. " +
- "Shouldn't be seen in production code.");
- // Ignore the error and go with defaults
- }
+ protected Drillbit getDrillbit() {
+ return bit;
}
}
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTestBase.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTestBase.java
index 3acd39a..6234bde 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTestBase.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTestBase.java
@@ -33,6 +33,10 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.apache.drill.exec.store.SchemaFactory;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.jdbc.impl.DrillConnectionImpl;
+import org.apache.drill.jdbc.impl.DrillConnectionUtils;
import org.apache.drill.shaded.guava.com.google.common.base.Function;
import org.apache.drill.shaded.guava.com.google.common.base.Strings;
@@ -47,11 +51,9 @@ import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.planner.PhysicalPlanReaderTestFactory;
import org.apache.drill.exec.util.StoragePluginTestUtils;
import org.apache.drill.jdbc.test.Hook;
-import org.apache.drill.test.BaseDirTestWatcher;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@@ -68,9 +70,6 @@ public class JdbcTestBase extends ExecTest {
@SuppressWarnings("unused")
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(JdbcTestBase.class);
- @ClassRule
- public static final BaseDirTestWatcher dirTestWatcher = new BaseDirTestWatcher();
-
@Rule
public final TestRule watcher = new TestWatcher() {
@Override
@@ -84,7 +83,11 @@ public class JdbcTestBase extends ExecTest {
@BeforeClass
public static void setUpTestCase() {
factory = new SingleConnectionCachingFactory(
- info -> DriverManager.getConnection(info.getUrl(), info.getParamsAsProperties()));
+ info -> {
+ Connection connection = DriverManager.getConnection(info.getUrl(), info.getParamsAsProperties());
+ updateSchemaLocations(connection);
+ return connection;
+ });
}
/**
@@ -112,6 +115,23 @@ public class JdbcTestBase extends ExecTest {
return conn;
}
+ private static void updateSchemaLocations(Connection conn) {
+ if (conn instanceof DrillConnectionImpl) {
+ StoragePluginRegistry storage = DrillConnectionUtils.getStorage((DrillConnectionImpl) conn);
+ try {
+ StoragePluginTestUtils.configureFormatPlugins(storage);
+ StoragePluginTestUtils.updateSchemaLocation(StoragePluginTestUtils.DFS_PLUGIN_NAME, storage,
+ dirTestWatcher.getDfsTestTmpDir(), StoragePluginTestUtils.TMP_SCHEMA);
+ StoragePluginTestUtils.updateSchemaLocation(StoragePluginTestUtils.DFS_PLUGIN_NAME, storage,
+ dirTestWatcher.getRootDir(), StoragePluginTestUtils.ROOT_SCHEMA);
+ StoragePluginTestUtils.updateSchemaLocation(StoragePluginTestUtils.DFS_PLUGIN_NAME, storage,
+ dirTestWatcher.getRootDir(), SchemaFactory.DEFAULT_WS_NAME);
+ } catch (StoragePluginRegistry.PluginException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
/**
* Changes schema of the given connection if the field "schema" is present in {@link java.util.Properties info}.
* Does nothing otherwise.
@@ -171,11 +191,7 @@ public class JdbcTestBase extends ExecTest {
*/
public static Properties getDefaultProperties() {
final Properties properties = new Properties();
- properties.setProperty(StoragePluginTestUtils.UNIT_TEST_PROP_PREFIX, "true");
- properties.setProperty(StoragePluginTestUtils.UNIT_TEST_DFS_TMP_PROP, dirTestWatcher.getDfsTestTmpDir().getAbsolutePath());
- properties.setProperty(StoragePluginTestUtils.UNIT_TEST_DFS_ROOT_PROP, dirTestWatcher.getRootDir().getAbsolutePath());
- properties.setProperty(StoragePluginTestUtils.UNIT_TEST_DFS_DEFAULT_PROP, dirTestWatcher.getRootDir().getAbsolutePath());
properties.setProperty(ExecConstants.DRILL_TMP_DIR, dirTestWatcher.getTmpDir().getAbsolutePath());
properties.setProperty(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, "false");
properties.setProperty(ExecConstants.HTTP_ENABLE, "false");
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/impl/DrillConnectionUtils.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/impl/DrillConnectionUtils.java
new file mode 100644
index 0000000..8c5d1b1
--- /dev/null
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/impl/DrillConnectionUtils.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.jdbc.impl;
+
+import org.apache.drill.exec.store.StoragePluginRegistry;
+
+public class DrillConnectionUtils {
+
+ public static StoragePluginRegistry getStorage(DrillConnectionImpl drillConnection) {
+ return drillConnection.getDrillbit().getContext().getStorage();
+ }
+}
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
index 8acedbc..bb8caca 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
@@ -62,7 +62,7 @@ public class TestJdbcQuery extends JdbcTestQueryBase {
// didn't yet receive a terminal message. To test this, we run CTAS then immediately run a query on the newly
// created table.
- final String tableName = "dfs.tmp.`testDDLs`";
+ final String tableName = "dfs.tmp.`testDDLs3635`";
try (Connection conn = connect()) {
Statement s = conn.createStatement();