You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/03/07 02:13:34 UTC
[1/3] PHOENIX-119 Removed unnecessary Expression.getByteSize() method
Repository: incubator-phoenix
Updated Branches:
refs/heads/master b44ad86aa -> 1159b6e1d
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java
index 3f6b12c..9fd753f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java
@@ -24,9 +24,9 @@ import java.sql.SQLException;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.parse.BindParseNode;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TypeMismatchException;
@@ -65,11 +65,6 @@ public class PhoenixParameterMetaData implements ParameterMetaData {
public SortOrder getSortOrder() {
return SortOrder.getDefault();
}
-
- @Override
- public Integer getByteSize() {
- return null;
- }
};
public static final PhoenixParameterMetaData EMPTY_PARAMETER_META_DATA = new PhoenixParameterMetaData(0);
public PhoenixParameterMetaData(int paramCount) {
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java
index fa5746d..b58d5ad 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java
@@ -17,7 +17,9 @@
*/
package org.apache.phoenix.jdbc;
-import java.sql.*;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
import org.apache.phoenix.compile.ColumnProjector;
import org.apache.phoenix.compile.RowProjector;
@@ -91,8 +93,8 @@ public class PhoenixResultSetMetaData implements ResultSetMetaData {
if (type.isCoercibleTo(PDataType.DATE)) {
return Math.min(Math.max(displaySize, connection.getDatePattern().length()), MAX_DISPLAY_WIDTH);
}
- if (projector.getExpression().getByteSize() != null) {
- return Math.min(Math.max(displaySize, projector.getExpression().getByteSize()), MAX_DISPLAY_WIDTH);
+ if (type.isFixedWidth() && projector.getExpression().getMaxLength() != null) {
+ return Math.min(Math.max(displaySize, projector.getExpression().getMaxLength()), MAX_DISPLAY_WIDTH);
}
return Math.min(Math.max(displaySize, DEFAULT_DISPLAY_WIDTH), MAX_DISPLAY_WIDTH);
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
index e0d23e7..ff1c953 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
@@ -279,10 +279,6 @@ public class PhoenixStatement implements Statement, SQLCloseable, org.apache.pho
return PDataType.VARCHAR;
}
@Override
- public Integer getByteSize() {
- return null;
- }
- @Override
public Integer getMaxLength() {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java
index 82a78f6..4b470d8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java
@@ -21,8 +21,8 @@ import java.sql.SQLException;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.util.SchemaUtil;
import com.google.common.base.Preconditions;
@@ -84,26 +84,24 @@ public class ColumnDef {
}
scale = null;
} else if (this.dataType == PDataType.DECIMAL) {
- Integer origMaxLength = maxLength;
- maxLength = maxLength == null ? PDataType.MAX_PRECISION : maxLength;
// for deciaml, 1 <= maxLength <= PDataType.MAX_PRECISION;
- if (maxLength < 1 || maxLength > PDataType.MAX_PRECISION) {
- throw new SQLExceptionInfo.Builder(SQLExceptionCode.DECIMAL_PRECISION_OUT_OF_RANGE)
- .setColumnName(columnDefName.getColumnName()).build().buildException();
+ if (maxLength != null) {
+ if (maxLength < 1 || maxLength > PDataType.MAX_PRECISION) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.DECIMAL_PRECISION_OUT_OF_RANGE)
+ .setColumnName(columnDefName.getColumnName()).build().buildException();
+ }
+ // When a precision is specified and a scale is not specified, it is set to 0.
+ //
+ // This is the standard as specified in
+ // http://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832
+ // and
+ // http://docs.oracle.com/javadb/10.6.2.1/ref/rrefsqlj15260.html.
+ // Otherwise, if scale is bigger than maxLength, just set it to the maxLength;
+ //
+ // When neither a precision nor a scale is specified, the precision and scale is
+ // ignored. All decimal are stored with as much decimal points as possible.
+ scale = scale == null ? PDataType.DEFAULT_SCALE : scale > maxLength ? maxLength : scale;
}
- // When a precision is specified and a scale is not specified, it is set to 0.
- //
- // This is the standard as specified in
- // http://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832
- // and
- // http://docs.oracle.com/javadb/10.6.2.1/ref/rrefsqlj15260.html.
- // Otherwise, if scale is bigger than maxLength, just set it to the maxLength;
- //
- // When neither a precision nor a scale is specified, the precision and scale is
- // ignored. All decimal are stored with as much decimal points as possible.
- scale = scale == null ?
- origMaxLength == null ? null : PDataType.DEFAULT_SCALE :
- scale > maxLength ? maxLength : scale;
} else if (this.dataType == PDataType.BINARY) {
if (maxLength == null) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.MISSING_BINARY_LENGTH)
@@ -114,12 +112,6 @@ public class ColumnDef {
.setColumnName(columnDefName.getColumnName()).build().buildException();
}
scale = null;
- } else if (this.dataType == PDataType.INTEGER) {
- maxLength = PDataType.INT_PRECISION;
- scale = PDataType.ZERO;
- } else if (this.dataType == PDataType.LONG) {
- maxLength = PDataType.LONG_PRECISION;
- scale = PDataType.ZERO;
} else {
// ignore maxLength and scale for other types.
maxLength = null;
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
index e0ee7f2..2c7ecbb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
@@ -86,7 +86,7 @@ public interface ConnectionQueryServices extends QueryServices, MetaDataMutated
boolean hasInvalidIndexConfiguration();
- long createSequence(String tenantId, String schemaName, String sequenceName, long startWith, long incrementBy, int batchSize, long timestamp) throws SQLException;
+ long createSequence(String tenantId, String schemaName, String sequenceName, long startWith, long incrementBy, long cacheSize, long timestamp) throws SQLException;
long dropSequence(String tenantId, String schemaName, String sequenceName, long timestamp) throws SQLException;
void validateSequences(List<SequenceKey> sequenceKeys, long timestamp, long[] values, SQLException[] exceptions, Sequence.Action action) throws SQLException;
void incrementSequences(List<SequenceKey> sequenceKeys, long timestamp, long[] values, SQLException[] exceptions) throws SQLException;
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
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 5dfb7c7..f5a80c6 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
@@ -1379,7 +1379,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
@Override
- public long createSequence(String tenantId, String schemaName, String sequenceName, long startWith, long incrementBy, int cacheSize, long timestamp)
+ public long createSequence(String tenantId, String schemaName, String sequenceName, long startWith, long incrementBy, long cacheSize, long timestamp)
throws SQLException {
SequenceKey sequenceKey = new SequenceKey(tenantId, schemaName, sequenceName);
Sequence newSequences = new Sequence(sequenceKey);
@@ -1802,6 +1802,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
}
+ private static final Integer DEFAULT_PRECISION = PDataType.MAX_PRECISION;
+ private static final Integer DEFAULT_SCALE = PDataType.DEFAULT_SCALE;
+
private void upgradeMetaDataTo3_0(String url, Properties props) throws SQLException {
if (upgradeWhiteList == null) {
return;
@@ -1886,28 +1889,46 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
/*
* Convert from old to new format:
+ * - sql date types to unsigend date types
+ * - don't persist maxLength and scale for non decimal numbers
+ * - don't persist default precision for decimal
*/
- // Convert sqlDataType if data/time type
- Integer dataType = (Integer)rs.getObject(DATA_TYPE);
- if (dataType != null) {
- switch (PDataType.fromTypeId(dataType)) {
+ Integer maxLength = (Integer)rs.getObject(COLUMN_SIZE);
+ Integer scale = (Integer)rs.getObject(DECIMAL_DIGITS);
+ Integer dataTypeNum = (Integer)rs.getObject(DATA_TYPE);
+ if (dataTypeNum != null) {
+ PDataType dataType = PDataType.fromTypeId(dataTypeNum);
+ switch (dataType) {
+ case DECIMAL:
+ if (DEFAULT_PRECISION.equals(maxLength) && DEFAULT_SCALE.equals(scale)) {
+ maxLength = null;
+ scale = null;
+ }
+ break;
case DATE:
- dataType = PDataType.UNSIGNED_DATE.getSqlType();
+ dataTypeNum = PDataType.UNSIGNED_DATE.getSqlType();
break;
case TIME:
- dataType = PDataType.UNSIGNED_TIME.getSqlType();
+ dataTypeNum = PDataType.UNSIGNED_TIME.getSqlType();
break;
case TIMESTAMP:
- dataType = PDataType.UNSIGNED_TIMESTAMP.getSqlType();
+ dataTypeNum = PDataType.UNSIGNED_TIMESTAMP.getSqlType();
break;
case BINARY:
// From way-back-when, we introduced VARBINARY after BINARY
rs.getInt(COLUMN_SIZE);
if (rs.wasNull()) {
- dataType = PDataType.VARBINARY.getSqlType();
+ dataTypeNum = PDataType.VARBINARY.getSqlType();
}
break;
default:
+ // Don't store precision and scale for int, long, etc, as
+ // there's no value (we actually lose information and need
+ // more special cases b/c we don't know that it wasn't set).
+ if (dataType.isCoercibleTo(PDataType.LONG)) {
+ maxLength = null;
+ scale = null;
+ }
break;
}
}
@@ -1922,7 +1943,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
stmt.setString(5,familyName);
stmt.setObject(6, rs.getObject(TABLE_SEQ_NUM));
stmt.setString(7, rs.getString(TABLE_TYPE));
- stmt.setObject(8, dataType);
+ stmt.setObject(8, dataTypeNum);
stmt.setString(9, pkName);
stmt.setObject(10, rs.getObject(COLUMN_COUNT));
stmt.setObject(11, rs.getObject(SALT_BUCKETS));
@@ -1930,8 +1951,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
stmt.setString(13, rs.getString(INDEX_STATE));
stmt.setObject(14, rs.getObject(IMMUTABLE_ROWS));
stmt.setString(15, defaultColumnFamily); // previous DEFAULT_COLUMN_FAMILY_NAME
- stmt.setObject(16, rs.getObject(COLUMN_SIZE));
- stmt.setObject(17, rs.getObject(DECIMAL_DIGITS));
+ stmt.setObject(16, maxLength);
+ stmt.setObject(17, scale);
stmt.setObject(18, rs.getObject(NULLABLE));
stmt.setObject(19, rs.getObject(ORDINAL_POSITION));
stmt.setObject(20, rs.getObject("COLUMN_MODIFIER")); // old column name
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
----------------------------------------------------------------------
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 f95bdc5..08048f4 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
@@ -286,7 +286,7 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices imple
}
@Override
- public long createSequence(String tenantId, String schemaName, String sequenceName, long startWith, long incrementBy, int cacheSize, long timestamp)
+ public long createSequence(String tenantId, String schemaName, String sequenceName, long startWith, long incrementBy, long cacheSize, long timestamp)
throws SQLException {
SequenceKey key = new SequenceKey(tenantId, schemaName, sequenceName);
if (sequenceMap.get(key) != null) {
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
index 06b508d..ac7c690 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
@@ -172,8 +172,8 @@ public class DelegateConnectionQueryServices extends DelegateQueryServices imple
@Override
public long createSequence(String tenantId, String schemaName, String sequenceName, long startWith,
- long incrementBy, int batchSize, long timestamp) throws SQLException {
- return getDelegate().createSequence(tenantId, schemaName, sequenceName, startWith, incrementBy, batchSize, timestamp);
+ long incrementBy, long cacheSize, long timestamp) throws SQLException {
+ return getDelegate().createSequence(tenantId, schemaName, sequenceName, startWith, incrementBy, cacheSize, timestamp);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/query/QueryConstants.java
----------------------------------------------------------------------
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 a5f72d4..d8dd8ac 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
@@ -218,7 +218,7 @@ public interface QueryConstants {
START_WITH + " BIGINT NOT NULL, \n" +
CURRENT_VALUE + " BIGINT NOT NULL, \n" +
INCREMENT_BY + " BIGINT NOT NULL, \n" +
- CACHE_SIZE + " INTEGER NOT NULL \n" +
+ CACHE_SIZE + " BIGINT NOT NULL \n" +
" CONSTRAINT " + SYSTEM_TABLE_PK_NAME + " PRIMARY KEY (" + TENANT_ID + "," + SEQUENCE_SCHEMA + "," + SEQUENCE_NAME + "))\n" +
HConstants.VERSIONS + "=" + MetaDataProtocol.DEFAULT_MAX_META_DATA_VERSIONS + "\n";
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
----------------------------------------------------------------------
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 fbed133..54c8945 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
@@ -111,7 +111,7 @@ public class QueryServicesOptions {
// Max size of 1st level main memory cache in bytes --> upper bound
public static final long DEFAULT_GROUPBY_MAX_CACHE_MAX = 1024L*1024L*100L; // 100 Mb
- public static final int DEFAULT_SEQUENCE_CACHE_SIZE = 100; // reserve 100 sequences at a time
+ public static final long DEFAULT_SEQUENCE_CACHE_SIZE = 100; // reserve 100 sequences at a time
public static final int DEFAULT_INDEX_MAX_FILESIZE_PERC = 50; // % of data table max file size for index table
public static final long DEFAULT_MAX_SERVER_METADATA_CACHE_TIME_TO_LIVE_MS = 60000 * 30; // 30 mins
public static final long DEFAULT_MAX_SERVER_METADATA_CACHE_SIZE = 1024L*1024L*20L; // 20 Mb
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java
index 55b8fd9..89e6c78 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java
@@ -35,13 +35,8 @@ public class DelegateDatum implements PDatum {
}
@Override
- public Integer getByteSize() {
- return delegate.getByteSize();
- }
-
- @Override
public Integer getMaxLength() {
- return delegate.getByteSize();
+ return delegate.getMaxLength();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
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 49316ee..1a67a68 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
@@ -686,14 +686,14 @@ public class MetaDataClient {
return new MutationState(1, connection);
}
- public MutationState createSequence(CreateSequenceStatement statement, long startWith, long incrementBy, int cacheSize) throws SQLException {
+ public MutationState createSequence(CreateSequenceStatement statement, long startWith, long incrementBy, long cacheSize) throws SQLException {
Long scn = connection.getSCN();
long timestamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
String tenantId = connection.getTenantId() == null ? null : connection.getTenantId().getString();
return createSequence(tenantId, statement.getSequenceName().getSchemaName(), statement.getSequenceName().getTableName(), statement.ifNotExists(), startWith, incrementBy, cacheSize, timestamp);
}
- private MutationState createSequence(String tenantId, String schemaName, String sequenceName, boolean ifNotExists, long startWith, long incrementBy, int cacheSize, long timestamp) throws SQLException {
+ private MutationState createSequence(String tenantId, String schemaName, String sequenceName, boolean ifNotExists, long startWith, long incrementBy, long cacheSize, long timestamp) throws SQLException {
try {
connection.getQueryServices().createSequence(tenantId, schemaName, sequenceName, startWith, incrementBy, cacheSize, timestamp);
} catch (SequenceAlreadyExistsException e) {
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/PBaseColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PBaseColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PBaseColumn.java
index e7e5c2c..2610739 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PBaseColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PBaseColumn.java
@@ -31,11 +31,6 @@ import org.apache.phoenix.util.SizedUtil;
public abstract class PBaseColumn implements PColumn {
@Override
- public final Integer getByteSize() {
- return getDataType().getByteSize();
- }
-
- @Override
public final Integer getMaxLength() {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java
index d702507..d3a9249 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java
@@ -129,13 +129,6 @@ public class PColumnImpl implements PColumn {
}
@Override
- public Integer getByteSize() {
- Integer dataTypeMaxLength = dataType.getByteSize();
- return dataTypeMaxLength == null ? dataType.estimateByteSizeFromLength(maxLength)
- : dataTypeMaxLength;
- }
-
- @Override
public boolean isNullable() {
return nullable;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
index de7ca5a..1e7a116 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
@@ -458,7 +458,8 @@ public enum PDataType {
@Override
public Integer getScale(Object o) {
- return ZERO;
+ return null;
+ //return ZERO;
}
@Override
@@ -589,7 +590,8 @@ public enum PDataType {
@Override
public Integer getScale(Object o) {
- return ZERO;
+ return null;
+ //return ZERO;
}
@Override
@@ -638,7 +640,8 @@ public enum PDataType {
@Override
public Integer getScale(Object o) {
- return ZERO;
+ return null;
+ //return ZERO;
}
@Override
@@ -765,7 +768,8 @@ public enum PDataType {
@Override
public Integer getScale(Object o) {
- return ZERO;
+ return null;
+ //return ZERO;
}
@Override
@@ -887,7 +891,7 @@ public enum PDataType {
}
Float v = (Float) o;
BigDecimal bd = BigDecimal.valueOf(v);
- return bd.scale();
+ return bd.scale() == 0 ? null : bd.scale();
}
@Override
@@ -1059,7 +1063,7 @@ public enum PDataType {
}
Double v = (Double) o;
BigDecimal bd = BigDecimal.valueOf(v);
- return bd.scale();
+ return bd.scale() == 0 ? null : bd.scale();
}
@Override
@@ -1262,7 +1266,7 @@ public enum PDataType {
@Override
public Integer getMaxLength(Object o) {
if (o == null) {
- return null;
+ return MAX_PRECISION;
}
BigDecimal v = (BigDecimal) o;
return v.precision();
@@ -1274,7 +1278,8 @@ public enum PDataType {
return null;
}
BigDecimal v = (BigDecimal) o;
- return v.scale();
+ int scale = v.scale();
+ return scale == 0 ? null : scale;
}
@Override
@@ -2534,7 +2539,8 @@ public enum PDataType {
@Override
public Integer getScale(Object o) {
- return ZERO;
+ return null;
+ //return ZERO;
}
@Override
@@ -2665,7 +2671,8 @@ public enum PDataType {
@Override
public Integer getScale(Object o) {
- return ZERO;
+ return null;
+ //return ZERO;
}
@Override
@@ -2781,7 +2788,7 @@ public enum PDataType {
}
Float v = (Float) o;
BigDecimal bd = BigDecimal.valueOf(v);
- return bd.scale();
+ return bd.scale() == 0 ? null : bd.scale();
}
@Override
@@ -2987,7 +2994,7 @@ public enum PDataType {
}
Double v = (Double) o;
BigDecimal bd = BigDecimal.valueOf(v);
- return bd.scale();
+ return bd.scale() == 0 ? null : bd.scale();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java
index 573f36e..792ba92 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java
@@ -30,11 +30,6 @@ public interface PDatum {
PDataType getDataType();
/**
- * @return maximum byte length of the column
- */
- Integer getByteSize();
-
- /**
* @return the actual length of the column. For decimal, it would be its precision. For char or
* varchar, it would be the maximum length as specified during schema definition.
*/
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
----------------------------------------------------------------------
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 94fda52..cee6d5b 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
@@ -443,11 +443,11 @@ public class PTableImpl implements PTable {
if (byteValue.length == 0 && !column.isNullable()) {
throw new ConstraintViolationException(name.getString() + "." + column.getName().getString() + " may not be null");
}
- Integer byteSize = column.getByteSize();
- if (byteSize != null && type.isFixedWidth() && byteValue.length <= byteSize) {
- byteValue = StringUtil.padChar(byteValue, byteSize);
- } else if (byteSize != null && byteValue.length > byteSize) {
- throw new ConstraintViolationException(name.getString() + "." + column.getName().getString() + " may not exceed " + byteSize + " bytes (" + SchemaUtil.toString(type, byteValue) + ")");
+ Integer maxLength = column.getMaxLength();
+ if (maxLength != null && type.isFixedWidth() && byteValue.length <= maxLength) {
+ byteValue = StringUtil.padChar(byteValue, maxLength);
+ } else if (maxLength != null && byteValue.length > maxLength) {
+ throw new ConstraintViolationException(name.getString() + "." + column.getName().getString() + " may not exceed " + maxLength + " bytes (" + SchemaUtil.toString(type, byteValue) + ")");
}
os.write(byteValue, 0, byteValue.length);
}
@@ -618,13 +618,14 @@ public class PTableImpl implements PTable {
deleteQuietly(unsetValues, kvBuilder, kvBuilder.buildDeleteColumns(keyPtr, column
.getFamilyName().getBytesPtr(), column.getName().getBytesPtr(), ts));
} else {
- Integer byteSize = column.getByteSize();
- if (byteSize != null && type.isFixedWidth()
- && byteValue.length <= byteSize) {
- byteValue = StringUtil.padChar(byteValue, byteSize);
- } else if (byteSize != null && byteValue.length > byteSize) {
- throw new ConstraintViolationException(name.getString() + "." + column.getName().getString() + " may not exceed " + byteSize + " bytes (" + type.toObject(byteValue) + ")");
- }
+ Integer maxLength = column.getMaxLength();
+ if (type.isFixedWidth() && maxLength != null) {
+ if (byteValue.length <= maxLength) {
+ byteValue = StringUtil.padChar(byteValue, maxLength);
+ } else if (byteValue.length > maxLength) {
+ throw new ConstraintViolationException(name.getString() + "." + column.getName().getString() + " may not exceed " + maxLength + " bytes (" + type.toObject(byteValue) + ")");
+ }
+ }
removeIfPresent(unsetValues, family, qualifier);
addQuietly(setValues, kvBuilder, kvBuilder.buildPut(keyPtr, column.getFamilyName()
.getBytesPtr(),
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java
index abd2a4e..03b2e6a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java
@@ -28,7 +28,6 @@ import java.util.List;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;
-
import org.apache.phoenix.util.ByteUtil;
@@ -65,7 +64,8 @@ public class RowKeyValueAccessor implements Writable {
int offset = 0;
if (datum.getDataType().isFixedWidth()) {
do {
- offset += datum.getByteSize();
+ Integer maxLength = datum.getMaxLength();
+ offset += maxLength == null ? datum.getDataType().getByteSize() : maxLength;
datum = iterator.next();
pos++;
} while (pos < index && datum.getDataType().isFixedWidth());
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
index 44c823f..4fc985a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
@@ -275,7 +275,7 @@ public class Sequence {
private static final class SequenceValue {
public final long incrementBy;
- public final int cacheSize;
+ public final long cacheSize;
public final long timestamp;
public long currentValue;
@@ -310,7 +310,7 @@ public class Sequence {
timestamp = currentValueKV.getTimestamp();
nextValue = PDataType.LONG.getCodec().decodeLong(currentValueKV.getBuffer(), currentValueKV.getValueOffset(), SortOrder.getDefault());
incrementBy = PDataType.LONG.getCodec().decodeLong(incrementByKV.getBuffer(), incrementByKV.getValueOffset(), SortOrder.getDefault());
- cacheSize = PDataType.INTEGER.getCodec().decodeInt(cacheSizeKV.getBuffer(), cacheSizeKV.getValueOffset(), SortOrder.getDefault());
+ cacheSize = PDataType.LONG.getCodec().decodeLong(cacheSizeKV.getBuffer(), cacheSizeKV.getValueOffset(), SortOrder.getDefault());
currentValue = nextValue - incrementBy * cacheSize;
}
}
@@ -342,7 +342,7 @@ public class Sequence {
.build().buildException();
}
- public Append createSequence(long startWith, long incrementBy, int cacheSize, long timestamp) {
+ public Append createSequence(long startWith, long incrementBy, long cacheSize, long timestamp) {
byte[] key = SchemaUtil.getSequenceKey(this.key.getTenantId(), this.key.getSchemaName(), this.key.getSequenceName());
Append append = new Append(key);
append.setAttribute(SequenceRegionObserver.OPERATION_ATTRIB, new byte[] {(byte)SequenceRegionObserver.Op.CREATE_SEQUENCE.ordinal()});
@@ -356,7 +356,7 @@ public class Sequence {
KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CURRENT_VALUE_BYTES, timestamp, startWithBuf),
KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.START_WITH_BYTES, timestamp, startWithBuf),
KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.INCREMENT_BY_BYTES, timestamp, PDataType.LONG.toBytes(incrementBy)),
- KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CACHE_SIZE_BYTES, timestamp, PDataType.INTEGER.toBytes(cacheSize))
+ KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CACHE_SIZE_BYTES, timestamp, PDataType.LONG.toBytes(cacheSize))
));
return append;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
index 95c99e0..65796eb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
@@ -181,8 +181,8 @@ public abstract class ValueSchema implements Writable {
this.count = count;
this.isNullable = isNullable;
if (this.type.isFixedWidth() && this.type.getByteSize() == null) {
- if (datum.getByteSize() != null) {
- this.byteSize = datum.getByteSize();
+ if (datum.getMaxLength() != null) {
+ this.byteSize = datum.getMaxLength();
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
----------------------------------------------------------------------
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 b998307..0df73d9 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
@@ -78,11 +78,6 @@ public class SchemaUtil {
}
@Override
- public Integer getByteSize() {
- return null;
- }
-
- @Override
public Integer getMaxLength() {
return null;
}
@@ -122,8 +117,9 @@ public class SchemaUtil {
List<PColumn> columns = table.getPKColumns();
while (i < columns.size()) {
PColumn keyColumn = columns.get(i++);
- Integer byteSize = keyColumn.getByteSize();
- maxKeyLength += (byteSize == null) ? VAR_LENGTH_ESTIMATE : byteSize;
+ PDataType type = keyColumn.getDataType();
+ Integer maxLength = keyColumn.getMaxLength();
+ maxKeyLength += !type.isFixedWidth() ? VAR_LENGTH_ESTIMATE : maxLength == null ? type.getByteSize() : maxLength;
}
return maxKeyLength;
}
@@ -392,7 +388,7 @@ public class SchemaUtil {
while (pos < pkColumns.size()) {
PColumn column = iterator.next();
if (column.getDataType().isFixedWidth()) { // Fixed width
- int length = column.getByteSize();
+ int length = SchemaUtil.getFixedByteSize(column);
if (maxOffset - offset < length) {
// The split truncates the field. Fill in the rest of the part and any fields that
// are missing after this field.
@@ -431,7 +427,7 @@ public class SchemaUtil {
while (iterator.hasNext()) {
PColumn column = iterator.next();
if (column.getDataType().isFixedWidth()) {
- length += column.getByteSize();
+ length += SchemaUtil.getFixedByteSize(column);
} else {
length += 1; // SEPARATOR byte.
}
@@ -538,6 +534,12 @@ public class SchemaUtil {
return maxKeyLength;
}
+ public static int getFixedByteSize(PDatum e) {
+ assert(e.getDataType().isFixedWidth());
+ Integer maxLength = e.getMaxLength();
+ return maxLength == null ? e.getDataType().getByteSize() : maxLength;
+ }
+
public static short getMaxKeySeq(PTable table) {
int offset = 0;
if (table.getBucketNum() != null) {
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java b/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
index dfda74f..9924d71 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
@@ -17,17 +17,24 @@
*/
package org.apache.phoenix.arithmetic;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.math.BigDecimal;
-import java.util.*;
+import java.util.Arrays;
+import java.util.List;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.junit.Test;
-
import org.apache.phoenix.exception.ValueTypeIncompatibleException;
-import org.apache.phoenix.expression.*;
+import org.apache.phoenix.expression.DecimalAddExpression;
+import org.apache.phoenix.expression.DecimalDivideExpression;
+import org.apache.phoenix.expression.DecimalMultiplyExpression;
+import org.apache.phoenix.expression.DecimalSubtractExpression;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.schema.PDataType;
+import org.junit.Test;
public class ArithmeticOperationTest {
@@ -109,6 +116,25 @@ public class ArithmeticOperationTest {
assertEqualValue(PDataType.DECIMAL, new BigDecimal("10000.2111"), ptr);
}
+ @Test
+ public void testIntPlusDecimal() throws Exception {
+ LiteralExpression op1, op2;
+ List<Expression> children;
+ ImmutableBytesWritable ptr;
+ DecimalAddExpression e;
+ boolean evaluated;
+
+ op1 = LiteralExpression.newConstant(new BigDecimal("1234.111"), PDataType.DECIMAL);
+ assertEquals(Integer.valueOf(3),op1.getScale());
+ op2 = LiteralExpression.newConstant(1, PDataType.INTEGER);
+ children = Arrays.<Expression>asList(op1, op2);
+ e = new DecimalAddExpression(children);
+ ptr = new ImmutableBytesWritable();
+ evaluated = e.evaluate(null, ptr);
+ assertTrue(evaluated);
+ assertEqualValue(PDataType.DECIMAL, new BigDecimal("1235.111"), ptr);
+ }
+
// Subtraction
// result scale should be: max(ls, rs)
// result precision should be: max(lp - ls, rp - rs) + 1 + max(ls, rs)
@@ -234,6 +260,7 @@ public class ArithmeticOperationTest {
// Decimal with no precision and scale.
op1 = LiteralExpression.newConstant(new BigDecimal("1111.1"), PDataType.DECIMAL);
+ assertEquals(Integer.valueOf(1),op1.getScale());
op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDataType.DECIMAL, 5, 4);
children = Arrays.<Expression>asList(op1, op2);
e = new DecimalMultiplyExpression(children);
@@ -282,12 +309,14 @@ public class ArithmeticOperationTest {
// Decimal with no precision and scale.
op1 = LiteralExpression.newConstant(new BigDecimal("10"), PDataType.DECIMAL);
op2 = LiteralExpression.newConstant(new BigDecimal("3"), PDataType.DECIMAL, 5, 4);
+ assertEquals(Integer.valueOf(4),op2.getScale());
children = Arrays.<Expression>asList(op1, op2);
e = new DecimalDivideExpression(children);
ptr = new ImmutableBytesWritable();
evaluated = e.evaluate(null, ptr);
assertTrue(evaluated);
- assertEqualValue(PDataType.DECIMAL, new BigDecimal("3.3333333333333333333333333333333333333"), ptr);
+ assertEqualValue(PDataType.DECIMAL, new BigDecimal("3.3333"), ptr);
+ // TODO: review, as this seems wrong: assertEqualValue(PDataType.DECIMAL, new BigDecimal("3.3333333333333333333333333333333333333"), ptr);
}
private static void assertEqualValue(PDataType type, Object value, ImmutableBytesWritable ptr) {
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java
index a7b5778..b9041fb 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java
@@ -23,6 +23,12 @@ import java.util.Collection;
import java.util.List;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.query.KeyRange;
+import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.ByteUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -30,12 +36,6 @@ import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
-import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
-import org.apache.phoenix.schema.PDatum;
-import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
-import org.apache.phoenix.util.ByteUtil;
/**
@@ -485,10 +485,6 @@ public class ScanRangesTest {
return PDataType.CHAR;
}
@Override
- public Integer getByteSize() {
- return width;
- }
- @Override
public Integer getMaxLength() {
return width;
}
@@ -512,10 +508,6 @@ public class ScanRangesTest {
return PDataType.VARCHAR;
}
@Override
- public Integer getByteSize() {
- return width;
- }
- @Override
public Integer getMaxLength() {
return width;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java
index dde53bf..222c66c 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataTest.java
@@ -209,8 +209,10 @@ public class QueryDatabaseMetaDataTest extends BaseClientManagedTimeTest {
assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
assertEquals(PDataType.INTEGER.getSqlType(), rs.getInt("DATA_TYPE"));
assertEquals(2, rs.getInt("ORDINAL_POSITION"));
- assertEquals(10, rs.getInt("COLUMN_SIZE"));
+ assertEquals(0, rs.getInt("COLUMN_SIZE"));
+ assertTrue(rs.wasNull());
assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
+ assertTrue(rs.wasNull());
assertTrue(rs.next());
assertEquals(rs.getString("TABLE_SCHEM"),null);
@@ -220,8 +222,10 @@ public class QueryDatabaseMetaDataTest extends BaseClientManagedTimeTest {
assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
assertEquals(PDataType.LONG.getSqlType(), rs.getInt("DATA_TYPE"));
assertEquals(3, rs.getInt("ORDINAL_POSITION"));
- assertEquals(19, rs.getInt("COLUMN_SIZE"));
+ assertEquals(0, rs.getInt("COLUMN_SIZE"));
+ assertTrue(rs.wasNull());
assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
+ assertTrue(rs.wasNull());
assertTrue(rs.next());
assertEquals(rs.getString("TABLE_SCHEM"),null);
@@ -231,8 +235,10 @@ public class QueryDatabaseMetaDataTest extends BaseClientManagedTimeTest {
assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
assertEquals(PDataType.DECIMAL.getSqlType(), rs.getInt("DATA_TYPE"));
assertEquals(4, rs.getInt("ORDINAL_POSITION"));
- assertEquals(PDataType.MAX_PRECISION, rs.getInt("COLUMN_SIZE"));
+ assertEquals(0, rs.getInt("COLUMN_SIZE"));
+ assertTrue(rs.wasNull());
assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
+ assertTrue(rs.wasNull());
assertTrue(rs.next());
assertEquals(rs.getString("TABLE_SCHEM"),null);
@@ -268,8 +274,10 @@ public class QueryDatabaseMetaDataTest extends BaseClientManagedTimeTest {
assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
assertEquals(PDataType.INTEGER.getSqlType(), rs.getInt("DATA_TYPE"));
assertEquals(2, rs.getInt("ORDINAL_POSITION"));
- assertEquals(10, rs.getInt("COLUMN_SIZE"));
+ assertEquals(0, rs.getInt("COLUMN_SIZE"));
+ assertTrue(rs.wasNull());
assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
+ assertTrue(rs.wasNull());
assertFalse(rs.next());
@@ -283,8 +291,10 @@ public class QueryDatabaseMetaDataTest extends BaseClientManagedTimeTest {
assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
assertEquals(PDataType.INTEGER.getSqlType(), rs.getInt("DATA_TYPE"));
assertEquals(2, rs.getInt("ORDINAL_POSITION"));
- assertEquals(10, rs.getInt("COLUMN_SIZE"));
+ assertEquals(0, rs.getInt("COLUMN_SIZE"));
+ assertTrue(rs.wasNull());
assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
+ assertTrue(rs.wasNull());
assertTrue(rs.next());
assertEquals(rs.getString("TABLE_SCHEM"),null);
@@ -294,8 +304,10 @@ public class QueryDatabaseMetaDataTest extends BaseClientManagedTimeTest {
assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
assertEquals(PDataType.LONG.getSqlType(), rs.getInt("DATA_TYPE"));
assertEquals(3, rs.getInt("ORDINAL_POSITION"));
- assertEquals(19, rs.getInt("COLUMN_SIZE"));
+ assertEquals(0, rs.getInt("COLUMN_SIZE"));
+ assertTrue(rs.wasNull());
assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
+ assertTrue(rs.wasNull());
assertTrue(rs.next());
assertEquals(rs.getString("TABLE_SCHEM"),null);
@@ -305,8 +317,10 @@ public class QueryDatabaseMetaDataTest extends BaseClientManagedTimeTest {
assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
assertEquals(PDataType.DECIMAL.getSqlType(), rs.getInt("DATA_TYPE"));
assertEquals(4, rs.getInt("ORDINAL_POSITION"));
- assertEquals(PDataType.MAX_PRECISION, rs.getInt("COLUMN_SIZE"));
+ assertEquals(0, rs.getInt("COLUMN_SIZE"));
+ assertTrue(rs.wasNull());
assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
+ assertTrue(rs.wasNull());
assertTrue(rs.next());
assertEquals(rs.getString("TABLE_SCHEM"),null);
@@ -318,6 +332,7 @@ public class QueryDatabaseMetaDataTest extends BaseClientManagedTimeTest {
assertEquals(5, rs.getInt("ORDINAL_POSITION"));
assertEquals(5, rs.getInt("COLUMN_SIZE"));
assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
+ assertFalse(rs.wasNull());
assertTrue(rs.next());
assertEquals(rs.getString("TABLE_SCHEM"),null);
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/test/java/org/apache/phoenix/end2end/SkipRangeParallelIteratorRegionSplitterTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/SkipRangeParallelIteratorRegionSplitterTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/SkipRangeParallelIteratorRegionSplitterTest.java
index e698346..676e7bb 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/SkipRangeParallelIteratorRegionSplitterTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/SkipRangeParallelIteratorRegionSplitterTest.java
@@ -257,10 +257,6 @@ public class SkipRangeParallelIteratorRegionSplitterTest extends BaseClientManag
return PDataType.CHAR;
}
@Override
- public Integer getByteSize() {
- return width;
- }
- @Override
public Integer getMaxLength() {
return width;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java
index 6164511..84dbb11 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java
@@ -33,6 +33,8 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
+import java.text.Format;
+import java.text.ParseException;
import java.util.Properties;
import org.apache.phoenix.exception.SQLExceptionCode;
@@ -446,6 +448,59 @@ public class UpsertValuesTest extends BaseClientManagedTimeTest {
} finally {
closeStmtAndConn(pstmt, conn);
}
+ }
+
+ private static Format DATE_FORMAT = DateUtil.getDateParser(DateUtil.DEFAULT_DATE_FORMAT);
+
+ private static Date toDate(String dateString) {
+ try {
+ return (Date)DATE_FORMAT.parseObject(dateString);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Test
+ public void testUpsertDateIntoUnsignedDate() throws Exception {
+ long ts = nextTimestamp();
+ Properties props = new Properties();
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = DriverManager.getConnection(getUrl(), props);
+ stmt = conn.prepareStatement("create table UpsertTimestamp (k varchar, v unsigned_date not null, constraint pk primary key (k,v))");
+ stmt.execute();
+ } finally {
+ closeStmtAndConn(stmt, conn);
+ }
+
+ String dateStr = "2013-01-01 04:00:00";
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2));
+ try {
+ conn = DriverManager.getConnection(getUrl(), props);
+ stmt = conn.prepareStatement("upsert into UpsertTimestamp(k,v) values ('a', to_date(?))");
+ stmt.setString(1, dateStr);
+ stmt.executeUpdate();
+ conn.commit();
+ } finally {
+ closeStmtAndConn(stmt, conn);
+ }
+ Date date = toDate(dateStr);
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 4));
+ try {
+ conn = DriverManager.getConnection(getUrl(), props);
+ stmt = conn.prepareStatement("select * from UpsertTimestamp");
+ ResultSet rs = stmt.executeQuery();
+ assertTrue(rs.next());
+ assertEquals("a", rs.getString(1));
+ assertEquals(date, rs.getDate(2));
+ assertFalse(rs.next());
+ } finally {
+ closeStmtAndConn(stmt, conn);
+ }
}
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java
index bd6f17d..6d44818 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java
@@ -25,6 +25,12 @@ import java.util.Collection;
import java.util.List;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.query.KeyRange;
+import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.RowKeySchema;
+import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
+import org.apache.phoenix.schema.SortOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -32,12 +38,6 @@ import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
-import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
-import org.apache.phoenix.schema.PDatum;
-import org.apache.phoenix.schema.RowKeySchema;
-import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
/**
@@ -481,13 +481,9 @@ public class SkipScanFilterIntersectTest {
public PDataType getDataType() {
return width <= 0 ? PDataType.VARCHAR : PDataType.CHAR;
}
- @Override
- public Integer getByteSize() {
- return width <= 0 ? null : width;
- }
- @Override
+ @Override
public Integer getMaxLength() {
- return getByteSize();
+ return width <= 0 ? null : width;
}
@Override
public Integer getScale() {
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java
index eeaba4b..102fe25 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java
@@ -27,6 +27,13 @@ import junit.framework.TestCase;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.filter.Filter.ReturnCode;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.query.KeyRange;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.ByteUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -34,13 +41,6 @@ import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
-import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
-import org.apache.phoenix.schema.PDatum;
-import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
-import org.apache.phoenix.util.ByteUtil;
//reset()
//filterAllRemaining() -> true indicates scan is over, false, keep going on.
@@ -73,13 +73,8 @@ public class SkipScanFilterTest extends TestCase {
}
@Override
- public Integer getByteSize() {
- return width <= 0 ? null : width;
- }
-
- @Override
public Integer getMaxLength() {
- return getByteSize();
+ return width <= 0 ? null : width;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java
index 16489bd..309dc45 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java
@@ -20,13 +20,11 @@ package org.apache.phoenix.schema;
import static org.junit.Assert.assertEquals;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Test;
-
import org.apache.phoenix.schema.KeyValueSchema.KeyValueSchemaBuilder;
+import org.junit.Test;
public class ValueBitSetTest {
- private static final int FIXED_WIDTH_CHAR_SIZE = 10;
private KeyValueSchema generateSchema(int nFields, int nRepeating, final int nNotNull) {
KeyValueSchemaBuilder builder = new KeyValueSchemaBuilder(nNotNull);
for (int i = 0; i < nFields; i++) {
@@ -42,10 +40,6 @@ public class ValueBitSetTest {
return PDataType.values()[fieldIndex % PDataType.values().length];
}
@Override
- public Integer getByteSize() {
- return !getDataType().isFixedWidth() ? null : getDataType().getByteSize() == null ? FIXED_WIDTH_CHAR_SIZE : getDataType().getByteSize();
- }
- @Override
public Integer getMaxLength() {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java
index dd4d95e..868dd46 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java
@@ -23,21 +23,21 @@ import java.util.Collection;
import java.util.List;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.query.KeyRange.Bound;
import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.PDatum;
import org.apache.phoenix.schema.RowKeySchema;
import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
+import org.apache.phoenix.schema.SortOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
/**
@@ -65,10 +65,6 @@ public class ScanUtilTest {
return PDataType.CHAR;
}
@Override
- public Integer getByteSize() {
- return width;
- }
- @Override
public Integer getMaxLength() {
return width;
}
@@ -92,10 +88,6 @@ public class ScanUtilTest {
return PDataType.VARCHAR;
}
@Override
- public Integer getByteSize() {
- return null;
- }
- @Override
public Integer getMaxLength() {
return null;
}
[3/3] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-phoenix
Posted by ja...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-phoenix
Project: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/commit/1159b6e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/tree/1159b6e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/diff/1159b6e1
Branch: refs/heads/master
Commit: 1159b6e1dda25a0543be5bb615629672bbda7960
Parents: d43adc6 b44ad86
Author: James Taylor <ja...@apache.org>
Authored: Thu Mar 6 17:13:18 2014 -0800
Committer: James Taylor <ja...@apache.org>
Committed: Thu Mar 6 17:13:18 2014 -0800
----------------------------------------------------------------------
.../phoenix/end2end/index/MutableIndexTest.java | 34 ++++++++++++++++++++
1 file changed, 34 insertions(+)
----------------------------------------------------------------------
[2/3] git commit: PHOENIX-119 Removed unnecessary
Expression.getByteSize() method
Posted by ja...@apache.org.
PHOENIX-119 Removed unnecessary Expression.getByteSize() method
Project: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/commit/d43adc62
Tree: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/tree/d43adc62
Diff: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/diff/d43adc62
Branch: refs/heads/master
Commit: d43adc62c22285a59f692fcd3d9567d5f287c287
Parents: 3931fc9
Author: James Taylor <ja...@apache.org>
Authored: Thu Mar 6 17:13:06 2014 -0800
Committer: James Taylor <ja...@apache.org>
Committed: Thu Mar 6 17:13:06 2014 -0800
----------------------------------------------------------------------
.../phoenix/compile/CreateSequenceCompiler.java | 16 +---
.../phoenix/compile/ExpressionCompiler.java | 24 +----
.../apache/phoenix/compile/LimitCompiler.java | 15 +--
.../phoenix/compile/ProjectionCompiler.java | 10 +-
.../apache/phoenix/compile/WhereOptimizer.java | 17 ++--
.../coprocessor/SequenceRegionObserver.java | 2 +-
.../expression/BaseAddSubtractExpression.java | 34 +++++--
.../phoenix/expression/BaseExpression.java | 11 +--
.../phoenix/expression/CaseExpression.java | 7 +-
.../phoenix/expression/CoerceExpression.java | 29 +++---
.../phoenix/expression/ColumnExpression.java | 26 +-----
.../expression/ComparisonExpression.java | 2 +-
.../expression/DecimalAddExpression.java | 12 +--
.../expression/DecimalSubtractExpression.java | 12 +--
.../phoenix/expression/DivideExpression.java | 39 +++++---
.../phoenix/expression/LiteralExpression.java | 17 +---
.../phoenix/expression/MultiplyExpression.java | 37 +++++---
.../expression/RowKeyColumnExpression.java | 17 +---
.../RowValueConstructorExpression.java | 5 +-
.../expression/function/ArrayIndexFunction.java | 7 +-
.../expression/function/CoalesceFunction.java | 12 +--
.../expression/function/InvertFunction.java | 10 +-
.../expression/function/LTrimFunction.java | 12 +--
.../expression/function/MD5Function.java | 98 +++++++++-----------
.../expression/function/PrefixFunction.java | 5 +-
.../expression/function/RTrimFunction.java | 16 +---
.../function/RegexpSubstrFunction.java | 15 +--
.../function/RoundDateExpression.java | 17 ++--
.../expression/function/SubstrFunction.java | 23 ++---
.../expression/function/TrimFunction.java | 11 +--
.../apache/phoenix/index/IndexMaintainer.java | 34 ++-----
.../phoenix/jdbc/PhoenixDatabaseMetaData.java | 4 -
.../phoenix/jdbc/PhoenixParameterMetaData.java | 7 +-
.../phoenix/jdbc/PhoenixResultSetMetaData.java | 8 +-
.../apache/phoenix/jdbc/PhoenixStatement.java | 4 -
.../org/apache/phoenix/parse/ColumnDef.java | 42 ++++-----
.../phoenix/query/ConnectionQueryServices.java | 2 +-
.../query/ConnectionQueryServicesImpl.java | 45 ++++++---
.../query/ConnectionlessQueryServicesImpl.java | 2 +-
.../query/DelegateConnectionQueryServices.java | 4 +-
.../apache/phoenix/query/QueryConstants.java | 2 +-
.../phoenix/query/QueryServicesOptions.java | 2 +-
.../apache/phoenix/schema/DelegateDatum.java | 7 +-
.../apache/phoenix/schema/MetaDataClient.java | 4 +-
.../org/apache/phoenix/schema/PBaseColumn.java | 5 -
.../org/apache/phoenix/schema/PColumnImpl.java | 7 --
.../org/apache/phoenix/schema/PDataType.java | 31 ++++---
.../java/org/apache/phoenix/schema/PDatum.java | 5 -
.../org/apache/phoenix/schema/PTableImpl.java | 25 ++---
.../phoenix/schema/RowKeyValueAccessor.java | 4 +-
.../org/apache/phoenix/schema/Sequence.java | 8 +-
.../org/apache/phoenix/schema/ValueSchema.java | 4 +-
.../org/apache/phoenix/util/SchemaUtil.java | 20 ++--
.../arithmetic/ArithmeticOperationTest.java | 41 ++++++--
.../apache/phoenix/compile/ScanRangesTest.java | 20 ++--
.../end2end/QueryDatabaseMetaDataTest.java | 29 ++++--
...RangeParallelIteratorRegionSplitterTest.java | 4 -
.../phoenix/end2end/UpsertValuesTest.java | 55 +++++++++++
.../filter/SkipScanFilterIntersectTest.java | 20 ++--
.../phoenix/filter/SkipScanFilterTest.java | 21 ++---
.../apache/phoenix/schema/ValueBitSetTest.java | 8 +-
.../org/apache/phoenix/util/ScanUtilTest.java | 24 ++---
62 files changed, 509 insertions(+), 547 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java
index d7297c4..94f13cb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java
@@ -59,11 +59,6 @@ public class CreateSequenceCompiler {
}
@Override
- public Integer getByteSize() {
- return PDataType.LONG.getByteSize();
- }
-
- @Override
public Integer getMaxLength() {
return null;
}
@@ -92,11 +87,6 @@ public class CreateSequenceCompiler {
}
@Override
- public Integer getByteSize() {
- return PDataType.INTEGER.getByteSize();
- }
-
- @Override
public Integer getMaxLength() {
return null;
}
@@ -167,17 +157,17 @@ public class CreateSequenceCompiler {
}
final long incrementBy = (Long)PDataType.LONG.toObject(ptr, incrementByExpr.getDataType());
- int cacheSizeValue = connection.getQueryServices().getProps().getInt(QueryServices.SEQUENCE_CACHE_SIZE_ATTRIB,QueryServicesOptions.DEFAULT_SEQUENCE_CACHE_SIZE);
+ long cacheSizeValue = connection.getQueryServices().getProps().getLong(QueryServices.SEQUENCE_CACHE_SIZE_ATTRIB,QueryServicesOptions.DEFAULT_SEQUENCE_CACHE_SIZE);
if (cacheNode != null) {
Expression cacheSizeExpr = cacheNode.accept(expressionCompiler);
cacheSizeExpr.evaluate(null, ptr);
- if (ptr.getLength() != 0 && (!cacheSizeExpr.getDataType().isCoercibleTo(PDataType.INTEGER) || (cacheSizeValue = (Integer)PDataType.INTEGER.toObject(ptr)) < 0)) {
+ if (ptr.getLength() != 0 && (!cacheSizeExpr.getDataType().isCoercibleTo(PDataType.LONG) || (cacheSizeValue = (Long)PDataType.LONG.toObject(ptr, cacheSizeExpr.getDataType())) < 0)) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.CACHE_MUST_BE_NON_NEGATIVE_CONSTANT)
.setSchemaName(sequence.getSequenceName().getSchemaName())
.setTableName(sequence.getSequenceName().getTableName()).build().buildException();
}
}
- final int cacheSize = Math.max(1, cacheSizeValue);
+ final long cacheSize = Math.max(1L, cacheSizeValue);
final MetaDataClient client = new MetaDataClient(connection);
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
----------------------------------------------------------------------
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 9d1f4f1..f03c378 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
@@ -435,13 +435,13 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
// to return NULL.
int index = LikeExpression.indexOfWildcard(pattern);
// Can't possibly be as long as the constant, then FALSE
- Integer lhsByteSize = lhs.getByteSize();
- if (lhsByteSize != null && lhsByteSize < index) {
+ Integer lhsMaxLength = lhs.getMaxLength();
+ if (lhsMaxLength != null && lhsMaxLength < index) {
return LiteralExpression.newConstant(false, rhs.isDeterministic());
}
if (index == -1) {
String rhsLiteral = LikeExpression.unescapeLike(pattern);
- if (lhsByteSize != null && lhsByteSize != rhsLiteral.length()) {
+ if (lhsMaxLength != null && lhsMaxLength != rhsLiteral.length()) {
return LiteralExpression.newConstant(false, rhs.isDeterministic());
}
CompareOp op = node.isNegate() ? CompareOp.NOT_EQUAL : CompareOp.EQUAL;
@@ -556,16 +556,12 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
return PDataType.DECIMAL;
}
@Override
- public Integer getByteSize() {
- return null;
- }
- @Override
public Integer getMaxLength() {
return null;
}
@Override
public Integer getScale() {
- return PDataType.DEFAULT_SCALE;
+ return null;
}
@Override
public SortOrder getSortOrder() {
@@ -683,10 +679,6 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
return type;
}
@Override
- public Integer getByteSize() {
- return type.getByteSize();
- }
- @Override
public Integer getMaxLength() {
return expression.getMaxLength();
}
@@ -712,10 +704,6 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
return PDataType.DECIMAL;
}
@Override
- public Integer getByteSize() {
- return null;
- }
- @Override
public Integer getMaxLength() {
return expression.getMaxLength();
}
@@ -860,10 +848,6 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
return PDataType.DECIMAL;
}
@Override
- public Integer getByteSize() {
- return null;
- }
- @Override
public Integer getMaxLength() {
return expression.getMaxLength();
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java
index 5e32e05..b114fba 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java
@@ -19,8 +19,15 @@ package org.apache.phoenix.compile;
import java.sql.SQLException;
-import org.apache.phoenix.parse.*;
-import org.apache.phoenix.schema.*;
+import org.apache.phoenix.parse.BindParseNode;
+import org.apache.phoenix.parse.FilterableStatement;
+import org.apache.phoenix.parse.LimitNode;
+import org.apache.phoenix.parse.LiteralParseNode;
+import org.apache.phoenix.parse.ParseNodeFactory;
+import org.apache.phoenix.parse.TraverseNoParseNodeVisitor;
+import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.SortOrder;
public class LimitCompiler {
@@ -36,10 +43,6 @@ public class LimitCompiler {
return PDataType.INTEGER;
}
@Override
- public Integer getByteSize() {
- return getDataType().getByteSize();
- }
- @Override
public Integer getMaxLength() {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
index 6e5d8d1..40a44fe 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
@@ -340,14 +340,16 @@ public class ProjectionCompiler {
PColumnFamily family = table.getColumnFamily(entry.getKey());
if (entry.getValue() == null) {
for (PColumn column : family.getColumns()) {
- Integer byteSize = column.getByteSize();
- estimatedByteSize += SizedUtil.KEY_VALUE_SIZE + estimatedKeySize + (byteSize == null ? RowKeySchema.ESTIMATED_VARIABLE_LENGTH_SIZE : byteSize);
+ Integer maxLength = column.getMaxLength();
+ int byteSize = column.getDataType().isFixedWidth() ? maxLength == null ? column.getDataType().getByteSize() : maxLength : RowKeySchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
+ estimatedByteSize += SizedUtil.KEY_VALUE_SIZE + estimatedKeySize + byteSize;
}
} else {
for (byte[] cq : entry.getValue()) {
PColumn column = family.getColumn(cq);
- Integer byteSize = column.getByteSize();
- estimatedByteSize += SizedUtil.KEY_VALUE_SIZE + estimatedKeySize + (byteSize == null ? RowKeySchema.ESTIMATED_VARIABLE_LENGTH_SIZE : byteSize);
+ Integer maxLength = column.getMaxLength();
+ int byteSize = column.getDataType().isFixedWidth() ? maxLength == null ? column.getDataType().getByteSize() : maxLength : RowKeySchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
+ estimatedByteSize += SizedUtil.KEY_VALUE_SIZE + estimatedKeySize + byteSize;
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
index 2d0b046..fa675f5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
@@ -727,7 +727,7 @@ public class WhereOptimizer {
// and the key length doesn't match the column length, the expression can
// never be true.
// An zero length byte literal is null which can never be compared against as true
- Integer childNodeFixedLength = node.getChildren().get(0).getByteSize();
+ Integer childNodeFixedLength = node.getChildren().get(0).getMaxLength();
if (childNodeFixedLength != null && key.length > childNodeFixedLength) {
return DEGENERATE_KEY_PARTS;
}
@@ -735,7 +735,7 @@ public class WhereOptimizer {
PColumn column = childSlot.getKeyPart().getColumn();
PDataType type = column.getDataType();
KeyRange keyRange = type.getKeyRange(key, true, ByteUtil.nextKey(key), false);
- Integer columnFixedLength = column.getByteSize();
+ Integer columnFixedLength = column.getMaxLength();
if (columnFixedLength != null) {
keyRange = keyRange.fill(columnFixedLength);
}
@@ -794,7 +794,7 @@ public class WhereOptimizer {
boolean isFixedWidth = type.isFixedWidth();
if (isFixedWidth) { // if column can't be null
return node.isNegate() ? null :
- newKeyParts(childSlot, node, type.getKeyRange(new byte[column.getByteSize()], true,
+ newKeyParts(childSlot, node, type.getKeyRange(new byte[SchemaUtil.getFixedByteSize(column)], true,
KeyRange.UNBOUND, true));
} else {
KeyRange keyRange = node.isNegate() ? KeyRange.IS_NOT_NULL_RANGE : KeyRange.IS_NULL_RANGE;
@@ -944,7 +944,7 @@ public class WhereOptimizer {
// If the column is fixed width, fill is up to it's byte size
PDataType type = getColumn().getDataType();
if (type.isFixedWidth()) {
- Integer length = getColumn().getByteSize();
+ Integer length = getColumn().getMaxLength();
if (length != null) {
key = ByteUtil.fillKey(key, length);
}
@@ -1075,8 +1075,8 @@ public class WhereOptimizer {
// use to compute the next key when we evaluate the RHS row value constructor
// below. We could create a new childPart with a delegate column that returns
// null for getByteSize().
- if (lhs.getByteSize() != null && key.length != lhs.getByteSize()) {
- key = Arrays.copyOf(key, lhs.getByteSize());
+ if (lhs.getDataType().isFixedWidth() && lhs.getMaxLength() != null && key.length != lhs.getMaxLength()) {
+ key = Arrays.copyOf(key, lhs.getMaxLength());
}
ptr.set(key);
return true;
@@ -1093,11 +1093,6 @@ public class WhereOptimizer {
}
@Override
- public Integer getByteSize() {
- return lhs.getByteSize();
- }
-
- @Override
public Integer getMaxLength() {
return lhs.getMaxLength();
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
index b8eb7d4..53cb2f1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
@@ -133,7 +133,7 @@ public class SequenceRegionObserver extends BaseRegionObserver {
KeyValue cacheSizeKV = Sequence.getCacheSizeKV(result);
long value = PDataType.LONG.getCodec().decodeLong(currentValueKV.getBuffer(), currentValueKV.getValueOffset(), SortOrder.getDefault());
long incrementBy = PDataType.LONG.getCodec().decodeLong(incrementByKV.getBuffer(), incrementByKV.getValueOffset(), SortOrder.getDefault());
- int cacheSize = PDataType.INTEGER.getCodec().decodeInt(cacheSizeKV.getBuffer(), cacheSizeKV.getValueOffset(), SortOrder.getDefault());
+ long cacheSize = PDataType.LONG.getCodec().decodeLong(cacheSizeKV.getBuffer(), cacheSizeKV.getValueOffset(), SortOrder.getDefault());
value += incrementBy * cacheSize;
byte[] valueBuffer = new byte[PDataType.LONG.getByteSize()];
PDataType.LONG.getCodec().encodeLong(value, valueBuffer, 0);
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java
index e3fcc9e..b91d5c7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java
@@ -30,20 +30,38 @@ abstract public class BaseAddSubtractExpression extends ArithmeticExpression {
super(children);
}
- protected static Integer getPrecision(Integer lp, Integer rp, Integer ls, Integer rs) {
- if (ls == null || rs == null) {
- return PDataType.MAX_PRECISION;
+ protected static Integer getPrecision(Integer lp, Integer ls, Expression childExpr) {
+ if (childExpr.getDataType() == null) {
+ return null;
+ }
+ Integer rp = childExpr.getMaxLength();
+ Integer rs = childExpr.getScale();
+ if (rp == null) {
+ rp = childExpr.getDataType().getMaxLength(null);
+ }
+ if (lp == null) {
+ return rp;
}
- int val = getScale(lp, rp, ls, rs) + Math.max(lp - ls, rp - rs) + 1;
+ if (rp == null) {
+ return lp;
+ }
+ if (ls == null || rs == null) {
+ return PDataType.MAX_PRECISION;
+ }
+ int val = getScale(lp, ls, childExpr) + Math.max(lp - ls, rp - rs) + 1;
return Math.min(PDataType.MAX_PRECISION, val);
}
- protected static Integer getScale(Integer lp, Integer rp, Integer ls, Integer rs) {
+ protected static Integer getScale(Integer lp, Integer ls, Expression childExpr) {
+ Integer rs = childExpr.getScale();
// If we are adding a decimal with scale and precision to a decimal
// with no precision nor scale, the scale system does not apply.
- if (ls == null || rs == null) {
- return null;
- }
+ if (ls == null) {
+ return rs;
+ }
+ if (rs == null) {
+ return ls;
+ }
int val = Math.max(ls, rs);
return Math.min(PDataType.MAX_PRECISION, val);
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java
index 29c1d2c..de6dc38 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java
@@ -76,7 +76,7 @@ public abstract class BaseExpression implements Expression {
} else if ((rhsType == PDataType.TIMESTAMP || rhsType == PDataType.UNSIGNED_TIMESTAMP) && (lhsType != PDataType.TIMESTAMP && lhsType != PDataType.UNSIGNED_TIMESTAMP)) {
e = FloorDateExpression.create(rhs, TimeUnit.MILLISECOND);
}
- e = CoerceExpression.create(e, lhsType, lhs.getSortOrder(), lhs.getByteSize());
+ e = CoerceExpression.create(e, lhsType, lhs.getSortOrder(), lhs.getMaxLength());
return e;
}
@@ -95,7 +95,7 @@ public abstract class BaseExpression implements Expression {
} else if ((rhsType == PDataType.TIMESTAMP || rhsType == PDataType.UNSIGNED_TIMESTAMP) && (lhsType != PDataType.TIMESTAMP && lhsType != PDataType.UNSIGNED_TIMESTAMP)) {
e = CeilTimestampExpression.create(rhs);
}
- e = CoerceExpression.create(e, lhsType, lhs.getSortOrder(), lhs.getByteSize());
+ e = CoerceExpression.create(e, lhsType, lhs.getSortOrder(), lhs.getMaxLength());
return e;
}
@@ -106,7 +106,7 @@ public abstract class BaseExpression implements Expression {
@Override
public Expression wrap(Expression lhs, Expression rhs) throws SQLException {
PDataType lhsType = lhs.getDataType();
- Expression e = CoerceExpression.create(rhs, lhsType, lhs.getSortOrder(), lhs.getByteSize());
+ Expression e = CoerceExpression.create(rhs, lhsType, lhs.getSortOrder(), lhs.getMaxLength());
return e;
}
@@ -194,11 +194,6 @@ public abstract class BaseExpression implements Expression {
}
@Override
- public Integer getByteSize() {
- return getDataType().isFixedWidth() ? getDataType().getByteSize() : null;
- }
-
- @Override
public Integer getMaxLength() {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
index 421249a..1fc21f7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
@@ -26,7 +26,6 @@ import java.util.List;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.WritableUtils;
-
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.expression.visitor.ExpressionVisitor;
@@ -125,6 +124,12 @@ public class CaseExpression extends BaseCompoundExpression {
return returnType;
}
+// @Override TODO: do we need this?
+// public Integer getMaxLength() {
+// return children.get(0).getMaxLength();
+// }
+
+
@Override
public void reset() {
foundIndex = false;
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
index a6517db..d991d63 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
@@ -36,7 +36,7 @@ import com.google.common.base.Preconditions;
public class CoerceExpression extends BaseSingleExpression {
private PDataType toType;
private SortOrder toSortOrder;
- private Integer byteSize;
+ private Integer maxLength;
public CoerceExpression() {
}
@@ -48,11 +48,11 @@ public class CoerceExpression extends BaseSingleExpression {
return new CoerceExpression(expression, toType);
}
- public static Expression create(Expression expression, PDataType toType, SortOrder toSortOrder, Integer byteSize) throws SQLException {
+ public static Expression create(Expression expression, PDataType toType, SortOrder toSortOrder, Integer maxLength) throws SQLException {
if (toType == expression.getDataType() && toSortOrder == expression.getSortOrder()) {
return expression;
}
- return new CoerceExpression(expression, toType, toSortOrder, byteSize);
+ return new CoerceExpression(expression, toType, toSortOrder, maxLength);
}
//Package protected for tests
@@ -60,29 +60,24 @@ public class CoerceExpression extends BaseSingleExpression {
this(expression, toType, SortOrder.getDefault(), null);
}
- CoerceExpression(Expression expression, PDataType toType, SortOrder toSortOrder, Integer byteSize) {
+ CoerceExpression(Expression expression, PDataType toType, SortOrder toSortOrder, Integer maxLength) {
super(expression);
Preconditions.checkNotNull(toSortOrder);
this.toType = toType;
this.toSortOrder = toSortOrder;
- this.byteSize = byteSize;
+ this.maxLength = maxLength;
}
@Override
- public Integer getByteSize() {
- return byteSize;
- }
-
- @Override
public Integer getMaxLength() {
- return byteSize;
+ return maxLength;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((byteSize == null) ? 0 : byteSize.hashCode());
+ result = prime * result + ((maxLength == null) ? 0 : maxLength.hashCode());
result = prime * result + ((toSortOrder == null) ? 0 : toSortOrder.hashCode());
result = prime * result + ((toType == null) ? 0 : toType.hashCode());
return result;
@@ -94,9 +89,9 @@ public class CoerceExpression extends BaseSingleExpression {
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
CoerceExpression other = (CoerceExpression)obj;
- if (byteSize == null) {
- if (other.byteSize != null) return false;
- } else if (!byteSize.equals(other.byteSize)) return false;
+ if (maxLength == null) {
+ if (other.maxLength != null) return false;
+ } else if (!maxLength.equals(other.maxLength)) return false;
if (toSortOrder != other.toSortOrder) return false;
if (toType != other.toType) return false;
return true;
@@ -108,7 +103,7 @@ public class CoerceExpression extends BaseSingleExpression {
toType = PDataType.values()[WritableUtils.readVInt(input)];
toSortOrder = SortOrder.fromSystemValue(WritableUtils.readVInt(input));
int byteSize = WritableUtils.readVInt(input);
- this.byteSize = byteSize == -1 ? null : byteSize;
+ this.maxLength = byteSize == -1 ? null : byteSize;
}
@Override
@@ -116,7 +111,7 @@ public class CoerceExpression extends BaseSingleExpression {
super.write(output);
WritableUtils.writeVInt(output, toType.ordinal());
WritableUtils.writeVInt(output, toSortOrder.getSystemValue());
- WritableUtils.writeVInt(output, byteSize == null ? -1 : byteSize);
+ WritableUtils.writeVInt(output, maxLength == null ? -1 : maxLength);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java
index 935c38b..eb60591 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java
@@ -22,11 +22,9 @@ import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.WritableUtils;
-
-import com.google.common.base.Objects;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.SortOrder;
/**
*
@@ -37,7 +35,6 @@ import org.apache.phoenix.schema.PDatum;
*/
abstract public class ColumnExpression extends BaseTerminalExpression {
protected PDataType type;
- private Integer byteSize;
private boolean isNullable;
private Integer maxLength;
private Integer scale;
@@ -46,13 +43,12 @@ abstract public class ColumnExpression extends BaseTerminalExpression {
public ColumnExpression() {
}
+ // TODO: review, as the hashCode() and equals() here seem unnecessary
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (isNullable() ? 1231 : 1237);
- Integer maxLength = this.getByteSize();
- result = prime * result + ((maxLength == null) ? 0 : maxLength.hashCode());
PDataType type = this.getDataType();
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
@@ -65,7 +61,6 @@ abstract public class ColumnExpression extends BaseTerminalExpression {
if (getClass() != obj.getClass()) return false;
ColumnExpression other = (ColumnExpression)obj;
if (this.isNullable() != other.isNullable()) return false;
- if (!Objects.equal(this.getByteSize(),other.getByteSize())) return false;
if (this.getDataType() != other.getDataType()) return false;
return true;
}
@@ -73,9 +68,6 @@ abstract public class ColumnExpression extends BaseTerminalExpression {
public ColumnExpression(PDatum datum) {
this.type = datum.getDataType();
this.isNullable = datum.isNullable();
- if (type.isFixedWidth() && type.getByteSize() == null) {
- this.byteSize = datum.getByteSize();
- }
this.maxLength = datum.getMaxLength();
this.scale = datum.getScale();
this.sortOrder = datum.getSortOrder();
@@ -97,14 +89,6 @@ abstract public class ColumnExpression extends BaseTerminalExpression {
}
@Override
- public Integer getByteSize() {
- if (byteSize != null) {
- return byteSize;
- }
- return super.getByteSize();
- }
-
- @Override
public Integer getMaxLength() {
return maxLength;
}
@@ -126,9 +110,6 @@ abstract public class ColumnExpression extends BaseTerminalExpression {
maxLength = WritableUtils.readVInt(input);
}
type = PDataType.values()[typeAndFlag >>> 3];
- if (type.isFixedWidth() && type.getByteSize() == null) {
- byteSize = WritableUtils.readVInt(input);
- }
sortOrder = SortOrder.fromSystemValue(WritableUtils.readVInt(input));
}
@@ -144,9 +125,6 @@ abstract public class ColumnExpression extends BaseTerminalExpression {
if (maxLength != null) {
WritableUtils.writeVInt(output, maxLength);
}
- if (type.isFixedWidth() && type.getByteSize() == null) {
- WritableUtils.writeVInt(output, byteSize);
- }
WritableUtils.writeVInt(output, sortOrder.getSystemValue());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java
index b7e3976..6256b6f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java
@@ -162,7 +162,7 @@ public class ComparisonExpression extends BaseCompoundExpression {
// into account the comparison operator.
if (rhsExprDataType != lhsExprDataType
|| rhsExpr.getSortOrder() != lhsExpr.getSortOrder()
- || (rhsExpr.getMaxLength() != null && lhsExpr.getMaxLength() != null && rhsExpr.getMaxLength() < lhsExpr.getMaxLength())) {
+ || (rhsExprDataType.isFixedWidth() && rhsExpr.getMaxLength() != null && lhsExprDataType.isFixedWidth() && lhsExpr.getMaxLength() != null && rhsExpr.getMaxLength() < lhsExpr.getMaxLength())) {
// TODO: if lengths are unequal and fixed width?
if (rhsExprDataType.isCoercibleTo(lhsExprDataType, rhsValue)) { // will convert 2.0 -> 2
children = Arrays.asList(children.get(0), LiteralExpression.newConstant(rhsValue, lhsExprDataType,
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java
index 29de664..169afb9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java
@@ -21,10 +21,9 @@ import java.math.BigDecimal;
import java.util.List;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.exception.ValueTypeIncompatibleException;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.NumberUtil;
@@ -40,13 +39,8 @@ public class DecimalAddExpression extends AddExpression {
super(children);
for (int i=0; i<children.size(); i++) {
Expression childExpr = children.get(i);
- if (i == 0) {
- maxLength = childExpr.getMaxLength();
- scale = childExpr.getScale();
- } else {
- maxLength = getPrecision(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
- scale = getScale(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
- }
+ maxLength = getPrecision(maxLength, scale, childExpr);
+ scale = getScale(maxLength, scale, childExpr);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java
index cbc05dd..0e39cd9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java
@@ -21,10 +21,9 @@ import java.math.BigDecimal;
import java.util.List;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.exception.ValueTypeIncompatibleException;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.NumberUtil;
@@ -47,13 +46,8 @@ public class DecimalSubtractExpression extends SubtractExpression {
super(children);
for (int i=0; i<children.size(); i++) {
Expression childExpr = children.get(i);
- if (i == 0) {
- maxLength = childExpr.getMaxLength();
- scale = childExpr.getScale();
- } else {
- maxLength = getPrecision(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
- scale = getScale(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
- }
+ maxLength = getPrecision(maxLength, scale, childExpr);
+ scale = getScale(maxLength, scale, childExpr);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java
index 863d49c..f064b9d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java
@@ -41,13 +41,8 @@ public abstract class DivideExpression extends ArithmeticExpression {
super(children);
for (int i=0; i<children.size(); i++) {
Expression childExpr = children.get(i);
- if (i == 0) {
- maxLength = childExpr.getMaxLength();
- scale = childExpr.getScale();
- } else {
- maxLength = getPrecision(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
- scale = getScale(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
- }
+ maxLength = getPrecision(maxLength, scale, childExpr);
+ scale = getScale(maxLength, scale, childExpr);
}
}
@@ -66,20 +61,38 @@ public abstract class DivideExpression extends ArithmeticExpression {
return " / ";
}
- private static Integer getPrecision(Integer lp, Integer rp, Integer ls, Integer rs) {
+ private static Integer getPrecision(Integer lp, Integer ls, Expression childExpr) {
+ if (childExpr.getDataType() == null) {
+ return null;
+ }
+ Integer rp = childExpr.getMaxLength();
+ if (rp == null) {
+ rp = childExpr.getDataType().getMaxLength(null);
+ }
+ if (lp == null) {
+ return rp;
+ }
+ if (rp == null) {
+ return lp;
+ }
+ Integer rs = childExpr.getScale();
if (ls == null || rs == null) {
return PDataType.MAX_PRECISION;
}
- int val = getScale(lp, rp, ls, rs) + lp - ls + rp;
+ int val = getScale(lp, ls, childExpr) + lp - ls + rp;
return Math.min(PDataType.MAX_PRECISION, val);
}
- private static Integer getScale(Integer lp, Integer rp, Integer ls, Integer rs) {
+ private static Integer getScale(Integer lp, Integer ls, Expression childExpr) {
// If we are adding a decimal with scale and precision to a decimal
// with no precision nor scale, the scale system does not apply.
- if (ls == null || rs == null) {
- return null;
- }
+ Integer rs = childExpr.getScale();
+ if (ls == null) {
+ return rs;
+ }
+ if (rs == null) {
+ return ls;
+ }
int val = Math.max(PDataType.MAX_PRECISION - lp + ls - rs, 0);
return Math.min(PDataType.MAX_PRECISION, val);
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
index 7aa7554..32950c6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
@@ -67,7 +67,6 @@ public class LiteralExpression extends BaseTerminalExpression {
private PDataType type;
private boolean isDeterministic;
private byte[] byteValue;
- private Integer byteSize;
private Integer maxLength;
private Integer scale;
private SortOrder sortOrder;
@@ -119,11 +118,11 @@ public class LiteralExpression extends BaseTerminalExpression {
}
public static LiteralExpression newConstant(Object value, PDataType type, SortOrder sortOrder) throws SQLException {
- return newConstant(value, type, null, null, sortOrder, true);
+ return newConstant(value, type, type == null || !type.isFixedWidth() ? null : type.getMaxLength(value), null, sortOrder, true);
}
public static LiteralExpression newConstant(Object value, PDataType type, SortOrder sortOrder, boolean isDeterministic) throws SQLException {
- return newConstant(value, type, null, null, sortOrder, isDeterministic);
+ return newConstant(value, type, type == null || !type.isFixedWidth() ? null : type.getMaxLength(value), null, sortOrder, isDeterministic);
}
public static LiteralExpression newConstant(Object value, PDataType type, Integer maxLength, Integer scale) throws SQLException {
@@ -182,7 +181,7 @@ public class LiteralExpression extends BaseTerminalExpression {
}
private LiteralExpression(Object value, PDataType type, byte[] byteValue, boolean isDeterministic) {
- this(value, type, byteValue, type == null? null : type.getMaxLength(value), type == null? null : type.getScale(value), SortOrder.getDefault(), isDeterministic);
+ this(value, type, byteValue, type == null || !type.isFixedWidth() ? null : type.getMaxLength(value), null, SortOrder.getDefault(), isDeterministic);
}
private LiteralExpression(Object value, PDataType type, byte[] byteValue,
@@ -191,9 +190,8 @@ public class LiteralExpression extends BaseTerminalExpression {
this.value = value;
this.type = type;
this.byteValue = byteValue;
- this.byteSize = byteValue.length;
this.maxLength = maxLength;
- this.scale = scale;
+ this.scale = scale != null ? scale : type == null ? null : type.getScale(value);
this.sortOrder = sortOrder;
this.isDeterministic = isDeterministic;
}
@@ -247,8 +245,6 @@ public class LiteralExpression extends BaseTerminalExpression {
} else {
this.value = this.type.toObject(byteValue, 0, byteValue.length, this.type, sortOrder);
}
- // Only to prevent continual reallocations of Integer
- this.byteSize = this.byteValue.length;
}
@Override
@@ -272,11 +268,6 @@ public class LiteralExpression extends BaseTerminalExpression {
}
@Override
- public Integer getByteSize() {
- return byteSize;
- }
-
- @Override
public Integer getMaxLength() {
return maxLength;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java
index e4bf9fa..6e089e9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java
@@ -41,13 +41,8 @@ public abstract class MultiplyExpression extends ArithmeticExpression {
super(children);
for (int i=0; i<children.size(); i++) {
Expression childExpr = children.get(i);
- if (i == 0) {
- maxLength = childExpr.getMaxLength();
- scale = childExpr.getScale();
- } else {
- maxLength = getPrecision(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
- scale = getScale(maxLength, childExpr.getMaxLength(), scale, childExpr.getScale());
- }
+ maxLength = getPrecision(maxLength, scale, childExpr);
+ scale = getScale(maxLength, scale, childExpr);
}
}
@@ -66,7 +61,21 @@ public abstract class MultiplyExpression extends ArithmeticExpression {
return " * ";
}
- private static Integer getPrecision(Integer lp, Integer rp, Integer ls, Integer rs) {
+ private static Integer getPrecision(Integer lp, Integer ls, Expression childExpr) {
+ Integer rp = childExpr.getMaxLength();
+ if (childExpr.getDataType() == null) {
+ return null;
+ }
+ if (rp == null) {
+ rp = childExpr.getDataType().getMaxLength(null);
+ }
+ if (lp == null) {
+ return rp;
+ }
+ if (rp == null) {
+ return lp;
+ }
+ Integer rs = childExpr.getScale();
if (ls == null || rs == null) {
return PDataType.MAX_PRECISION;
}
@@ -74,12 +83,16 @@ public abstract class MultiplyExpression extends ArithmeticExpression {
return Math.min(PDataType.MAX_PRECISION, val);
}
- private static Integer getScale(Integer lp, Integer rp, Integer ls, Integer rs) {
+ private static Integer getScale(Integer lp, Integer ls, Expression childExpr) {
// If we are adding a decimal with scale and precision to a decimal
// with no precision nor scale, the scale system does not apply.
- if (ls == null || rs == null) {
- return null;
- }
+ Integer rs = childExpr.getScale();
+ if (ls == null) {
+ return rs;
+ }
+ if (rs == null) {
+ return ls;
+ }
int val = ls + rs;
return Math.min(PDataType.MAX_PRECISION, val);
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java
index c0f025d..46331d8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java
@@ -22,7 +22,6 @@ import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.expression.visitor.ExpressionVisitor;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.PDatum;
@@ -101,22 +100,16 @@ public class RowKeyColumnExpression extends ColumnExpression {
int maxOffset = ptr.getOffset() + ptr.getLength();
if (offset < maxOffset) {
byte[] buffer = ptr.get();
- int fixedByteSize = -1;
+ int byteSize = -1;
// FIXME: fixedByteSize <= maxByteSize ? fixedByteSize : 0 required because HBase passes bogus keys to filter to position scan (HBASE-6562)
if (fromType.isFixedWidth()) {
- fixedByteSize = getByteSize();
- fixedByteSize = fixedByteSize <= maxOffset ? fixedByteSize : 0;
+ Integer maxLength = getMaxLength();
+ byteSize = maxLength == null ? fromType.getByteSize() : maxLength;
+ byteSize = byteSize <= maxOffset ? byteSize : 0;
}
- int length = fixedByteSize >= 0 ? fixedByteSize : accessor.getLength(buffer, offset, maxOffset);
+ int length = byteSize >= 0 ? byteSize : accessor.getLength(buffer, offset, maxOffset);
// In the middle of the key, an empty variable length byte array represents null
if (length > 0) {
- /*
- if (type == fromType) {
- ptr.set(buffer,offset,length);
- } else {
- ptr.set(type.toBytes(type.toObject(buffer, offset, length, fromType)));
- }
- */
ptr.set(buffer,offset,length);
type.coerceBytes(ptr, fromType, getSortOrder(), getSortOrder());
} else {
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
index cfeb46e..e875512 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
@@ -36,6 +36,7 @@ import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TrustedByteArrayOutputStream;
public class RowValueConstructorExpression extends BaseCompoundExpression {
@@ -113,9 +114,7 @@ public class RowValueConstructorExpression extends BaseCompoundExpression {
return 1;
} else {
// Write at least one null byte in the case of the child being null with a childType of null
- Integer byteSize = e.getByteSize();
- int bytesToWrite = byteSize == null ? 1 : Math.max(1, byteSize);
- return bytesToWrite;
+ return childType == null || !childType.isFixedWidth() ? 1 : SchemaUtil.getFixedByteSize(e);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java
index 17dce62..a89b648 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java
@@ -66,7 +66,7 @@ public class ArrayIndexFunction extends ScalarFunction {
// Given a ptr to the entire array, set ptr to point to a particular element within that array
// given the type of an array element (see comments in PDataTypeForArray)
- PArrayDataType.positionAtArrayElement(ptr, index-1, getDataType(), getByteSize());
+ PArrayDataType.positionAtArrayElement(ptr, index-1, getDataType(), getMaxLength());
return true;
}
@@ -78,11 +78,6 @@ public class ArrayIndexFunction extends ScalarFunction {
}
@Override
- public Integer getByteSize() {
- return this.children.get(0).getMaxLength();
- }
-
- @Override
public Integer getMaxLength() {
return this.children.get(0).getMaxLength();
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java
index 360fd07..20d952d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java
@@ -78,12 +78,12 @@ public class CoalesceFunction extends ScalarFunction {
}
@Override
- public Integer getByteSize() {
- Integer maxByteSize1 = children.get(0).getByteSize();
- if (maxByteSize1 != null) {
- Integer maxByteSize2 = children.get(1).getByteSize();
- if (maxByteSize2 != null) {
- return maxByteSize1 > maxByteSize2 ? maxByteSize1 : maxByteSize2;
+ public Integer getMaxLength() {
+ Integer maxLength1 = children.get(0).getMaxLength();
+ if (maxLength1 != null) {
+ Integer maxLength2 = children.get(1).getMaxLength();
+ if (maxLength2 != null) {
+ return maxLength1 > maxLength2 ? maxLength1 : maxLength2;
}
}
return null;
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java
index 611c5f1..6756806 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java
@@ -22,15 +22,14 @@ import java.util.List;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.compile.KeyPart;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
@BuiltInFunction(name = InvertFunction.NAME, args = { @Argument() })
@@ -69,11 +68,6 @@ public class InvertFunction extends ScalarFunction {
}
@Override
- public Integer getByteSize() {
- return getChildExpression().getByteSize();
- }
-
- @Override
public boolean isNullable() {
return getChildExpression().isNullable();
}
@@ -115,7 +109,7 @@ public class InvertFunction extends ScalarFunction {
}
};
}
-
+
@Override
public OrderPreserving preservesOrder() {
return OrderPreserving.YES;
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java
index 5e70408..987b006 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java
@@ -21,12 +21,11 @@ import java.sql.SQLException;
import java.util.List;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.StringUtil;
@@ -46,15 +45,10 @@ import org.apache.phoenix.util.StringUtil;
public class LTrimFunction extends ScalarFunction {
public static final String NAME = "LTRIM";
- private Integer byteSize;
-
public LTrimFunction() { }
public LTrimFunction(List<Expression> children) throws SQLException {
super(children);
- if (getStringExpression().getDataType().isFixedWidth()) {
- byteSize = getStringExpression().getByteSize();
- }
}
private Expression getStringExpression() {
@@ -94,8 +88,8 @@ public class LTrimFunction extends ScalarFunction {
}
@Override
- public Integer getByteSize() {
- return byteSize;
+ public Integer getMaxLength() {
+ return getStringExpression().getMaxLength();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java
index d4d996d..3bac400 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java
@@ -23,76 +23,68 @@ import java.sql.SQLException;
import java.util.List;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.tuple.Tuple;
-@BuiltInFunction(name = MD5Function.NAME, args={@Argument()})
+@BuiltInFunction(name = MD5Function.NAME, args = { @Argument() })
public class MD5Function extends ScalarFunction {
- public static final String NAME = "MD5";
- public static final Integer LENGTH = 16;
+ public static final String NAME = "MD5";
+ public static final Integer LENGTH = 16;
- private final MessageDigest messageDigest;
+ private final MessageDigest messageDigest;
- public MD5Function() throws SQLException {
- try {
- messageDigest = MessageDigest.getInstance("MD5");
+ public MD5Function() throws SQLException {
+ try {
+ messageDigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
- throw new SQLException(e);
- }
- }
-
- public MD5Function(List<Expression> children) throws SQLException {
- super(children);
- try {
- messageDigest = MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException e) {
- throw new RuntimeException(e);
+ throw new SQLException(e);
+ }
}
- }
-
- @Override
- public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
- if (!getChildExpression().evaluate(tuple, ptr)) {
- return false;
+
+ public MD5Function(List<Expression> children) throws SQLException {
+ super(children);
+ try {
+ messageDigest = MessageDigest.getInstance("MD5");
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException(e);
+ }
}
- // Update the digest value
- messageDigest.update(ptr.get(), ptr.getOffset(), ptr.getLength());
- // Get the digest bytes (note this resets the messageDigest as well)
- ptr.set(messageDigest.digest());
- return true;
- }
+ @Override
+ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+ if (!getChildExpression().evaluate(tuple, ptr)) { return false; }
- @Override
- public PDataType getDataType() {
- return PDataType.BINARY;
- }
+ // Update the digest value
+ messageDigest.update(ptr.get(), ptr.getOffset(), ptr.getLength());
+ // Get the digest bytes (note this resets the messageDigest as well)
+ ptr.set(messageDigest.digest());
+ return true;
+ }
- @Override
- public Integer getMaxLength() {
- return LENGTH;
- }
+ @Override
+ public PDataType getDataType() {
+ return PDataType.BINARY;
+ }
- @Override
- public Integer getByteSize() {
- return LENGTH;
- }
+ @Override
+ public Integer getMaxLength() {
+ return LENGTH;
+ }
- @Override
- public boolean isNullable() {
- return getChildExpression().isNullable();
- }
+ @Override
+ public boolean isNullable() {
+ return getChildExpression().isNullable();
+ }
- @Override
- public String getName() {
- return NAME;
- }
+ @Override
+ public String getName() {
+ return NAME;
+ }
- private Expression getChildExpression() {
- return children.get(0);
- }
+ private Expression getChildExpression() {
+ return children.get(0);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java
index bb52b87..156f860 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java
@@ -23,7 +23,6 @@ import java.util.List;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.compile.KeyPart;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.query.KeyRange;
@@ -91,8 +90,8 @@ abstract public class PrefixFunction extends ScalarFunction {
default:
return childPart.getKeyRange(op, rhs);
}
- Integer length = getColumn().getByteSize();
- return length == null ? range : range.fill(length);
+ Integer length = getColumn().getMaxLength();
+ return length == null || !type.isFixedWidth() ? range : range.fill(length);
}
};
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java
index 33f5f78..1a46334 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java
@@ -23,15 +23,14 @@ import java.util.List;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.compile.KeyPart;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.StringUtil;
@@ -50,15 +49,10 @@ import org.apache.phoenix.util.StringUtil;
public class RTrimFunction extends ScalarFunction {
public static final String NAME = "RTRIM";
- private Integer byteSize;
-
public RTrimFunction() { }
public RTrimFunction(List<Expression> children) throws SQLException {
super(children);
- if (getStringExpression().getDataType().isFixedWidth()) {
- byteSize = getStringExpression().getByteSize();
- }
}
private Expression getStringExpression() {
@@ -126,8 +120,8 @@ public class RTrimFunction extends ScalarFunction {
range = childPart.getKeyRange(op, rhs);
break;
}
- Integer length = getColumn().getByteSize();
- return length == null ? range : range.fill(length);
+ Integer length = getColumn().getMaxLength();
+ return length == null || !type.isFixedWidth() ? range : range.fill(length);
}
@Override
@@ -143,8 +137,8 @@ public class RTrimFunction extends ScalarFunction {
}
@Override
- public Integer getByteSize() {
- return byteSize;
+ public Integer getMaxLength() {
+ return getStringExpression().getMaxLength();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java
index e69ab2e..b75c2dc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java
@@ -22,7 +22,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
@@ -53,7 +52,7 @@ public class RegexpSubstrFunction extends PrefixFunction {
private Pattern pattern;
private boolean isOffsetConstant;
- private Integer byteSize;
+ private Integer maxLength;
public RegexpSubstrFunction() { }
@@ -75,11 +74,13 @@ public class RegexpSubstrFunction extends PrefixFunction {
Number offsetNumber = (Number)((LiteralExpression)getOffsetExpression()).getValue();
if (offsetNumber != null) {
int offset = offsetNumber.intValue();
- if (getSourceStrExpression().getDataType().isFixedWidth()) {
+ PDataType type = getSourceStrExpression().getDataType();
+ if (type.isFixedWidth()) {
if (offset >= 0) {
- byteSize = getSourceStrExpression().getByteSize() - offset - (offset == 0 ? 0 : 1);
+ Integer maxLength = getSourceStrExpression().getMaxLength();
+ this.maxLength = maxLength - offset - (offset == 0 ? 0 : 1);
} else {
- byteSize = -offset;
+ this.maxLength = -offset;
}
}
}
@@ -126,8 +127,8 @@ public class RegexpSubstrFunction extends PrefixFunction {
}
@Override
- public Integer getByteSize() {
- return byteSize;
+ public Integer getMaxLength() {
+ return maxLength;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
index 1756228..f928218 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
@@ -28,20 +28,19 @@ import java.util.List;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.WritableUtils;
-
-import com.google.common.collect.Lists;
-
import org.apache.phoenix.compile.KeyPart;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PDataType;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType.PDataCodec;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.ByteUtil;
+import com.google.common.collect.Lists;
+
/**
* Function used to bucketize date/time values by rounding them to
* an even increment. Usage:
@@ -180,15 +179,15 @@ public class RoundDateExpression extends ScalarFunction {
}
@Override
- public PDataType getDataType() {
- return children.get(0).getDataType();
+ public Integer getMaxLength() {
+ return children.get(0).getMaxLength();
}
@Override
- public Integer getByteSize() {
- return children.get(0).getByteSize();
+ public PDataType getDataType() {
+ return children.get(0).getDataType();
}
-
+
@Override
public boolean isNullable() {
return children.get(0).isNullable() || divBy == 0;
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java
index 2ec4441..4d84ed6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java
@@ -23,13 +23,12 @@ import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.StringUtil;
@@ -57,7 +56,7 @@ public class SubstrFunction extends PrefixFunction {
private boolean isOffsetConstant;
private boolean isLengthConstant;
private boolean isFixedWidth;
- private Integer byteSize;
+ private Integer maxLength;
public SubstrFunction() {
}
@@ -74,16 +73,18 @@ public class SubstrFunction extends PrefixFunction {
isFixedWidth = getStrExpression().getDataType().isFixedWidth() && ((hasLengthExpression && isLengthConstant) || (!hasLengthExpression && isOffsetConstant));
if (hasLengthExpression && isLengthConstant) {
Integer maxLength = ((Number)((LiteralExpression)getLengthExpression()).getValue()).intValue();
- this.byteSize = maxLength >= 0 ? maxLength : 0;
+ this.maxLength = maxLength >= 0 ? maxLength : 0;
} else if (isOffsetConstant) {
Number offsetNumber = (Number)((LiteralExpression)getOffsetExpression()).getValue();
if (offsetNumber != null) {
int offset = offsetNumber.intValue();
- if (getStrExpression().getDataType().isFixedWidth()) {
+ PDataType type = getStrExpression().getDataType();
+ if (type.isFixedWidth()) {
if (offset >= 0) {
- byteSize = getStrExpression().getByteSize() - offset + (offset == 0 ? 0 : 1);
+ Integer maxLength = getStrExpression().getMaxLength();
+ this.maxLength = maxLength - offset + (offset == 0 ? 0 : 1);
} else {
- byteSize = -offset;
+ this.maxLength = -offset;
}
}
}
@@ -152,14 +153,8 @@ public class SubstrFunction extends PrefixFunction {
}
@Override
- public Integer getByteSize() {
- return byteSize;
- }
-
- // TODO: we shouldn't need both getByteSize() and getMaxLength()
- @Override
public Integer getMaxLength() {
- return byteSize;
+ return maxLength;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java
index 60ff0d6..d14ddf9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java
@@ -21,12 +21,11 @@ import java.sql.SQLException;
import java.util.List;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.StringUtil;
@@ -44,14 +43,14 @@ import org.apache.phoenix.util.StringUtil;
public class TrimFunction extends ScalarFunction {
public static final String NAME = "TRIM";
- private Integer byteSize;
+ private Integer maxLength;
public TrimFunction() { }
public TrimFunction(List<Expression> children) throws SQLException {
super(children);
if (getStringExpression().getDataType().isFixedWidth()) {
- byteSize = getStringExpression().getByteSize();
+ maxLength = getStringExpression().getMaxLength();
}
}
@@ -89,8 +88,8 @@ public class TrimFunction extends ScalarFunction {
}
@Override
- public Integer getByteSize() {
- return byteSize;
+ public Integer getMaxLength() {
+ return maxLength;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
index ffda55d..9c41364 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
@@ -91,6 +91,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
IndexMaintainer maintainer = new IndexMaintainer(dataTable, index);
int indexPosOffset = (index.getBucketNum() == null ? 0 : 1) + (maintainer.isMultiTenant ? 1 : 0) + (maintainer.viewIndexId == null ? 0 : 1);
RowKeyMetaData rowKeyMetaData = maintainer.getRowKeyMetaData();
+ int indexColByteSize = 0;
for (int i = indexPosOffset; i < index.getPKColumns().size(); i++) {
PColumn indexColumn = index.getPKColumns().get(i);
int indexPos = i - indexPosOffset;
@@ -100,8 +101,8 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
int dataPkPos = dataTable.getPKColumns().indexOf(column) - (dataTable.getBucketNum() == null ? 0 : 1) - (maintainer.isMultiTenant ? 1 : 0);
rowKeyMetaData.setIndexPkPosition(dataPkPos, indexPos);
} else {
+ indexColByteSize += column.getDataType().isFixedWidth() ? SchemaUtil.getFixedByteSize(column) : ValueSchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
maintainer.getIndexedColumnTypes().add(column.getDataType());
- maintainer.getIndexedColumnSizes().add(column.getByteSize());
maintainer.getIndexedColumns().add(new ColumnReference(column.getFamilyName().getBytes(), column.getName().getBytes()));
}
if (indexColumn.getSortOrder() == SortOrder.DESC) {
@@ -115,6 +116,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
maintainer.getCoverededColumns().add(new ColumnReference(column.getFamilyName().getBytes(), column.getName().getBytes()));
}
}
+ maintainer.estimatedIndexRowKeyBytes = maintainer.estimateIndexRowKeyByteSize(indexColByteSize);
maintainer.initCachedState();
return maintainer;
}
@@ -200,7 +202,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
private Set<ColumnReference> coveredColumns;
private Set<ColumnReference> allColumns;
private List<PDataType> indexedColumnTypes;
- private List<Integer> indexedColumnByteSizes;
private RowKeyMetaData rowKeyMetaData;
private byte[] indexTableName;
private int nIndexSaltBuckets;
@@ -258,7 +259,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
this.indexTableName = indexTableName;
this.indexedColumns = Sets.newLinkedHashSetWithExpectedSize(nIndexPKColumns-nDataPKColumns);
this.indexedColumnTypes = Lists.<PDataType>newArrayListWithExpectedSize(nIndexPKColumns-nDataPKColumns);
- this.indexedColumnByteSizes = Lists.<Integer>newArrayListWithExpectedSize(nIndexPKColumns-nDataPKColumns);
this.coveredColumns = Sets.newLinkedHashSetWithExpectedSize(nIndexColumns-nIndexPKColumns);
this.allColumns = Sets.newLinkedHashSetWithExpectedSize(nDataPKColumns + nIndexColumns);
this.allColumns.addAll(indexedColumns);
@@ -464,7 +464,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
/**
* Used for immutable indexes that only index PK column values. In that case, we can handle a data row deletion,
* since we can build the corresponding index row key.
- * @param kvBuilder TODO
*/
public Delete buildDeleteMutation(KeyValueBuilder kvBuilder, ImmutableBytesWritable dataRowKeyPtr, long ts) throws IOException {
return buildDeleteMutation(kvBuilder, null, dataRowKeyPtr, Collections.<KeyValue>emptyList(), ts);
@@ -523,10 +522,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
return rowKeyMetaData;
}
- private List<Integer> getIndexedColumnSizes() {
- return indexedColumnByteSizes;
- }
-
private List<PDataType> getIndexedColumnTypes() {
return indexedColumnTypes;
}
@@ -555,11 +550,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
PDataType type = PDataType.values()[WritableUtils.readVInt(input)];
indexedColumnTypes.add(type);
}
- indexedColumnByteSizes = Lists.newArrayListWithExpectedSize(nIndexedColumns);
- for (int i = 0; i < nIndexedColumns; i++) {
- int byteSize = WritableUtils.readVInt(input);
- indexedColumnByteSizes.add(byteSize == 0 ? null : Integer.valueOf(byteSize));
- }
int nCoveredColumns = WritableUtils.readVInt(input);
coveredColumns = Sets.newLinkedHashSetWithExpectedSize(nCoveredColumns);
for (int i = 0; i < nCoveredColumns; i++) {
@@ -577,6 +567,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
// Encode indexWALDisabled in nDataCFs
indexWALDisabled = nDataCFs < 0;
this.nDataCFs = Math.abs(nDataCFs) - 1;
+ this.estimatedIndexRowKeyBytes = WritableUtils.readVInt(input);
initCachedState();
}
@@ -598,10 +589,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
PDataType type = indexedColumnTypes.get(i);
WritableUtils.writeVInt(output, type.ordinal());
}
- for (int i = 0; i < indexedColumnByteSizes.size(); i++) {
- Integer byteSize = indexedColumnByteSizes.get(i);
- WritableUtils.writeVInt(output, byteSize == null ? 0 : byteSize);
- }
WritableUtils.writeVInt(output, coveredColumns.size());
for (ColumnReference ref : coveredColumns) {
Bytes.writeByteArray(output, ref.getFamily());
@@ -615,10 +602,12 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
rowKeyMetaData.write(output);
// Encode indexWALDisabled in nDataCFs
WritableUtils.writeVInt(output, (nDataCFs + 1) * (indexWALDisabled ? -1 : 1));
+ WritableUtils.writeVInt(output, estimatedIndexRowKeyBytes);
}
public int getEstimatedByteSize() {
int size = WritableUtils.getVIntSize(nIndexSaltBuckets);
+ size += WritableUtils.getVIntSize(estimatedIndexRowKeyBytes);
size += WritableUtils.getVIntSize(indexedColumns.size());
size += viewIndexId == null ? 0 : viewIndexId.length;
for (ColumnReference ref : indexedColumns) {
@@ -628,7 +617,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
size += ref.getQualifier().length;
}
size += indexedColumnTypes.size();
- size += indexedColumnByteSizes.size();
size += WritableUtils.getVIntSize(coveredColumns.size());
for (ColumnReference ref : coveredColumns) {
size += WritableUtils.getVIntSize(ref.getFamily().length);
@@ -644,11 +632,8 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
return size;
}
- private int estimateIndexRowKeyByteSize() {
- int estimatedIndexRowKeyBytes = dataRowKeySchema.getEstimatedValueLength() + (nIndexSaltBuckets == 0 ? 0 : SaltingUtil.NUM_SALTING_BYTES);
- for (Integer byteSize : indexedColumnByteSizes) {
- estimatedIndexRowKeyBytes += (byteSize == null ? ValueSchema.ESTIMATED_VARIABLE_LENGTH_SIZE : byteSize);
- }
+ private int estimateIndexRowKeyByteSize(int indexColByteSize) {
+ int estimatedIndexRowKeyBytes = indexColByteSize + dataRowKeySchema.getEstimatedValueLength() + (nIndexSaltBuckets == 0 || this.isDataTableSalted ? 0 : SaltingUtil.NUM_SALTING_BYTES);
return estimatedIndexRowKeyBytes;
}
@@ -665,7 +650,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
indexQualifiers.add(new ImmutableBytesPtr(IndexUtil.getIndexColumnName(
ref.getFamily(), ref.getQualifier())));
}
- estimatedIndexRowKeyBytes = estimateIndexRowKeyByteSize();
this.allColumns = Sets.newLinkedHashSetWithExpectedSize(indexedColumns.size() + coveredColumns.size());
allColumns.addAll(indexedColumns);
@@ -741,7 +725,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
}
protected int getByteSize() {
- return BitSet.getByteSize(getIndexPkColumnCount()) * 3;
+ return BitSet.getByteSize(getIndexPkColumnCount()) * 3 + BitSet.getByteSize(dataRowKeySchema.getMaxFields());
}
protected abstract int getIndexPkPosition(int dataPkPosition);
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/d43adc62/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
index 2bfd91f..607bd85 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
@@ -792,10 +792,6 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData, org.apache.pho
return PDataType.VARCHAR;
}
@Override
- public Integer getByteSize() {
- return null;
- }
- @Override
public Integer getMaxLength() {
return null;
}