Skip to content

Commit

Permalink
[MINOR UPDATE] use StandardCharsets (#2870)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning authored Jan 19, 2024
1 parent 6df6806 commit bfdafd9
Show file tree
Hide file tree
Showing 130 changed files with 450 additions and 444 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import com.google.common.base.Charsets;
import com.google.common.io.Files;

public class DrillFileUtils {
Expand All @@ -41,7 +41,7 @@ public static File getResourceAsFile(String fileName) throws IOException {
}

public static String getResourceAsString(String fileName) throws IOException {
return Files.asCharSource(getResourceAsFile(fileName), Charsets.UTF_8).read();
return Files.asCharSource(getResourceAsFile(fileName), StandardCharsets.UTF_8).read();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.drill.exec.record.metadata.MetadataUtils;
import org.apache.drill.exec.store.dfs.easy.EasySubScan;
import org.apache.drill.exec.vector.accessor.ScalarWriter;
import com.google.common.base.Charsets;
import org.apache.hadoop.fs.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -40,6 +39,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class HttpdLogBatchReader implements ManagedReader {

Expand Down Expand Up @@ -168,7 +168,7 @@ private void openFile() {
.addContext(e.getMessage())
.build(logger);
}
reader = new BufferedReader(new InputStreamReader(fsStream, Charsets.UTF_8));
reader = new BufferedReader(new InputStreamReader(fsStream, StandardCharsets.UTF_8));
}

private ScalarWriter addImplicitColumn(String colName, MinorType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import org.apache.drill.exec.vector.accessor.ScalarWriter;
import org.apache.drill.exec.vector.accessor.TupleWriter;
import org.apache.drill.exec.vector.accessor.ValueWriter;
import com.google.common.base.Charsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -193,7 +193,7 @@ private void openFile() {
.addContext(loader.errorContext())
.build(logger);
}
reader = new BufferedReader(new InputStreamReader(in, Charsets.UTF_8));
reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -829,7 +828,7 @@ private RexNode convertLikeToRange(RexCall condition, RexBuilder builder) {
// WILDCARD present. This turns the LIKE predicate to RANGE predicate
byte[] startKey = HConstants.EMPTY_START_ROW;
byte[] stopKey = HConstants.EMPTY_END_ROW;
startKey = prefix.getBytes(Charsets.UTF_8);
startKey = prefix.getBytes(StandardCharsets.UTF_8);
stopKey = startKey.clone();
boolean isMaxVal = true;
for (int i = stopKey.length - 1; i >= 0; --i) {
Expand All @@ -848,9 +847,9 @@ private RexNode convertLikeToRange(RexCall condition, RexBuilder builder) {
// TODO: This maybe a potential bug since we assume UTF-8 encoding. However, we follow the
// current DB implementation. See HBaseFilterBuilder.createHBaseScanSpec "like" CASE statement
RexLiteral startKeyLiteral = builder.makeLiteral(new String(startKey,
Charsets.UTF_8));
StandardCharsets.UTF_8));
RexLiteral stopKeyLiteral = builder.makeLiteral(new String(stopKey,
Charsets.UTF_8));
StandardCharsets.UTF_8));
if (arg != null) {
RexNode startPred = builder.makeCall(SqlStdOperatorTable.GREATER_THAN_OR_EQUAL,
arg, startKeyLiteral);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import org.apache.hadoop.hbase.filter.RowFilter;
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;

import com.google.common.base.Charsets;

public class MapRDBFilterBuilder extends AbstractExprVisitor<HBaseScanSpec, Void, RuntimeException> implements DrillHBaseConstants {

final private BinaryTableGroupScan groupScan;
Expand Down Expand Up @@ -295,7 +293,7 @@ private HBaseScanSpec createHBaseScanSpec(FunctionCall call, MaprDBCompareFuncti
startRow = stopRow = fieldValue;
compareOp = null;
} else {
startRow = prefix.getBytes(Charsets.UTF_8);
startRow = prefix.getBytes(StandardCharsets.UTF_8);
stopRow = startRow.clone();
boolean isMaxVal = true;
for (int i = stopRow.length - 1; i >= 0; --i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.drill.exec.store.mapr.db.binary;

import com.google.common.base.Charsets;
import io.netty.buffer.ByteBuf;
import org.apache.drill.common.expression.FunctionCall;
import org.apache.drill.common.expression.LogicalExpression;
Expand Down Expand Up @@ -46,7 +45,7 @@ protected ByteBuf getByteBuf(LogicalExpression valueArg, String encodingType) {
case "UTF8_OB":
case "UTF8_OBD":
if (valueArg instanceof ValueExpressions.QuotedString) {
int stringLen = ((ValueExpressions.QuotedString) valueArg).value.getBytes(Charsets.UTF_8).length;
int stringLen = ((ValueExpressions.QuotedString) valueArg).value.getBytes(StandardCharsets.UTF_8).length;
ByteBuf bb = newByteBuf(stringLen + 2, true);
PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, stringLen + 2);
if (encodingType.endsWith("_OBD")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void eval() {
sb.append(", ").append(org.ojai.FieldPath.parseFrom(decodedPath).asPathString());
}
String outputString = "[" + sb.substring(2) + "]";
final byte[] strBytes = outputString.getBytes(com.google.common.base.Charsets.UTF_8);
final byte[] strBytes = outputString.getBytes(java.nio.charset.StandardCharsets.UTF_8);
buffer.setBytes(0, strBytes);
buffer.setIndex(0, strBytes.length);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import org.apache.drill.exec.oauth.PersistentTokenTable;
import org.apache.drill.exec.store.StoragePluginRegistry;
import org.apache.drill.exec.store.StoragePluginRegistry.PluginException;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import org.apache.drill.test.ClusterFixtureBuilder;
import org.apache.drill.test.ClusterTest;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -55,7 +55,8 @@ public class TestGoogleSheetsLimitPushdown extends ClusterTest {
@BeforeClass
public static void init() throws Exception {

String oauthJson = Files.asCharSource(DrillFileUtils.getResourceAsFile("/tokens/oauth_tokens.json"), Charsets.UTF_8).read();
String oauthJson = Files.asCharSource(DrillFileUtils.getResourceAsFile("/tokens/oauth_tokens.json"),
StandardCharsets.UTF_8).read();

ObjectMapper mapper = JacksonUtils.createObjectMapper();
Map<String,String> tokenMap = mapper.readValue(oauthJson, Map.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.drill.exec.rpc.user.QueryDataBatch;
import org.apache.drill.exec.store.StoragePluginRegistry;
import org.apache.drill.exec.store.StoragePluginRegistry.PluginException;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import org.apache.drill.test.ClusterFixtureBuilder;
import org.apache.drill.test.ClusterTest;
Expand All @@ -39,6 +38,7 @@
import org.junit.Ignore;
import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -72,7 +72,7 @@ public class TestGoogleSheetsQueries extends ClusterTest {
@BeforeClass
public static void init() throws Exception {

String oauthJson = Files.asCharSource(DrillFileUtils.getResourceAsFile("/tokens/oauth_tokens.json"), Charsets.UTF_8).read();
String oauthJson = Files.asCharSource(DrillFileUtils.getResourceAsFile("/tokens/oauth_tokens.json"), StandardCharsets.UTF_8).read();

ObjectMapper mapper = JacksonUtils.createObjectMapper();
Map<String,String> tokenMap = mapper.readValue(oauthJson, Map.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.drill.exec.record.metadata.TupleMetadata;
import org.apache.drill.exec.store.StoragePluginRegistry;
import org.apache.drill.exec.store.StoragePluginRegistry.PluginException;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import org.apache.drill.test.ClusterFixture;
import org.apache.drill.test.ClusterTest;
Expand All @@ -40,6 +39,7 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -74,7 +74,7 @@ public static void init() throws Exception {
ClusterTest.startCluster(ClusterFixture.builder(dirTestWatcher));
dirTestWatcher.copyResourceToRoot(Paths.get(""));

String oauthJson = Files.asCharSource(DrillFileUtils.getResourceAsFile("/tokens/oauth_tokens.json"), Charsets.UTF_8).read();
String oauthJson = Files.asCharSource(DrillFileUtils.getResourceAsFile("/tokens/oauth_tokens.json"), StandardCharsets.UTF_8).read();

ObjectMapper mapper = JacksonUtils.createObjectMapper();
Map<String,String> tokenMap = mapper.readValue(oauthJson, Map.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -49,7 +50,6 @@
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.PrefixFilter;

import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

Expand Down Expand Up @@ -511,7 +511,7 @@ public Boolean visitUnknown(LogicalExpression e, LogicalExpression valueArg) thr
@Override
public Boolean visitSchemaPath(SchemaPath path, LogicalExpression valueArg) throws RuntimeException {
if (valueArg instanceof QuotedString) {
this.value = ((QuotedString) valueArg).value.getBytes(Charsets.UTF_8);
this.value = ((QuotedString) valueArg).value.getBytes(StandardCharsets.UTF_8);
this.path = path;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.drill.exec.store.hbase;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

Expand All @@ -36,8 +37,6 @@
import org.apache.hadoop.hbase.filter.RowFilter;
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;

import com.google.common.base.Charsets;

public class HBaseFilterBuilder extends AbstractExprVisitor<HBaseScanSpec, Void, RuntimeException> implements DrillHBaseConstants {

final private HBaseGroupScan groupScan;
Expand Down Expand Up @@ -290,7 +289,7 @@ private HBaseScanSpec createHBaseScanSpec(FunctionCall call, CompareFunctionsPro
startRow = stopRow = fieldValue;
compareOp = null;
} else {
startRow = prefix.getBytes(Charsets.UTF_8);
startRow = prefix.getBytes(StandardCharsets.UTF_8);
stopRow = startRow.clone();
boolean isMaxVal = true;
for (int i = stopRow.length - 1; i >= 0; --i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.drill.hbase;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

import org.apache.drill.test.BaseTestQuery;
Expand All @@ -33,7 +34,6 @@
import org.junit.Assert;
import org.junit.BeforeClass;

import com.google.common.base.Charsets;
import com.google.common.io.Files;

public class BaseHBaseTest extends BaseTestQuery {
Expand Down Expand Up @@ -67,7 +67,7 @@ public static void tearDownAfterClass() throws Exception {
}

protected String getPlanText(String planFile, String tableName) throws IOException {
return Files.asCharSource(DrillFileUtils.getResourceAsFile(planFile), Charsets.UTF_8).read()
return Files.asCharSource(DrillFileUtils.getResourceAsFile(planFile), StandardCharsets.UTF_8).read()
.replaceFirst(
"\"hbase\\.zookeeper\\.property\\.clientPort\".*:.*\\d+",
"\"hbase.zookeeper.property.clientPort\" : " + HBaseTestsSuite.getZookeeperPort())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.drill.exec.vector.VarCharVector;
import org.junit.Test;

import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import org.junit.experimental.categories.Category;

Expand All @@ -62,7 +61,7 @@ protected <T> void verifyPhysicalPlan(String expression, T expectedResults) thro
expression = expression.replace("\\", "\\\\\\\\"); // "\\\\\\\\" => Java => "\\\\" => JsonParser => "\\" => AntlrParser "\"

if (textFileContent == null) {
textFileContent = Resources.toString(Resources.getResource(CONVERSION_TEST_PHYSICAL_PLAN), Charsets.UTF_8);
textFileContent = Resources.toString(Resources.getResource(CONVERSION_TEST_PHYSICAL_PLAN), StandardCharsets.UTF_8);
}
String planString = textFileContent.replace("__CONVERT_EXPRESSION__", expression);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.nio.charset.StandardCharsets;
import java.util.List;

import org.apache.drill.test.BaseTestQuery;
Expand All @@ -35,7 +36,6 @@
import org.apache.drill.exec.vector.VarCharVector;
import org.junit.Test;

import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import org.junit.experimental.categories.Category;

Expand All @@ -44,7 +44,8 @@ public class TestHiveUDFs extends BaseTestQuery {

@Test
public void testGenericUDF() throws Throwable {
String planString = Resources.toString(Resources.getResource("functions/hive/GenericUDF.json"), Charsets.UTF_8);
String planString = Resources.toString(Resources.getResource("functions/hive/GenericUDF.json"),
StandardCharsets.UTF_8);
List<QueryDataBatch> results = testPhysicalWithResults(planString);

RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
Expand Down Expand Up @@ -72,22 +73,22 @@ public void testGenericUDF() throws Throwable {
NullableVarCharVector upperNullableStr1V = (NullableVarCharVector) batchLoader.getValueAccessorById(NullableVarCharVector.class, 6).getValueVector();

for (int i=0; i<batchLoader.getRecordCount(); i++) {
String in = new String(str1V.getAccessor().get(i), Charsets.UTF_8);
String upper = new String(upperStr1V.getAccessor().get(i), Charsets.UTF_8);
String in = new String(str1V.getAccessor().get(i), StandardCharsets.UTF_8);
String upper = new String(upperStr1V.getAccessor().get(i), StandardCharsets.UTF_8);
assertTrue(in.toUpperCase().equals(upper));


String concat = new String(concatV.getAccessor().get(i), Charsets.UTF_8);
String concat = new String(concatV.getAccessor().get(i), StandardCharsets.UTF_8);
assertTrue(concat.equals(in+"-"+in));

String nullableStr1 = null;
if (!nullableStr1V.getAccessor().isNull(i)) {
nullableStr1 = new String(nullableStr1V.getAccessor().get(i), Charsets.UTF_8);
nullableStr1 = new String(nullableStr1V.getAccessor().get(i), StandardCharsets.UTF_8);
}

String upperNullableStr1 = null;
if (!upperNullableStr1V.getAccessor().isNull(i)) {
upperNullableStr1 = new String(upperNullableStr1V.getAccessor().get(i), Charsets.UTF_8);
upperNullableStr1 = new String(upperNullableStr1V.getAccessor().get(i), StandardCharsets.UTF_8);
}

assertEquals(nullableStr1 != null, upperNullableStr1 != null);
Expand All @@ -103,7 +104,7 @@ public void testGenericUDF() throws Throwable {

@Test
public void testUDF() throws Throwable {
String planString = Resources.toString(Resources.getResource("functions/hive/UDF.json"), Charsets.UTF_8);
String planString = Resources.toString(Resources.getResource("functions/hive/UDF.json"), StandardCharsets.UTF_8);
List<QueryDataBatch> results = testPhysicalWithResults(planString);

RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
Expand All @@ -128,7 +129,7 @@ public void testUDF() throws Throwable {
NullableFloat8Vector powV = (NullableFloat8Vector) batchLoader.getValueAccessorById(NullableFloat8Vector.class, 4).getValueVector();

for (int i=0; i<batchLoader.getRecordCount(); i++) {
String str1 = new String(str1V.getAccessor().get(i), Charsets.UTF_8);
String str1 = new String(str1V.getAccessor().get(i), StandardCharsets.UTF_8);
long str1Length = str1LengthV.getAccessor().get(i);
assertTrue(str1.length() == str1Length);

Expand Down
Loading

0 comments on commit bfdafd9

Please sign in to comment.