This is an automated email from the ASF dual-hosted git repository. stoty pushed a commit to branch 4.16 in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.16 by this push: new d7d6ebd PHOENIX-6557 Fix code problems flagged by SpotBugs as High priority d7d6ebd is described below commit d7d6ebd476e536efb989637d2516ce48ce207981 Author: Istvan Toth <st...@apache.org> AuthorDate: Tue Sep 21 15:16:54 2021 +0200 PHOENIX-6557 Fix code problems flagged by SpotBugs as High priority --- .../phoenix/cache/aggcache/SpillManager.java | 2 +- .../apache/phoenix/compile/ExpressionCompiler.java | 3 ++- .../org/apache/phoenix/compile/JoinCompiler.java | 1 - .../phoenix/compile/OrderPreservingTracker.java | 3 ++- .../phoenix/compile/ServerBuildIndexCompiler.java | 2 +- .../apache/phoenix/compile/SubselectRewriter.java | 3 ++- .../phoenix/compile/TupleProjectionCompiler.java | 2 +- .../phoenix/coprocessor/MetaDataEndpointImpl.java | 7 +++-- .../coprocessor/PhoenixAccessController.java | 6 +++-- .../org/apache/phoenix/execute/BaseQueryPlan.java | 4 ++- .../org/apache/phoenix/execute/HashJoinPlan.java | 4 ++- .../apache/phoenix/expression/LikeExpression.java | 10 +++++++- .../expression/ProjectedColumnExpression.java | 2 +- .../aggregator/BaseDecimalStddevAggregator.java | 3 +-- .../aggregator/FirstLastValueServerAggregator.java | 5 ++-- .../expression/function/ArrayFillFunction.java | 2 +- .../phoenix/expression/util/regex/JONIPattern.java | 2 +- .../TrackingParallelWriterIndexCommitter.java | 2 +- .../apache/phoenix/index/PhoenixIndexCodec.java | 2 +- .../iterate/NonAggregateRegionScannerFactory.java | 2 +- .../org/apache/phoenix/jdbc/PhoenixConnection.java | 7 ++--- .../phoenix/jdbc/PhoenixPreparedStatement.java | 5 ---- .../phoenix/mapreduce/CsvBulkImportUtil.java | 7 +++-- .../phoenix/mapreduce/MultiHfileOutputFormat.java | 7 ++++- .../apache/phoenix/mapreduce/OrphanViewTool.java | 16 +++++++++--- .../phoenix/mapreduce/PhoenixInputFormat.java | 2 +- .../PhoenixServerBuildIndexInputFormat.java | 10 ++++---- .../bulkload/TargetTableRefFunctions.java | 10 ++++---- .../mapreduce/index/IndexScrutinyMapper.java | 2 +- .../mapreduce/index/IndexScrutinyTableOutput.java | 2 +- .../phoenix/mapreduce/index/IndexScrutinyTool.java | 1 - .../apache/phoenix/mapreduce/index/IndexTool.java | 2 +- .../phoenix/mapreduce/index/IndexUpgradeTool.java | 4 ++- .../index/IndexVerificationOutputRepository.java | 2 +- .../index/IndexVerificationResultRepository.java | 12 ++++----- .../index/PhoenixIndexImportDirectMapper.java | 6 +++-- .../index/PhoenixIndexImportDirectReducer.java | 2 +- .../index/PhoenixIndexPartialBuildMapper.java | 6 +++-- .../index/PhoenixServerBuildIndexMapper.java | 7 +++-- .../index/automation/PhoenixMRJobSubmitter.java | 1 - .../util/DefaultMultiViewSplitStrategy.java | 2 +- .../mapreduce/util/PhoenixConfigurationUtil.java | 4 +-- .../phoenix/monitoring/CombinableMetric.java | 6 ++--- .../phoenix/monitoring/CombinableMetricImpl.java | 2 +- .../java/org/apache/phoenix/optimize/Cost.java | 4 +-- .../apache/phoenix/parse/ChangePermsStatement.java | 3 ++- .../java/org/apache/phoenix/parse/PFunction.java | 6 +++-- .../phoenix/query/ConnectionQueryServicesImpl.java | 9 ++++--- .../query/ConnectionlessQueryServicesImpl.java | 4 --- .../phoenix/query/ITGuidePostsCacheFactory.java | 2 +- .../org/apache/phoenix/query/QueryConstants.java | 5 ++-- .../apache/phoenix/query/QueryServicesOptions.java | 2 +- .../org/apache/phoenix/schema/MetaDataClient.java | 20 ++++++++------- .../org/apache/phoenix/schema/PMetaDataImpl.java | 2 +- .../java/org/apache/phoenix/schema/PTableImpl.java | 2 +- .../apache/phoenix/schema/SequenceAllocation.java | 4 +++ .../phoenix/schema/stats/GuidePostsInfo.java | 5 ++++ .../phoenix/schema/stats/UpdateStatisticsTool.java | 5 +++- .../java/org/apache/phoenix/schema/task/Task.java | 4 +++ .../schema/tool/SchemaSynthesisProcessor.java | 7 +++-- .../org/apache/phoenix/schema/tool/SchemaTool.java | 4 +++ .../phoenix/schema/types/PArrayDataType.java | 4 +++ .../schema/types/PArrayDataTypeEncoder.java | 2 +- .../org/apache/phoenix/schema/types/PDataType.java | 8 +----- .../org/apache/phoenix/schema/types/PDecimal.java | 5 ++-- .../apache/phoenix/schema/types/PhoenixArray.java | 2 +- .../org/apache/phoenix/trace/TracingUtils.java | 8 ++++-- .../org/apache/phoenix/trace/util/NullSpan.java | 2 +- .../java/org/apache/phoenix/util/ColumnInfo.java | 5 ++-- .../java/org/apache/phoenix/util/IndexUtil.java | 3 ++- .../java/org/apache/phoenix/util/MetaDataUtil.java | 5 ++-- .../org/apache/phoenix/util/PhoenixMRJobUtil.java | 3 ++- .../org/apache/phoenix/util/PhoenixRuntime.java | 15 ++++++++--- .../java/org/apache/phoenix/util/QueryUtil.java | 2 +- .../java/org/apache/phoenix/util/SchemaUtil.java | 9 ++++--- .../java/org/apache/phoenix/util/StringUtil.java | 12 +++++++-- .../java/org/apache/phoenix/util/UpgradeUtil.java | 21 ++++++++++----- .../java/org/apache/phoenix/util/ViewUtil.java | 7 +++-- pom.xml | 4 +++ src/main/config/spotbugs/spotbugs-exclude.xml | 30 ++++++++++++++++++++++ 80 files changed, 279 insertions(+), 148 deletions(-) diff --git a/phoenix-core/src/main/java/org/apache/phoenix/cache/aggcache/SpillManager.java b/phoenix-core/src/main/java/org/apache/phoenix/cache/aggcache/SpillManager.java index 60ded75..e37691b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/cache/aggcache/SpillManager.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/cache/aggcache/SpillManager.java @@ -248,7 +248,7 @@ public class SpillManager implements Closeable { // Determines the partition, i.e. spillFile the tuple should get spilled to. private int getPartition(ImmutableBytesWritable key) { // Simple implementation hash mod numFiles - return Math.abs(key.hashCode()) % numSpillFiles; + return (int)(Math.abs((long)key.hashCode()) % numSpillFiles); } /** diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java index 0addea9..d1b44df 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java @@ -19,6 +19,7 @@ package org.apache.phoenix.compile; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.util.ArrayList; @@ -520,7 +521,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio byte[] wildcardString = new byte[pattern.length()]; byte[] wildcard = {StringUtil.MULTI_CHAR_LIKE}; StringUtil.fill(wildcardString, 0, pattern.length(), wildcard, 0, 1, false); - if (pattern.equals(new String (wildcardString))) { + if (pattern.equals(new String(wildcardString, StandardCharsets.UTF_8))) { List<Expression> compareChildren = Arrays.asList(lhs, NOT_NULL_STRING); return new ComparisonExpression(compareChildren, node.isNegate() ? CompareOp.LESS : CompareOp.GREATER_OR_EQUAL); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java index 7318e92..d195415 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java @@ -1489,7 +1489,6 @@ public class JoinCompiler { } private boolean isWildCardSelectForTable(List<AliasedNode> select, TableRef tableRef, ColumnResolver resolver) throws SQLException { - ColumnRefParseNodeVisitor visitor = new ColumnRefParseNodeVisitor(resolver, phoenixStatement.getConnection()); for (AliasedNode aliasedNode : select) { ParseNode node = aliasedNode.getNode(); if (node instanceof TableWildcardParseNode) { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/OrderPreservingTracker.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/OrderPreservingTracker.java index 80a0f42..2701a48 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/OrderPreservingTracker.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/OrderPreservingTracker.java @@ -310,7 +310,8 @@ public class OrderPreservingTracker { for (int i = 0; i < orderPreservingTrackInfos.size(); i++) { Info entry = orderPreservingTrackInfos.get(i); int pos = entry.pkPosition; - isOrderPreserving &= entry.orderPreserving != OrderPreserving.NO && + isOrderPreserving = isOrderPreserving && + entry.orderPreserving != OrderPreserving.NO && prevOrderPreserving == OrderPreserving.YES && (pos == prevPos || pos - prevSlotSpan == prevPos || diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ServerBuildIndexCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ServerBuildIndexCompiler.java index 007bb23..27e3585 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ServerBuildIndexCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ServerBuildIndexCompiler.java @@ -132,7 +132,7 @@ public class ServerBuildIndexCompiler { .get(QueryServices.INDEX_REBUILD_PAGE_SIZE_IN_ROWS); if (rebuildPageRowSize != null) { scan.setAttribute(BaseScannerRegionObserver.INDEX_REBUILD_PAGE_ROWS, - Bytes.toBytes(Long.valueOf(rebuildPageRowSize))); + Bytes.toBytes(Long.parseLong(rebuildPageRowSize))); } BaseQueryPlan.serializeViewConstantsIntoScan(scan, dataTable); addEmptyColumnToScan(scan, indexMaintainer.getDataEmptyKeyValueCF(), indexMaintainer.getEmptyKeyValueQualifier()); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/SubselectRewriter.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/SubselectRewriter.java index c3da4fb..29ddcbb 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/SubselectRewriter.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/SubselectRewriter.java @@ -512,7 +512,8 @@ public class SubselectRewriter extends ParseNodeRewriter { ParseNode node = aliasedNode.getNode(); if (node instanceof WildcardParseNode || (node instanceof TableWildcardParseNode - && ((TableWildcardParseNode) node).getTableName().equals(tableAlias))) { + && ((TableWildcardParseNode) node).getTableName().toString(). + equals(tableAlias))) { for (AliasedNode aNode : subselect.getSelect()) { String alias = aNode.getAlias(); String aliasRewrite = alias == null ? null : SchemaUtil.getColumnName(tableAlias, alias); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java index 3d9264b..2a67d8d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java @@ -150,7 +150,7 @@ public class TupleProjectionCompiler { projectedColumns.add(column); // Wildcard or FamilyWildcard will be handled by ProjectionCompiler. - if (!isWildcard && !families.contains(sourceColumn.getFamilyName())) { + if (!isWildcard && !families.contains(sourceColumn.getFamilyName().toString())) { EncodedColumnsUtil.setColumns(column, table, context.getScan()); } } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java index bd1ee73..3c317bc 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java @@ -87,6 +87,7 @@ import static org.apache.phoenix.util.ViewUtil.findAllDescendantViews; import static org.apache.phoenix.util.ViewUtil.getSystemTableForChildLinks; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.security.PrivilegedExceptionAction; import java.sql.ResultSetMetaData; import java.sql.SQLException; @@ -1721,8 +1722,10 @@ TABLE_FAMILY_BYTES, TABLE_SEQ_NUM_BYTES); byte[] colBytes = rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]; byte[] famBytes = rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]; if ((colBytes == null || colBytes.length == 0) && (famBytes != null && famBytes.length > 0)) { - byte[] sName = SchemaUtil.getSchemaNameFromFullName(famBytes).getBytes(); - byte[] tName = SchemaUtil.getTableNameFromFullName(famBytes).getBytes(); + byte[] sName = + SchemaUtil.getSchemaNameFromFullName(famBytes).getBytes(StandardCharsets.UTF_8); + byte[] tName = + SchemaUtil.getTableNameFromFullName(famBytes).getBytes(StandardCharsets.UTF_8); schemaTableNames[0] = tenantId; schemaTableNames[1] = sName; schemaTableNames[2] = tName; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java index e668137..bbe6786 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixAccessController.java @@ -69,6 +69,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.InetAddress; +import java.nio.charset.StandardCharsets; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Arrays; @@ -621,7 +622,8 @@ public class PhoenixAccessController extends BaseMetaDataEndpointObserver { && accessChecker.getAuthManager().userHasAccess(user, table, action)) { return true; } - List<UserPermission> permissionsForUser = getPermissionForUser(perms, user.getShortName().getBytes()); + List<UserPermission> permissionsForUser = getPermissionForUser(perms, + user.getShortName().getBytes(StandardCharsets.UTF_8)); if (permissionsForUser != null) { for (UserPermission permissionForUser : permissionsForUser) { if (permissionForUser.implies(action)) { return true; } @@ -739,7 +741,7 @@ public class PhoenixAccessController extends BaseMetaDataEndpointObserver { StringBuilder sb = new StringBuilder(); sb.append(" (user=").append(user != null ? user : "UNKNOWN").append(", "); sb.append("scope=").append(table == null ? "GLOBAL" : table.getNameWithNamespaceInclAsString()).append(", "); - sb.append(actions.size() > 1 ? "actions=" : "action=").append(actions != null ? actions.toString() : "") + sb.append(actions.size() > 1 ? "actions=" : "action=").append(actions.toString()) .append(")"); return sb.toString(); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java index 0db7701..d9aacd7 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java @@ -20,6 +20,7 @@ package org.apache.phoenix.execute; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.sql.ParameterMetaData; import java.sql.SQLException; import java.util.Collections; @@ -324,7 +325,8 @@ public abstract class BaseQueryPlan implements QueryPlan { ScanUtil.setTenantId(scan, tenantIdBytes); String customAnnotations = LogUtil.customAnnotationsToString(connection); - ScanUtil.setCustomAnnotations(scan, customAnnotations == null ? null : customAnnotations.getBytes()); + ScanUtil.setCustomAnnotations(scan, customAnnotations == null ? null + : customAnnotations.getBytes(StandardCharsets.UTF_8)); // Set local index related scan attributes. if (table.getIndexType() == IndexType.LOCAL) { ScanUtil.setLocalIndex(scan); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java index c1a3b1d..25d9fb3 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java @@ -23,6 +23,7 @@ import static org.apache.phoenix.util.NumberUtil.add; import static org.apache.phoenix.util.NumberUtil.getMin; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; @@ -542,7 +543,8 @@ public class HashJoinPlan extends DelegateQueryPlan { final byte[] cacheId; String queryString = plan.getStatement().toString().replaceAll("\\$[0-9]+", "\\$"); if (usePersistentCache) { - cacheId = Arrays.copyOfRange(digest.digest(queryString.getBytes()), 0, 8); + cacheId = Arrays.copyOfRange(digest.digest( + queryString.getBytes(StandardCharsets.UTF_8)), 0, 8); boolean retrying = parent.delegate.getContext().getRetryingPersistentCache(Bytes.toLong(cacheId)); if (!retrying) { try { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java index e68bff0..6386a23 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java @@ -56,13 +56,21 @@ public abstract class LikeExpression extends BaseCompoundExpression { private static final String ZERO_OR_MORE = "\\E.*\\Q"; private static final String ANY_ONE = "\\E.\\Q"; + private static final String[] LIKE_ESCAPE_SEQS; + private static final String[] LIKE_UNESCAPED_SEQS; + + static { + LIKE_ESCAPE_SEQS = StringUtil.getLikeEscapeSeqs(); + LIKE_UNESCAPED_SEQS = StringUtil.getLikeUnescapedSeqs(); + } + /** * Store whether this like expression has to be case sensitive or not. */ private LikeType likeType; public static String unescapeLike(String s) { - return StringUtil.replace(s, StringUtil.LIKE_ESCAPE_SEQS, StringUtil.LIKE_UNESCAPED_SEQS); + return StringUtil.replace(s, LIKE_ESCAPE_SEQS, LIKE_UNESCAPED_SEQS); } /** diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java index 52db52c..21eb2fe 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java @@ -35,7 +35,7 @@ import org.apache.phoenix.schema.tuple.Tuple; import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.SchemaUtil; -public class ProjectedColumnExpression extends ColumnExpression { +public class ProjectedColumnExpression extends ColumnExpression implements Cloneable { private KeyValueSchema schema; private ValueBitSet bitSet; private int position; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseDecimalStddevAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseDecimalStddevAggregator.java index 38c3060..0583f35 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseDecimalStddevAggregator.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseDecimalStddevAggregator.java @@ -71,8 +71,7 @@ public abstract class BaseDecimalStddevAggregator extends DistinctValueWithCount } BigDecimal result = new BigDecimal(Math.sqrt(ssd.doubleValue()), new MathContext(resultPrecision, RoundingMode.HALF_UP)); - result.setScale(this.colScale, RoundingMode.HALF_UP); - cachedResult = result; + cachedResult = result.setScale(this.colScale, RoundingMode.HALF_UP); } if (buffer == null) { initBuffer(); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueServerAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueServerAggregator.java index f647c45..298877e 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueServerAggregator.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueServerAggregator.java @@ -18,6 +18,7 @@ package org.apache.phoenix.expression.aggregator; import java.io.IOException; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.TreeMap; @@ -141,11 +142,11 @@ public class FirstLastValueServerAggregator extends BaseAggregator { + " is ascending: " + isAscending + " value="); if (useOffset) { for (byte[] key : topValues.keySet()) { - out.append(topValues.get(key)); + out.append(Arrays.asList(topValues.get(key))); } out.append(" offset = ").append(offset); } else { - out.append(topValue); + out.append(Arrays.asList(topValue)); } return out.toString(); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayFillFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayFillFunction.java index c8db7f9..996be3d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayFillFunction.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayFillFunction.java @@ -59,7 +59,7 @@ public class ArrayFillFunction extends ScalarFunction { Arrays.fill(elements, element); PhoenixArray array = PDataType.instantiatePhoenixArray(getElementExpr().getDataType(), elements); //When max length of a char array is not the max length of the element passed in - if (getElementExpr().getDataType().isFixedWidth() && getMaxLength() != null && getMaxLength() != array.getMaxLength()) { + if (getElementExpr().getDataType().isFixedWidth() && getMaxLength() != null && !getMaxLength().equals(array.getMaxLength())) { array = new PhoenixArray(array, getMaxLength()); } ptr.set(((PArrayDataType) getDataType()).toBytes(array, getElementExpr().getDataType(), getElementExpr().getSortOrder())); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java index 0ac33af..d9bb54d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java @@ -52,7 +52,7 @@ public class JONIPattern extends AbstractBasePattern implements AbstractBaseSpli public JONIPattern(String patternString, int flags, Encoding coding) { this.patternString = patternString; if (patternString != null) { - byte[] bytes = patternString.getBytes(); + byte[] bytes = patternString.getBytes(coding.getCharset()); pattern = new Regex(bytes, 0, bytes.length, flags, coding, Syntax.Java); } else { pattern = null; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/TrackingParallelWriterIndexCommitter.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/TrackingParallelWriterIndexCommitter.java index 9e40a2f..238461c 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/TrackingParallelWriterIndexCommitter.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/TrackingParallelWriterIndexCommitter.java @@ -254,7 +254,7 @@ public class TrackingParallelWriterIndexCommitter implements IndexCommitter { throw exception; } else { exception = new MultiIndexWriteFailureException(Collections.unmodifiableList(failedTables), - disableIndexOnFailure && PhoenixIndexFailurePolicy.getDisableIndexOnFailure(env), cause); + false, cause); throw wrapInDoNotRetryIOException("At least one index write failed after retries", exception, EnvironmentEdgeManager.currentTimeMillis()); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java index 93c300b..9630a0f 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java @@ -44,7 +44,7 @@ public class PhoenixIndexCodec extends BaseIndexCodec { public static final String INDEX_PROTO_MD = "IdxProtoMD"; public static final String INDEX_UUID = "IdxUUID"; public static final String INDEX_MAINTAINERS = "IndexMaintainers"; - public static KeyValueBuilder KV_BUILDER = GenericKeyValueBuilder.INSTANCE; + public static final KeyValueBuilder KV_BUILDER = GenericKeyValueBuilder.INSTANCE; private byte[] tableName; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/NonAggregateRegionScannerFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/NonAggregateRegionScannerFactory.java index 0f544ce..e258e2a 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/NonAggregateRegionScannerFactory.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/NonAggregateRegionScannerFactory.java @@ -138,7 +138,7 @@ public class NonAggregateRegionScannerFactory extends RegionScannerFactory { } int clientVersion = ScanUtil.getClientVersion(scan); List<IndexMaintainer> indexMaintainers = - localIndexBytes == null ? null : IndexMaintainer.deserialize(localIndexBytes, useProto); + IndexMaintainer.deserialize(localIndexBytes, useProto); indexMaintainer = indexMaintainers.get(0); viewConstants = IndexUtil.deserializeViewConstantsFromScan(scan); byte[] txState = scan.getAttribute(BaseScannerRegionObserver.TX_STATE); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java index 4cfd8ae..8ce95e0 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java @@ -174,6 +174,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea private LogLevel logLevel; private Double logSamplingRate; private String sourceOfOperation; + private static final String[] CONNECTION_PROPERTIES; private final ConcurrentLinkedQueue<PhoenixConnection> childConnections = new ConcurrentLinkedQueue<>(); @@ -184,6 +185,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea static { Tracing.addTraceMetricsSource(); + CONNECTION_PROPERTIES = PhoenixRuntime.getConnectionProperties(); } private static Properties newPropsWithSCN(long scn, Properties props) { @@ -263,8 +265,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea } // Copy so client cannot change - this.info = info == null ? new Properties() : PropertiesUtil - .deepCopy(info); + this.info = PropertiesUtil.deepCopy(info); final PName tenantId = JDBCUtil.getTenantId(url, info); if (this.info.isEmpty() && tenantId == null) { this.services = services; @@ -434,7 +435,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea private static Properties filterKnownNonProperties(Properties info) { Properties prunedProperties = info; - for (String property : PhoenixRuntime.CONNECTION_PROPERTIES) { + for (String property : CONNECTION_PROPERTIES) { if (info.containsKey(property)) { if (prunedProperties == info) { prunedProperties = PropertiesUtil.deepCopy(info); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java index b54efc8..980a82d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java @@ -124,11 +124,6 @@ public class PhoenixPreparedStatement extends PhoenixStatement implements Prepar parameterCount + " bind parameters are defined") .build().buildException(); } - if (parameterIndex < 1) { - throw new SQLExceptionInfo.Builder(SQLExceptionCode.PARAM_INDEX_OUT_OF_BOUND) - .setMessage("Invalid bind parameter index " + parameterIndex) - .build().buildException(); - } this.parameters.set(parameterIndex - 1, value); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/CsvBulkImportUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/CsvBulkImportUtil.java index 7d21325..5fd60e6 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/CsvBulkImportUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/CsvBulkImportUtil.java @@ -17,6 +17,9 @@ */ package org.apache.phoenix.mapreduce; + +import java.nio.charset.StandardCharsets; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.util.Base64; @@ -69,7 +72,7 @@ public class CsvBulkImportUtil { @VisibleForTesting static void setChar(Configuration conf, String confKey, Character charValue) { if(charValue!=null) { - conf.set(confKey, Base64.encodeBytes(charValue.toString().getBytes())); + conf.set(confKey, Base64.encodeBytes(charValue.toString().getBytes(StandardCharsets.UTF_8))); } } @@ -79,7 +82,7 @@ public class CsvBulkImportUtil { if (strValue == null) { return null; } - return new String(Base64.decode(strValue)).charAt(0); + return new String(Base64.decode(strValue), StandardCharsets.UTF_8).charAt(0); } public static Path getOutputPath(Path outputdir, String tableName) { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/MultiHfileOutputFormat.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/MultiHfileOutputFormat.java index 5394d59..e13fa5e 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/MultiHfileOutputFormat.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/MultiHfileOutputFormat.java @@ -22,6 +22,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.Collection; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import java.util.Set; @@ -73,6 +74,8 @@ import org.apache.phoenix.util.EnvironmentEdgeManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import edu.umd.cs.findbugs.annotations.SuppressWarnings; + import org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting; import org.apache.phoenix.thirdparty.com.google.common.collect.Maps; import org.apache.phoenix.thirdparty.com.google.common.collect.Sets; @@ -436,7 +439,7 @@ public class MultiHfileOutputFormat extends FileOutputFormat<TableRowkeyPair, Ce continue; } try { - confValMap.put(URLDecoder.decode(familySplit[0], "UTF-8").getBytes(), + confValMap.put(URLDecoder.decode(familySplit[0], "UTF-8").getBytes(StandardCharsets.UTF_8), URLDecoder.decode(familySplit[1], "UTF-8")); } catch (UnsupportedEncodingException e) { // will not happen with UTF-8 encoding @@ -467,6 +470,8 @@ public class MultiHfileOutputFormat extends FileOutputFormat<TableRowkeyPair, Ce TotalOrderPartitioner.setPartitionFile(conf, partitionsPath); } + @SuppressWarnings(value="EC_ARRAY_AND_NONARRAY", + justification="ImmutableBytesWritable DOES implement equals(byte])") private static void writePartitions(Configuration conf, Path partitionsPath, Set<TableRowkeyPair> tablesStartKeys) throws IOException { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java index ce5c25a..3acfb0c 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java @@ -31,9 +31,14 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -229,7 +234,7 @@ public class OrphanViewTool extends Configured implements Tool { IDENTIFY_ORPHAN_VIEWS_OPTION.getOpt() + " or " + CLEAN_ORPHAN_VIEWS_OPTION.getOpt()); } if (cmdLine.hasOption(AGE_OPTION.getOpt())) { - ageMs = Long.valueOf(cmdLine.getOptionValue(AGE_OPTION.getOpt())); + ageMs = Long.parseLong(cmdLine.getOptionValue(AGE_OPTION.getOpt())); } outputPath = cmdLine.getOptionValue(OUTPUT_PATH_OPTION.getOpt()); @@ -769,7 +774,8 @@ public class OrphanViewTool extends Configured implements Tool { private void readOrphanViews() throws Exception { String aLine; - reader[VIEW] = new BufferedReader(new FileReader(inputPath + fileName[VIEW])); + reader[VIEW] = new BufferedReader(new InputStreamReader( + new FileInputStream(inputPath + fileName[VIEW]), StandardCharsets.UTF_8)); while ((aLine = reader[VIEW].readLine()) != null) { Key key = new Key(aLine); orphanViewSet.put(key, new View(key)); @@ -779,7 +785,8 @@ public class OrphanViewTool extends Configured implements Tool { private void readAndRemoveOrphanLinks(PhoenixConnection phoenixConnection) throws Exception{ String aLine; for (byte i = VIEW+1; i < ORPHAN_TYPE_COUNT; i++) { - reader[i] = new BufferedReader(new FileReader(inputPath + fileName[i])); + reader[i] = new BufferedReader(new InputStreamReader( + new FileInputStream(inputPath + fileName[i]), StandardCharsets.UTF_8)); while ((aLine = reader[i].readLine()) != null) { String ends[] = aLine.split("-->"); removeLink(phoenixConnection, new Key(ends[0]), new Key(ends[1]), getLinkType(i)); @@ -842,7 +849,8 @@ public class OrphanViewTool extends Configured implements Tool { file.delete(); } file.createNewFile(); - writer[i] = new BufferedWriter(new FileWriter(file)); + writer[i] = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(file), StandardCharsets.UTF_8)); } } Properties props = new Properties(); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/PhoenixInputFormat.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/PhoenixInputFormat.java index 77b3a0b..12aed00 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/PhoenixInputFormat.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/PhoenixInputFormat.java @@ -205,7 +205,7 @@ public class PhoenixInputFormat<T extends DBWritable> extends InputFormat<NullWr // since we can't set a scn on connections with txn set TX_SCN attribute so that the max time range is set by BaseScannerRegionObserver if (txnScnValue != null) { - scan.setAttribute(BaseScannerRegionObserver.TX_SCN, Bytes.toBytes(Long.valueOf(txnScnValue))); + scan.setAttribute(BaseScannerRegionObserver.TX_SCN, Bytes.toBytes(Long.parseLong(txnScnValue))); } // setting the snapshot configuration diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/PhoenixServerBuildIndexInputFormat.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/PhoenixServerBuildIndexInputFormat.java index 536f889..1052b30 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/PhoenixServerBuildIndexInputFormat.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/PhoenixServerBuildIndexInputFormat.java @@ -150,15 +150,15 @@ public class PhoenixServerBuildIndexInputFormat<T extends DBWritable> extends Ph try (final Connection connection = ConnectionUtil.getInputConnection(configuration, overridingProps)) { PhoenixConnection phoenixConnection = connection.unwrap(PhoenixConnection.class); - Long scn = (currentScnValue != null) ? Long.valueOf(currentScnValue) : EnvironmentEdgeManager.currentTimeMillis(); + Long scn = (currentScnValue != null) ? Long.parseLong(currentScnValue) : EnvironmentEdgeManager.currentTimeMillis(); setCurrentScnValue(configuration, scn); - Long startTime = (startTimeValue == null) ? 0L : Long.valueOf(startTimeValue); + Long startTime = (startTimeValue == null) ? 0L : Long.parseLong(startTimeValue); queryPlan = queryPlanBuilder.getQueryPlan(phoenixConnection, dataTableFullName, indexTableFullName); Scan scan = queryPlan.getContext().getScan(); - Long lastVerifyTimeValue = lastVerifyTime == null ? 0L : Long.valueOf(lastVerifyTime); + Long lastVerifyTimeValue = lastVerifyTime == null ? 0L : Long.parseLong(lastVerifyTime); try { scan.setTimeRange(startTime, scn); scan.setAttribute(BaseScannerRegionObserver.INDEX_REBUILD_PAGING, TRUE_BYTES); @@ -167,7 +167,7 @@ public class PhoenixServerBuildIndexInputFormat<T extends DBWritable> extends Ph configuration.get(QueryServices.INDEX_REBUILD_PAGE_SIZE_IN_ROWS); if (rebuildPageRowSize != null) { scan.setAttribute(BaseScannerRegionObserver.INDEX_REBUILD_PAGE_ROWS, - Bytes.toBytes(Long.valueOf(rebuildPageRowSize))); + Bytes.toBytes(Long.parseLong(rebuildPageRowSize))); } scan.setAttribute(BaseScannerRegionObserver.INDEX_REBUILD_VERIFY_TYPE, getIndexVerifyType(configuration).toBytes()); scan.setAttribute(BaseScannerRegionObserver.INDEX_RETRY_VERIFY, Bytes.toBytes(lastVerifyTimeValue)); @@ -184,7 +184,7 @@ public class PhoenixServerBuildIndexInputFormat<T extends DBWritable> extends Ph } // since we can't set a scn on connections with txn set TX_SCN attribute so that the max time range is set by BaseScannerRegionObserver if (txnScnValue != null) { - scan.setAttribute(BaseScannerRegionObserver.TX_SCN, Bytes.toBytes(Long.valueOf(txnScnValue))); + scan.setAttribute(BaseScannerRegionObserver.TX_SCN, Bytes.toBytes(Long.parseLong(txnScnValue))); } return queryPlan; } catch (Exception exception) { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/bulkload/TargetTableRefFunctions.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/bulkload/TargetTableRefFunctions.java index 2ff120c..b087a1a 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/bulkload/TargetTableRefFunctions.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/bulkload/TargetTableRefFunctions.java @@ -32,7 +32,7 @@ import org.apache.phoenix.thirdparty.com.google.common.collect.Lists; */ public class TargetTableRefFunctions { - public static Function<TargetTableRef,String> TO_JSON = new Function<TargetTableRef,String>() { + public static final Function<TargetTableRef,String> TO_JSON = new Function<TargetTableRef,String>() { @Override public String apply(TargetTableRef input) { @@ -45,7 +45,7 @@ public class TargetTableRefFunctions { } }; - public static Function<String,TargetTableRef> FROM_JSON = new Function<String,TargetTableRef>() { + public static final Function<String,TargetTableRef> FROM_JSON = new Function<String,TargetTableRef>() { @Override public TargetTableRef apply(String json) { @@ -58,7 +58,7 @@ public class TargetTableRefFunctions { } }; - public static Function<List<TargetTableRef>,String> NAMES_TO_JSON = new Function<List<TargetTableRef>,String>() { + public static final Function<List<TargetTableRef>,String> NAMES_TO_JSON = new Function<List<TargetTableRef>,String>() { @Override public String apply(List<TargetTableRef> input) { @@ -75,7 +75,7 @@ public class TargetTableRefFunctions { } }; - public static Function<List<TargetTableRef>,String> LOGICAL_NAMES_TO_JSON = new Function<List<TargetTableRef>,String>() { + public static final Function<List<TargetTableRef>,String> LOGICAL_NAMES_TO_JSON = new Function<List<TargetTableRef>,String>() { @Override public String apply(List<TargetTableRef> input) { @@ -92,7 +92,7 @@ public class TargetTableRefFunctions { } }; - public static Function<String,List<String>> NAMES_FROM_JSON = new Function<String,List<String>>() { + public static final Function<String,List<String>> NAMES_FROM_JSON = new Function<String,List<String>>() { @SuppressWarnings("unchecked") @Override diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyMapper.java index 559e823..6be30f9 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyMapper.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyMapper.java @@ -112,7 +112,7 @@ public class IndexScrutinyMapper extends Mapper<NullWritable, PhoenixIndexDBWrit final Properties overrideProps = new Properties(); String scn = configuration.get(PhoenixConfigurationUtil.CURRENT_SCN_VALUE); overrideProps.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, scn); - scnTimestamp = new Long(scn); + scnTimestamp = Long.parseLong(scn); connection = ConnectionUtil.getOutputConnection(configuration, overrideProps); connection.setAutoCommit(false); batchSize = PhoenixConfigurationUtil.getScrutinyBatchSize(configuration); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTableOutput.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTableOutput.java index b2075dc..6a2aa90 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTableOutput.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTableOutput.java @@ -54,7 +54,7 @@ public class IndexScrutinyTableOutput { * This table holds the invalid rows in the source table (either missing a target, or a bad * covered column value). Dynamic columns hold the original source and target table column data. */ - public static String OUTPUT_TABLE_NAME = "PHOENIX_INDEX_SCRUTINY"; + public static final String OUTPUT_TABLE_NAME = "PHOENIX_INDEX_SCRUTINY"; public static final String SCRUTINY_EXECUTE_TIME_COL_NAME = "SCRUTINY_EXECUTE_TIME"; public static final String TARGET_TABLE_COL_NAME = "TARGET_TABLE"; public static final String SOURCE_TABLE_COL_NAME = "SOURCE_TABLE"; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTool.java index 15a9869..4d3b6cd 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTool.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyTool.java @@ -323,7 +323,6 @@ public class IndexScrutinyTool extends Configured implements Tool { // root dir not a subdirectory of hbase dir Path rootDir = new Path("hdfs:///index-snapshot-dir"); FSUtils.setRootDir(configuration, rootDir); - Path restoreDir = new Path(FSUtils.getRootDir(configuration), "restore-dir"); // set input for map reduce job using hbase snapshots //PhoenixMapReduceUtil.setInput(job, PhoenixIndexDBWritable.class, snapshotName, diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java index 38ae045..7590f6b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java @@ -565,7 +565,7 @@ public class IndexTool extends Configured implements Tool { if (pDataTable.isTransactional()) { long maxTimeRange = pDataTable.getTimeStamp() + 1; scan.setAttribute(BaseScannerRegionObserver.TX_SCN, - Bytes.toBytes(Long.valueOf(Long.toString(TransactionUtil.convertToNanoseconds(maxTimeRange))))); + Bytes.toBytes(TransactionUtil.convertToNanoseconds(maxTimeRange))); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java index d55d10f..c44dbd7 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java @@ -65,6 +65,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.phoenix.util.SchemaUtil; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.sql.Connection; @@ -318,7 +319,8 @@ public class IndexUpgradeTool extends Configured implements Tool { prop.put(NonTxIndexBuilder.CODEC_CLASS_NAME_KEY, PhoenixIndexCodec.class.getName()); if (inputTables == null) { - inputTables = new String(Files.readAllBytes(Paths.get(inputFile))); + inputTables = new String( + Files.readAllBytes(Paths.get(inputFile)), StandardCharsets.UTF_8); } if (inputTables == null) { LOGGER.severe("Tables' list is not available; use -tb or -f option"); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java index feab6cf..6383d9c 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java @@ -75,7 +75,7 @@ public class IndexVerificationOutputRepository implements AutoCloseable { public static final String ERROR_TYPE = "ErrorType"; public static final byte[] ERROR_TYPE_BYTES = Bytes.toBytes(ERROR_TYPE); - public static String VERIFICATION_PHASE = "Phase"; + public static final String VERIFICATION_PHASE = "Phase"; public final static byte[] VERIFICATION_PHASE_BYTES = Bytes.toBytes(VERIFICATION_PHASE); public final static String EXPECTED_VALUE = "ExpectedValue"; public final static byte[] EXPECTED_VALUE_BYTES = Bytes.toBytes(EXPECTED_VALUE); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java index de25606..ec5c505 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java @@ -111,14 +111,14 @@ public class IndexVerificationResultRepository implements AutoCloseable { public final static byte[] AFTER_REBUILD_BEYOND_MAXLOOKBACK_INVALID_INDEX_ROW_COUNT_BYTES = Bytes.toBytes(AFTER_REBUILD_BEYOND_MAXLOOKBACK_INVALID_INDEX_ROW_COUNT); - public static String BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS = "BeforeRebuildInvalidIndexRowCountCozExtraCells"; - public final static byte[] BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS_BYTES = Bytes.toBytes(BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS); - public static String BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS = "BeforeRebuildInvalidIndexRowCountCozMissingCells"; - public final static byte[] BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS_BYTES = Bytes.toBytes(BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS); + public final static String BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS = "BeforeRebuildInvalidIndexRowCountCozExtraCells"; + public final static byte[] BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS_BYTES = Bytes.toBytes(BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS); + public final static String BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS = "BeforeRebuildInvalidIndexRowCountCozMissingCells"; + public final static byte[] BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS_BYTES = Bytes.toBytes(BEFORE_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS); - public static String AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS = "AfterRebuildInvalidIndexRowCountCozExtraCells"; + public final static String AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS = "AfterRebuildInvalidIndexRowCountCozExtraCells"; public final static byte[] AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS_BYTES = Bytes.toBytes(AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_EXTRA_CELLS); - public static String AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS = "AfterRebuildInvalidIndexRowCountCozMissingCells"; + public final static String AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS = "AfterRebuildInvalidIndexRowCountCozMissingCells"; public final static byte[] AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS_BYTES = Bytes.toBytes(AFTER_REBUILD_INVALID_INDEX_ROW_COUNT_COZ_MISSING_CELLS); public final static String BEFORE_REPAIR_EXTRA_VERIFIED_INDEX_ROW_COUNT = "BeforeRepairExtraVerifiedIndexRowCount"; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectMapper.java index eca3a9e..d4c9798 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectMapper.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectMapper.java @@ -18,6 +18,7 @@ package org.apache.phoenix.mapreduce.index; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -172,8 +173,9 @@ public class PhoenixIndexImportDirectMapper extends } // We are writing some dummy key-value as map output here so that we commit only one // output to reducer. - context.write(new ImmutableBytesWritable(UUID.randomUUID().toString().getBytes()), - new IntWritable(0)); + context.write(new ImmutableBytesWritable( + UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)), + new IntWritable(0)); super.cleanup(context); } catch (SQLException e) { LOGGER.error(" Error {} while read/write of a record ", e.getMessage()); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectReducer.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectReducer.java index ab13729..2724990 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectReducer.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectReducer.java @@ -63,7 +63,7 @@ public class PhoenixIndexImportDirectReducer extends throws IOException { Configuration configuration = context.getConfiguration(); try (final Connection connection = ConnectionUtil.getInputConnection(configuration)) { - long ts = Long.valueOf(configuration.get(PhoenixConfigurationUtil.CURRENT_SCN_VALUE)); + long ts = Long.parseLong(configuration.get(PhoenixConfigurationUtil.CURRENT_SCN_VALUE)); IndexToolVerificationResult verificationResult = resultRepository.getVerificationResult(connection, ts, indexTableNameBytes); context.getCounter(PhoenixIndexToolJobCounters.SCANNED_DATA_ROW_COUNT). diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexPartialBuildMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexPartialBuildMapper.java index 8a2d13f..1ecd514 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexPartialBuildMapper.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexPartialBuildMapper.java @@ -18,6 +18,7 @@ package org.apache.phoenix.mapreduce.index; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.sql.SQLException; import java.util.List; import java.util.Properties; @@ -164,8 +165,9 @@ public class PhoenixIndexPartialBuildMapper extends TableMapper<ImmutableBytesWr } // We are writing some dummy key-value as map output here so that we commit only one // output to reducer. - context.write(new ImmutableBytesWritable(UUID.randomUUID().toString().getBytes()), - new IntWritable(0)); + context.write(new ImmutableBytesWritable( + UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)), + new IntWritable(0)); super.cleanup(context); } catch (SQLException e) { LOGGER.error(" Error {} while read/write of a record ", e.getMessage()); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixServerBuildIndexMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixServerBuildIndexMapper.java index 7a75cf6..8cdcb6a 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixServerBuildIndexMapper.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixServerBuildIndexMapper.java @@ -18,6 +18,7 @@ package org.apache.phoenix.mapreduce.index; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.UUID; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; @@ -41,7 +42,7 @@ public class PhoenixServerBuildIndexMapper extends String rebuildPageRowSizeConf = context.getConfiguration().get(QueryServices.INDEX_REBUILD_PAGE_SIZE_IN_ROWS); if (rebuildPageRowSizeConf != null) { - this.rebuildPageRowSize = Long.valueOf(rebuildPageRowSizeConf); + this.rebuildPageRowSize = Long.parseLong(rebuildPageRowSizeConf); } else { this.rebuildPageRowSize = -1L; } @@ -63,7 +64,9 @@ public class PhoenixServerBuildIndexMapper extends @Override protected void cleanup(Context context) throws IOException, InterruptedException { - context.write(new ImmutableBytesWritable(UUID.randomUUID().toString().getBytes()), new IntWritable(0)); + context.write(new ImmutableBytesWritable( + UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)), + new IntWritable(0)); super.cleanup(context); } } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java index 06a334d..f77fd9f 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java @@ -298,7 +298,6 @@ public class PhoenixMRJobSubmitter { toScheduleJobs.remove(candidateJobs.get(jobId)); } } - toScheduleJobs.removeAll(submittedJobs); return toScheduleJobs; } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/DefaultMultiViewSplitStrategy.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/DefaultMultiViewSplitStrategy.java index 79808ca..62e5150 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/DefaultMultiViewSplitStrategy.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/DefaultMultiViewSplitStrategy.java @@ -55,7 +55,7 @@ public class DefaultMultiViewSplitStrategy implements MultiViewSplitStrategy { */ public int getNumberOfMappers(int viewSize, int numViewsInSplit) { int numberOfMappers = viewSize / numViewsInSplit; - if (Math.ceil(viewSize % numViewsInSplit) > 0) { + if (viewSize % numViewsInSplit > 0) { numberOfMappers++; } return numberOfMappers; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java index 2a95b9a..131b573 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java @@ -457,7 +457,7 @@ public final class PhoenixConfigurationUtil { public static int getMultiViewQueryMoreSplitSize(final Configuration configuration) { final String batchSize = configuration.get(MAPREDUCE_MULTI_INPUT_QUERY_BATCH_SIZE); Preconditions.checkNotNull(batchSize); - return Integer.valueOf(batchSize); + return Integer.parseInt(batchSize); } public static List<ColumnInfo> getSelectColumnMetadataList(final Configuration configuration) throws SQLException { @@ -487,7 +487,7 @@ public final class PhoenixConfigurationUtil { public static int getMultiViewSplitSize(final Configuration configuration) { final String splitSize = configuration.get(MAPREDUCE_MULTI_INPUT_MAPPER_SPLIT_SIZE); Preconditions.checkNotNull(splitSize); - return Integer.valueOf(splitSize); + return Integer.parseInt(splitSize); } private static List<String> getSelectColumnList( diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetric.java b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetric.java index 103fd14..07cd25d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetric.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetric.java @@ -17,8 +17,6 @@ */ package org.apache.phoenix.monitoring; - - /** * Interface for representing a metric that could be published and possibly combined with a metric of the same * type. @@ -31,9 +29,9 @@ public interface CombinableMetric extends Metric { CombinableMetric clone(); - public class NoOpRequestMetric implements CombinableMetric { + public class NoOpRequestMetric implements CombinableMetric, Cloneable { - public static NoOpRequestMetric INSTANCE = new NoOpRequestMetric(); + public static final NoOpRequestMetric INSTANCE = new NoOpRequestMetric(); private static final String EMPTY_STRING = ""; @Override diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetricImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetricImpl.java index bd22418..40cb516 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetricImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetricImpl.java @@ -17,7 +17,7 @@ */ package org.apache.phoenix.monitoring; -public class CombinableMetricImpl implements CombinableMetric { +public class CombinableMetricImpl implements CombinableMetric, Cloneable { private final Metric metric; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/optimize/Cost.java b/phoenix-core/src/main/java/org/apache/phoenix/optimize/Cost.java index b83f354..788e4b9 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/Cost.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/Cost.java @@ -26,7 +26,7 @@ import java.util.Objects; */ public class Cost implements Comparable<Cost> { /** The unknown cost. */ - public static Cost UNKNOWN = new Cost(Double.NaN, Double.NaN, Double.NaN) { + public static final Cost UNKNOWN = new Cost(Double.NaN, Double.NaN, Double.NaN) { @Override public String toString() { return "{unknown}"; @@ -34,7 +34,7 @@ public class Cost implements Comparable<Cost> { }; /** The zero cost. */ - public static Cost ZERO = new Cost(0, 0, 0) { + public static final Cost ZERO = new Cost(0, 0, 0) { @Override public String toString() { return "{zero}"; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ChangePermsStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ChangePermsStatement.java index 0eae26f..b49183d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ChangePermsStatement.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ChangePermsStatement.java @@ -23,6 +23,7 @@ import org.apache.phoenix.exception.PhoenixParserException; import org.apache.phoenix.jdbc.PhoenixStatement; import org.apache.phoenix.util.SchemaUtil; +import java.nio.charset.StandardCharsets; import java.util.Arrays; /** @@ -44,7 +45,7 @@ public class ChangePermsStatement implements BindableStatement { // To comply with SQL standards, we may support the user given permissions to revoke specific permissions in future. // GRANT permissions statement requires this parameter and the parsing will fail if it is not specified in SQL if(permsString != null) { - Permission permission = new Permission(permsString.getBytes()); + Permission permission = new Permission(permsString.getBytes(StandardCharsets.UTF_8)); permsList = permission.getActions(); } if(isSchemaName) { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/PFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/PFunction.java index a5263ad..f914fba 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/parse/PFunction.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/PFunction.java @@ -101,11 +101,12 @@ public class PFunction implements PMetaDataEntity { this.returnType = PNameFactory.newName(returnType); this.functionKey = new PTableKey(this.tenantId, this.functionName.getString()); this.timeStamp = timeStamp; - int estimatedSize = SizedUtil.OBJECT_SIZE * 2 + 23 * SizedUtil.POINTER_SIZE + 4 * SizedUtil.INT_SIZE + 2 * SizedUtil.LONG_SIZE + 2 * SizedUtil.INT_OBJECT_SIZE + + this.estimatedSize = SizedUtil.OBJECT_SIZE * 2 + 23 * SizedUtil.POINTER_SIZE + + 4 * SizedUtil.INT_SIZE + 2 * SizedUtil.LONG_SIZE + 2 * SizedUtil.INT_OBJECT_SIZE + PNameFactory.getEstimatedSize(tenantId) + PNameFactory.getEstimatedSize(this.functionName) + PNameFactory.getEstimatedSize(this.className) + - (jarPath==null?0:PNameFactory.getEstimatedSize(this.jarPath)); + (jarPath == null ? 0 : PNameFactory.getEstimatedSize(this.jarPath)); this.temporary = temporary; this.replace = replace; } @@ -269,6 +270,7 @@ public class PFunction implements PMetaDataEntity { timeStamp, false, function.hasIsReplace() ? true : false); } + @Override public int getEstimatedSize() { return estimatedSize; } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java index 0d54118..9a3c24e 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java @@ -80,6 +80,7 @@ import static org.apache.phoenix.util.UpgradeUtil.upgradeTo4_5_0; import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.ref.WeakReference; +import java.nio.charset.StandardCharsets; import java.sql.PreparedStatement; import java.sql.ResultSetMetaData; import java.sql.SQLException; @@ -371,7 +372,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement private final int maxConnectionsAllowed; private final int maxInternalConnectionsAllowed; private final boolean shouldThrottleNumConnections; - public static final byte[] MUTEX_LOCKED = "MUTEX_LOCKED".getBytes(); + public static final byte[] MUTEX_LOCKED = "MUTEX_LOCKED".getBytes(StandardCharsets.UTF_8); private static interface FeatureSupported { boolean isSupported(ConnectionQueryServices services); @@ -1241,7 +1242,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement if (!success) { throw new TimeoutException("Operation " + op.getOperationName() + " didn't complete within " + watch.elapsedMillis() + " ms " - + (numTries > 1 ? ("after trying " + numTries + (numTries > 1 ? "times." : "time.")) : "")); + + "after trying " + numTries + "times."); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Operation " @@ -1249,7 +1250,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement + " completed within " + watch.elapsedMillis() + "ms " - + (numTries > 1 ? ("after trying " + numTries + (numTries > 1 ? "times." : "time.")) : "")); + + "after trying " + numTries + " times." ); } } } @@ -1666,7 +1667,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement + getServerVersion(serverJarVersion)); } } - hasIndexWALCodec &= hasIndexWALCodec(serverJarVersion); + hasIndexWALCodec = hasIndexWALCodec && hasIndexWALCodec(serverJarVersion); if (minHBaseVersion > MetaDataUtil.decodeHBaseVersion(serverJarVersion)) { minHBaseVersion = MetaDataUtil.decodeHBaseVersion(serverJarVersion); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java index 3457e9e..3f0544c 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java @@ -716,10 +716,6 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices imple @Override public MetaDataMutationResult getSchema(String schemaName, long clientTimestamp) throws SQLException { - try { - PSchema schema = metaData.getSchema(new PTableKey(null, schemaName)); - new MetaDataMutationResult(MutationCode.SCHEMA_ALREADY_EXISTS, schema, 0); - } catch (SchemaNotFoundException e) {} return new MetaDataMutationResult(MutationCode.SCHEMA_NOT_FOUND, 0, null); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ITGuidePostsCacheFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ITGuidePostsCacheFactory.java index a22a650..61a9175 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ITGuidePostsCacheFactory.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ITGuidePostsCacheFactory.java @@ -20,7 +20,7 @@ import org.apache.phoenix.util.ReadOnlyProps; * Test Class Only used to verify in e2e tests */ public class ITGuidePostsCacheFactory implements GuidePostsCacheFactory { - public static ConcurrentHashMap<Integer, DefaultGuidePostsCacheFactory> map = + public static final ConcurrentHashMap<Integer, DefaultGuidePostsCacheFactory> map = new ConcurrentHashMap<>(); private static AtomicInteger count = new AtomicInteger(); private Integer key; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java index 8d970ac..28161e0 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java @@ -19,6 +19,7 @@ package org.apache.phoenix.query; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -462,8 +463,8 @@ public interface QueryConstants { ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS.name() + ",\n" + TableProperty.COLUMN_ENCODED_BYTES.toString()+" = 1"; - byte[] OFFSET_FAMILY = "f_offset".getBytes(); - byte[] OFFSET_COLUMN = "c_offset".getBytes(); + byte[] OFFSET_FAMILY = "f_offset".getBytes(StandardCharsets.UTF_8); + byte[] OFFSET_COLUMN = "c_offset".getBytes(StandardCharsets.UTF_8); String LAST_SCAN = "LAST_SCAN"; String HASH_JOIN_CACHE_RETRIES = "hashjoin.client.retries.number"; int DEFAULT_HASH_JOIN_CACHE_RETRIES = 5; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java index a2f7197..abb1dcb 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java @@ -185,7 +185,7 @@ public class QueryServicesOptions { // Spillable GroupBy - SPGBY prefix // // Enable / disable spillable group by - public static boolean DEFAULT_GROUPBY_SPILLABLE = true; + public static final boolean DEFAULT_GROUPBY_SPILLABLE = true; // Number of spill files / partitions the keys are distributed to // Each spill file fits 2GB of data public static final int DEFAULT_GROUPBY_SPILL_FILES = 2; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java index a4c155a..977749d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java @@ -117,6 +117,7 @@ import static org.apache.phoenix.schema.types.PDataType.FALSE_BYTES; import static org.apache.phoenix.schema.types.PDataType.TRUE_BYTES; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -273,6 +274,8 @@ import org.apache.phoenix.thirdparty.com.google.common.collect.Maps; import org.apache.phoenix.thirdparty.com.google.common.collect.Sets; import org.apache.phoenix.thirdparty.com.google.common.primitives.Ints; +import edu.umd.cs.findbugs.annotations.SuppressWarnings; + public class MetaDataClient { private static final Logger LOGGER = LoggerFactory.getLogger(MetaDataClient.class); @@ -2081,7 +2084,8 @@ public class MetaDataClient { // TODO: PHOENIX_TABLE_TTL if (tableType == VIEW && parentPhysicalName != null) { - HTableDescriptor desc = connection.getQueryServices().getTableDescriptor(parentPhysicalName.getBytes()); + HTableDescriptor desc = connection.getQueryServices().getTableDescriptor( + parentPhysicalName.getBytes(StandardCharsets.UTF_8)); if (desc != null) { Integer tableTTLProp = desc.getFamily(SchemaUtil.getEmptyColumnFamily(parent)).getTimeToLive(); if ((tableTTLProp != null) && (tableTTLProp != HConstants.FOREVER)) { @@ -3005,7 +3009,7 @@ public class MetaDataClient { } tableUpsert.setBoolean(24, isAppendOnlySchema); if (guidePostsWidth == null) { - tableUpsert.setNull(25, Types.BIGINT); + tableUpsert.setNull(25, Types.BIGINT); } else { tableUpsert.setLong(25, guidePostsWidth); } @@ -3143,10 +3147,8 @@ public class MetaDataClient { .setNamespaceMapped(isNamespaceMapped) .setAutoPartitionSeqName(autoPartitionSeq) .setAppendOnlySchema(isAppendOnlySchema) - .setImmutableStorageScheme(immutableStorageScheme == null ? - ImmutableStorageScheme.ONE_CELL_PER_COLUMN : immutableStorageScheme) - .setQualifierEncodingScheme(encodingScheme == null ? - QualifierEncodingScheme.NON_ENCODED_QUALIFIERS : encodingScheme) + .setImmutableStorageScheme(immutableStorageScheme) + .setQualifierEncodingScheme(encodingScheme) .setBaseColumnCount(baseTableColumnCount) .setEncodedCQCounter(cqCounterToBe) .setUseStatsForParallelization(useStatsForParallelizationProp) @@ -3162,8 +3164,7 @@ public class MetaDataClient { .setIndexes(Collections.<PTable>emptyList()) .setParentSchemaName((parent == null) ? null : parent.getSchemaName()) .setParentTableName((parent == null) ? null : parent.getTableName()) - .setPhysicalNames(physicalNames == null ? - ImmutableList.<PName>of() : ImmutableList.copyOf(physicalNames)) + .setPhysicalNames(ImmutableList.copyOf(physicalNames)) .setColumns(columns.values()) .setPhoenixTTL(phoenixTTL == null ? PHOENIX_TTL_NOT_DEFINED : phoenixTTL) .setPhoenixTTLHighWaterMark(phoenixTTLHighWaterMark == null ? MIN_PHOENIX_TTL_HWM : phoenixTTLHighWaterMark) @@ -4105,7 +4106,8 @@ public class MetaDataClient { connection.rollback(); } - byte[] family = families.size() > 0 ? families.iterator().next().getBytes() : null; + byte[] family = families.size() > 0 ? + families.iterator().next().getBytes(StandardCharsets.UTF_8) : null; // Figure out if the empty column family is changing as a result of adding the new column byte[] emptyCF = null; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java index 6ba1b76..0b363ba 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java @@ -182,7 +182,7 @@ public class PMetaDataImpl implements PMetaData { PTableImpl.Builder parentTableBuilder = PTableImpl.builderWithColumns(parentTableRef.getTable(), getColumnsToClone(parentTableRef.getTable())) - .setIndexes(newIndexes == null ? Collections.<PTable>emptyList() : newIndexes); + .setIndexes(newIndexes); if (tableTimeStamp != HConstants.LATEST_TIMESTAMP) { parentTableBuilder.setTimeStamp(tableTimeStamp); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java index 9ffd77c..0b38bbe 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java @@ -652,7 +652,7 @@ public class PTableImpl implements PTable { Collections.sort(sortedColumns, new Comparator<PColumn>() { @Override public int compare(PColumn o1, PColumn o2) { - return Integer.valueOf(o1.getPosition()).compareTo(o2.getPosition()); + return Integer.compare(o1.getPosition(), o2.getPosition()); } }); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/SequenceAllocation.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/SequenceAllocation.java index af87e56..e24c2ad 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/SequenceAllocation.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/SequenceAllocation.java @@ -17,6 +17,8 @@ */ package org.apache.phoenix.schema; +import edu.umd.cs.findbugs.annotations.SuppressWarnings; + /** * A SequenceKey and the number of slots requested to be allocated for the sequence. * It binds these two together to allow operations such as sorting @@ -53,6 +55,8 @@ public class SequenceAllocation implements Comparable<SequenceAllocation> { } @Override + @SuppressWarnings(value="EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS", + justification="Checked in called function") public boolean equals(Object obj) { return sequenceKey.equals(obj); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/GuidePostsInfo.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/GuidePostsInfo.java index 0f325f4..dc14cdb 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/GuidePostsInfo.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/GuidePostsInfo.java @@ -26,6 +26,9 @@ import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.SizedUtil; import org.apache.phoenix.thirdparty.com.google.common.primitives.Longs; + +import edu.umd.cs.findbugs.annotations.SuppressWarnings; + /** * A class that holds the guidePosts of a region and also allows combining the * guidePosts of different regions when the GuidePostsInfo is formed for a table. @@ -136,6 +139,8 @@ public class GuidePostsInfo { return estimatedSize; } + @SuppressWarnings(value="EC_ARRAY_AND_NONARRAY", + justification="ImmutableBytesWritable DOES implement equals(byte])") public boolean isEmptyGuidePost() { return guidePosts.equals(EMPTY_GUIDEPOST_KEY) && guidePostsCount == 0 && byteCounts.length == 1 && gpTimestamps.length == 1; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/UpdateStatisticsTool.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/UpdateStatisticsTool.java index a14fac8..9a3d5de 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/UpdateStatisticsTool.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/UpdateStatisticsTool.java @@ -59,6 +59,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY; + +import java.nio.charset.StandardCharsets; import java.sql.Connection; import static org.apache.phoenix.query.QueryServices.IS_NAMESPACE_MAPPING_ENABLED; @@ -121,7 +123,8 @@ public class UpdateStatisticsTool extends Configured implements Tool { HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin(); boolean namespaceMapping = getConf().getBoolean(IS_NAMESPACE_MAPPING_ENABLED, DEFAULT_IS_NAMESPACE_MAPPING_ENABLED); - String physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), + String physicalTableName = SchemaUtil.getPhysicalTableName( + tableName.getBytes(StandardCharsets.UTF_8), namespaceMapping).getNameAsString(); admin.snapshot(snapshotName, physicalTableName); LOGGER.info("Successfully created snapshot " + snapshotName + " for " + physicalTableName); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/task/Task.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/task/Task.java index a23a9a2..1929bf6 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/task/Task.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/task/Task.java @@ -55,6 +55,10 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import edu.umd.cs.findbugs.annotations.SuppressWarnings; + +@SuppressWarnings(value="SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING", + justification="Not possible to avoid") public class Task { public static final Logger LOGGER = LoggerFactory.getLogger(Task.class); private static void mutateSystemTaskTable(final PhoenixConnection conn, final PreparedStatement stmt, boolean accessCheckEnabled) diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tool/SchemaSynthesisProcessor.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tool/SchemaSynthesisProcessor.java index 7fe13bb..761621a 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tool/SchemaSynthesisProcessor.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tool/SchemaSynthesisProcessor.java @@ -36,8 +36,10 @@ import org.apache.phoenix.schema.SortOrder; import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -208,7 +210,8 @@ public class SchemaSynthesisProcessor implements SchemaProcessor { private List<String> getQueriesFromFile(String ddlFile) throws IOException { StringBuilder sb = new StringBuilder(); File file = new File(ddlFile); - BufferedReader br = new BufferedReader(new FileReader(file)); + BufferedReader br = new BufferedReader(new InputStreamReader( + new FileInputStream(file), StandardCharsets.UTF_8)); String st; while ((st = br.readLine()) != null) { sb.append(st).append("\n"); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tool/SchemaTool.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tool/SchemaTool.java index e1f9e06..0386c78 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tool/SchemaTool.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tool/SchemaTool.java @@ -36,6 +36,8 @@ import org.apache.hadoop.util.ToolRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import edu.umd.cs.findbugs.annotations.SuppressWarnings; + public class SchemaTool extends Configured implements Tool { private static final Logger LOGGER = LoggerFactory.getLogger(SchemaTool.class); @@ -98,6 +100,8 @@ public class SchemaTool extends Configured implements Tool { } } + @SuppressWarnings(value="NP_NULL_ON_SOME_PATH", + justification="null path call calls System.exit()") private CommandLine parseOptions(String[] args) { final Options options = getOptions(); CommandLineParser parser = new DefaultParser(false, false); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java index a6dc4c3..db5df22 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java @@ -37,6 +37,8 @@ import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.SchemaUtil; import org.apache.phoenix.util.TrustedByteArrayOutputStream; +import edu.umd.cs.findbugs.annotations.SuppressWarnings; + import org.apache.phoenix.thirdparty.com.google.common.base.Objects; import org.apache.phoenix.thirdparty.com.google.common.base.Preconditions; @@ -310,6 +312,8 @@ public abstract class PArrayDataType<T> extends PDataType<T> { return true; } + @SuppressWarnings(value="RC_REF_COMPARISON", + justification="PDataTypes are expected to be singletons") private void coerceBytes(ImmutableBytesWritable ptr, Object value, PDataType actualType, Integer maxLength, Integer scale, Integer desiredMaxLength, Integer desiredScale, PDataType desiredType, SortOrder actualSortOrder, SortOrder desiredSortOrder, diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataTypeEncoder.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataTypeEncoder.java index 7467981..da1a42b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataTypeEncoder.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataTypeEncoder.java @@ -207,7 +207,7 @@ public class PArrayDataTypeEncoder implements ColumnValueEncoder { } else { // count the bytes written to serialize nulls if (nulls > 0) { - cellSize += (1 + Math.ceil(nulls / 255)); + cellSize += (1 + Math.ceil(nulls / 255.0)); nulls = 0; } maxOffset = cellSize; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java index 21e7751..16d3ce6 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java @@ -178,9 +178,6 @@ public abstract class PDataType<T> implements DataType<T>, Comparable<PDataType< rhsConverted = ((PArrayDataType)this).toBytes(o, PArrayDataType.arrayBaseType(this), lhsSortOrder, PArrayDataType.isRowKeyOrderOptimized(this, lhsSortOrder, lhs, lhsOffset, lhsLength)); } else { rhsConverted = this.toBytes(o); - if (rhsSortOrder == SortOrder.DESC) { - rhsSortOrder = SortOrder.ASC; - } if (lhsSortOrder == SortOrder.DESC) { lhs = SortOrder.invert(lhs, lhsOffset, new byte[lhsLength], 0, lhsLength); lhsOffset = 0; @@ -199,9 +196,6 @@ public abstract class PDataType<T> implements DataType<T>, Comparable<PDataType< lhsConverted = ((PArrayDataType)rhsType).toBytes(o, PArrayDataType.arrayBaseType(rhsType), rhsSortOrder, PArrayDataType.isRowKeyOrderOptimized(rhsType, rhsSortOrder, rhs, rhsOffset, rhsLength)); } else { lhsConverted = rhsType.toBytes(o); - if (lhsSortOrder == SortOrder.DESC) { - lhsSortOrder = SortOrder.ASC; - } if (rhsSortOrder == SortOrder.DESC) { rhs = SortOrder.invert(rhs, rhsOffset, new byte[rhsLength], 0, rhsLength); } @@ -312,7 +306,7 @@ public abstract class PDataType<T> implements DataType<T>, Comparable<PDataType< @Override public boolean equals(Object o) { - // PDataType's are expected to be singletons. + // PDataTypes are expected to be singletons. // TODO: this doesn't jive with HBase's DataType if (o == null) return false; return getClass() == o.getClass(); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java index fe8d306..a0480b5 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java @@ -335,9 +335,8 @@ public class PDecimal extends PRealNumber<BigDecimal> { maxLength = v[0]; scale = v[1]; } - if (desiredMaxLength != null && desiredScale != null && maxLength != null && scale != null && - ((desiredScale == null && desiredMaxLength < maxLength) || - (desiredMaxLength - desiredScale) < (maxLength - scale))) { + if (desiredMaxLength != null && desiredScale != null && maxLength != null && scale != null + && ((desiredMaxLength - desiredScale) < (maxLength - scale))) { return false; } return true; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PhoenixArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PhoenixArray.java index 7e8f960..73f3c67 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PhoenixArray.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PhoenixArray.java @@ -172,7 +172,7 @@ public class PhoenixArray implements Array,SQLCloseable { } private void boundaryCheck(long index, int count, Object[] arr) { - if ((--index) + count > arr.length) { + if (index - 1 + count > arr.length) { throw new IllegalArgumentException("The array index is out of range of the total number of elements in the array " + arr.length); } } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java b/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java index 8bd918e..47409e0 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java @@ -17,6 +17,8 @@ */ package org.apache.phoenix.trace; +import java.nio.charset.StandardCharsets; + import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Pair; import org.apache.htrace.Span; @@ -34,11 +36,13 @@ public class TracingUtils { public static final String METRICS_MARKER_CONTEXT = "marker"; public static void addAnnotation(Span span, String message, int value) { - span.addKVAnnotation(message.getBytes(), Bytes.toBytes(Integer.toString(value))); + span.addKVAnnotation(message.getBytes(StandardCharsets.UTF_8), + Bytes.toBytes(Integer.toString(value))); } public static Pair<String, String> readAnnotation(byte[] key, byte[] value) { - return new Pair<String, String>(new String(key), Bytes.toString(value)); + return new Pair<String, String>(new String(key, StandardCharsets.UTF_8), + Bytes.toString(value)); } /** diff --git a/phoenix-core/src/main/java/org/apache/phoenix/trace/util/NullSpan.java b/phoenix-core/src/main/java/org/apache/phoenix/trace/util/NullSpan.java index b4f70b9..afde492 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/trace/util/NullSpan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/trace/util/NullSpan.java @@ -31,7 +31,7 @@ import org.apache.phoenix.util.StringUtil; */ public class NullSpan implements Span { - public static Span INSTANCE = new NullSpan(); + public static final Span INSTANCE = new NullSpan(); /** * Private constructor to limit garbage diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ColumnInfo.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ColumnInfo.java index e373ed3..eea838d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/ColumnInfo.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ColumnInfo.java @@ -12,6 +12,7 @@ package org.apache.phoenix.util; import java.sql.Types; import java.util.List; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -110,8 +111,8 @@ public class ColumnInfo { ColumnInfo that = (ColumnInfo) o; if (sqlType != that.sqlType) return false; - if (precision != that.precision) return false; - if (scale != that.scale) return false; + if (!Objects.equals(precision, that.precision)) return false; + if (!Objects.equals(scale, that.scale)) return false; if (!columnName.equals(that.columnName)) return false; return true; diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java index 49203b7..e4d271d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java @@ -29,6 +29,7 @@ import static org.apache.phoenix.util.PhoenixRuntime.getTable; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; @@ -232,7 +233,7 @@ public class IndexUtil { public static byte[] getLocalIndexColumnFamily(byte[] dataColumnFamilyBytes) { String dataCF = Bytes.toString(dataColumnFamilyBytes); - return getLocalIndexColumnFamily(dataCF).getBytes(); + return getLocalIndexColumnFamily(dataCF).getBytes(StandardCharsets.UTF_8); } public static PColumn getDataColumn(PTable dataTable, String indexColumnName) { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java index ef48f99..1dd9d8d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java @@ -22,6 +22,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FAMILY_NAME_INDEX; import static org.apache.phoenix.util.SchemaUtil.getVarChars; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.sql.SQLException; import java.util.*; @@ -1020,7 +1021,8 @@ public class MetaDataUtil { family.getPColumnForColumnNameBytes(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]); } else if (pkCount > COLUMN_NAME_INDEX && rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX].length > 0) { - col = table.getPKColumn(new String(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX])); + col = table.getPKColumn(new String( + rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX], StandardCharsets.UTF_8)); } return col; } @@ -1033,7 +1035,6 @@ public class MetaDataUtil { try { connection.setAutoCommit(true); Set<String> physicalTablesSet = new HashSet<>(); - Set<String> columnFamilies = new HashSet<>(); physicalTablesSet.add(table.getPhysicalName().getString()); for(byte[] physicalTableName:physicalTableNames) { physicalTablesSet.add(Bytes.toString(physicalTableName)); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixMRJobUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixMRJobUtil.java index fa35e46..a684648 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixMRJobUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixMRJobUtil.java @@ -26,6 +26,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; @@ -181,7 +182,7 @@ public class PhoenixMRJobUtil { BufferedReader in = null; StringBuilder response = null; try { - in = new BufferedReader(new InputStreamReader(is)); + in = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); String inputLine; response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java index 085c242..302f9ec 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java @@ -22,9 +22,11 @@ import static org.apache.phoenix.thirdparty.com.google.common.base.Preconditions import static org.apache.phoenix.schema.types.PDataType.ARRAY_TYPE_SUFFIX; import java.io.File; -import java.io.FileReader; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -32,6 +34,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -210,7 +213,7 @@ public class PhoenixRuntime { * All Phoenix specific connection properties * TODO: use enum instead */ - public final static String[] CONNECTION_PROPERTIES = { + private final static String[] CONNECTION_PROPERTIES = { CURRENT_SCN_ATTRIB, TENANT_ID_ATTRIB, UPSERT_BATCH_SIZE_ATTRIB, @@ -296,7 +299,9 @@ public class PhoenixRuntime { } else { for (String inputFile : execCmd.getInputFiles()) { if (inputFile.endsWith(SQL_FILE_EXT)) { - PhoenixRuntime.executeStatements(conn, new FileReader(inputFile), Collections.emptyList()); + PhoenixRuntime.executeStatements(conn, new InputStreamReader( + new FileInputStream(inputFile), StandardCharsets.UTF_8), + Collections.emptyList()); } else if (inputFile.endsWith(CSV_FILE_EXT)) { String tableName = execCmd.getTableName(); @@ -333,6 +338,10 @@ public class PhoenixRuntime { private PhoenixRuntime() { } + public static final String[] getConnectionProperties() { + return Arrays.copyOf(CONNECTION_PROPERTIES, CONNECTION_PROPERTIES.length); + } + /** * Runs a series of semicolon-terminated SQL statements using the connection provided, returning * the number of SQL statements executed. Note that if the connection has specified an SCN through diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java index e9b6a35..145e6ba 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java @@ -220,7 +220,7 @@ public final class QueryUtil { new Function<String, String>() { @Nullable @Override - public String apply(@Nullable String columnName) { + public String apply(String columnName) { return getEscapedFullColumnName(columnName); } })), diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java index 425f35e..93c98c8 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java @@ -29,6 +29,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES import static org.apache.phoenix.query.QueryConstants.SEPARATOR_BYTE; import static org.apache.phoenix.query.QueryConstants.SEPARATOR_BYTE_ARRAY; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; @@ -37,6 +38,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; @@ -146,8 +148,8 @@ public class SchemaUtil { // See PHOENIX-4424 public static final String SCHEMA_FOR_DEFAULT_NAMESPACE = "default"; public static final String HBASE_NAMESPACE = "hbase"; - public static final List<String> NOT_ALLOWED_SCHEMA_LIST = Arrays.asList(SCHEMA_FOR_DEFAULT_NAMESPACE, - HBASE_NAMESPACE); + public static final List<String> NOT_ALLOWED_SCHEMA_LIST = Collections.unmodifiableList( + Arrays.asList(SCHEMA_FOR_DEFAULT_NAMESPACE, HBASE_NAMESPACE)); /** * May not be instantiated @@ -1134,7 +1136,8 @@ public class SchemaUtil { public static byte[] getParentTableNameFromIndexTable(byte[] physicalTableName, String indexPrefix) { String tableName = Bytes.toString(physicalTableName); - return getParentTableNameFromIndexTable(tableName, indexPrefix).getBytes(); + return getParentTableNameFromIndexTable(tableName, indexPrefix) + .getBytes(StandardCharsets.UTF_8); } public static String getParentTableNameFromIndexTable(String physicalTableName, String indexPrefix) { diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/StringUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/StringUtil.java index 2b436c9..136a444 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/StringUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/StringUtil.java @@ -42,13 +42,21 @@ public class StringUtil { public final static char SINGLE_CHAR_LIKE = '_'; public final static char MULTI_CHAR_WILDCARD = '*'; public final static char MULTI_CHAR_LIKE = '%'; - public final static String[] LIKE_ESCAPE_SEQS = new String[]{"\\"+SINGLE_CHAR_LIKE, "\\"+MULTI_CHAR_LIKE}; - public final static String[] LIKE_UNESCAPED_SEQS = new String[]{""+SINGLE_CHAR_LIKE, ""+MULTI_CHAR_LIKE}; + private final static String[] LIKE_ESCAPE_SEQS = new String[]{"\\"+SINGLE_CHAR_LIKE, "\\"+MULTI_CHAR_LIKE}; + private final static String[] LIKE_UNESCAPED_SEQS = new String[]{""+SINGLE_CHAR_LIKE, ""+MULTI_CHAR_LIKE}; private StringUtil() { } + public static final String[] getLikeEscapeSeqs() { + return Arrays.copyOf(LIKE_ESCAPE_SEQS, LIKE_ESCAPE_SEQS.length); + } + + public static final String[] getLikeUnescapedSeqs() { + return Arrays.copyOf(LIKE_UNESCAPED_SEQS, LIKE_UNESCAPED_SEQS.length); + } + /** Replace instances of character ch in String value with String replacement */ public static String replaceChar(String value, char ch, CharSequence replacement) { if (value == null) diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java index 6cdb1a6..a23a3a6 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java @@ -59,6 +59,7 @@ import static org.apache.phoenix.query.QueryConstants.BASE_TABLE_BASE_COLUMN_COU import static org.apache.phoenix.query.QueryConstants.DIVERGED_VIEW_BASE_COLUMN_COUNT; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.Date; @@ -138,6 +139,10 @@ import org.apache.phoenix.thirdparty.com.google.common.base.Objects; import org.apache.phoenix.thirdparty.com.google.common.collect.Lists; import org.apache.phoenix.thirdparty.com.google.common.collect.Sets; +import edu.umd.cs.findbugs.annotations.SuppressWarnings; + +@SuppressWarnings(value = "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING", + justification="Not possible to avoid") public class UpgradeUtil { private static final Logger LOGGER = LoggerFactory.getLogger(UpgradeUtil.class); private static final byte[] SEQ_PREFIX_BYTES = ByteUtil.concat(QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes("_SEQ_")); @@ -148,7 +153,7 @@ public class UpgradeUtil { * of this attribute overrides a true value for {@value QueryServices#AUTO_UPGRADE_ENABLED}. */ private static final String DO_NOT_UPGRADE = "DoNotUpgrade"; - public static String UPSERT_BASE_COLUMN_COUNT_IN_HEADER_ROW = "UPSERT " + public static final String UPSERT_BASE_COLUMN_COUNT_IN_HEADER_ROW = "UPSERT " + "INTO SYSTEM.CATALOG " + "(TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, COLUMN_FAMILY, BASE_COLUMN_COUNT) " + "VALUES (?, ?, ?, ?, ?, ?) "; @@ -161,7 +166,7 @@ public class UpgradeUtil { UPDATE_CACHE_FREQUENCY + ") VALUES (?, ?, ?, ?)"; - public static String SELECT_BASE_COLUMN_COUNT_FROM_HEADER_ROW = "SELECT " + public static final String SELECT_BASE_COLUMN_COUNT_FROM_HEADER_ROW = "SELECT " + "BASE_COLUMN_COUNT " + "FROM \"SYSTEM\".CATALOG " + "WHERE " @@ -2099,7 +2104,8 @@ public class UpgradeUtil { SQLException { srcTableName = SchemaUtil.normalizeIdentifier(srcTableName); if (!SchemaUtil.isNamespaceMappingEnabled(pTableType, - props)) { throw new IllegalArgumentException(SchemaUtil.isSystemTable(srcTableName.getBytes()) + props)) { throw new IllegalArgumentException(SchemaUtil.isSystemTable( + srcTableName.getBytes(StandardCharsets.UTF_8)) ? "For system table " + QueryServices.IS_SYSTEM_TABLE_MAPPED_TO_NAMESPACE + " also needs to be enabled along with " + QueryServices.IS_NAMESPACE_MAPPING_ENABLED : QueryServices.IS_NAMESPACE_MAPPING_ENABLED + " is not enabled"); } @@ -2212,8 +2218,9 @@ public class UpgradeUtil { byte[] tenantId = conn.getTenantId() != null ? conn.getTenantId().getBytes() : null; ViewUtil.findAllRelatives(sysCatOrSysChildLinkTable, tenantId, - schemaName.getBytes(), - tableName.getBytes(), LinkType.CHILD_TABLE, childViewsResult); + schemaName.getBytes(StandardCharsets.UTF_8), + tableName.getBytes(StandardCharsets.UTF_8), LinkType.CHILD_TABLE, + childViewsResult); break; } catch (TableNotFoundException ex) { // try again with SYSTEM.CATALOG in case the schema is old @@ -2266,7 +2273,7 @@ public class UpgradeUtil { index.getName(), srcTableName)); destTableName = Bytes .toString(MetaDataUtil.getLocalIndexPhysicalName( - newPhysicalTablename.getBytes())); + newPhysicalTablename.getBytes(StandardCharsets.UTF_8))); // update parent_table property in local index table descriptor conn.createStatement() .execute(String.format("ALTER TABLE %s set " + @@ -2278,7 +2285,7 @@ public class UpgradeUtil { index.getName(), srcTableName)); destTableName = Bytes .toString(MetaDataUtil.getViewIndexPhysicalName( - newPhysicalTablename.getBytes())); + newPhysicalTablename.getBytes(StandardCharsets.UTF_8))); } else { LOGGER.info(String.format( "Global index '%s' found with physical hbase table name ''..", diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ViewUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ViewUtil.java index 25e3a88..074ef6b 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/ViewUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ViewUtil.java @@ -29,6 +29,7 @@ import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB; import static org.apache.phoenix.util.SchemaUtil.getVarChars; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; @@ -284,9 +285,11 @@ public class ViewUtil { continue; } byte[] viewSchemaName = SchemaUtil.getSchemaNameFromFullName( - rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]).getBytes(); + rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]) + .getBytes(StandardCharsets.UTF_8); byte[] viewName = SchemaUtil.getTableNameFromFullName( - rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]).getBytes(); + rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]) + .getBytes(StandardCharsets.UTF_8); tableInfoList.add(new TableInfo(viewTenantId, viewSchemaName, viewName)); } return new TableViewFinderResult(tableInfoList); diff --git a/pom.xml b/pom.xml index a95aef5..d21560e 100644 --- a/pom.xml +++ b/pom.xml @@ -209,6 +209,7 @@ <configuration> <effort>Max</effort> <maxHeap>2048</maxHeap> + <excludeFilterFile>${top.dir}/src/main/config/spotbugs/spotbugs-exclude.xml</excludeFilterFile> </configuration> </plugin> <!--This plugin's configuration is used to store Eclipse m2e settings @@ -546,6 +547,9 @@ <!-- Argparse is bundled to work around system Python version issues, compatibile with ALv2 --> <exclude>bin/argparse-1.4.0/argparse.py</exclude> + <!-- tmp files --> + <exclude>dev/work/**</exclude> + <exclude>dev/artifacts/**</exclude> </excludes> </configuration> </plugin> diff --git a/src/main/config/spotbugs/spotbugs-exclude.xml b/src/main/config/spotbugs/spotbugs-exclude.xml new file mode 100644 index 0000000..76104b1 --- /dev/null +++ b/src/main/config/spotbugs/spotbugs-exclude.xml @@ -0,0 +1,30 @@ +<!-- +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. +--> +<FindBugsFilter> + <Match> + <Class name="~org\.apache\.phoenix\.coprocessor\.generated\..*" /> + </Match> + <Match> + <!-- Guava annotates some interfaces with @Null for some unfathomable reason --> + <BugPattern name="NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE" /> + </Match> + <Match> + <!-- We cannot avoid hand-built SQL statements when manipulating SYSTEM.% tables --> + <BugPattern name="SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" /> + </Match> +</FindBugsFilter> \ No newline at end of file