Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -249,7 +249,7 @@ public <K extends ImmutableBytesWritable> CacheEntry<K> toCacheEntry(byte[] byte
// 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);
}

/**
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@


import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ArrayList;
Expand DownExpand Up@@ -520,7 +521,7 @@ public Expression visitLeave(LikeParseNode node, List<Expression> children) thro
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);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1489,7 +1489,6 @@ private static ParseNode combine(List<ParseNode> nodes) {
}

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) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -310,7 +310,8 @@ public int compare(Info o1, Info o2) {
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 ||
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,7 +132,7 @@ public MutationPlan compile(PTable index) throws SQLException {
.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());
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -510,7 +510,8 @@ private SelectStatement flatten(SelectStatement select, SelectStatement subselec
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);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -150,7 +150,7 @@ public static PTable createProjectedTable(SelectStatement select, StatementConte

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());
}
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,6 +89,7 @@
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;
Expand DownExpand Up@@ -1276,8 +1277,8 @@ private PTable getTable(RegionScanner scanner, long clientTimeStamp, long tableT
// famName contains the logical name of the parent table. We need to get the actual physical name of the table
PTable parentTable = null;
if (indexType != IndexType.LOCAL) {
parentTable = getTable(null, SchemaUtil.getSchemaNameFromFullName(famName.getBytes()).getBytes(),
SchemaUtil.getTableNameFromFullName(famName.getBytes()).getBytes(), clientTimeStamp, clientVersion);
parentTable = getTable(null, SchemaUtil.getSchemaNameFromFullName(famName.getBytes()).getBytes(StandardCharsets.UTF_8),
SchemaUtil.getTableNameFromFullName(famName.getBytes()).getBytes(StandardCharsets.UTF_8), clientTimeStamp, clientVersion);
if (parentTable == null) {
// parentTable is not in the cache. Since famName is only logical name, we need to find the physical table.
try (PhoenixConnection connection = QueryUtil.getConnectionOnServer(env.getConfiguration()).unwrap(PhoenixConnection.class)) {
Expand All@@ -1290,8 +1291,13 @@ private PTable getTable(RegionScanner scanner, long clientTimeStamp, long tableT

if (parentTable == null) {
if (indexType == IndexType.LOCAL) {
PName tablePhysicalName = getPhysicalTableName(env.getRegion(),null, SchemaUtil.getSchemaNameFromFullName(famName.getBytes()).getBytes(),
SchemaUtil.getTableNameFromFullName(famName.getBytes()).getBytes(), clientTimeStamp);
PName tablePhysicalName = getPhysicalTableName(
env.getRegion(),null,
SchemaUtil.getSchemaNameFromFullName(
famName.getBytes()).getBytes(StandardCharsets.UTF_8),
SchemaUtil.getTableNameFromFullName(
famName.getBytes()).getBytes(StandardCharsets.UTF_8),
clientTimeStamp);
if (tablePhysicalName == null) {
physicalTables.add(famName);
} else {
Expand DownExpand Up@@ -1821,8 +1827,10 @@ private static void getSchemaTableNames(Mutation row, byte[][] schemaTableNames)
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;
Expand DownExpand Up@@ -1980,7 +1988,7 @@ public void createTable(RpcController controller, CreateTableRequest request,
// The view index physical table name is constructed from logical name of base table.
// For example, _IDX_SC.TBL1 is the view index name and SC.TBL1 is the logical name of the base table.
String namepaceMappedParentLogicalName = MetaDataUtil.getNamespaceMappedName(parentTable.getBaseTableLogicalName(), isNamespaceMapped);
cPhysicalName = MetaDataUtil.getViewIndexPhysicalName(namepaceMappedParentLogicalName.getBytes());
cPhysicalName = MetaDataUtil.getViewIndexPhysicalName(namepaceMappedParentLogicalName.getBytes(StandardCharsets.UTF_8));
cParentPhysicalName = parentTable.getPhysicalName().getBytes();
} else {
cParentPhysicalName = SchemaUtil
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -746,7 +746,7 @@ public String authString(String user, TableName table, Set<Action> actions) {
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();
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@
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;
Expand DownExpand Up@@ -324,7 +325,8 @@ public final ResultIterator iterator(final Map<ImmutableBytesPtr,ServerCache> ca

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);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
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;
Expand DownExpand Up@@ -542,7 +543,8 @@ public ServerCache execute(HashJoinPlan parent) throws SQLException {
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 {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -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);
}

/**
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,7 +35,7 @@
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;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,8 +71,7 @@ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
}
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();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
Expand DownExpand Up@@ -141,11 +142,11 @@ public String toString() {
+ " 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();
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,7 @@ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
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()));
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,7 +52,7 @@ public JONIPattern(String patternString, int flags) {
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;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,7 +254,7 @@ private void throwFailureIfDone() throws SingleIndexWriteFailureException {
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());
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,7 +138,7 @@ public RegionScanner getRegionScanner(final Scan scan, final RegionScanner s) th
}
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);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,6 +176,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea
private LogLevel auditLogLevel;
private Double logSamplingRate;
private String sourceOfOperation;
private static final String[] CONNECTION_PROPERTIES;

private final ConcurrentLinkedQueue<PhoenixConnection> childConnections =
new ConcurrentLinkedQueue<>();
Expand All@@ -186,6 +187,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea

static {
Tracing.addTraceMetricsSource();
CONNECTION_PROPERTIES = PhoenixRuntime.getConnectionProperties();
}

private static Properties newPropsWithSCN(long scn, Properties props) {
Expand DownExpand Up@@ -265,8 +267,7 @@ private PhoenixConnection(ConnectionQueryServices services, String url,
}

// 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;
Expand DownExpand Up@@ -438,7 +439,7 @@ private static void checkScnAndBuildIndexAtEquality(Long scnParam, Long replayAt

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);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,11 +124,6 @@ private void setParameter(int parameterIndex, Object value) throws SQLException
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);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@
*/
package org.apache.phoenix.mapreduce;

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

import org.apache.hadoop.conf.Configuration;
Expand DownExpand Up@@ -69,10 +70,10 @@ public static void configurePreUpsertProcessor(Configuration conf,
}

@VisibleForTesting

static void setChar(Configuration conf, String confKey, Character charValue) {
if(charValue!=null) {
conf.set(confKey, Bytes.toString(Base64.getEncoder().encode(charValue.toString().getBytes())));
conf.set(confKey, Bytes.toString(Base64.getEncoder().encode(
charValue.toString().getBytes(StandardCharsets.UTF_8))));
}
}

Expand All@@ -82,7 +83,8 @@ static Character getCharacter(Configuration conf, String confKey) {
if (strValue == null) {
return null;
}
return new String(Base64.getDecoder().decode(strValue)).charAt(0);
return new String(Base64.getDecoder().decode(strValue.getBytes(StandardCharsets.UTF_8)),
StandardCharsets.UTF_8).charAt(0);
}

public static Path getOutputPath(Path outputdir, String tableName) {
Expand Down
Loading