Skip to content

Commit

Permalink
DRILL-8117: Clean up deprecated Apache code in Drill
Browse files Browse the repository at this point in the history
  • Loading branch information
kingswanwho authored and kingswanwho committed Feb 13, 2023
1 parent 9d6af6d commit 829381f
Show file tree
Hide file tree
Showing 24 changed files with 1,292 additions and 868 deletions.
5 changes: 5 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>

<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.apache.drill.common;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils;

/**
* Builds a string in Drill's "plan string" format: that shown in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private <T> Class<T> getClassAt(String location, Class<T> clazz) throws DrillCon
public <T> T getInstanceOf(String location, Class<T> clazz) throws DrillConfigurationException{
final Class<T> c = getClassAt(location, clazz);
try {
return c.newInstance();
return c.getDeclaredConstructor().newInstance();
} catch (Exception ex) {
throw new DrillConfigurationException(String.format("Failure while instantiating class [%s] located at '%s.", clazz.getCanonicalName(), location), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import io.netty.buffer.ByteBuf;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
package org.apache.drill.common.util.function;

import org.apache.drill.test.BaseTest;
import org.junit.Rule;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.HashMap;
import java.util.Map;

public class TestCheckedFunction extends BaseTest {
import static org.hamcrest.CoreMatchers.containsString;

@Rule
public ExpectedException thrown = ExpectedException.none();
public class TestCheckedFunction extends BaseTest {

@Test
public void testComputeIfAbsentWithCheckedFunction() {
Expand All @@ -37,10 +36,8 @@ public void testComputeIfAbsentWithCheckedFunction() {
String message = "Exception message";
CheckedFunction<String, String, Exception> function = producer::failWithMessage;

thrown.expect(Exception.class);
thrown.expectMessage(message);

map.computeIfAbsent(message, function);
Exception exception = Assert.assertThrows(Exception.class, () -> map.computeIfAbsent(message, function));
MatcherAssert.assertThat(exception.getMessage(), containsString(message));
}

private class ExceptionProducer {
Expand Down
8 changes: 0 additions & 8 deletions common/src/test/java/org/apache/drill/test/DrillTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.DisableOnDebug;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
Expand Down Expand Up @@ -58,13 +57,6 @@ public class DrillTest extends BaseTest {

@Rule public final TestRule REPEAT_RULE = TestTools.getRepeatRule(false);

/**
* Rule for tests that verify {@link org.apache.drill.common.exceptions.UserException} type and message. See
* {@link UserExceptionMatcher} and e.g. apache.drill.exec.server.TestOptions#checkValidationException.
* Tests that do not use this rule are not affected.
*/
@Rule public final ExpectedException thrownException = ExpectedException.none();

@BeforeClass
public static void initDrillTest() {
memWatcher = new MemWatcher();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.apache.drill.exec.store.log;

import static org.junit.Assert.assertEquals;
import static org.hamcrest.CoreMatchers.containsString;

import java.io.File;
import java.util.HashMap;
Expand All @@ -32,11 +32,13 @@
import org.apache.drill.exec.physical.rowSet.RowSetBuilder;
import org.apache.drill.exec.record.metadata.SchemaBuilder;
import org.apache.drill.exec.record.metadata.TupleMetadata;
import org.apache.drill.exec.rpc.RpcException;
import org.apache.drill.exec.store.easy.text.compliant.BaseCsvTest;
import org.apache.drill.shaded.guava.com.google.common.collect.Lists;
import org.apache.drill.test.QueryBuilder;
import org.apache.drill.test.QueryBuilder.QuerySummary;
import org.apache.drill.test.rowSet.RowSetComparison;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down Expand Up @@ -106,10 +108,12 @@ public void testIssue7853UseValidDatetimeFormat() throws Exception {

@Test
public void testIssue7853() throws Exception {
thrownException.expect(UserRemoteException.class);
thrownException.expectMessage("is not valid for type TIMESTAMP");
String sql = "SELECT type, `time` FROM `dfs.data`.`root/issue7853.log2`";
QuerySummary result = client.queryBuilder().sql(sql).run();
assertEquals(2, result.recordCount());
UserRemoteException userRemoteException = Assert.assertThrows(UserRemoteException.class, () -> client.queryBuilder().sql(sql).run());
MatcherAssert.assertThat(userRemoteException.getMessage(), containsString("is not valid for type TIMESTAMP"));

try {
client.testBuilder().sqlQuery(sql).expectsNumRecords(2).go();
} catch (UserRemoteException | RpcException ignored) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.drill.exec.hive.HiveTestUtilities;
import org.apache.drill.exec.impersonation.BaseTestImpersonation;
import org.apache.drill.exec.store.hive.HiveStoragePluginConfig;
import org.apache.drill.test.ClientFixture;
import org.apache.drill.test.ClusterFixture;
import org.apache.drill.test.TestBuilder;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
Expand Down Expand Up @@ -94,8 +96,8 @@ protected static void prepHiveConfAndData() throws Exception {
whDir = hiveConf.get(ConfVars.METASTOREWAREHOUSE.varname);
FileSystem.mkdirs(fs, new Path(whDir), new FsPermission((short) 0777));

studentData = getPhysicalFileFromResource("student.txt");
voterData = getPhysicalFileFromResource("voter.txt");
studentData = ClusterFixture.getResource("student.txt");
voterData = ClusterFixture.getResource("voter.txt");
}

protected static void startHiveMetaStore() throws Exception {
Expand Down Expand Up @@ -143,12 +145,13 @@ protected static Path getWhPathForHiveObject(final String dbName, final String t
}

protected static void addHiveStoragePlugin(final Map<String, String> hiveConfig) throws Exception {
getDrillbitContext().getStorage().put(hivePluginName, createHiveStoragePlugin(hiveConfig));
cluster.storageRegistry().put(hivePluginName, createHiveStoragePlugin(hiveConfig));
}

protected void showTablesHelper(final String db, List<String> expectedTables) throws Exception {
protected void showTablesHelper(final String db, List<String> expectedTables, ClientFixture
client) throws Exception {
final String dbQualified = hivePluginName + "." + db;
final TestBuilder testBuilder = testBuilder()
final TestBuilder testBuilder = client.testBuilder()
.sqlQuery("SHOW TABLES IN " + dbQualified)
.unOrdered()
.baselineColumns("TABLE_SCHEMA", "TABLE_NAME");
Expand All @@ -164,9 +167,10 @@ protected void showTablesHelper(final String db, List<String> expectedTables) th
testBuilder.go();
}

protected void fromInfoSchemaHelper(final String db, List<String> expectedTables, List<TableType> expectedTableTypes) throws Exception {
protected void fromInfoSchemaHelper(final String db, List<String> expectedTables, List<TableType>
expectedTableTypes, ClientFixture client) throws Exception {
final String dbQualified = hivePluginName + "." + db;
final TestBuilder testBuilder = testBuilder()
final TestBuilder testBuilder = client.testBuilder()
.sqlQuery("SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE \n" +
"FROM INFORMATION_SCHEMA.`TABLES` \n" +
"WHERE TABLE_SCHEMA = '" + dbQualified + "'")
Expand All @@ -190,20 +194,29 @@ public static void stopHiveMetaStore() throws Exception {
// server instances this should be ok.
}

static void queryView(String viewName) throws Exception {
static void queryView(String viewName, ClientFixture client) throws Exception {
String query = String.format("SELECT rownum FROM %s.tmp.%s ORDER BY rownum LIMIT 1", MINI_DFS_STORAGE_PLUGIN_NAME, viewName);
testBuilder()
client.testBuilder()
.sqlQuery(query)
.unOrdered()
.baselineColumns("rownum")
.baselineValues(1)
.go();
}

static void queryViewNotAuthorized(String viewName) throws Exception {
static void queryViewNotAuthorized(String viewName, ClientFixture client) throws Exception {
String query = String.format("SELECT rownum FROM %s.tmp.%s ORDER BY rownum LIMIT 1", MINI_DFS_STORAGE_PLUGIN_NAME, viewName);
errorMsgTestHelper(query, String.format(
"Not authorized to read view [%s] in schema [%s.tmp]", viewName, MINI_DFS_STORAGE_PLUGIN_NAME));
String expectedMsg = String.format(
"Not authorized to read view [%s] in schema [%s.tmp]",
viewName,
MINI_DFS_STORAGE_PLUGIN_NAME
);

client.queryBuilder()
.sql(query)
.userExceptionMatcher()
.include(expectedMsg)
.match();
}

static void createTableWithStoragePermissions(final Driver hiveDriver, final String db, final String tbl, final String tblDef,
Expand Down

0 comments on commit 829381f

Please sign in to comment.