This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 0b93ff5833f replacing the TreeMap with CaseInsensitiveMap.(#28602)
(#28606)
0b93ff5833f is described below
commit 0b93ff5833f9ec47b49fba3bc8e623e80403a54c
Author: Cong Hu <[email protected]>
AuthorDate: Sun Oct 8 15:41:02 2023 +0800
replacing the TreeMap with CaseInsensitiveMap.(#28602) (#28606)
* replacing the TreeMap with CaseInsensitiveMap.(#28602)
* Optimize comment .
---
.../shardingsphere/encrypt/rule/EncryptTable.java | 6 +++---
.../apache/shardingsphere/mask/rule/MaskTable.java | 4 ++--
.../merge/ddl/ShardingDDLResultMerger.java | 4 ++--
.../merge/dql/ShardingDQLResultMerger.java | 4 ++--
.../context/segment/table/TablesContext.java | 23 ++++++++++------------
.../metadata/database/datatype/DataTypeLoader.java | 4 ++--
.../core/resultset/DatabaseMetaDataResultSet.java | 6 +++---
.../impl/BinaryOperationExpressionConverter.java | 4 ++--
.../impl/UnaryOperationExpressionConverter.java | 4 ++--
.../impl/AggregationProjectionConverter.java | 4 ++--
.../hbase/result/query/HBaseGetResultSet.java | 4 ++--
11 files changed, 32 insertions(+), 35 deletions(-)
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
index e230de7450d..871e63a5f56 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.encrypt.rule;
import lombok.Getter;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
@@ -35,14 +36,13 @@ import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
-import java.util.TreeMap;
/**
* Encrypt table.
*/
+@Getter
public final class EncryptTable {
- @Getter
private final String table;
private final Map<String, EncryptColumn> columns;
@@ -57,7 +57,7 @@ public final class EncryptTable {
@SuppressWarnings("rawtypes")
private Map<String, EncryptColumn> createEncryptColumns(final
EncryptTableRuleConfiguration config, final Map<String,
StandardEncryptAlgorithm> standardEncryptors,
final Map<String,
AssistedEncryptAlgorithm> assistedEncryptors, final Map<String,
LikeEncryptAlgorithm> likeEncryptors) {
- Map<String, EncryptColumn> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, EncryptColumn> result = new CaseInsensitiveMap<>();
for (EncryptColumnRuleConfiguration each : config.getColumns()) {
result.put(each.getName(), createEncryptColumn(each,
standardEncryptors, assistedEncryptors, likeEncryptors));
}
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTable.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTable.java
index 1e3f24ab927..3157c8196b4 100644
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTable.java
+++
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTable.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.mask.rule;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import
org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration;
import
org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
import java.util.Map;
import java.util.Optional;
-import java.util.TreeMap;
/**
* Mask table.
@@ -32,7 +32,7 @@ public final class MaskTable {
private final Map<String, MaskColumn> columns;
public MaskTable(final MaskTableRuleConfiguration config) {
- columns = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ columns = new CaseInsensitiveMap<>();
for (MaskColumnRuleConfiguration each : config.getColumns()) {
columns.put(each.getLogicColumn(), new
MaskColumn(each.getLogicColumn(), each.getMaskAlgorithm()));
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMerger.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMerger.java
index 5d0a8c33f72..2ebafed58b1 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMerger.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMerger.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.merge.ddl;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.FetchStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
@@ -34,7 +35,6 @@ import
org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
-import java.util.TreeMap;
/**
* DDL result merger for Sharding.
@@ -62,7 +62,7 @@ public final class ShardingDDLResultMerger implements
ResultMerger {
}
private Map<String, Integer> getColumnLabelIndexMap(final QueryResult
queryResult) throws SQLException {
- Map<String, Integer> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, Integer> result = new CaseInsensitiveMap<>();
for (int i = 0; i < queryResult.getMetaData().getColumnCount(); i++) {
result.put(SQLUtils.getExactlyValue(queryResult.getMetaData().getColumnLabel(i
+ 1)), i + 1);
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java
index 9fbd36d2bb5..62c9081919b 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sharding.merge.dql;
import lombok.RequiredArgsConstructor;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import
org.apache.shardingsphere.infra.binder.context.segment.select.orderby.OrderByItem;
import
org.apache.shardingsphere.infra.binder.context.segment.select.pagination.PaginationContext;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
@@ -45,7 +46,6 @@ import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.TreeMap;
/**
* DQL result merger for Sharding.
@@ -73,7 +73,7 @@ public final class ShardingDQLResultMerger implements
ResultMerger {
}
private Map<String, Integer> getColumnLabelIndexMap(final QueryResult
queryResult) throws SQLException {
- Map<String, Integer> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, Integer> result = new CaseInsensitiveMap<>();
for (int i = queryResult.getMetaData().getColumnCount(); i > 0; i--) {
result.put(SQLUtils.getExactlyValue(queryResult.getMetaData().getColumnLabel(i)),
i);
}
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java
index 09836ebed26..c83f30ce12c 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.infra.binder.context.segment.table;
import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.ToString;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import
org.apache.shardingsphere.infra.binder.context.segment.select.subquery.SubqueryTableContext;
import
org.apache.shardingsphere.infra.binder.context.segment.select.subquery.engine.SubqueryTableContextEngine;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
@@ -42,7 +43,6 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Optional;
-import java.util.TreeMap;
import java.util.TreeSet;
/**
@@ -56,6 +56,12 @@ public final class TablesContext {
private final Collection<SimpleTableSegment> simpleTableSegments = new
LinkedList<>();
+ /**
+ * Get table names.
+ *
+ * @return table names
+ */
+ @Getter
private final Collection<String> tableNames = new HashSet<>();
private final Collection<String> schemaNames = new HashSet<>();
@@ -112,15 +118,6 @@ public final class TablesContext {
return result;
}
- /**
- * Get table names.
- *
- * @return table names
- */
- public Collection<String> getTableNames() {
- return tableNames;
- }
-
/**
* Find expression table name map by column segment.
*
@@ -132,7 +129,7 @@ public final class TablesContext {
if (1 == simpleTableSegments.size()) {
return findTableNameFromSingleTableByColumnSegment(columns);
}
- Map<String, String> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, String> result = new CaseInsensitiveMap<>();
Map<String, Collection<String>> ownerColumnNames =
getOwnerColumnNamesByColumnSegment(columns);
result.putAll(findTableNameFromSQL(ownerColumnNames));
Collection<String> noOwnerColumnNames =
getNoOwnerColumnNamesByColumnSegment(columns);
@@ -163,7 +160,7 @@ public final class TablesContext {
private Map<String, String>
findTableNameFromSingleTableByColumnSegment(final Collection<ColumnSegment>
columns) {
String tableName =
simpleTableSegments.iterator().next().getTableName().getIdentifier().getValue();
- Map<String, String> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, String> result = new CaseInsensitiveMap<>();
for (ColumnSegment each : columns) {
result.putIfAbsent(each.getExpression(), tableName);
}
@@ -171,7 +168,7 @@ public final class TablesContext {
}
private Map<String, Collection<String>>
getOwnerColumnNamesByColumnSegment(final Collection<ColumnSegment> columns) {
- Map<String, Collection<String>> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, Collection<String>> result = new CaseInsensitiveMap<>();
for (ColumnSegment each : columns) {
if (!each.getOwner().isPresent()) {
continue;
diff --git
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/datatype/DataTypeLoader.java
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/datatype/DataTypeLoader.java
index 343ad397a04..7671e9f6cbd 100644
---
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/datatype/DataTypeLoader.java
+++
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/datatype/DataTypeLoader.java
@@ -17,6 +17,7 @@
package
org.apache.shardingsphere.infra.database.core.metadata.database.datatype;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
@@ -24,7 +25,6 @@ import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
-import java.util.TreeMap;
/**
* Data type loader.
@@ -46,7 +46,7 @@ public final class DataTypeLoader {
}
private Map<String, Integer> loadStandardDataTypes(final DatabaseMetaData
databaseMetaData) throws SQLException {
- Map<String, Integer> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, Integer> result = new CaseInsensitiveMap<>();
try (ResultSet resultSet = databaseMetaData.getTypeInfo()) {
while (resultSet.next()) {
result.put(resultSet.getString("TYPE_NAME"),
resultSet.getInt("DATA_TYPE"));
diff --git
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java
index 6d1c2a76822..4bbc4b180f6 100644
---
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java
+++
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java
@@ -18,9 +18,10 @@
package org.apache.shardingsphere.driver.jdbc.core.resultset;
import lombok.EqualsAndHashCode;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
+import
org.apache.shardingsphere.driver.jdbc.exception.connection.ResultSetClosedException;
import
org.apache.shardingsphere.driver.jdbc.exception.syntax.ColumnIndexOutOfRangeException;
import
org.apache.shardingsphere.driver.jdbc.exception.syntax.ColumnLabelNotFoundException;
-import
org.apache.shardingsphere.driver.jdbc.exception.connection.ResultSetClosedException;
import
org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedDatabaseMetaDataResultSet;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.util.ResultSetUtils;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -43,7 +44,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.TreeMap;
/**
* Database meta data result set.
@@ -83,7 +83,7 @@ public final class DatabaseMetaDataResultSet extends
AbstractUnsupportedDatabase
}
private Map<String, Integer> initIndexMap() throws SQLException {
- Map<String, Integer> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, Integer> result = new CaseInsensitiveMap<>();
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
result.put(resultSetMetaData.getColumnLabel(i), i);
}
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
index 82e296c97c8..2208b48e5c5 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
@@ -24,6 +24,7 @@ import org.apache.calcite.sql.SqlNodeList;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
import
org.apache.shardingsphere.sqlfederation.compiler.converter.function.dialect.mysql.SQLExtensionOperatorTable;
@@ -35,14 +36,13 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.TreeMap;
/**
* Binary operation expression converter.
*/
public final class BinaryOperationExpressionConverter implements
SQLSegmentConverter<BinaryOperationExpression, SqlNode> {
- private static final Map<String, SqlOperator> REGISTRY = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ private static final Map<String, SqlOperator> REGISTRY = new
CaseInsensitiveMap<>();
static {
register();
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/expression/impl/UnaryOperationExpressionConverter.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/expression/impl/UnaryOperationExpressionConverter.java
index 98ad1691926..4c4f65543b1 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/expression/impl/UnaryOperationExpressionConverter.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/expression/impl/UnaryOperationExpressionConverter.java
@@ -23,6 +23,7 @@ import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.UnaryOperationExpression;
import
org.apache.shardingsphere.sqlfederation.compiler.converter.function.dialect.mysql.SQLExtensionOperatorTable;
import
org.apache.shardingsphere.sqlfederation.compiler.converter.segment.SQLSegmentConverter;
@@ -32,14 +33,13 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.TreeMap;
/**
* Unary operation expression converter.
*/
public final class UnaryOperationExpressionConverter implements
SQLSegmentConverter<UnaryOperationExpression, SqlNode> {
- private static final Map<String, SqlOperator> REGISTRY = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ private static final Map<String, SqlOperator> REGISTRY = new
CaseInsensitiveMap<>();
static {
register();
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/projection/impl/AggregationProjectionConverter.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/projection/impl/AggregationProjectionConverter.java
index 7349c8ef64d..4a217f1e90a 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/projection/impl/AggregationProjectionConverter.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/converter/segment/projection/impl/AggregationProjectionConverter.java
@@ -26,6 +26,7 @@ import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlSelectKeyword;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationDistinctProjectionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment;
@@ -39,14 +40,13 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.TreeMap;
/**
* Aggregation projection converter.
*/
public final class AggregationProjectionConverter implements
SQLSegmentConverter<AggregationProjectionSegment, SqlNode> {
- private static final Map<String, SqlAggFunction> REGISTRY = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ private static final Map<String, SqlAggFunction> REGISTRY = new
CaseInsensitiveMap<>();
static {
register(SqlStdOperatorTable.MAX);
diff --git
a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseGetResultSet.java
b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseGetResultSet.java
index 278777c929b..3c1829daa41 100644
---
a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseGetResultSet.java
+++
b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseGetResultSet.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.proxy.backend.hbase.result.query;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Get;
@@ -51,7 +52,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.TreeMap;
import java.util.stream.Collectors;
/**
@@ -144,7 +144,7 @@ public final class HBaseGetResultSet implements
HBaseQueryResultSet {
}
private Map<String, String> parseResult(final Result result) {
- Map<String, String> row = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, String> row = new CaseInsensitiveMap<>();
row.put(ROW_KEY_COLUMN_NAME, Bytes.toString(result.getRow()));
Long timestamp = null;
for (Cell each : result.listCells()) {