Skip to content

Commit

Permalink
Prefer String.toLowerCase(ENGLISH) over String.toLowerCase()
Browse files Browse the repository at this point in the history
  • Loading branch information
kokosing committed Jul 9, 2018
1 parent 49be67a commit 9e828bc
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.NoSuchElementException;

import static java.lang.String.format;
Expand All @@ -35,7 +36,7 @@ public class TestingAtopFactory
@Override
public Atop create(AtopTable table, ZonedDateTime date)
{
InputStream data = TestingAtopFactory.class.getResourceAsStream(table.name().toLowerCase() + ".txt");
InputStream data = TestingAtopFactory.class.getResourceAsStream(table.name().toLowerCase(Locale.ENGLISH) + ".txt");
requireNonNull(data, format("No data found for %s", table));
return new TestingAtop(data, date);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.SortedSet;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void store(BenchmarkSchema benchmarkSchema, BenchmarkQueryResult result)
.add(NANOSECONDS.toMillis((long) result.getQueryCpuTimeNanos().getMedian()))
.add(NANOSECONDS.toMillis((long) result.getQueryCpuTimeNanos().getMean()))
.add(NANOSECONDS.toMillis((long) result.getQueryCpuTimeNanos().getStandardDeviation()))
.add(result.getStatus().toString().toLowerCase())
.add(result.getStatus().toString().toLowerCase(Locale.ENGLISH))
.add(errorMessage.orElse(""))
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void setup()
assertInstanceOf(recordSetProvider, CassandraRecordSetProvider.class);

database = keyspace;
table = new SchemaTableName(database, TABLE_ALL_TYPES.toLowerCase());
table = new SchemaTableName(database, TABLE_ALL_TYPES.toLowerCase(ENGLISH));
tableUnpartitioned = new SchemaTableName(database, "presto_test_unpartitioned");
invalidTable = new SchemaTableName(database, "totally_invalid_table_name");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

import static com.facebook.presto.hive.HiveErrorCode.HIVE_INVALID_METADATA;
Expand Down Expand Up @@ -120,7 +121,7 @@ private static void setStorageBuilder(StorageDescriptor sd, Storage.Builder stor

private static Column convertColumn(com.amazonaws.services.glue.model.Column glueColumn)
{
return new Column(glueColumn.getName(), HiveType.valueOf(glueColumn.getType().toLowerCase()), Optional.ofNullable(glueColumn.getComment()));
return new Column(glueColumn.getName(), HiveType.valueOf(glueColumn.getType().toLowerCase(Locale.ENGLISH)), Optional.ofNullable(glueColumn.getComment()));
}

public static Partition convertPartition(com.amazonaws.services.glue.model.Partition gluePartition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
Expand Down Expand Up @@ -119,7 +120,7 @@ public static PrincipalPrivilegeSet toMetastoreApiPrincipalPrivilegeSet(String g
public static PrivilegeGrantInfo toMetastoreApiPrivilegeGrantInfo(String grantee, HivePrivilegeInfo privilegeInfo)
{
return new PrivilegeGrantInfo(
privilegeInfo.getHivePrivilege().name().toLowerCase(),
privilegeInfo.getHivePrivilege().name().toLowerCase(Locale.ENGLISH),
0,
grantee,
org.apache.hadoop.hive.metastore.api.PrincipalType.USER, privilegeInfo.isGrantOption());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -182,7 +183,7 @@ public static Type getPrestoType(RichColumnDescriptor descriptor)
public static int getFieldIndex(MessageType fileSchema, String name)
{
try {
return fileSchema.getFieldIndex(name.toLowerCase());
return fileSchema.getFieldIndex(name.toLowerCase(Locale.ENGLISH));
}
catch (InvalidRecordException e) {
for (parquet.schema.Type type : fileSchema.getFields()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -120,7 +121,7 @@ public static ParquetMetadata readFooter(FSDataInputStream inputStream, Path fil
"all column chunks of the same row group must be in the same file");
ColumnMetaData metaData = columnChunk.meta_data;
String[] path = metaData.path_in_schema.stream()
.map(String::toLowerCase)
.map(value -> value.toLowerCase(Locale.ENGLISH))
.toArray(String[]::new);
ColumnPath columnPath = ColumnPath.get(path);
PrimitiveTypeName primitiveTypeName = messageType.getType(columnPath.toArray()).asPrimitiveType().getPrimitiveTypeName();
Expand Down Expand Up @@ -190,7 +191,7 @@ private static void readTypeSchema(Types.GroupBuilder<?> builder, Iterator<Schem
if (element.isSetField_id()) {
typeBuilder.id(element.field_id);
}
typeBuilder.named(element.name.toLowerCase());
typeBuilder.named(element.name.toLowerCase(Locale.ENGLISH));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import parquet.schema.Types;

import java.util.List;
import java.util.Locale;

import static parquet.schema.OriginalType.MAP_KEY_VALUE;

Expand Down Expand Up @@ -102,11 +103,11 @@ else if (typeInfo.equals(TypeInfoFactory.timestampTypeInfo)) {
else if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
throw new UnsupportedOperationException("Void type not implemented");
}
else if (typeInfo.getTypeName().toLowerCase().startsWith(
else if (typeInfo.getTypeName().toLowerCase(Locale.ENGLISH).startsWith(
serdeConstants.CHAR_TYPE_NAME)) {
return Types.optional(PrimitiveTypeName.BINARY).as(OriginalType.UTF8).named(name);
}
else if (typeInfo.getTypeName().toLowerCase().startsWith(
else if (typeInfo.getTypeName().toLowerCase(Locale.ENGLISH).startsWith(
serdeConstants.VARCHAR_TYPE_NAME)) {
return Types.optional(PrimitiveTypeName.BINARY).as(OriginalType.UTF8).named(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import parquet.schema.Types;

import java.util.List;
import java.util.Locale;

import static parquet.schema.OriginalType.MAP_KEY_VALUE;

Expand Down Expand Up @@ -103,7 +104,7 @@ else if (typeInfo.equals(TypeInfoFactory.timestampTypeInfo)) {
else if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
throw new UnsupportedOperationException("Void type not implemented");
}
else if (typeInfo.getTypeName().toLowerCase().startsWith(
else if (typeInfo.getTypeName().toLowerCase(Locale.ENGLISH).startsWith(
serdeConstants.CHAR_TYPE_NAME)) {
if (repetition == Repetition.OPTIONAL) {
return Types.optional(PrimitiveTypeName.BINARY).as(OriginalType.UTF8).named(name);
Expand All @@ -112,7 +113,7 @@ else if (typeInfo.getTypeName().toLowerCase().startsWith(
return Types.repeated(PrimitiveTypeName.BINARY).as(OriginalType.UTF8).named(name);
}
}
else if (typeInfo.getTypeName().toLowerCase().startsWith(
else if (typeInfo.getTypeName().toLowerCase(Locale.ENGLISH).startsWith(
serdeConstants.VARCHAR_TYPE_NAME)) {
if (repetition == Repetition.OPTIONAL) {
return Types.optional(PrimitiveTypeName.BINARY).as(OriginalType.UTF8).named(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import parquet.schema.Types;

import java.util.List;
import java.util.Locale;

/**
* This class is copied from org.apache.hadoop.hive.ql.io.parquet.convert.HiveSchemaConverter
Expand Down Expand Up @@ -101,7 +102,7 @@ else if (typeInfo.equals(TypeInfoFactory.timestampTypeInfo)) {
else if (typeInfo.equals(TypeInfoFactory.voidTypeInfo)) {
throw new UnsupportedOperationException("Void type not implemented");
}
else if (typeInfo.getTypeName().toLowerCase().startsWith(
else if (typeInfo.getTypeName().toLowerCase(Locale.ENGLISH).startsWith(
serdeConstants.CHAR_TYPE_NAME)) {
if (repetition == Repetition.OPTIONAL) {
return Types.optional(PrimitiveTypeName.BINARY).as(OriginalType.UTF8).named(name);
Expand All @@ -110,7 +111,7 @@ else if (typeInfo.getTypeName().toLowerCase().startsWith(
return Types.repeated(PrimitiveTypeName.BINARY).as(OriginalType.UTF8).named(name);
}
}
else if (typeInfo.getTypeName().toLowerCase().startsWith(
else if (typeInfo.getTypeName().toLowerCase(Locale.ENGLISH).startsWith(
serdeConstants.VARCHAR_TYPE_NAME)) {
if (repetition == Repetition.OPTIONAL) {
return Types.optional(PrimitiveTypeName.BINARY).as(OriginalType.UTF8).named(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand All @@ -41,7 +42,9 @@ public JmxHistoricalData(JmxConnectorConfig jmxConfig)

public JmxHistoricalData(int maxEntries, Set<String> tableNames)
{
tables = tableNames.stream().map(String::toLowerCase).collect(toSet());
tables = tableNames.stream()
.map(tableName -> tableName.toLowerCase(Locale.ENGLISH))
.collect(toSet());
for (String tableName : tables) {
tableData.put(tableName, EvictingQueue.create(maxEntries));
}
Expand All @@ -54,14 +57,14 @@ public Set<String> getTables()

public synchronized void addRow(String tableName, List<Object> row)
{
String lowerCaseTableName = tableName.toLowerCase();
String lowerCaseTableName = tableName.toLowerCase(Locale.ENGLISH);
checkArgument(tableData.containsKey(lowerCaseTableName));
tableData.get(lowerCaseTableName).add(row);
}

public synchronized List<List<Object>> getRows(String objectName, List<Integer> selectedColumns)
{
String lowerCaseObjectName = objectName.toLowerCase();
String lowerCaseObjectName = objectName.toLowerCase(Locale.ENGLISH);
if (!tableData.containsKey(lowerCaseObjectName)) {
return ImmutableList.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TestJmxMetadata
private static final SchemaTableName RUNTIME_TABLE = new SchemaTableName(JMX_SCHEMA_NAME, RUNTIME_OBJECT.toLowerCase(ENGLISH));
private static final SchemaTableName RUNTIME_HISTORY_TABLE = new SchemaTableName(HISTORY_SCHEMA_NAME, RUNTIME_OBJECT.toLowerCase(ENGLISH));

private final JmxMetadata metadata = new JmxMetadata(getPlatformMBeanServer(), new JmxHistoricalData(1000, ImmutableSet.of(RUNTIME_OBJECT.toLowerCase())));
private final JmxMetadata metadata = new JmxMetadata(getPlatformMBeanServer(), new JmxHistoricalData(1000, ImmutableSet.of(RUNTIME_OBJECT.toLowerCase(ENGLISH))));

@Test
public void testListSchemas()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.collect.ImmutableSet;
import org.testng.annotations.Test;

import java.util.Locale;
import java.util.Set;

import static com.facebook.presto.connector.informationSchema.InformationSchemaMetadata.INFORMATION_SCHEMA;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void testShowSchemas()
public void testShowTables()
{
Set<String> standardNamesLower = STANDARD_NAMES.stream()
.map(String::toLowerCase)
.map(name -> name.toLowerCase(Locale.ENGLISH))
.collect(toImmutableSet());
MaterializedResult result = computeActual("SHOW TABLES");
assertTrue(result.getOnlyColumnAsSet().containsAll(standardNamesLower));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import javax.inject.Inject;

import java.util.Locale;
import java.util.Set;

import static com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder;
Expand Down Expand Up @@ -88,7 +89,7 @@ public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, Connect
private void addRows(Builder table, Set<Node> nodes, NodeState state)
{
for (Node node : nodes) {
table.addRow(node.getNodeIdentifier(), node.getHttpUri().toString(), getNodeVersion(node), isCoordinator(node), state.toString().toLowerCase());
table.addRow(node.getNodeIdentifier(), node.getHttpUri().toString(), getNodeVersion(node), isCoordinator(node), state.toString().toLowerCase(Locale.ENGLISH));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ else if (element instanceof LikeClause) {
likeTableMetadata.getColumns().stream()
.filter(column -> !column.isHidden())
.forEach(column -> {
if (columns.containsKey(column.getName().toLowerCase())) {
if (columns.containsKey(column.getName().toLowerCase(Locale.ENGLISH))) {
throw new SemanticException(DUPLICATE_COLUMN_NAME, element, "Column name '%s' specified more than once", column.getName());
}
columns.put(column.getName().toLowerCase(), column);
columns.put(column.getName().toLowerCase(Locale.ENGLISH), column);
});
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ protected Scope visitInsert(Insert insert, Optional<Scope> scope)
if (insert.getColumns().isPresent()) {
insertColumns = insert.getColumns().get().stream()
.map(Identifier::getValue)
.map(String::toLowerCase)
.map(column -> column.toLowerCase(ENGLISH))
.collect(toImmutableList());

Set<String> columnNames = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
Expand Down Expand Up @@ -1667,7 +1668,7 @@ private Optional<Expression> removeExpressionFromFilter(Expression filter, Expre

private SpatialPredicate spatialTest(FunctionCall functionCall, boolean probeFirst, Optional<ComparisonExpressionType> comparisonType)
{
switch (functionCall.getName().toString().toLowerCase()) {
switch (functionCall.getName().toString().toLowerCase(Locale.ENGLISH)) {
case ST_CONTAINS:
if (probeFirst) {
return (buildGeometry, probeGeometry, radius) -> probeGeometry.contains(buildGeometry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
Expand Down Expand Up @@ -1258,7 +1259,7 @@ public static void parseJsonToSingleRowBlock(
if (parser.currentToken() != FIELD_NAME) {
throw new JsonCastException(format("Expected a json field name, but got %s", parser.getText()));
}
String fieldName = parser.getText().toLowerCase();
String fieldName = parser.getText().toLowerCase(Locale.ENGLISH);
Integer fieldIndex = fieldNameToIndex.get().get(fieldName);
parser.nextToken();
if (fieldIndex != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableMap;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -90,7 +91,7 @@ public Optional<SymbolReference> getOptional(String alias)
private static String toKey(String alias)
{
// Required because the SqlParser lower cases SymbolReferences in the expressions we parse with it.
return alias.toLowerCase();
return alias.toLowerCase(Locale.ENGLISH);
}

private Map<String, SymbolReference> getUpdatedAssignments(Assignments assignments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static com.facebook.presto.tests.TestGroups.STORAGE_FORMATS;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void testInsertIntoTable(StorageFormat storageFormat)
{
setSessionProperties(storageFormat);

String tableName = "storage_formats_test_insert_into_" + storageFormat.getName().toLowerCase();
String tableName = "storage_formats_test_insert_into_" + storageFormat.getName().toLowerCase(Locale.ENGLISH);

query(format("DROP TABLE IF EXISTS %s", tableName));

Expand Down Expand Up @@ -107,7 +108,7 @@ public void testCreateTableAs(StorageFormat storageFormat)
{
setSessionProperties(storageFormat);

String tableName = "storage_formats_test_create_table_as_select_" + storageFormat.getName().toLowerCase();
String tableName = "storage_formats_test_create_table_as_select_" + storageFormat.getName().toLowerCase(Locale.ENGLISH);

query(format("DROP TABLE IF EXISTS %s", tableName));

Expand All @@ -131,7 +132,7 @@ public void testInsertIntoPartitionedTable(StorageFormat storageFormat)
{
setSessionProperties(storageFormat);

String tableName = "storage_formats_test_insert_into_partitioned_" + storageFormat.getName().toLowerCase();
String tableName = "storage_formats_test_insert_into_partitioned_" + storageFormat.getName().toLowerCase(Locale.ENGLISH);

query(format("DROP TABLE IF EXISTS %s", tableName));

Expand Down Expand Up @@ -172,7 +173,7 @@ public void testCreatePartitionedTableAs(StorageFormat storageFormat)
{
setSessionProperties(storageFormat);

String tableName = "storage_formats_test_create_table_as_select_partitioned_" + storageFormat.getName().toLowerCase();
String tableName = "storage_formats_test_create_table_as_select_partitioned_" + storageFormat.getName().toLowerCase(Locale.ENGLISH);

query(format("DROP TABLE IF EXISTS %s", tableName));

Expand Down
Loading

0 comments on commit 9e828bc

Please sign in to comment.