You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2016/12/23 01:27:35 UTC
[01/42] phoenix git commit: Set version to 5.0.0-HBase-0.98-SNAPSHOT
after release [Forced Update!]
Repository: phoenix
Updated Branches:
refs/heads/encodecolumns2 f955c025c -> 11c0c3b7b (forced update)
Set version to 5.0.0-HBase-0.98-SNAPSHOT after release
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/f18e780c
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f18e780c
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f18e780c
Branch: refs/heads/encodecolumns2
Commit: f18e780c3b11141aaf438d595bc7f541a3fb21e3
Parents: 30bb79b
Author: Mujtaba <mu...@apache.org>
Authored: Wed Nov 23 09:26:01 2016 -0800
Committer: Mujtaba <mu...@apache.org>
Committed: Wed Nov 23 09:26:01 2016 -0800
----------------------------------------------------------------------
phoenix-assembly/pom.xml | 2 +-
phoenix-client/pom.xml | 2 +-
phoenix-core/pom.xml | 2 +-
phoenix-flume/pom.xml | 2 +-
phoenix-hive/pom.xml | 2 +-
phoenix-pherf/pom.xml | 2 +-
phoenix-pig/pom.xml | 2 +-
phoenix-queryserver-client/pom.xml | 2 +-
phoenix-queryserver/pom.xml | 2 +-
phoenix-server/pom.xml | 2 +-
phoenix-spark/pom.xml | 2 +-
phoenix-tracing-webapp/pom.xml | 2 +-
pom.xml | 2 +-
13 files changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-assembly/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-assembly/pom.xml b/phoenix-assembly/pom.xml
index 8ff1618..e8a1900 100644
--- a/phoenix-assembly/pom.xml
+++ b/phoenix-assembly/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-assembly</artifactId>
<name>Phoenix Assembly</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-client/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-client/pom.xml b/phoenix-client/pom.xml
index 2c30342..a21303c 100644
--- a/phoenix-client/pom.xml
+++ b/phoenix-client/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-client</artifactId>
<name>Phoenix Client</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-core/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-core/pom.xml b/phoenix-core/pom.xml
index ea3f316..9396882 100644
--- a/phoenix-core/pom.xml
+++ b/phoenix-core/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-core</artifactId>
<name>Phoenix Core</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-flume/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-flume/pom.xml b/phoenix-flume/pom.xml
index 236e06a..b013518 100644
--- a/phoenix-flume/pom.xml
+++ b/phoenix-flume/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-flume</artifactId>
<name>Phoenix - Flume</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-hive/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-hive/pom.xml b/phoenix-hive/pom.xml
index c36e737..6aa2f61 100644
--- a/phoenix-hive/pom.xml
+++ b/phoenix-hive/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-hive</artifactId>
<name>Phoenix - Hive</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-pherf/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-pherf/pom.xml b/phoenix-pherf/pom.xml
index bf74445..20fc1cc 100644
--- a/phoenix-pherf/pom.xml
+++ b/phoenix-pherf/pom.xml
@@ -15,7 +15,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-pherf</artifactId>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-pig/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-pig/pom.xml b/phoenix-pig/pom.xml
index 6292d81..1e7ca4e 100644
--- a/phoenix-pig/pom.xml
+++ b/phoenix-pig/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-pig</artifactId>
<name>Phoenix - Pig</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-queryserver-client/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-queryserver-client/pom.xml b/phoenix-queryserver-client/pom.xml
index d0e321e..88e6eff 100644
--- a/phoenix-queryserver-client/pom.xml
+++ b/phoenix-queryserver-client/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-queryserver-client</artifactId>
<name>Phoenix Query Server Client</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-queryserver/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-queryserver/pom.xml b/phoenix-queryserver/pom.xml
index 81ee77d..2f81069 100644
--- a/phoenix-queryserver/pom.xml
+++ b/phoenix-queryserver/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-queryserver</artifactId>
<name>Phoenix Query Server</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-server/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-server/pom.xml b/phoenix-server/pom.xml
index 1c2dfcd..9b6f28b 100644
--- a/phoenix-server/pom.xml
+++ b/phoenix-server/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-server</artifactId>
<name>Phoenix Server</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-spark/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-spark/pom.xml b/phoenix-spark/pom.xml
index c7d8f73..ee15c25 100644
--- a/phoenix-spark/pom.xml
+++ b/phoenix-spark/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-spark</artifactId>
<name>Phoenix - Spark</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/phoenix-tracing-webapp/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-tracing-webapp/pom.xml b/phoenix-tracing-webapp/pom.xml
index 7983f58..21c6381 100755
--- a/phoenix-tracing-webapp/pom.xml
+++ b/phoenix-tracing-webapp/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-tracing-webapp</artifactId>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f18e780c/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a1b248c..eede19d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>4.9.0-HBase-0.98</version>
+ <version>5.0.0-HBase-0.98-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Apache Phoenix</name>
<description>A SQL layer over HBase</description>
[23/42] phoenix git commit: Fail-fast iterators for
EncodedColumnQualifierCellsList. Use list iterators instead of get(index) for
navigating lists. Use HBase bytes utility for encoded column names. Fix test
failures for immutable tables and indexes.
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 8afdec4..a9acb63 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -27,6 +27,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLASS_NAME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_COUNT_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_DEF_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_NAME_INDEX;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER_COUNTER_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_SIZE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DATA_TABLE_NAME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DATA_TYPE_BYTES;
@@ -34,6 +35,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DECIMAL_DIGITS_BYT
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAMILY_NAME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_VALUE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL_BYTES;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FAMILY_NAME_INDEX;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IMMUTABLE_ROWS_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP_BYTES;
@@ -57,6 +59,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.RETURN_TYPE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SALT_BUCKETS_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SCHEMA_NAME_INDEX;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SORT_ORDER_BYTES;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.STORAGE_SCHEME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.STORE_NULLS_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME_INDEX;
@@ -74,6 +77,7 @@ import static org.apache.phoenix.query.QueryConstants.DIVERGED_VIEW_BASE_COLUMN_
import static org.apache.phoenix.query.QueryConstants.SEPARATOR_BYTE_ARRAY;
import static org.apache.phoenix.schema.PTableType.INDEX;
import static org.apache.phoenix.util.ByteUtil.EMPTY_BYTE_ARRAY;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import static org.apache.phoenix.util.SchemaUtil.getVarCharLength;
import static org.apache.phoenix.util.SchemaUtil.getVarChars;
@@ -156,7 +160,6 @@ import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.expression.ProjectedColumnExpression;
import org.apache.phoenix.expression.RowKeyColumnExpression;
import org.apache.phoenix.expression.visitor.StatelessTraverseAllExpressionVisitor;
-import org.apache.phoenix.hbase.index.covered.update.ColumnReference;
import org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder;
import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
@@ -189,8 +192,10 @@ import org.apache.phoenix.schema.PMetaDataEntity;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTable.LinkType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTable.ViewType;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
@@ -209,10 +214,12 @@ import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PLong;
import org.apache.phoenix.schema.types.PSmallint;
+import org.apache.phoenix.schema.types.PTinyint;
import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.schema.types.PVarchar;
import org.apache.phoenix.trace.util.Tracing;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.EnvironmentEdgeManager;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.KeyValueUtil;
@@ -283,6 +290,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
TABLE_FAMILY_BYTES, IS_NAMESPACE_MAPPED_BYTES);
private static final KeyValue AUTO_PARTITION_SEQ_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, AUTO_PARTITION_SEQ_BYTES);
private static final KeyValue APPEND_ONLY_SCHEMA_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, APPEND_ONLY_SCHEMA_BYTES);
+ private static final KeyValue STORAGE_SCHEME_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, STORAGE_SCHEME_BYTES);
private static final List<KeyValue> TABLE_KV_COLUMNS = Arrays.<KeyValue>asList(
EMPTY_KEYVALUE_KV,
@@ -309,7 +317,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
UPDATE_CACHE_FREQUENCY_KV,
IS_NAMESPACE_MAPPED_KV,
AUTO_PARTITION_SEQ_KV,
- APPEND_ONLY_SCHEMA_KV
+ APPEND_ONLY_SCHEMA_KV,
+ STORAGE_SCHEME_KV
);
static {
Collections.sort(TABLE_KV_COLUMNS, KeyValue.COMPARATOR);
@@ -339,6 +348,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private static final int IS_NAMESPACE_MAPPED_INDEX = TABLE_KV_COLUMNS.indexOf(IS_NAMESPACE_MAPPED_KV);
private static final int AUTO_PARTITION_SEQ_INDEX = TABLE_KV_COLUMNS.indexOf(AUTO_PARTITION_SEQ_KV);
private static final int APPEND_ONLY_SCHEMA_INDEX = TABLE_KV_COLUMNS.indexOf(APPEND_ONLY_SCHEMA_KV);
+ private static final int STORAGE_SCHEME_INDEX = TABLE_KV_COLUMNS.indexOf(STORAGE_SCHEME_KV);
// KeyValues for Column
private static final KeyValue DECIMAL_DIGITS_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, DECIMAL_DIGITS_BYTES);
@@ -352,6 +362,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private static final KeyValue IS_VIEW_REFERENCED_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, IS_VIEW_REFERENCED_BYTES);
private static final KeyValue COLUMN_DEF_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, COLUMN_DEF_BYTES);
private static final KeyValue IS_ROW_TIMESTAMP_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, IS_ROW_TIMESTAMP_BYTES);
+ private static final KeyValue ENCODED_COLUMN_QUALIFIER_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, ENCODED_COLUMN_QUALIFIER_BYTES);
private static final List<KeyValue> COLUMN_KV_COLUMNS = Arrays.<KeyValue>asList(
DECIMAL_DIGITS_KV,
COLUMN_SIZE_KV,
@@ -364,11 +375,13 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
VIEW_CONSTANT_KV,
IS_VIEW_REFERENCED_KV,
COLUMN_DEF_KV,
- IS_ROW_TIMESTAMP_KV
+ IS_ROW_TIMESTAMP_KV,
+ ENCODED_COLUMN_QUALIFIER_KV
);
static {
Collections.sort(COLUMN_KV_COLUMNS, KeyValue.COMPARATOR);
}
+ private static final KeyValue QUALIFIER_COUNTER_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, COLUMN_QUALIFIER_COUNTER_BYTES);
private static final int DECIMAL_DIGITS_INDEX = COLUMN_KV_COLUMNS.indexOf(DECIMAL_DIGITS_KV);
private static final int COLUMN_SIZE_INDEX = COLUMN_KV_COLUMNS.indexOf(COLUMN_SIZE_KV);
private static final int NULLABLE_INDEX = COLUMN_KV_COLUMNS.indexOf(NULLABLE_KV);
@@ -380,9 +393,10 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private static final int IS_VIEW_REFERENCED_INDEX = COLUMN_KV_COLUMNS.indexOf(IS_VIEW_REFERENCED_KV);
private static final int COLUMN_DEF_INDEX = COLUMN_KV_COLUMNS.indexOf(COLUMN_DEF_KV);
private static final int IS_ROW_TIMESTAMP_INDEX = COLUMN_KV_COLUMNS.indexOf(IS_ROW_TIMESTAMP_KV);
+ private static final int ENCODED_COLUMN_QUALIFIER_INDEX = COLUMN_KV_COLUMNS.indexOf(ENCODED_COLUMN_QUALIFIER_KV);
private static final int LINK_TYPE_INDEX = 0;
-
+
private static final KeyValue CLASS_NAME_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, CLASS_NAME_BYTES);
private static final KeyValue JAR_PATH_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, JAR_PATH_BYTES);
private static final KeyValue RETURN_TYPE_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, RETURN_TYPE_BYTES);
@@ -718,8 +732,12 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
isRowTimestampKV == null ? false : Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(
isRowTimestampKV.getValueArray(), isRowTimestampKV.getValueOffset(),
isRowTimestampKV.getValueLength()));
-
- PColumn column = new PColumnImpl(colName, famName, dataType, maxLength, scale, isNullable, position-1, sortOrder, arraySize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, false);
+ Cell columnQualifierKV = colKeyValues[ENCODED_COLUMN_QUALIFIER_INDEX];
+ Integer columnQualifier =
+ columnQualifierKV == null ? null : getEncodedColumnQualifier(
+ columnQualifierKV.getValueArray(), columnQualifierKV.getValueOffset(),
+ columnQualifierKV.getValueLength());
+ PColumn column = new PColumnImpl(colName, famName, dataType, maxLength, scale, isNullable, position-1, sortOrder, arraySize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, false, columnQualifier);
columns.add(column);
}
@@ -927,37 +945,49 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
boolean isAppendOnlySchema = isAppendOnlySchemaKv == null ? false
: Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(isAppendOnlySchemaKv.getValueArray(),
isAppendOnlySchemaKv.getValueOffset(), isAppendOnlySchemaKv.getValueLength()));
-
-
+ Cell storageSchemeKv = tableKeyValues[STORAGE_SCHEME_INDEX];
+ //TODO: change this once we start having other values for storage schemes
+ StorageScheme storageScheme = storageSchemeKv == null ? StorageScheme.NON_ENCODED_COLUMN_NAMES : StorageScheme
+ .fromSerializedValue((byte)PTinyint.INSTANCE.toObject(storageSchemeKv.getValueArray(),
+ storageSchemeKv.getValueOffset(), storageSchemeKv.getValueLength()));
+
List<PColumn> columns = Lists.newArrayListWithExpectedSize(columnCount);
List<PTable> indexes = Lists.newArrayList();
List<PName> physicalTables = Lists.newArrayList();
PName parentTableName = tableType == INDEX ? dataTableName : null;
PName parentSchemaName = tableType == INDEX ? schemaName : null;
+ EncodedCQCounter cqCounter = (storageScheme == StorageScheme.NON_ENCODED_COLUMN_NAMES || tableType == PTableType.VIEW) ? PTable.EncodedCQCounter.NULL_COUNTER : new EncodedCQCounter();
while (true) {
- results.clear();
- scanner.next(results);
- if (results.isEmpty()) {
- break;
- }
- Cell colKv = results.get(LINK_TYPE_INDEX);
- int colKeyLength = colKv.getRowLength();
- PName colName = newPName(colKv.getRowArray(), colKv.getRowOffset() + offset, colKeyLength-offset);
- int colKeyOffset = offset + colName.getBytes().length + 1;
- PName famName = newPName(colKv.getRowArray(), colKv.getRowOffset() + colKeyOffset, colKeyLength-colKeyOffset);
- if (colName.getString().isEmpty() && famName != null) {
- LinkType linkType = LinkType.fromSerializedValue(colKv.getValueArray()[colKv.getValueOffset()]);
- if (linkType == LinkType.INDEX_TABLE) {
- addIndexToTable(tenantId, schemaName, famName, tableName, clientTimeStamp, indexes);
- } else if (linkType == LinkType.PHYSICAL_TABLE) {
- physicalTables.add(famName);
- } else if (linkType == LinkType.PARENT_TABLE) {
- parentTableName = PNameFactory.newName(SchemaUtil.getTableNameFromFullName(famName.getBytes()));
- parentSchemaName = PNameFactory.newName(SchemaUtil.getSchemaNameFromFullName(famName.getBytes()));
- }
- } else {
- addColumnToTable(results, colName, famName, colKeyValues, columns, saltBucketNum != null);
- }
+ results.clear();
+ scanner.next(results);
+ if (results.isEmpty()) {
+ break;
+ }
+ Cell colKv = results.get(LINK_TYPE_INDEX);
+ if (colKv != null) {
+ int colKeyLength = colKv.getRowLength();
+ PName colName = newPName(colKv.getRowArray(), colKv.getRowOffset() + offset, colKeyLength-offset);
+ int colKeyOffset = offset + colName.getBytes().length + 1;
+ PName famName = newPName(colKv.getRowArray(), colKv.getRowOffset() + colKeyOffset, colKeyLength-colKeyOffset);
+ if (isQualifierCounterKV(colKv)) {
+ Integer value = PInteger.INSTANCE.getCodec().decodeInt(colKv.getValueArray(), colKv.getValueOffset(), SortOrder.ASC);
+ cqCounter.setValue(famName.getString(), value);
+ } else {
+ if (colName.getString().isEmpty() && famName != null) {
+ LinkType linkType = LinkType.fromSerializedValue(colKv.getValueArray()[colKv.getValueOffset()]);
+ if (linkType == LinkType.INDEX_TABLE) {
+ addIndexToTable(tenantId, schemaName, famName, tableName, clientTimeStamp, indexes);
+ } else if (linkType == LinkType.PHYSICAL_TABLE) {
+ physicalTables.add(famName);
+ } else if (linkType == LinkType.PARENT_TABLE) {
+ parentTableName = PNameFactory.newName(SchemaUtil.getTableNameFromFullName(famName.getBytes()));
+ parentSchemaName = PNameFactory.newName(SchemaUtil.getSchemaNameFromFullName(famName.getBytes()));
+ }
+ } else {
+ addColumnToTable(results, colName, famName, colKeyValues, columns, saltBucketNum != null);
+ }
+ }
+ }
}
// Avoid querying the stats table because we're holding the rowLock here. Issuing an RPC to a remote
// server while holding this lock is a bad idea and likely to cause contention.
@@ -965,9 +995,17 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
pkName, saltBucketNum, columns, parentSchemaName, parentTableName, indexes, isImmutableRows, physicalTables, defaultFamilyName,
viewStatement, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType,
rowKeyOrderOptimizable, transactional, updateCacheFrequency, baseColumnCount,
- indexDisableTimestamp, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema);
+ indexDisableTimestamp, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, storageScheme, cqCounter);
}
-
+
+ private boolean isQualifierCounterKV(Cell kv) {
+ int cmp =
+ Bytes.compareTo(kv.getQualifierArray(), kv.getQualifierOffset(),
+ kv.getQualifierLength(), QUALIFIER_COUNTER_KV.getQualifierArray(),
+ QUALIFIER_COUNTER_KV.getQualifierOffset(), QUALIFIER_COUNTER_KV.getQualifierLength());
+ return cmp == 0;
+ }
+
private PSchema getSchema(RegionScanner scanner, long clientTimeStamp) throws IOException, SQLException {
List<Cell> results = Lists.newArrayList();
scanner.next(results);
@@ -1487,46 +1525,46 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
Short indexId = null;
if (request.hasAllocateIndexId() && request.getAllocateIndexId()) {
String tenantIdStr = tenantIdBytes.length == 0 ? null : Bytes.toString(tenantIdBytes);
- try (PhoenixConnection connection = QueryUtil.getConnectionOnServer(env.getConfiguration()).unwrap(PhoenixConnection.class)){
- PName physicalName = parentTable.getPhysicalName();
- int nSequenceSaltBuckets = connection.getQueryServices().getSequenceSaltBuckets();
- SequenceKey key = MetaDataUtil.getViewIndexSequenceKey(tenantIdStr, physicalName,
+ try (PhoenixConnection connection = QueryUtil.getConnectionOnServer(env.getConfiguration()).unwrap(PhoenixConnection.class)) {
+ PName physicalName = parentTable.getPhysicalName();
+ int nSequenceSaltBuckets = connection.getQueryServices().getSequenceSaltBuckets();
+ SequenceKey key = MetaDataUtil.getViewIndexSequenceKey(tenantIdStr, physicalName,
nSequenceSaltBuckets, parentTable.isNamespaceMapped() );
// TODO Review Earlier sequence was created at (SCN-1/LATEST_TIMESTAMP) and incremented at the client max(SCN,dataTable.getTimestamp), but it seems we should
// use always LATEST_TIMESTAMP to avoid seeing wrong sequence values by different connection having SCN
// or not.
- long sequenceTimestamp = HConstants.LATEST_TIMESTAMP;
- try {
- connection.getQueryServices().createSequence(key.getTenantId(), key.getSchemaName(), key.getSequenceName(),
+ long sequenceTimestamp = HConstants.LATEST_TIMESTAMP;
+ try {
+ connection.getQueryServices().createSequence(key.getTenantId(), key.getSchemaName(), key.getSequenceName(),
Short.MIN_VALUE, 1, 1, Long.MIN_VALUE, Long.MAX_VALUE, false, sequenceTimestamp);
- } catch (SequenceAlreadyExistsException e) {
- }
- long[] seqValues = new long[1];
- SQLException[] sqlExceptions = new SQLException[1];
- connection.getQueryServices().incrementSequences(Collections.singletonList(new SequenceAllocation(key, 1)),
+ } catch (SequenceAlreadyExistsException e) {
+ }
+ long[] seqValues = new long[1];
+ SQLException[] sqlExceptions = new SQLException[1];
+ connection.getQueryServices().incrementSequences(Collections.singletonList(new SequenceAllocation(key, 1)),
HConstants.LATEST_TIMESTAMP, seqValues, sqlExceptions);
- if (sqlExceptions[0] != null) {
- throw sqlExceptions[0];
- }
- long seqValue = seqValues[0];
- if (seqValue > Short.MAX_VALUE) {
- builder.setReturnCode(MetaDataProtos.MutationCode.TOO_MANY_INDEXES);
- builder.setMutationTime(EnvironmentEdgeManager.currentTimeMillis());
- done.run(builder.build());
- return;
- }
- Put tableHeaderPut = MetaDataUtil.getPutOnlyTableHeaderRow(tableMetadata);
- NavigableMap<byte[], List<Cell>> familyCellMap = tableHeaderPut.getFamilyCellMap();
- List<Cell> cells = familyCellMap.get(TABLE_FAMILY_BYTES);
- Cell cell = cells.get(0);
- PDataType dataType = MetaDataUtil.getViewIndexIdDataType();
- Object val = dataType.toObject(seqValue, PLong.INSTANCE);
- byte[] bytes = new byte [dataType.getByteSize() + 1];
- dataType.toBytes(val, bytes, 0);
- Cell indexIdCell = new KeyValue(cell.getRow(), cell.getFamily(), VIEW_INDEX_ID_BYTES,
+ if (sqlExceptions[0] != null) {
+ throw sqlExceptions[0];
+ }
+ long seqValue = seqValues[0];
+ if (seqValue > Short.MAX_VALUE) {
+ builder.setReturnCode(MetaDataProtos.MutationCode.TOO_MANY_INDEXES);
+ builder.setMutationTime(EnvironmentEdgeManager.currentTimeMillis());
+ done.run(builder.build());
+ return;
+ }
+ Put tableHeaderPut = MetaDataUtil.getPutOnlyTableHeaderRow(tableMetadata);
+ NavigableMap<byte[], List<Cell>> familyCellMap = tableHeaderPut.getFamilyCellMap();
+ List<Cell> cells = familyCellMap.get(TABLE_FAMILY_BYTES);
+ Cell cell = cells.get(0);
+ PDataType dataType = MetaDataUtil.getViewIndexIdDataType();
+ Object val = dataType.toObject(seqValue, PLong.INSTANCE);
+ byte[] bytes = new byte [dataType.getByteSize() + 1];
+ dataType.toBytes(val, bytes, 0);
+ Cell indexIdCell = new KeyValue(cell.getRow(), cell.getFamily(), VIEW_INDEX_ID_BYTES,
cell.getTimestamp(), Type.codeToType(cell.getTypeByte()), bytes);
- cells.add(indexIdCell);
- indexId = (short) seqValue;
+ cells.add(indexIdCell);
+ indexId = (short) seqValue;
}
}
@@ -1537,7 +1575,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
// indexing on the system table. This is an issue because of the way we manage batch mutation
// in the Indexer.
region.mutateRowsWithLocks(tableMetadata, Collections.<byte[]> emptySet());
-
+
// Invalidate the cache - the next getTable call will add it
// TODO: consider loading the table that was just created here, patching up the parent table, and updating the cache
Cache<ImmutableBytesPtr,PMetaDataEntity> metaDataCache = GlobalCache.getInstance(this.env).getMetaDataCache();
@@ -1989,7 +2027,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
return result;
}
region.mutateRowsWithLocks(tableMetadata, Collections.<byte[]> emptySet());
- // Invalidate from cache
+ // Invalidate from cache.
for (ImmutableBytesPtr invalidateKey : invalidateList) {
metaDataCache.invalidate(invalidateKey);
}
@@ -2169,6 +2207,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
int pkCount = getVarChars(m.getRow(), rkmd);
// check if this put is for adding a column
if (pkCount > COLUMN_NAME_INDEX
+ && rkmd[COLUMN_NAME_INDEX] != null && rkmd[COLUMN_NAME_INDEX].length > 0
&& Bytes.compareTo(schemaName, rkmd[SCHEMA_NAME_INDEX]) == 0
&& Bytes.compareTo(tableName, rkmd[TABLE_NAME_INDEX]) == 0) {
columnPutsForBaseTable.add(new PutWithOrdinalPosition((Put)m, getInteger((Put)m, TABLE_FAMILY_BYTES, ORDINAL_POSITION_BYTES)));
@@ -2221,8 +2260,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
String columnName = Bytes.toString(rkmd[COLUMN_NAME_INDEX]);
String columnFamily = rkmd[FAMILY_NAME_INDEX] == null ? null : Bytes.toString(rkmd[FAMILY_NAME_INDEX]);
try {
- existingViewColumn = columnFamily == null ? view.getColumn(columnName) : view.getColumnFamily(
- columnFamily).getColumn(columnName);
+ existingViewColumn = columnFamily == null ? view.getPColumnForColumnName(columnName) : view.getColumnFamily(
+ columnFamily).getPColumnForColumnName(columnName);
} catch (ColumnFamilyNotFoundException e) {
// ignore since it means that the column family is not present for the column to be added.
} catch (ColumnNotFoundException e) {
@@ -2551,8 +2590,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
byte[] columnKey = getColumnKey(viewKey, columnName, columnFamily);
try {
existingViewColumn =
- columnFamily == null ? view.getColumn(columnName) : view
- .getColumnFamily(columnFamily).getColumn(columnName);
+ columnFamily == null ? view.getPColumnForColumnName(columnName) : view
+ .getColumnFamily(columnFamily).getPColumnForColumnName(columnName);
} catch (ColumnFamilyNotFoundException e) {
// ignore since it means that the column family is not present for the column to
// be added.
@@ -2618,7 +2657,25 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private MetaDataMutationResult validateColumnForAddToBaseTable(PColumn existingViewColumn, Put columnToBeAdded, PTable basePhysicalTable, boolean isColumnToBeAddPkCol, PTable view) {
if (existingViewColumn != null) {
-
+ if (EncodedColumnsUtil.usesEncodedColumnNames(basePhysicalTable) && !SchemaUtil.isPKColumn(existingViewColumn)) {
+ /*
+ * If the column already exists in a view, then we cannot add the column to the base
+ * table. The reason is subtle and is as follows: consider the case where a table
+ * has two views where both the views have the same key value column KV. Now, we
+ * dole out encoded column qualifiers for key value columns in views by using the
+ * counters stored in the base physical table. So the KV column can have different
+ * column qualifiers for the two views. For example, 11 for VIEW1 and 12 for VIEW2.
+ * This naturally extends to rows being inserted using the two views having
+ * different column qualifiers for the column named KV. Now, when an attempt is made
+ * to add column KV to the base table, we cannot decide which column qualifier
+ * should that column be assigned. It cannot be a number different than 11 or 12
+ * since a query like SELECT KV FROM BASETABLE would return null for KV which is
+ * incorrect since column KV is present in rows inserted from the two views. We
+ * cannot use 11 or 12 either because we will then incorrectly return value of KV
+ * column inserted using only one view.
+ */
+ return new MetaDataMutationResult(MutationCode.UNALLOWED_TABLE_MUTATION, EnvironmentEdgeManager.currentTimeMillis(), basePhysicalTable);
+ }
// Validate data type is same
int baseColumnDataType = getInteger(columnToBeAdded, TABLE_FAMILY_BYTES, DATA_TYPE_BYTES);
if (baseColumnDataType != existingViewColumn.getDataType().getSqlType()) {
@@ -2848,6 +2905,16 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
return mutationResult;
}
}
+ } else if (type == PTableType.VIEW
+ && EncodedColumnsUtil.usesEncodedColumnNames(table)) {
+ /*
+ * When adding a column to a view that uses encoded column name scheme, we
+ * need to modify the CQ counters stored in the view's physical table. So to
+ * make sure clients get the latest PTable, we need to invalidate the cache
+ * entry.
+ */
+ invalidateList.add(new ImmutableBytesPtr(MetaDataUtil
+ .getPhysicalTableRowForView(table)));
}
for (Mutation m : tableMetaData) {
byte[] key = m.getRow();
@@ -2861,7 +2928,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
&& rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX].length > 0) {
PColumnFamily family =
table.getColumnFamily(rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]);
- family.getColumn(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]);
+ family.getPColumnForColumnNameBytes(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]);
} else if (pkCount > COLUMN_NAME_INDEX
&& rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX].length > 0) {
addingPKColumn = true;
@@ -3114,7 +3181,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
PColumnFamily family =
table.getColumnFamily(rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]);
columnToDelete =
- family.getColumn(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]);
+ family.getPColumnForColumnNameBytes(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]);
} else if (pkCount > COLUMN_NAME_INDEX
&& rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX].length > 0) {
deletePKColumn = true;
@@ -3203,10 +3270,11 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
byte[] indexKey =
SchemaUtil.getTableKey(tenantId, index.getSchemaName().getBytes(), index
.getTableName().getBytes());
+ Pair<String, String> columnToDeleteInfo = new Pair<>(columnToDelete.getFamilyName().getString(), columnToDelete.getName().getString());
+ boolean isColumnIndexed = indexMaintainer.getIndexedColumnInfo().contains(columnToDeleteInfo);
+ boolean isCoveredColumn = indexMaintainer.getCoveredColumnInfo().contains(columnToDeleteInfo);
// If index requires this column for its pk, then drop it
- if (indexMaintainer.getIndexedColumns().contains(
- new ColumnReference(columnToDelete.getFamilyName().getBytes(), columnToDelete
- .getName().getBytes()))) {
+ if (isColumnIndexed) {
// Since we're dropping the index, lock it to ensure
// that a change in index state doesn't
// occur while we're dropping it.
@@ -3227,9 +3295,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
invalidateList.add(new ImmutableBytesPtr(indexKey));
}
// If the dropped column is a covered index column, invalidate the index
- else if (indexMaintainer.getCoveredColumns().contains(
- new ColumnReference(columnToDelete.getFamilyName().getBytes(), columnToDelete
- .getName().getBytes()))) {
+ else if (isCoveredColumn){
invalidateList.add(new ImmutableBytesPtr(indexKey));
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
index 3cfe790..8a833ac 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
@@ -107,7 +107,7 @@ public class ScanRegionObserver extends BaseScannerRegionObserver {
}
}
- public static OrderedResultIterator deserializeFromScan(Scan scan, RegionScanner s) {
+ private static OrderedResultIterator deserializeFromScan(Scan scan, RegionScanner s) {
byte[] topN = scan.getAttribute(BaseScannerRegionObserver.TOPN);
if (topN == null) {
return null;
@@ -125,7 +125,7 @@ public class ScanRegionObserver extends BaseScannerRegionObserver {
orderByExpression.readFields(input);
orderByExpressions.add(orderByExpression);
}
- ResultIterator inner = new RegionScannerResultIterator(s);
+ ResultIterator inner = new RegionScannerResultIterator(s, ScanUtil.getMinMaxQualifiersFromScan(scan));
return new OrderedResultIterator(inner, orderByExpressions, thresholdBytes, limit >= 0 ? limit : null, null,
estimatedRowSize);
} catch (IOException e) {
@@ -218,21 +218,24 @@ public class ScanRegionObserver extends BaseScannerRegionObserver {
final TupleProjector p = TupleProjector.deserializeProjectorFromScan(scan);
final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan);
+ //TODO: samarth make this a client side check by looking at order by and group by expressions. Then use that to set min max qualifiers. We can then make useQualifierListAsIndex
+ // a member variable of BaseScannerRegionObserver.
+ boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(ScanUtil.getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null;
innerScanner =
getWrappedScanner(c, innerScanner, arrayKVRefs, arrayFuncRefs, offset, scan,
dataColumns, tupleProjector, dataRegion, indexMaintainer, tx,
- viewConstants, kvSchema, kvSchemaBitSet, j == null ? p : null, ptr);
+ viewConstants, kvSchema, kvSchemaBitSet, j == null ? p : null, ptr, useQualifierAsIndex);
final ImmutableBytesPtr tenantId = ScanUtil.getTenantId(scan);
if (j != null) {
- innerScanner = new HashJoinRegionScanner(innerScanner, p, j, tenantId, c.getEnvironment());
+ innerScanner = new HashJoinRegionScanner(innerScanner, p, j, tenantId, c.getEnvironment(), useQualifierAsIndex);
}
if (scanOffset != null) {
innerScanner = getOffsetScanner(c, innerScanner,
- new OffsetResultIterator(new RegionScannerResultIterator(innerScanner), scanOffset),
+ new OffsetResultIterator(new RegionScannerResultIterator(innerScanner, ScanUtil.getMinMaxQualifiersFromScan(scan)), scanOffset),
scan.getAttribute(QueryConstants.LAST_SCAN) != null);
}
- final OrderedResultIterator iterator = deserializeFromScan(scan,innerScanner);
+ final OrderedResultIterator iterator = deserializeFromScan(scan, innerScanner);
if (iterator == null) {
return innerScanner;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
index 0d0f0c2..a313dd1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
@@ -24,6 +24,7 @@ import static org.apache.phoenix.query.QueryConstants.UNGROUPED_AGG_ROW_KEY;
import static org.apache.phoenix.query.QueryServices.MUTATE_BATCH_SIZE_ATTRIB;
import static org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker.COMPACTION_UPDATE_STATS_ROW_COUNT;
import static org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker.CONCURRENT_UPDATE_STATS_ROW_COUNT;
+import static org.apache.phoenix.util.ScanUtil.getMinMaxQualifiersFromScan;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -96,7 +97,10 @@ import org.apache.phoenix.schema.ValueSchema.Field;
import org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker;
import org.apache.phoenix.schema.stats.StatisticsCollector;
import org.apache.phoenix.schema.stats.StatisticsCollectorFactory;
+import org.apache.phoenix.schema.tuple.EncodedColumnQualiferCellsList;
import org.apache.phoenix.schema.tuple.MultiKeyValueTuple;
+import org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple;
+import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PBinary;
import org.apache.phoenix.schema.types.PChar;
import org.apache.phoenix.schema.types.PDataType;
@@ -305,6 +309,7 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
byte[] deleteCQ = null;
byte[] deleteCF = null;
byte[] emptyCF = null;
+ byte[] emptyKVQualifier = null;
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
if (upsertSelectTable != null) {
isUpsert = true;
@@ -320,12 +325,14 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
deleteCQ = scan.getAttribute(BaseScannerRegionObserver.DELETE_CQ);
}
emptyCF = scan.getAttribute(BaseScannerRegionObserver.EMPTY_CF);
+ emptyKVQualifier = scan.getAttribute(BaseScannerRegionObserver.EMPTY_COLUMN_QUALIFIER);
}
TupleProjector tupleProjector = null;
byte[][] viewConstants = null;
ColumnReference[] dataColumns = IndexUtil.deserializeDataTableColumnsToJoin(scan);
final TupleProjector p = TupleProjector.deserializeProjectorFromScan(scan);
final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan);
+ boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(ScanUtil.getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null;
if ((localIndexScan && !isDelete && !isDescRowKeyOrderUpgrade) || (j == null && p != null)) {
if (dataColumns != null) {
tupleProjector = IndexUtil.getTupleProjector(scan, dataColumns);
@@ -334,11 +341,11 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
ImmutableBytesWritable tempPtr = new ImmutableBytesWritable();
theScanner =
getWrappedScanner(c, theScanner, offset, scan, dataColumns, tupleProjector,
- c.getEnvironment().getRegion(), indexMaintainers == null ? null : indexMaintainers.get(0), viewConstants, p, tempPtr);
+ c.getEnvironment().getRegion(), indexMaintainers == null ? null : indexMaintainers.get(0), viewConstants, p, tempPtr, useQualifierAsIndex);
}
if (j != null) {
- theScanner = new HashJoinRegionScanner(theScanner, p, j, ScanUtil.getTenantId(scan), env);
+ theScanner = new HashJoinRegionScanner(theScanner, p, j, ScanUtil.getTenantId(scan), env, useQualifierAsIndex);
}
int batchSize = 0;
@@ -374,7 +381,8 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
Aggregator[] rowAggregators = aggregators.getAggregators();
boolean hasMore;
boolean hasAny = false;
- MultiKeyValueTuple result = new MultiKeyValueTuple();
+ Pair<Integer, Integer> minMaxQualifiers = getMinMaxQualifiersFromScan(scan);
+ Tuple result = useQualifierAsIndex ? new PositionBasedMultiKeyValueTuple() : new MultiKeyValueTuple();
if (logger.isDebugEnabled()) {
logger.debug(LogUtil.addCustomAnnotations("Starting ungrouped coprocessor scan " + scan + " "+region.getRegionInfo(), ScanUtil.getCustomAnnotations(scan)));
}
@@ -392,7 +400,7 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
acquiredLock = true;
synchronized (innerScanner) {
do {
- List<Cell> results = new ArrayList<Cell>();
+ List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond()) : new ArrayList<Cell>();
// Results are potentially returned even when the return value of s.next is false
// since this is an indication of whether or not there are more values after the
// ones returned
[09/42] phoenix git commit: PHOENIX-3517 Switch sqlline-thin.py to
use argparse
Posted by td...@apache.org.
PHOENIX-3517 Switch sqlline-thin.py to use argparse
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/42a84b33
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/42a84b33
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/42a84b33
Branch: refs/heads/encodecolumns2
Commit: 42a84b338d73ef43005df8933e812545bb6be845
Parents: d2a2241
Author: Josh Elser <el...@apache.org>
Authored: Sat Dec 3 17:33:46 2016 -0500
Committer: Josh Elser <el...@apache.org>
Committed: Mon Dec 19 10:23:20 2016 -0500
----------------------------------------------------------------------
bin/sqlline-thin.py | 49 +++++++++++++++++++++++++++++-------------------
1 file changed, 30 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/42a84b33/bin/sqlline-thin.py
----------------------------------------------------------------------
diff --git a/bin/sqlline-thin.py b/bin/sqlline-thin.py
index 12501dc..e4cb540 100755
--- a/bin/sqlline-thin.py
+++ b/bin/sqlline-thin.py
@@ -25,6 +25,7 @@ import sys
import phoenix_utils
import atexit
import urlparse
+import argparse
global childProc
childProc = None
@@ -36,10 +37,25 @@ def kill_child():
os.system("reset")
atexit.register(kill_child)
+parser = argparse.ArgumentParser(description='Launches the Apache Phoenix Thin Client.')
+# Positional argument "url" is optional
+parser.add_argument('url', nargs='?', help='The URL to the Phoenix Query Server.', default='http://localhost:8765')
+# Positional argument "sqlfile" is optional
+parser.add_argument('sqlfile', nargs='?', help='A file of SQL commands to execute.', default='')
+parser.add_argument('-u', '--user', help='Username for database authentication (unsupported).', default='none')
+parser.add_argument('-p', '--password', help='Password for database authentication (unsupported).', default='none')
+parser.add_argument('-a', '--authentication', help='Mechanism for HTTP authentication.', choices=('SPNEGO', 'BASIC', 'DIGEST', 'NONE'), default='')
+parser.add_argument('-s', '--serialization', help='Serialization type for HTTP API.', choices=('PROTOBUF', 'JSON'), default=None)
+parser.add_argument('-au', '--auth-user', help='Username for HTTP authentication.')
+parser.add_argument('-ap', '--auth-password', help='Password for HTTP authentication.')
+parser.add_argument('-v', '--verbose', help='Verbosity on sqlline.', default='true')
+parser.add_argument('-c', '--color', help='Color setting for sqlline.', default='true')
+args=parser.parse_args()
+
phoenix_utils.setPath()
-url = "localhost:8765"
-sqlfile = ""
+url = args.url
+sqlfile = args.sqlfile
serialization_key = 'phoenix.queryserver.serialization'
def usage_and_exit():
@@ -86,25 +102,12 @@ def get_serialization():
return default_serialization
return stdout
-if len(sys.argv) == 1:
- pass
-elif len(sys.argv) == 2:
- if os.path.isfile(sys.argv[1]):
- sqlfile = sys.argv[1]
- else:
- url = sys.argv[1]
-elif len(sys.argv) == 3:
- url = sys.argv[1]
- sqlfile = sys.argv[2]
-else:
- usage_and_exit()
-
url = cleanup_url(url)
if sqlfile != "":
sqlfile = "--run=" + sqlfile
-colorSetting = "true"
+colorSetting = args.color
# disable color setting for windows OS
if os.name == 'nt':
colorSetting = "false"
@@ -113,7 +116,7 @@ if os.name == 'nt':
# HBase/Phoenix client side property override
hbase_config_path = os.getenv('HBASE_CONF_DIR', phoenix_utils.current_dir)
-serialization = get_serialization()
+serialization = args.serialization if args.serialization else get_serialization()
java_home = os.getenv('JAVA_HOME')
@@ -145,13 +148,21 @@ if java_home:
else:
java = 'java'
+jdbc_url = 'jdbc:phoenix:thin:url=' + url + ';serialization=' + serialization
+if args.authentication:
+ jdbc_url += ';authentication=' + args.authentication
+if args.auth_user:
+ jdbc_url += ';avatica_user=' + args.auth_user
+if args.auth_password:
+ jdbc_url += ';avatica_password=' + args.auth_password
+
java_cmd = java + ' $PHOENIX_OPTS ' + \
' -cp "' + phoenix_utils.hbase_conf_dir + os.pathsep + phoenix_utils.phoenix_thin_client_jar + \
os.pathsep + phoenix_utils.hadoop_conf + os.pathsep + phoenix_utils.hadoop_classpath + '" -Dlog4j.configuration=file:' + \
os.path.join(phoenix_utils.current_dir, "log4j.properties") + \
" org.apache.phoenix.queryserver.client.SqllineWrapper -d org.apache.phoenix.queryserver.client.Driver " + \
- " -u \"jdbc:phoenix:thin:url=" + url + ";serialization=" + serialization + "\"" + \
- " -n none -p none --color=" + colorSetting + " --fastConnect=false --verbose=true " + \
+ ' -u "' + jdbc_url + '"' + " -n " + args.user + " -p " + args.password + \
+ " --color=" + colorSetting + " --fastConnect=false --verbose=" + args.verbose + \
" --incremental=false --isolation=TRANSACTION_READ_COMMITTED " + sqlfile
exitcode = subprocess.call(java_cmd, shell=True)
[21/42] phoenix git commit: Fail-fast iterators for
EncodedColumnQualifierCellsList. Use list iterators instead of get(index) for
navigating lists. Use HBase bytes utility for encoded column names. Fix test
failures for immutable tables and indexes.
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java
index 00ece40..15a9f74 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java
@@ -26,6 +26,7 @@ import org.apache.phoenix.expression.ArrayConstructorExpression;
import org.apache.phoenix.expression.CaseExpression;
import org.apache.phoenix.expression.CoerceExpression;
import org.apache.phoenix.expression.ComparisonExpression;
+import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.expression.CorrelateVariableFieldAccessExpression;
import org.apache.phoenix.expression.DivideExpression;
import org.apache.phoenix.expression.Expression;
@@ -80,6 +81,11 @@ public abstract class CloneExpressionVisitor extends TraverseAllExpressionVisito
public Expression visit(KeyValueColumnExpression node) {
return node;
}
+
+ @Override
+ public Expression visit(ArrayColumnExpression node) {
+ return node;
+ }
@Override
public Expression visit(ProjectedColumnExpression node) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/ExpressionVisitor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/ExpressionVisitor.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/ExpressionVisitor.java
index 31f340d..100f099 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/ExpressionVisitor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/ExpressionVisitor.java
@@ -27,6 +27,7 @@ import org.apache.phoenix.expression.ArrayConstructorExpression;
import org.apache.phoenix.expression.CaseExpression;
import org.apache.phoenix.expression.CoerceExpression;
import org.apache.phoenix.expression.ComparisonExpression;
+import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.expression.CorrelateVariableFieldAccessExpression;
import org.apache.phoenix.expression.DivideExpression;
import org.apache.phoenix.expression.Expression;
@@ -113,6 +114,7 @@ public interface ExpressionVisitor<E> {
public E visit(LiteralExpression node);
public E visit(RowKeyColumnExpression node);
public E visit(KeyValueColumnExpression node);
+ public E visit(ArrayColumnExpression node);
public E visit(ProjectedColumnExpression node);
public E visit(SequenceValueExpression node);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseAllExpressionVisitor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseAllExpressionVisitor.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseAllExpressionVisitor.java
index 3b7067a..9e50bc4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseAllExpressionVisitor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseAllExpressionVisitor.java
@@ -26,9 +26,9 @@ import org.apache.phoenix.expression.ArrayConstructorExpression;
import org.apache.phoenix.expression.CaseExpression;
import org.apache.phoenix.expression.CoerceExpression;
import org.apache.phoenix.expression.ComparisonExpression;
+import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.expression.CorrelateVariableFieldAccessExpression;
import org.apache.phoenix.expression.DivideExpression;
-import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.InListExpression;
import org.apache.phoenix.expression.IsNullExpression;
import org.apache.phoenix.expression.KeyValueColumnExpression;
@@ -121,6 +121,11 @@ public class StatelessTraverseAllExpressionVisitor<E> extends TraverseAllExpress
}
@Override
+ public E visit(ArrayColumnExpression node) {
+ return null;
+ }
+
+ @Override
public E visit(ProjectedColumnExpression node) {
return null;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseNoExpressionVisitor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseNoExpressionVisitor.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseNoExpressionVisitor.java
index 83b28bd..1a2f2cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseNoExpressionVisitor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/StatelessTraverseNoExpressionVisitor.java
@@ -26,9 +26,9 @@ import org.apache.phoenix.expression.ArrayConstructorExpression;
import org.apache.phoenix.expression.CaseExpression;
import org.apache.phoenix.expression.CoerceExpression;
import org.apache.phoenix.expression.ComparisonExpression;
+import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.expression.CorrelateVariableFieldAccessExpression;
import org.apache.phoenix.expression.DivideExpression;
-import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.InListExpression;
import org.apache.phoenix.expression.IsNullExpression;
import org.apache.phoenix.expression.KeyValueColumnExpression;
@@ -114,6 +114,11 @@ public class StatelessTraverseNoExpressionVisitor<E> extends TraverseNoExpressio
public E visit(RowKeyColumnExpression node) {
return null;
}
+
+ @Override
+ public E visit(ArrayColumnExpression node) {
+ return null;
+ }
@Override
public E visit(KeyValueColumnExpression node) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/filter/ColumnProjectionFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/filter/ColumnProjectionFilter.java b/phoenix-core/src/main/java/org/apache/phoenix/filter/ColumnProjectionFilter.java
index 92e5c20..3d6843d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/filter/ColumnProjectionFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/filter/ColumnProjectionFilter.java
@@ -41,7 +41,7 @@ import org.apache.hadoop.hbase.util.Writables;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;
import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
-import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.EncodedColumnsUtil;
/**
* When selecting specific columns in a SELECT query, this filter passes only selected columns
@@ -54,6 +54,8 @@ public class ColumnProjectionFilter extends FilterBase implements Writable {
private byte[] emptyCFName;
private Map<ImmutableBytesPtr, NavigableSet<ImmutableBytesPtr>> columnsTracker;
private Set<byte[]> conditionOnlyCfs;
+ private boolean usesEncodedColumnNames;
+ private byte[] emptyKVQualifier;
public ColumnProjectionFilter() {
@@ -61,10 +63,12 @@ public class ColumnProjectionFilter extends FilterBase implements Writable {
public ColumnProjectionFilter(byte[] emptyCFName,
Map<ImmutableBytesPtr, NavigableSet<ImmutableBytesPtr>> columnsTracker,
- Set<byte[]> conditionOnlyCfs) {
+ Set<byte[]> conditionOnlyCfs, boolean usesEncodedColumnNames) {
this.emptyCFName = emptyCFName;
this.columnsTracker = columnsTracker;
this.conditionOnlyCfs = conditionOnlyCfs;
+ this.usesEncodedColumnNames = usesEncodedColumnNames;
+ this.emptyKVQualifier = EncodedColumnsUtil.getEmptyKeyValueInfo(usesEncodedColumnNames).getFirst();
}
@Override
@@ -88,6 +92,9 @@ public class ColumnProjectionFilter extends FilterBase implements Writable {
familyMapSize--;
}
int conditionOnlyCfsSize = WritableUtils.readVInt(input);
+ usesEncodedColumnNames = conditionOnlyCfsSize > 0;
+ emptyKVQualifier = EncodedColumnsUtil.getEmptyKeyValueInfo(usesEncodedColumnNames).getFirst();
+ conditionOnlyCfsSize = Math.abs(conditionOnlyCfsSize) - 1; // restore to the actual value.
this.conditionOnlyCfs = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
while (conditionOnlyCfsSize > 0) {
this.conditionOnlyCfs.add(WritableUtils.readCompressedByteArray(input));
@@ -111,12 +118,13 @@ public class ColumnProjectionFilter extends FilterBase implements Writable {
}
}
}
- // Write conditionOnlyCfs
- WritableUtils.writeVInt(output, this.conditionOnlyCfs.size());
+ // Encode usesEncodedColumnNames in conditionOnlyCfs size.
+ WritableUtils.writeVInt(output, (this.conditionOnlyCfs.size() + 1) * (usesEncodedColumnNames ? 1 : -1));
for (byte[] f : this.conditionOnlyCfs) {
WritableUtils.writeCompressedByteArray(output, f);
}
- }
+
+}
@Override
public byte[] toByteArray() throws IOException {
@@ -156,9 +164,9 @@ public class ColumnProjectionFilter extends FilterBase implements Writable {
// make sure we're not holding to any of the byte[]'s
ptr.set(HConstants.EMPTY_BYTE_ARRAY);
if (kvs.isEmpty()) {
- kvs.add(new KeyValue(firstKV.getRowArray(), firstKV.getRowOffset(),firstKV.getRowLength(), this.emptyCFName,
- 0, this.emptyCFName.length, QueryConstants.EMPTY_COLUMN_BYTES, 0,
- QueryConstants.EMPTY_COLUMN_BYTES.length, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0));
+ kvs.add(new KeyValue(firstKV.getRowArray(), firstKV.getRowOffset(), firstKV.getRowLength(),
+ this.emptyCFName, 0, this.emptyCFName.length, emptyKVQualifier, 0,
+ emptyKVQualifier.length, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0));
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java b/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java
index dba700b..a7146fc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/filter/MultiKeyValueComparisonFilter.java
@@ -26,6 +26,7 @@ import java.util.TreeSet;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.KeyValueColumnExpression;
import org.apache.phoenix.expression.visitor.ExpressionVisitor;
@@ -94,7 +95,7 @@ public abstract class MultiKeyValueComparisonFilter extends BooleanExpressionFil
refCount = foundColumns.size();
}
- public ReturnCode resolveColumn(Cell value) {
+ private ReturnCode resolveColumn(Cell value) {
// Always set key, in case we never find a key value column of interest,
// and our expression uses row key columns.
setKey(value);
@@ -184,7 +185,7 @@ public abstract class MultiKeyValueComparisonFilter extends BooleanExpressionFil
ExpressionVisitor<Void> visitor = new StatelessTraverseAllExpressionVisitor<Void>() {
@Override
public Void visit(KeyValueColumnExpression expression) {
- inputTuple.addColumn(expression.getColumnFamily(), expression.getColumnName());
+ inputTuple.addColumn(expression.getColumnFamily(), expression.getColumnQualifier());
return null;
}
};
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleCQKeyValueComparisonFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleCQKeyValueComparisonFilter.java b/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleCQKeyValueComparisonFilter.java
index 0d904bc..195c89c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleCQKeyValueComparisonFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleCQKeyValueComparisonFilter.java
@@ -47,7 +47,8 @@ public class SingleCQKeyValueComparisonFilter extends SingleKeyValueComparisonFi
public static SingleCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
try {
- return (SingleCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new SingleCQKeyValueComparisonFilter());
+ SingleCQKeyValueComparisonFilter writable = (SingleCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new SingleCQKeyValueComparisonFilter());
+ return writable;
} catch (IOException e) {
throw new DeserializationException(e);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleKeyValueComparisonFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleKeyValueComparisonFilter.java b/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleKeyValueComparisonFilter.java
index eaf8d35..b97c4e9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleKeyValueComparisonFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/filter/SingleKeyValueComparisonFilter.java
@@ -22,11 +22,13 @@ import java.io.IOException;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.KeyValueColumnExpression;
import org.apache.phoenix.expression.visitor.StatelessTraverseAllExpressionVisitor;
import org.apache.phoenix.expression.visitor.TraverseAllExpressionVisitor;
import org.apache.phoenix.schema.tuple.SingleKeyValueTuple;
+import org.apache.phoenix.schema.tuple.Tuple;
@@ -58,7 +60,7 @@ public abstract class SingleKeyValueComparisonFilter extends BooleanExpressionFi
@Override
public Void visit(KeyValueColumnExpression expression) {
cf = expression.getColumnFamily();
- cq = expression.getColumnName();
+ cq = expression.getColumnQualifier();
return null;
}
};
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/ValueGetter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/ValueGetter.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/ValueGetter.java
index bcadc2b..19797cf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/ValueGetter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/ValueGetter.java
@@ -35,4 +35,5 @@ public interface ValueGetter {
public ImmutableBytesWritable getLatestValue(ColumnReference ref) throws IOException;
public byte[] getRowKey();
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java
index 6f9caa6..0f960e4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java
@@ -32,7 +32,6 @@ import org.apache.phoenix.hbase.index.covered.TableState;
import org.apache.phoenix.hbase.index.scanner.Scanner;
import com.google.common.collect.Lists;
-import com.google.common.collect.Lists;
/**
*
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/KeyValueBuilder.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/KeyValueBuilder.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/KeyValueBuilder.java
index 741bf87..56b60e9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/KeyValueBuilder.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/KeyValueBuilder.java
@@ -125,4 +125,5 @@ public abstract class KeyValueBuilder {
public abstract KVComparator getKeyValueComparator();
public abstract List<Mutation> cloneIfNecessary(List<Mutation> mutations);
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 237ed75..7c88a25 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
@@ -17,12 +17,15 @@
*/
package org.apache.phoenix.index;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
+
import java.io.ByteArrayInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -32,6 +35,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.apache.hadoop.hbase.Cell;
@@ -44,16 +48,20 @@ import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;
import org.apache.phoenix.compile.ColumnResolver;
import org.apache.phoenix.compile.FromCompiler;
import org.apache.phoenix.compile.IndexExpressionCompiler;
import org.apache.phoenix.compile.StatementContext;
+import org.apache.phoenix.expression.ArrayColumnExpression;
+import org.apache.phoenix.expression.ArrayConstructorExpression;
import org.apache.phoenix.expression.CoerceExpression;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.ExpressionType;
import org.apache.phoenix.expression.KeyValueColumnExpression;
+import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.expression.visitor.KeyValueExpressionVisitor;
import org.apache.phoenix.hbase.index.ValueGetter;
import org.apache.phoenix.hbase.index.covered.update.ColumnReference;
@@ -67,14 +75,16 @@ import org.apache.phoenix.parse.SQLParser;
import org.apache.phoenix.parse.StatelessTraverseAllParseNodeVisitor;
import org.apache.phoenix.parse.UDFParseNode;
import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.AmbiguousColumnException;
+import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
import org.apache.phoenix.schema.ColumnNotFoundException;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnFamily;
import org.apache.phoenix.schema.PDatum;
import org.apache.phoenix.schema.PIndexState;
-import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.RowKeySchema;
import org.apache.phoenix.schema.SaltingUtil;
@@ -82,10 +92,13 @@ import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.ValueSchema;
import org.apache.phoenix.schema.ValueSchema.Field;
+import org.apache.phoenix.schema.tuple.BaseTuple;
import org.apache.phoenix.schema.tuple.ValueGetterTuple;
import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
import org.apache.phoenix.util.BitSet;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.ExpressionUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.MetaDataUtil;
@@ -93,6 +106,7 @@ import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TrustedByteArrayOutputStream;
import org.apache.tephra.TxConstants;
+import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
@@ -276,8 +290,14 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
// columns required to evaluate all expressions in indexedExpressions (this does not include columns in the data row key)
private Set<ColumnReference> indexedColumns;
private Set<ColumnReference> coveredColumns;
- // Map used to cache column family of data table and the corresponding column family for the local index
- private Map<ImmutableBytesPtr, ImmutableBytesWritable> dataTableLocalIndexFamilyMap;
+ // Information for columns of data tables that are being indexed. The first part of the pair is column family and second part is the column name.
+ private Set<Pair<String, String>> indexedColumnsInfo;
+ // Information for columns of data tables that are being covered by the index. The first part of the pair is column family and second part is the column name.
+ private Set<Pair<String, String>> coveredColumnsInfo;
+ // Map of covered columns where a key is column reference for a column in the data table
+ // and value is column reference for corresponding column in the index table.
+ // TODO: samarth confirm that we don't need a separate map for tracking column families of local indexes.
+ private Map<ColumnReference, ColumnReference> coveredColumnsMap;
// columns required to create index row i.e. indexedColumns + coveredColumns (this does not include columns in the data row key)
private Set<ColumnReference> allColumns;
// TODO remove this in the next major release
@@ -291,39 +311,40 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
private boolean indexWALDisabled;
private boolean isLocalIndex;
private boolean immutableRows;
+ private boolean storeColsInSingleCell;
// Transient state
private final boolean isDataTableSalted;
private final RowKeySchema dataRowKeySchema;
- private List<ImmutableBytesPtr> indexQualifiers;
private int estimatedIndexRowKeyBytes;
private int estimatedExpressionSize;
private int[] dataPkPosition;
private int maxTrailingNulls;
private ColumnReference dataEmptyKeyValueRef;
private boolean rowKeyOrderOptimizable;
+ private boolean usesEncodedColumnNames;
+ private ImmutableBytesPtr emptyKeyValueQualifierPtr;
private IndexMaintainer(RowKeySchema dataRowKeySchema, boolean isDataTableSalted) {
this.dataRowKeySchema = dataRowKeySchema;
this.isDataTableSalted = isDataTableSalted;
}
- private IndexMaintainer(PTable dataTable, PTable index, PhoenixConnection connection) {
+ private IndexMaintainer(final PTable dataTable, final PTable index, PhoenixConnection connection) {
this(dataTable.getRowKeySchema(), dataTable.getBucketNum() != null);
assert(dataTable.getType() == PTableType.SYSTEM || dataTable.getType() == PTableType.TABLE || dataTable.getType() == PTableType.VIEW);
this.rowKeyOrderOptimizable = index.rowKeyOrderOptimizable();
this.isMultiTenant = dataTable.isMultiTenant();
this.viewIndexId = index.getViewIndexId() == null ? null : MetaDataUtil.getViewIndexIdDataType().toBytes(index.getViewIndexId());
this.isLocalIndex = index.getIndexType() == IndexType.LOCAL;
-
+ this.usesEncodedColumnNames = EncodedColumnsUtil.usesEncodedColumnNames(index);
byte[] indexTableName = index.getPhysicalName().getBytes();
// Use this for the nDataSaltBuckets as we need this for local indexes
// TODO: persist nDataSaltBuckets separately, but maintain b/w compat.
Integer nIndexSaltBuckets = isLocalIndex ? dataTable.getBucketNum() : index.getBucketNum();
boolean indexWALDisabled = index.isWALDisabled();
int indexPosOffset = (index.getBucketNum() == null ? 0 : 1) + (this.isMultiTenant ? 1 : 0) + (this.viewIndexId == null ? 0 : 1);
-// int indexPosOffset = !isLocalIndex && nIndexSaltBuckets > 0 ? 1 : 0;
int nIndexColumns = index.getColumns().size() - indexPosOffset;
int nIndexPKColumns = index.getPKColumns().size() - indexPosOffset;
// number of expressions that are indexed that are not present in the row key of the data table
@@ -334,7 +355,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
String dataFamilyName = IndexUtil.getDataColumnFamilyName(indexColumnName);
String dataColumnName = IndexUtil.getDataColumnName(indexColumnName);
try {
- PColumn dataColumn = dataFamilyName.equals("") ? dataTable.getColumn(dataColumnName) : dataTable.getColumnFamily(dataFamilyName).getColumn(dataColumnName);
+ PColumn dataColumn = dataFamilyName.equals("") ? dataTable.getPColumnForColumnName(dataColumnName) : dataTable.getColumnFamily(dataFamilyName).getPColumnForColumnName(dataColumnName);
if (SchemaUtil.isPKColumn(dataColumn))
continue;
} catch (ColumnNotFoundException e) {
@@ -367,7 +388,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
this.indexedColumnTypes = Lists.<PDataType>newArrayListWithExpectedSize(nIndexPKColumns-nDataPKColumns);
this.indexedExpressions = Lists.newArrayListWithExpectedSize(nIndexPKColumns-nDataPKColumns);
this.coveredColumns = Sets.newLinkedHashSetWithExpectedSize(nIndexColumns-nIndexPKColumns);
- this.dataTableLocalIndexFamilyMap = Maps.newHashMapWithExpectedSize(nIndexColumns-nIndexPKColumns);
+ this.coveredColumnsMap = Maps.newHashMapWithExpectedSize(nIndexColumns - nIndexPKColumns);
this.nIndexSaltBuckets = nIndexSaltBuckets == null ? 0 : nIndexSaltBuckets;
this.dataEmptyKeyValueCF = SchemaUtil.getEmptyColumnFamily(dataTable);
this.emptyKeyValueCFPtr = SchemaUtil.getEmptyColumnFamilyPtr(index);
@@ -376,6 +397,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
// TODO: check whether index is immutable or not. Currently it's always false so checking
// data table is with immutable rows or not.
this.immutableRows = dataTable.isImmutableRows();
+ this.storeColsInSingleCell = index.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
int indexColByteSize = 0;
ColumnResolver resolver = null;
List<ParseNode> parseNodes = new ArrayList<ParseNode>(1);
@@ -397,6 +419,9 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
throw new RuntimeException(e); // Impossible
}
StatementContext context = new StatementContext(new PhoenixStatement(connection), resolver);
+ this.indexedColumnsInfo = Sets.newHashSetWithExpectedSize(nIndexColumns - nIndexPKColumns);
+ this.coveredColumnsInfo = Sets.newHashSetWithExpectedSize(nIndexColumns - nIndexPKColumns);
+
IndexExpressionCompiler expressionIndexCompiler = new IndexExpressionCompiler(context);
for (int i = indexPosOffset; i < index.getPKColumns().size(); i++) {
PColumn indexColumn = index.getPKColumns().get(i);
@@ -409,12 +434,13 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
throw new RuntimeException(e); // Impossible
}
if ( expressionIndexCompiler.getColumnRef()!=null ) {
- // get the column of the data table that corresponds to this index column
+ // get the column of the data column that corresponds to this index column
PColumn column = IndexUtil.getDataColumn(dataTable, indexColumn.getName().getString());
boolean isPKColumn = SchemaUtil.isPKColumn(column);
if (isPKColumn) {
int dataPkPos = dataTable.getPKColumns().indexOf(column) - (dataTable.getBucketNum() == null ? 0 : 1) - (this.isMultiTenant ? 1 : 0);
this.rowKeyMetaData.setIndexPkPosition(dataPkPos, indexPos);
+ indexedColumnsInfo.add(new Pair<>((String)null, column.getName().getString()));
} else {
indexColByteSize += column.getDataType().isFixedWidth() ? SchemaUtil.getFixedByteSize(column) : ValueSchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
try {
@@ -424,6 +450,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
expression = CoerceExpression.create(expression, indexColumn.getDataType());
}
this.indexedExpressions.add(expression);
+ indexedColumnsInfo.add(new Pair<>(column.getFamilyName().getString(), column.getName().getString()));
} catch (SQLException e) {
throw new RuntimeException(e); // Impossible
}
@@ -432,6 +459,45 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
else {
indexColByteSize += expression.getDataType().isFixedWidth() ? SchemaUtil.getFixedByteSize(expression) : ValueSchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
this.indexedExpressions.add(expression);
+ KeyValueExpressionVisitor kvVisitor = new KeyValueExpressionVisitor() {
+ @Override
+ public Void visit(KeyValueColumnExpression colExpression) {
+ return addDataColInfo(dataTable, colExpression);
+ }
+
+ @Override
+ public Void visit(ArrayColumnExpression expression) {
+ return addDataColInfo(dataTable, expression);
+ }
+
+ private Void addDataColInfo(final PTable dataTable, Expression expression) {
+ Preconditions.checkArgument(expression instanceof ArrayColumnExpression
+ || expression instanceof KeyValueColumnExpression);
+
+ KeyValueColumnExpression colExpression = null;
+ if (expression instanceof ArrayColumnExpression) {
+ colExpression =
+ ((ArrayColumnExpression) expression).getKeyValueExpression();
+ } else {
+ colExpression = ((KeyValueColumnExpression) expression);
+ }
+ byte[] cf = colExpression.getColumnFamily();
+ byte[] cq = colExpression.getColumnQualifier();
+ try {
+ PColumn dataColumn =
+ cf == null ? dataTable.getPColumnForColumnQualifier(null, cq)
+ : dataTable.getColumnFamily(cf)
+ .getPColumnForColumnQualifier(cq);
+ indexedColumnsInfo.add(new Pair<>(dataColumn.getFamilyName()
+ .getString(), dataColumn.getName().getString()));
+ } catch (ColumnNotFoundException | ColumnFamilyNotFoundException
+ | AmbiguousColumnException e) {
+ throw new RuntimeException(e);
+ }
+ return null;
+ }
+ };
+ expression.accept(kvVisitor);
}
// set the sort order of the expression correctly
if (indexColumn.getSortOrder() == SortOrder.DESC) {
@@ -442,18 +508,19 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
for (int i = 0; i < index.getColumnFamilies().size(); i++) {
PColumnFamily family = index.getColumnFamilies().get(i);
for (PColumn indexColumn : family.getColumns()) {
- PColumn column = IndexUtil.getDataColumn(dataTable, indexColumn.getName().getString());
- PName dataTableFamily = column.getFamilyName();
- this.coveredColumns.add(new ColumnReference(dataTableFamily.getBytes(), column.getName().getBytes()));
- if(isLocalIndex) {
- this.dataTableLocalIndexFamilyMap.put(new ImmutableBytesPtr(dataTableFamily.getBytes()), new ImmutableBytesWritable(Bytes.toBytes(IndexUtil.getLocalIndexColumnFamily(dataTableFamily.getString()))));
- }
+ PColumn dataColumn = IndexUtil.getDataColumn(dataTable, indexColumn.getName().getString());
+ byte[] dataColumnCq = EncodedColumnsUtil.getColumnQualifier(dataColumn, dataTable);
+ byte[] indexColumnCq = EncodedColumnsUtil.getColumnQualifier(indexColumn, index);
+ this.coveredColumns.add(new ColumnReference(dataColumn.getFamilyName().getBytes(), dataColumnCq));
+ this.coveredColumnsMap.put(new ColumnReference(dataColumn.getFamilyName().getBytes(), dataColumnCq),
+ new ColumnReference(indexColumn.getFamilyName().getBytes(), indexColumnCq));
+ this.coveredColumnsInfo.add(new Pair<>(dataColumn.getFamilyName().getString(), dataColumn.getName().getString()));
}
}
this.estimatedIndexRowKeyBytes = estimateIndexRowKeyByteSize(indexColByteSize);
initCachedState();
}
-
+
public byte[] buildRowKey(ValueGetter valueGetter, ImmutableBytesWritable rowKeyPtr, byte[] regionStartKey, byte[] regionEndKey) {
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
boolean prependRegionStartKey = isLocalIndex && regionStartKey != null;
@@ -856,35 +923,113 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
}
public Put buildUpdateMutation(KeyValueBuilder kvBuilder, ValueGetter valueGetter, ImmutableBytesWritable dataRowKeyPtr, long ts, byte[] regionStartKey, byte[] regionEndKey) throws IOException {
- Put put = null;
+ byte[] indexRowKey = this.buildRowKey(valueGetter, dataRowKeyPtr, regionStartKey, regionEndKey);
+ Put put = null;
// New row being inserted: add the empty key value
if (valueGetter.getLatestValue(dataEmptyKeyValueRef) == null) {
- byte[] indexRowKey = this.buildRowKey(valueGetter, dataRowKeyPtr, regionStartKey, regionEndKey);
put = new Put(indexRowKey);
// add the keyvalue for the empty row
put.add(kvBuilder.buildPut(new ImmutableBytesPtr(indexRowKey),
- this.getEmptyKeyValueFamily(), QueryConstants.EMPTY_COLUMN_BYTES_PTR, ts,
+ this.getEmptyKeyValueFamily(), emptyKeyValueQualifierPtr, ts,
// set the value to the empty column name
- QueryConstants.EMPTY_COLUMN_BYTES_PTR));
+ emptyKeyValueQualifierPtr));
put.setDurability(!indexWALDisabled ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
}
- int i = 0;
- for (ColumnReference ref : this.getCoveredColumns()) {
- ImmutableBytesPtr cq = this.indexQualifiers.get(i++);
- ImmutableBytesWritable value = valueGetter.getLatestValue(ref);
- byte[] indexRowKey = this.buildRowKey(valueGetter, dataRowKeyPtr, regionStartKey, regionEndKey);
- ImmutableBytesPtr rowKey = new ImmutableBytesPtr(indexRowKey);
- if (value != null) {
+ ImmutableBytesPtr rowKey = new ImmutableBytesPtr(indexRowKey);
+ if (storeColsInSingleCell) {
+ // map from index column family to list of pair of index column and data column (for covered columns)
+ Map<ByteBuffer, List<Pair<ColumnReference, ColumnReference>>> familyToColListMap = Maps.newHashMap();
+ for (ColumnReference ref : this.getCoveredColumns()) {
+ ColumnReference indexColRef = this.coveredColumnsMap.get(ref);
+ ByteBuffer cf = ByteBuffer.wrap(indexColRef.getFamily());
+ if (!familyToColListMap.containsKey(cf)) {
+ familyToColListMap.put(cf, Lists.<Pair<ColumnReference, ColumnReference>>newArrayList());
+ }
+ familyToColListMap.get(cf).add(Pair.newPair(indexColRef, ref));
+ }
+ // iterate over each column family and create a byte[] containing all the columns
+ for (Entry<ByteBuffer, List<Pair<ColumnReference, ColumnReference>>> entry : familyToColListMap.entrySet()) {
+ byte[] columnFamily = entry.getKey().array();
+ List<Pair<ColumnReference, ColumnReference>> colRefPairs = entry.getValue();
+ int maxIndex = Integer.MIN_VALUE;
+ // find the max col qualifier
+ for (Pair<ColumnReference, ColumnReference> colRefPair : colRefPairs) {
+ int qualifier = getEncodedColumnQualifier(colRefPair.getFirst().getQualifier());
+ maxIndex = Math.max(maxIndex, qualifier);
+ }
+ byte[][] colValues = new byte[maxIndex+1][];
+ // set the values of the columns
+ for (Pair<ColumnReference, ColumnReference> colRefPair : colRefPairs) {
+ ColumnReference indexColRef = colRefPair.getFirst();
+ ColumnReference dataColRef = colRefPair.getSecond();
+ int dataArrayPos = getEncodedColumnQualifier(dataColRef.getQualifier());
+ Expression expression = new ArrayColumnExpression(new PDatum() {
+ @Override
+ public boolean isNullable() {
+ return false;
+ }
+
+ @Override
+ public SortOrder getSortOrder() {
+ return null;
+ }
+
+ @Override
+ public Integer getScale() {
+ return null;
+ }
+
+ @Override
+ public Integer getMaxLength() {
+ return null;
+ }
+
+ @Override
+ public PDataType getDataType() {
+ return null;
+ }
+ }, dataColRef.getFamily(), dataArrayPos);
+ ImmutableBytesPtr ptr = new ImmutableBytesPtr();
+ expression.evaluate(new ValueGetterTuple(valueGetter), ptr);
+ byte[] value = ptr.copyBytesIfNecessary();
+ if (value != null) {
+ int indexArrayPos = getEncodedColumnQualifier(indexColRef.getQualifier());
+ colValues[indexArrayPos] = value;
+ }
+ }
+
+ List<Expression> children = Lists.newArrayListWithExpectedSize(colRefPairs.size());
+ // create an expression list with all the columns
+ for (int j=0; j<colValues.length; ++j) {
+ children.add(new LiteralExpression(colValues[j]==null ? ByteUtil.EMPTY_BYTE_ARRAY : colValues[j] ));
+ }
+ // we use ArrayConstructorExpression to serialize multiple columns into a single byte[]
+ // construct the ArrayConstructorExpression with a variable length data type (PVarchar) since columns can be of fixed or variable length
+ ArrayConstructorExpression arrayExpression = new ArrayConstructorExpression(children, PVarchar.INSTANCE, rowKeyOrderOptimizable);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+ arrayExpression.evaluate(new BaseTuple() {}, ptr);
if (put == null) {
put = new Put(indexRowKey);
put.setDurability(!indexWALDisabled ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
}
+ ImmutableBytesPtr colFamilyPtr = new ImmutableBytesPtr(columnFamily);
//this is a little bit of extra work for installations that are running <0.94.14, but that should be rare and is a short-term set of wrappers - it shouldn't kill GC
- if(this.isLocalIndex) {
- ImmutableBytesWritable localIndexColFamily = this.dataTableLocalIndexFamilyMap.get(ref.getFamilyWritable());
- put.add(kvBuilder.buildPut(rowKey, localIndexColFamily, cq, ts, value));
- } else {
- put.add(kvBuilder.buildPut(rowKey, ref.getFamilyWritable(), cq, ts, value));
+ put.add(kvBuilder.buildPut(rowKey, colFamilyPtr, colFamilyPtr, ts, ptr));
+ }
+ }
+ else {
+ for (ColumnReference ref : this.getCoveredColumns()) {
+ //FIXME: samarth figure out a backward compatible way to handle this as coveredcolumnsmap won't be availble for older phoenix clients.
+ ColumnReference indexColRef = this.coveredColumnsMap.get(ref);
+ ImmutableBytesPtr cq = indexColRef.getQualifierWritable();
+ ImmutableBytesPtr cf = indexColRef.getFamilyWritable();
+ ImmutableBytesWritable value = valueGetter.getLatestValue(ref);
+ if (value != null) {
+ if (put == null) {
+ put = new Put(indexRowKey);
+ put.setDurability(!indexWALDisabled ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
+ }
+ put.add(kvBuilder.buildPut(rowKey, cf, cq, ts, value));
}
}
}
@@ -973,14 +1118,12 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
for (ColumnReference ref : getCoveredColumns()) {
byte[] family = ref.getFamily();
- if (this.isLocalIndex) {
- family = this.dataTableLocalIndexFamilyMap.get(ref.getFamilyWritable()).get();
- }
+ ColumnReference indexColumn = coveredColumnsMap.get(ref);
// If table delete was single version, then index delete should be as well
if (deleteType == DeleteType.SINGLE_VERSION) {
- delete.deleteFamilyVersion(family, ts);
+ delete.deleteFamilyVersion(indexColumn.getFamily(), ts);
} else {
- delete.deleteFamily(family, ts);
+ delete.deleteFamily(indexColumn.getFamily(), ts);
}
}
if (deleteType == DeleteType.SINGLE_VERSION) {
@@ -1001,12 +1144,15 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
delete = new Delete(indexRowKey);
delete.setDurability(!indexWALDisabled ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
}
- byte[] family = this.isLocalIndex ? this.dataTableLocalIndexFamilyMap.get(ref.getFamilyWritable()).get() : ref.getFamily();
+ ColumnReference indexColumn = coveredColumnsMap.get(ref);
// If point delete for data table, then use point delete for index as well
- if (kv.getTypeByte() == KeyValue.Type.Delete.getCode()) {
- delete.deleteColumn(family, IndexUtil.getIndexColumnName(ref.getFamily(), ref.getQualifier()), ts);
+ if (kv.getTypeByte() == KeyValue.Type.Delete.getCode()) {
+ //FIXME: samarth change this. Index column qualifiers are not derivable from data table cqs.
+ // Figure out a backward compatible way of going this since coveredColumnsMap won't be available
+ // for older clients.
+ delete.deleteColumn(indexColumn.getFamily(), indexColumn.getQualifier(), ts);
} else {
- delete.deleteColumns(family, IndexUtil.getIndexColumnName(ref.getFamily(), ref.getQualifier()), ts);
+ delete.deleteColumns(indexColumn.getFamily(), indexColumn.getQualifier(), ts);
}
}
}
@@ -1061,15 +1207,16 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
isLocalIndex = encodedCoveredolumnsAndLocalIndex < 0;
int nCoveredColumns = Math.abs(encodedCoveredolumnsAndLocalIndex) - 1;
coveredColumns = Sets.newLinkedHashSetWithExpectedSize(nCoveredColumns);
- dataTableLocalIndexFamilyMap = Maps.newHashMapWithExpectedSize(nCoveredColumns);
+ coveredColumnsMap = Maps.newHashMapWithExpectedSize(nCoveredColumns);
for (int i = 0; i < nCoveredColumns; i++) {
- byte[] cf = Bytes.readByteArray(input);
- byte[] cq = Bytes.readByteArray(input);
- ColumnReference ref = new ColumnReference(cf,cq);
- coveredColumns.add(ref);
- if(isLocalIndex) {
- dataTableLocalIndexFamilyMap.put(ref.getFamilyWritable(), new ImmutableBytesWritable(Bytes.toBytes(IndexUtil.getLocalIndexColumnFamily(Bytes.toString(cf)))));
- }
+ byte[] dataTableCf = Bytes.readByteArray(input);
+ byte[] dataTableCq = Bytes.readByteArray(input);
+ byte[] indexTableCf = Bytes.readByteArray(input);
+ byte[] indexTableCq = Bytes.readByteArray(input);
+ ColumnReference dataColumn = new ColumnReference(dataTableCf, dataTableCq);
+ coveredColumns.add(dataColumn);
+ ColumnReference indexColumn = new ColumnReference(indexTableCf, indexTableCq);
+ coveredColumnsMap.put(dataColumn, indexColumn);
}
// Hack to serialize whether the index row key is optimizable
int len = WritableUtils.readVInt(input);
@@ -1095,6 +1242,8 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
if (isNewClient) {
int numIndexedExpressions = WritableUtils.readVInt(input);
+ usesEncodedColumnNames = numIndexedExpressions > 0;
+ numIndexedExpressions = Math.abs(numIndexedExpressions) - 1;
indexedExpressions = Lists.newArrayListWithExpectedSize(numIndexedExpressions);
for (int i = 0; i < numIndexedExpressions; i++) {
Expression expression = ExpressionType.values()[WritableUtils.readVInt(input)].newInstance();
@@ -1148,6 +1297,22 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
int encodedEstimatedIndexRowKeyBytesAndImmutableRows = WritableUtils.readVInt(input);
this.immutableRows = encodedEstimatedIndexRowKeyBytesAndImmutableRows < 0;
this.estimatedIndexRowKeyBytes = Math.abs(encodedEstimatedIndexRowKeyBytesAndImmutableRows);
+ int numCols = WritableUtils.readVInt(input);
+ //TODO: samarth figure out a backward compatible way of reading/writing indexedColumnsInfo
+ indexedColumnsInfo = Sets.newHashSetWithExpectedSize(numCols);
+ for (int i = 1; i <= numCols; i++) {
+ byte[] dataTableCf = Bytes.readByteArray(input);
+ byte[] dataTableCq = Bytes.readByteArray(input);
+ indexedColumnsInfo.add(new Pair<>(Bytes.toString(dataTableCf), Bytes.toString(dataTableCq)));
+ }
+ coveredColumnsInfo = Sets.newHashSetWithExpectedSize(numCols);
+ int numCoveredCols = WritableUtils.readVInt(input);
+ for (int i = 1; i <= numCoveredCols; i++) {
+ byte[] dataTableCf = Bytes.readByteArray(input);
+ byte[] dataTableCq = Bytes.readByteArray(input);
+ coveredColumnsInfo.add(new Pair<>(Bytes.toString(dataTableCf), Bytes.toString(dataTableCq)));
+ }
+ storeColsInSingleCell = WritableUtils.readVInt(input) > 0;
initCachedState();
}
@@ -1171,9 +1336,13 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
}
// Encode coveredColumns.size() and whether or not this is a local index
WritableUtils.writeVInt(output, (coveredColumns.size() + 1) * (isLocalIndex ? -1 : 1));
- for (ColumnReference ref : coveredColumns) {
- Bytes.writeByteArray(output, ref.getFamily());
- Bytes.writeByteArray(output, ref.getQualifier());
+ for (Entry<ColumnReference, ColumnReference> ref : coveredColumnsMap.entrySet()) {
+ ColumnReference dataColumn = ref.getKey();
+ ColumnReference indexColumn = ref.getValue();
+ Bytes.writeByteArray(output, dataColumn.getFamily());
+ Bytes.writeByteArray(output, dataColumn.getQualifier());
+ Bytes.writeByteArray(output, indexColumn.getFamily());
+ Bytes.writeByteArray(output, indexColumn.getQualifier());
}
// TODO: remove when rowKeyOrderOptimizable hack no longer needed
WritableUtils.writeVInt(output,indexTableName.length * (rowKeyOrderOptimizable ? 1 : -1));
@@ -1184,7 +1353,9 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
WritableUtils.writeVInt(output,-emptyKeyValueCFPtr.getLength());
output.write(emptyKeyValueCFPtr.get(),emptyKeyValueCFPtr.getOffset(), emptyKeyValueCFPtr.getLength());
- WritableUtils.writeVInt(output, indexedExpressions.size());
+ // Hack to encode usesEncodedColumnNames in indexedExpressions size.
+ int indexedExpressionsSize = (indexedExpressions.size() + 1) * (usesEncodedColumnNames ? 1 : -1);
+ WritableUtils.writeVInt(output, indexedExpressionsSize);
for (Expression expression : indexedExpressions) {
WritableUtils.writeVInt(output, ExpressionType.valueOf(expression).ordinal());
expression.write(output);
@@ -1195,6 +1366,17 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
WritableUtils.writeVInt(output, (nDataCFs + 1) * (indexWALDisabled ? -1 : 1));
// Encode estimatedIndexRowKeyBytes and immutableRows together.
WritableUtils.writeVInt(output, estimatedIndexRowKeyBytes * (immutableRows ? -1 : 1));
+ WritableUtils.writeVInt(output, indexedColumnsInfo.size());
+ for (Pair<String, String> colInfo : indexedColumnsInfo) {
+ Bytes.writeByteArray(output, colInfo.getFirst() == null ? null : colInfo.getFirst().getBytes());
+ Bytes.writeByteArray(output, colInfo.getSecond().getBytes());
+ }
+ WritableUtils.writeVInt(output, coveredColumnsInfo.size());
+ for (Pair<String, String> colInfo : coveredColumnsInfo) {
+ Bytes.writeByteArray(output, colInfo.getFirst() == null ? null : colInfo.getFirst().getBytes());
+ Bytes.writeByteArray(output, colInfo.getSecond().getBytes());
+ }
+ WritableUtils.writeVInt(output, storeColsInSingleCell ? 1 : -1);
}
public int getEstimatedByteSize() {
@@ -1241,16 +1423,9 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
* Init calculated state reading/creating
*/
private void initCachedState() {
- dataEmptyKeyValueRef =
- new ColumnReference(emptyKeyValueCFPtr.copyBytesIfNecessary(),
- QueryConstants.EMPTY_COLUMN_BYTES);
-
- indexQualifiers = Lists.newArrayListWithExpectedSize(this.coveredColumns.size());
- for (ColumnReference ref : coveredColumns) {
- indexQualifiers.add(new ImmutableBytesPtr(IndexUtil.getIndexColumnName(
- ref.getFamily(), ref.getQualifier())));
- }
-
+ byte[] emptyKvQualifier = EncodedColumnsUtil.getEmptyKeyValueInfo(usesEncodedColumnNames).getFirst();
+ dataEmptyKeyValueRef = new ColumnReference(emptyKeyValueCFPtr.copyBytesIfNecessary(), emptyKvQualifier);
+ emptyKeyValueQualifierPtr = new ImmutableBytesPtr(emptyKvQualifier);
this.allColumns = Sets.newLinkedHashSetWithExpectedSize(indexedExpressions.size() + coveredColumns.size());
// columns that are required to evaluate all expressions in indexedExpressions (not including columns in data row key)
this.indexedColumns = Sets.newLinkedHashSetWithExpectedSize(indexedExpressions.size());
@@ -1258,7 +1433,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
KeyValueExpressionVisitor visitor = new KeyValueExpressionVisitor() {
@Override
public Void visit(KeyValueColumnExpression expression) {
- if (indexedColumns.add(new ColumnReference(expression.getColumnFamily(), expression.getColumnName()))) {
+ if (indexedColumns.add(new ColumnReference(expression.getColumnFamily(), expression.getColumnQualifier()))) {
indexedColumnTypes.add(expression.getDataType());
}
return null;
@@ -1523,4 +1698,26 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
return udfParseNodes;
}
}
+
+ public byte[] getEmptyKeyValueQualifier() {
+ return emptyKeyValueQualifierPtr.copyBytes();
+ }
+
+ public Set<Pair<String, String>> getCoveredColumnInfo() {
+ return coveredColumnsInfo;
+ }
+
+ public Set<Pair<String, String>> getIndexedColumnInfo() {
+ return indexedColumnsInfo;
+ }
+
+ public StorageScheme getIndexStorageScheme() {
+ if (storeColsInSingleCell) {
+ return StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
+ }
+ if (usesEncodedColumnNames) {
+ return StorageScheme.ENCODED_COLUMN_NAMES;
+ }
+ return StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java
index bf1d0fb..05211c0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java
@@ -166,7 +166,7 @@ public class PhoenixIndexBuilder extends NonTxIndexBuilder {
ExpressionVisitor<Void> visitor = new StatelessTraverseAllExpressionVisitor<Void>() {
@Override
public Void visit(KeyValueColumnExpression expression) {
- get.addColumn(expression.getColumnFamily(), expression.getColumnName());
+ get.addColumn(expression.getColumnFamily(), expression.getColumnQualifier());
estimatedSizeHolder[0]++;
return null;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
index eb73d6b..d382005 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
@@ -158,12 +158,13 @@ public class PhoenixIndexFailurePolicy extends DelegateIndexFailurePolicy {
.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, env.getConfiguration()));
// Mimic the Put that gets generated by the client on an update of the index state
Put put = new Put(indexTableKey);
- if (blockWriteRebuildIndex)
+ if (blockWriteRebuildIndex) {
put.add(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.INDEX_STATE_BYTES,
PIndexState.ACTIVE.getSerializedBytes());
- else
+ } else {
put.add(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.INDEX_STATE_BYTES,
PIndexState.DISABLE.getSerializedBytes());
+ }
put.add(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP_BYTES,
PLong.INSTANCE.toBytes(minTimeStamp));
final List<Mutation> tableMetadata = Collections.<Mutation>singletonList(put);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
index c67da6e..9ee5ea7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
@@ -67,7 +67,6 @@ import org.apache.phoenix.hbase.index.covered.update.IndexedColumnGroup;
import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
import org.apache.phoenix.hbase.index.write.IndexWriter;
import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.trace.TracingUtils;
import org.apache.phoenix.trace.util.NullSpan;
@@ -304,8 +303,16 @@ public class PhoenixTransactionalIndexer extends BaseRegionObserver {
for (ColumnReference ref : mutableColumns) {
scan.addColumn(ref.getFamily(), ref.getQualifier());
}
+ /*
+ * Indexes inherit the storage scheme of the data table which means all the indexes have the same
+ * storage scheme and empty key value qualifier. Note that this assumption would be broken if we start
+ * supporting new indexes over existing data tables to have a different storage scheme than the data
+ * table.
+ */
+ byte[] emptyKeyValueQualifier = indexMaintainers.get(0).getEmptyKeyValueQualifier();
+
// Project empty key value column
- scan.addColumn(indexMaintainers.get(0).getDataEmptyKeyValueCF(), QueryConstants.EMPTY_COLUMN_BYTES);
+ scan.addColumn(indexMaintainers.get(0).getDataEmptyKeyValueCF(), emptyKeyValueQualifier);
ScanRanges scanRanges = ScanRanges.create(SchemaUtil.VAR_BINARY_SCHEMA, Collections.singletonList(keys), ScanUtil.SINGLE_COLUMN_SLOT_SPAN, KeyRange.EVERYTHING_RANGE, null, true, -1);
scanRanges.initializeScan(scan);
TableName tableName = env.getRegion().getRegionInfo().getTable();
@@ -356,7 +363,8 @@ public class PhoenixTransactionalIndexer extends BaseRegionObserver {
Map<ImmutableBytesPtr, MultiMutation> mutationsToFindPreviousValue) throws IOException {
if (scanner != null) {
Result result;
- ColumnReference emptyColRef = new ColumnReference(indexMetaData.getIndexMaintainers().get(0).getDataEmptyKeyValueCF(), QueryConstants.EMPTY_COLUMN_BYTES);
+ ColumnReference emptyColRef = new ColumnReference(indexMetaData.getIndexMaintainers().get(0)
+ .getDataEmptyKeyValueCF(), indexMetaData.getIndexMaintainers().get(0).getEmptyKeyValueQualifier());
// Process existing data table rows by removing the old index row and adding the new index row
while ((result = scanner.next()) != null) {
Mutation m = mutationsToFindPreviousValue.remove(new ImmutableBytesPtr(result.getRow()));
@@ -384,7 +392,7 @@ public class PhoenixTransactionalIndexer extends BaseRegionObserver {
// to generate point delete markers for all index rows that were added. We don't have Tephra
// manage index rows in change sets because we don't want to be hit with the additional
// memory hit and do not need to do conflict detection on index rows.
- ColumnReference emptyColRef = new ColumnReference(indexMetaData.getIndexMaintainers().get(0).getDataEmptyKeyValueCF(), QueryConstants.EMPTY_COLUMN_BYTES);
+ ColumnReference emptyColRef = new ColumnReference(indexMetaData.getIndexMaintainers().get(0).getDataEmptyKeyValueCF(), indexMetaData.getIndexMaintainers().get(0).getEmptyKeyValueQualifier());
while ((result = scanner.next()) != null) {
Mutation m = mutations.remove(new ImmutableBytesPtr(result.getRow()));
// Sort by timestamp, type, cf, cq so we can process in time batches from oldest to newest
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
index c0f9707..cdd9cbc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
@@ -17,12 +17,18 @@
*/
package org.apache.phoenix.iterate;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_ACTUAL_START_ROW;
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_START_ROW_SUFFIX;
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_STOP_ROW_SUFFIX;
import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_FAILED_QUERY_COUNTER;
import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_QUERY_TIMEOUT_COUNTER;
+import static org.apache.phoenix.query.QueryConstants.ENCODED_EMPTY_COLUMN_NAME;
+import static org.apache.phoenix.schema.PTable.IndexType.LOCAL;
+import static org.apache.phoenix.schema.PTableType.INDEX;
import static org.apache.phoenix.util.ByteUtil.EMPTY_BYTE_ARRAY;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
+import static org.apache.phoenix.util.ScanUtil.setQualifierRanges;
import java.io.ByteArrayInputStream;
import java.io.DataInput;
@@ -78,20 +84,25 @@ import org.apache.phoenix.parse.HintNode;
import org.apache.phoenix.parse.HintNode.Hint;
import org.apache.phoenix.query.ConnectionQueryServices;
import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.schema.PColumnFamily;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTable.ViewType;
+import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.StaleRegionBoundaryCacheException;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.stats.GuidePostsInfo;
import org.apache.phoenix.schema.stats.GuidePostsKey;
import org.apache.phoenix.schema.stats.StatisticsUtil;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.Closeables;
+import org.apache.phoenix.util.EncodedColumnsUtil;
+import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.LogUtil;
import org.apache.phoenix.util.PrefixByteCodec;
import org.apache.phoenix.util.PrefixByteDecoder;
@@ -159,7 +170,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
return true;
}
- private static void initializeScan(QueryPlan plan, Integer perScanLimit, Integer offset, Scan scan) {
+ private static void initializeScan(QueryPlan plan, Integer perScanLimit, Integer offset, Scan scan) throws SQLException {
StatementContext context = plan.getContext();
TableRef tableRef = plan.getTableRef();
PTable table = tableRef.getTable();
@@ -210,7 +221,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
// Project empty key value unless the column family containing it has
// been projected in its entirety.
if (!familyMap.containsKey(ecf) || familyMap.get(ecf) != null) {
- scan.addColumn(ecf, QueryConstants.EMPTY_COLUMN_BYTES);
+ scan.addColumn(ecf, EncodedColumnsUtil.getEmptyKeyValueInfo(table).getFirst());
}
}
}
@@ -228,7 +239,6 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
if(offset!=null){
ScanUtil.addOffsetAttribute(scan, offset);
}
-
int cols = plan.getGroupBy().getOrderPreservingColumnCount();
if (cols > 0 && keyOnlyFilter &&
!plan.getStatement().getHint().hasHint(HintNode.Hint.RANGE_SCAN) &&
@@ -243,13 +253,86 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
ScanUtil.andFilterAtEnd(scan, new PageFilter(plan.getLimit()));
}
}
-
+ // When analyzing the table, there is no look up for key values being done.
+ // So there is no point setting the range.
+ if (setQualifierRanges(table) && !ScanUtil.isAnalyzeTable(scan)) {
+ Pair<Integer, Integer> range = getEncodedQualifierRange(scan, context);
+ if (range != null) {
+ scan.setAttribute(BaseScannerRegionObserver.MIN_QUALIFIER, getEncodedColumnQualifier(range.getFirst()));
+ scan.setAttribute(BaseScannerRegionObserver.MAX_QUALIFIER, getEncodedColumnQualifier(range.getSecond()));
+ }
+ }
if (optimizeProjection) {
optimizeProjection(context, scan, table, statement);
}
}
}
+
+ private static Pair<Integer, Integer> getEncodedQualifierRange(Scan scan, StatementContext context)
+ throws SQLException {
+ PTable table = context.getCurrentTable().getTable();
+ StorageScheme storageScheme = table.getStorageScheme();
+ checkArgument(storageScheme == StorageScheme.ENCODED_COLUMN_NAMES,
+ "Method should only be used for tables using encoded column names");
+ Pair<Integer, Integer> minMaxQualifiers = new Pair<>();
+ for (Pair<byte[], byte[]> whereCol : context.getWhereConditionColumns()) {
+ byte[] cq = whereCol.getSecond();
+ if (cq != null) {
+ int qualifier = getEncodedColumnQualifier(cq);
+ determineQualifierRange(qualifier, minMaxQualifiers);
+ }
+ }
+ Map<byte[], NavigableSet<byte[]>> familyMap = scan.getFamilyMap();
+
+ Map<String, Pair<Integer, Integer>> qualifierRanges = SchemaUtil.getQualifierRanges(table);
+ for (Entry<byte[], NavigableSet<byte[]>> entry : familyMap.entrySet()) {
+ if (entry.getValue() != null) {
+ for (byte[] cq : entry.getValue()) {
+ if (cq != null) {
+ int qualifier = getEncodedColumnQualifier(cq);
+ determineQualifierRange(qualifier, minMaxQualifiers);
+ }
+ }
+ } else {
+ /*
+ * All the columns of the column family are being projected. So we will need to
+ * consider all the columns in the column family to determine the min-max range.
+ */
+ String family = Bytes.toString(entry.getKey());
+ if (table.getType() == INDEX && table.getIndexType() == LOCAL && !IndexUtil.isLocalIndexFamily(family)) {
+ //TODO: samarth confirm with James why do we need this hack here :(
+ family = IndexUtil.getLocalIndexColumnFamily(family);
+ }
+ Pair<Integer, Integer> range = qualifierRanges.get(family);
+ determineQualifierRange(range.getFirst(), minMaxQualifiers);
+ determineQualifierRange(range.getSecond(), minMaxQualifiers);
+ }
+ }
+ if (minMaxQualifiers.getFirst() == null) {
+ return null;
+ }
+ return minMaxQualifiers;
+ }
+ /**
+ *
+ * @param cq
+ * @param minMaxQualifiers
+ * @return true if the empty column was projected
+ */
+ private static void determineQualifierRange(Integer qualifier, Pair<Integer, Integer> minMaxQualifiers) {
+ if (minMaxQualifiers.getFirst() == null) {
+ minMaxQualifiers.setFirst(qualifier);
+ minMaxQualifiers.setSecond(qualifier);
+ } else {
+ if (minMaxQualifiers.getFirst() > qualifier) {
+ minMaxQualifiers.setFirst(qualifier);
+ } else if (minMaxQualifiers.getSecond() < qualifier) {
+ minMaxQualifiers.setSecond(qualifier);
+ }
+ }
+ }
+
private static void optimizeProjection(StatementContext context, Scan scan, PTable table, FilterableStatement statement) {
Map<byte[], NavigableSet<byte[]>> familyMap = scan.getFamilyMap();
// columnsTracker contain cf -> qualifiers which should get returned.
@@ -346,7 +429,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
// the ExplicitColumnTracker not to be used, though.
if (!statement.isAggregate() && filteredColumnNotInProjection) {
ScanUtil.andFilterAtEnd(scan, new ColumnProjectionFilter(SchemaUtil.getEmptyColumnFamily(table),
- columnsTracker, conditionOnlyCfs));
+ columnsTracker, conditionOnlyCfs, EncodedColumnsUtil.usesEncodedColumnNames(table.getStorageScheme())));
}
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/iterate/LookAheadResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/LookAheadResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/LookAheadResultIterator.java
index 3293f65..1e5f09e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/LookAheadResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/LookAheadResultIterator.java
@@ -49,7 +49,7 @@ abstract public class LookAheadResultIterator implements PeekingResultIterator {
};
}
- private final static Tuple UNINITIALIZED = new ResultTuple();
+ private final static Tuple UNINITIALIZED = ResultTuple.EMPTY_TUPLE;
private Tuple next = UNINITIALIZED;
abstract protected Tuple advance() throws SQLException;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/iterate/MappedByteBufferQueue.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/MappedByteBufferQueue.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/MappedByteBufferQueue.java
index 8ada952..135ab26 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/MappedByteBufferQueue.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/MappedByteBufferQueue.java
@@ -180,6 +180,7 @@ public abstract class MappedByteBufferQueue<T> extends AbstractQueue<T> {
return this.index;
}
+ @Override
public int size() {
if (flushBuffer)
return flushedCount;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java
index 8dcb2e8..e4c52c0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java
@@ -32,6 +32,7 @@ import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.OrderByExpression;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.util.ServerUtil;
import org.apache.phoenix.util.SizedUtil;
import com.google.common.base.Function;
@@ -264,7 +265,7 @@ public class OrderedResultIterator implements PeekingResultIterator {
}
this.byteSize = queueEntries.getByteSize();
} catch (IOException e) {
- throw new SQLException("", e);
+ ServerUtil.createIOException(e.getMessage(), e);
} finally {
delegate.close();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
index 88e141a..816b78c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
@@ -24,16 +24,24 @@ import java.util.List;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.regionserver.RegionScanner;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.schema.tuple.EncodedColumnQualiferCellsList;
import org.apache.phoenix.schema.tuple.MultiKeyValueTuple;
+import org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple;
import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.util.ScanUtil;
import org.apache.phoenix.util.ServerUtil;
public class RegionScannerResultIterator extends BaseResultIterator {
private final RegionScanner scanner;
+ private final Pair<Integer, Integer> minMaxQualifiers;
+ private final boolean useQualifierAsIndex;
- public RegionScannerResultIterator(RegionScanner scanner) {
+ public RegionScannerResultIterator(RegionScanner scanner, Pair<Integer, Integer> minMaxQualifiers) {
this.scanner = scanner;
+ this.useQualifierAsIndex = ScanUtil.useQualifierAsIndex(minMaxQualifiers);
+ this.minMaxQualifiers = minMaxQualifiers;
}
@Override
@@ -43,7 +51,7 @@ public class RegionScannerResultIterator extends BaseResultIterator {
synchronized (scanner) {
try {
// TODO: size
- List<Cell> results = new ArrayList<Cell>();
+ List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond()) : new ArrayList<Cell>();
// Results are potentially returned even when the return value of s.next is false
// since this is an indication of whether or not there are more values after the
// ones returned
@@ -53,7 +61,7 @@ public class RegionScannerResultIterator extends BaseResultIterator {
}
// We instantiate a new tuple because in all cases currently we hang on to it
// (i.e. to compute and hold onto the TopN).
- MultiKeyValueTuple tuple = new MultiKeyValueTuple();
+ Tuple tuple = useQualifierAsIndex ? new PositionBasedMultiKeyValueTuple() : new MultiKeyValueTuple();
tuple.setKeyValues(results);
return tuple;
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 b4f2adc..bc81447 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
@@ -205,7 +205,7 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData {
public static final byte[] BASE_COLUMN_COUNT_BYTES = Bytes.toBytes(BASE_COLUMN_COUNT);
public static final String IS_ROW_TIMESTAMP = "IS_ROW_TIMESTAMP";
public static final byte[] IS_ROW_TIMESTAMP_BYTES = Bytes.toBytes(IS_ROW_TIMESTAMP);
-
+
public static final String TABLE_FAMILY = QueryConstants.DEFAULT_COLUMN_FAMILY;
public static final byte[] TABLE_FAMILY_BYTES = QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
@@ -320,6 +320,13 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData {
/** Version below which we fall back on the generic KeyValueBuilder */
public static final int CLIENT_KEY_VALUE_BUILDER_THRESHOLD = VersionUtil.encodeVersion("0", "94", "14");
+ public static final String STORAGE_SCHEME = "STORAGE_SCHEME";
+ public static final byte[] STORAGE_SCHEME_BYTES = Bytes.toBytes(STORAGE_SCHEME);
+ public static final String ENCODED_COLUMN_QUALIFIER = "COLUMN_QUALIFIER";
+ public static final byte[] ENCODED_COLUMN_QUALIFIER_BYTES = Bytes.toBytes(ENCODED_COLUMN_QUALIFIER);
+ public static final String COLUMN_QUALIFIER_COUNTER = "QUALIFIER_COUNTER";
+ public static final byte[] COLUMN_QUALIFIER_COUNTER_BYTES = Bytes.toBytes(COLUMN_QUALIFIER_COUNTER);
+
PhoenixDatabaseMetaData(PhoenixConnection connection) throws SQLException {
this.emptyResultSet = new PhoenixResultSet(ResultIterator.EMPTY_ITERATOR, RowProjector.EMPTY_PROJECTOR, new StatementContext(new PhoenixStatement(connection), false));
this.connection = connection;
@@ -593,9 +600,8 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData {
newCells.addAll(cells);
newCells.add(kv);
Collections.sort(newCells, KeyValue.COMPARATOR);
- resultTuple.setResult(Result.create(newCells));
+ tuple = new ResultTuple(Result.create(newCells));
}
-
return tuple;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
index 47c17ae..3ca48a1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
@@ -107,7 +107,7 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable {
private final static String STRING_FALSE = "0";
private final static BigDecimal BIG_DECIMAL_FALSE = BigDecimal.valueOf(0);
private final static Integer INTEGER_FALSE = Integer.valueOf(0);
- private final static Tuple BEFORE_FIRST = new ResultTuple();
+ private final static Tuple BEFORE_FIRST = ResultTuple.EMPTY_TUPLE;
private final ResultIterator scanner;
private final RowProjector rowProjector;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheFactory.java
index 908a117..2d7550a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheFactory.java
@@ -122,6 +122,7 @@ public class HashCacheFactory implements ServerCacheFactory {
int resultSize = (int)Bytes.readVLong(hashCacheByteArray, offset);
offset += WritableUtils.decodeVIntSize(hashCacheByteArray[offset]);
ImmutableBytesWritable value = new ImmutableBytesWritable(hashCacheByteArray,offset,resultSize);
+ //TODO: samarth make joins work with position look up.
Tuple result = new ResultTuple(ResultUtil.toResult(value));
ImmutableBytesPtr key = TupleUtil.getConcatenatedValue(result, onExpressions);
List<Tuple> tuples = hashCacheMap.get(key);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
index b12326a..a6a57c7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
@@ -49,6 +49,7 @@ import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.util.ColumnInfo;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -208,7 +209,7 @@ public abstract class FormatToBytesWritableMapper<RECORD> extends Mapper<LongWri
not care about it
*/
private void initColumnIndexes() throws SQLException {
- columnIndexes = new TreeMap(Bytes.BYTES_COMPARATOR);
+ columnIndexes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
int columnIndex = 0;
for(int index = 0; index < logicalNames.size(); index++) {
PTable table = PhoenixRuntime.getTable(conn, logicalNames.get(index));
@@ -216,18 +217,23 @@ public abstract class FormatToBytesWritableMapper<RECORD> extends Mapper<LongWri
for (int i = 0; i < cls.size(); i++) {
PColumn c = cls.get(i);
byte[] family = new byte[0];
- if (c.getFamilyName() != null) // Skip PK column
+ byte[] cq;
+ if (!SchemaUtil.isPKColumn(c)) {
family = c.getFamilyName().getBytes();
- byte[] name = c.getName().getBytes();
- byte[] cfn = Bytes.add(family, QueryConstants.NAMESPACE_SEPARATOR_BYTES, name);
+ cq = EncodedColumnsUtil.getColumnQualifier(c, table);
+ } else {
+ // TODO: samarth verify if this is the right thing to do here.
+ cq = c.getName().getBytes();
+ }
+ byte[] cfn = Bytes.add(family, QueryConstants.NAMESPACE_SEPARATOR_BYTES, cq);
if (!columnIndexes.containsKey(cfn)) {
columnIndexes.put(cfn, new Integer(columnIndex));
columnIndex++;
}
}
byte[] emptyColumnFamily = SchemaUtil.getEmptyColumnFamily(table);
- byte[] cfn = Bytes.add(emptyColumnFamily, QueryConstants.NAMESPACE_SEPARATOR_BYTES,
- QueryConstants.EMPTY_COLUMN_BYTES);
+ byte[] emptyKeyValue = EncodedColumnsUtil.getEmptyKeyValueInfo(table).getFirst();
+ byte[] cfn = Bytes.add(emptyColumnFamily, QueryConstants.NAMESPACE_SEPARATOR_BYTES, emptyKeyValue);
columnIndexes.put(cfn, new Integer(columnIndex));
columnIndex++;
}
@@ -243,9 +249,9 @@ public abstract class FormatToBytesWritableMapper<RECORD> extends Mapper<LongWri
private int findIndex(Cell cell) throws IOException {
byte[] familyName = Bytes.copy(cell.getFamilyArray(), cell.getFamilyOffset(),
cell.getFamilyLength());
- byte[] name = Bytes.copy(cell.getQualifierArray(), cell.getQualifierOffset(),
+ byte[] cq = Bytes.copy(cell.getQualifierArray(), cell.getQualifierOffset(),
cell.getQualifierLength());
- byte[] cfn = Bytes.add(familyName, QueryConstants.NAMESPACE_SEPARATOR_BYTES, name);
+ byte[] cfn = Bytes.add(familyName, QueryConstants.NAMESPACE_SEPARATOR_BYTES, cq);
if(columnIndexes.containsKey(cfn)) {
return columnIndexes.get(cfn);
}
[04/42] phoenix git commit: Memory Leak in RenewLeaseTask
Posted by td...@apache.org.
Memory Leak in RenewLeaseTask
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/96b6554f
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/96b6554f
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/96b6554f
Branch: refs/heads/encodecolumns2
Commit: 96b6554f1572d2134fcae639e0c15c99590d7ab1
Parents: 1704545
Author: Samarth <sa...@salesforce.com>
Authored: Mon Dec 12 12:01:14 2016 -0800
Committer: Samarth <sa...@salesforce.com>
Committed: Mon Dec 12 12:01:14 2016 -0800
----------------------------------------------------------------------
.../query/ConnectionQueryServicesImpl.java | 33 +++++++++++++++-----
1 file changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/96b6554f/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 1203c81..9bc088d 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
@@ -3867,6 +3867,12 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
private void waitForRandomDuration() throws InterruptedException {
new CountDownLatch(1).await(random.nextInt(MAX_WAIT_TIME), MILLISECONDS);
}
+
+ private static class InternalRenewLeaseTaskException extends Exception {
+ public InternalRenewLeaseTaskException(String msg) {
+ super(msg);
+ }
+ }
@Override
public void run() {
@@ -3888,7 +3894,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
WeakReference<PhoenixConnection> connRef =
connectionsQueue.poll(1, TimeUnit.MILLISECONDS);
if (connRef == null) {
- throw new IllegalStateException(
+ throw new InternalRenewLeaseTaskException(
"Connection ref found to be null. This is a bug. Some other thread removed items from the connection queue.");
}
PhoenixConnection conn = connRef.get();
@@ -3907,7 +3913,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
WeakReference<TableResultIterator> ref =
scannerQueue.poll(1, TimeUnit.MILLISECONDS);
if (ref == null) {
- throw new IllegalStateException(
+ throw new InternalRenewLeaseTaskException(
"TableResulIterator ref found to be null. This is a bug. Some other thread removed items from the scanner queue.");
}
TableResultIterator scanningItr = ref.get();
@@ -3944,13 +3950,24 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
numConnections--;
}
- } catch (InterruptedException e1) {
+ } catch (InternalRenewLeaseTaskException e) {
+ logger.error("Exception thrown when renewing lease. Draining the queue of scanners ", e);
+ // clear up the queue since the task is about to be unscheduled.
+ connectionsQueue.clear();
+ // throw an exception since we want the task execution to be suppressed because we just encountered an
+ // exception that happened because of a bug.
+ throw new RuntimeException(e);
+ } catch (InterruptedException e) {
Thread.currentThread().interrupt(); // restore the interrupt status
- logger.warn("Thread interrupted when renewing lease ", e1);
- throw new RuntimeException(e1);
- } catch (Exception e2) {
- logger.warn("Exception thrown when renewing lease ", e2);
- throw new RuntimeException(e2);
+ logger.error("Thread interrupted when renewing lease.", e);
+ } catch (Exception e) {
+ logger.error("Exception thrown when renewing lease ", e);
+ // don't drain the queue and swallow the exception in this case since we don't want the task
+ // execution to be suppressed because renewing lease of a scanner failed.
+ } catch (Throwable e) {
+ logger.error("Exception thrown when renewing lease. Draining the queue of scanners ", e);
+ connectionsQueue.clear(); // clear up the queue since the task is about to be unscheduled.
+ throw new RuntimeException(e);
}
}
}
[33/42] phoenix git commit: Replace
StorageScheme.NON_ENCODED_QUALIFIER with
QualifierEncodingScheme.NON_ENCODED_QUALIFIERS
Posted by td...@apache.org.
Replace StorageScheme.NON_ENCODED_QUALIFIER with QualifierEncodingScheme.NON_ENCODED_QUALIFIERS
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/3426262a
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3426262a
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3426262a
Branch: refs/heads/encodecolumns2
Commit: 3426262afb720ab0a42b0db35c501665c7cfd9c4
Parents: 8a1de1c
Author: Samarth <sa...@salesforce.com>
Authored: Tue Nov 22 19:11:36 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../apache/phoenix/compile/FromCompiler.java | 2 +-
.../apache/phoenix/compile/JoinCompiler.java | 2 +-
.../compile/PostLocalIndexDDLCompiler.java | 2 +-
.../compile/TupleProjectionCompiler.java | 7 +--
.../apache/phoenix/compile/UnionCompiler.java | 2 +-
.../apache/phoenix/compile/WhereCompiler.java | 2 +-
.../GroupedAggregateRegionObserver.java | 12 ++---
.../coprocessor/MetaDataEndpointImpl.java | 6 ++-
.../phoenix/coprocessor/ScanRegionObserver.java | 7 +--
.../UngroupedAggregateRegionObserver.java | 6 +--
.../apache/phoenix/execute/BaseQueryPlan.java | 2 +-
.../apache/phoenix/index/IndexMaintainer.java | 10 +---
.../phoenix/iterate/BaseResultIterators.java | 11 ++---
.../iterate/RegionScannerResultIterator.java | 4 +-
.../org/apache/phoenix/schema/ColumnRef.java | 6 +--
.../apache/phoenix/schema/MetaDataClient.java | 51 +++++++++-----------
.../java/org/apache/phoenix/schema/PTable.java | 8 ++-
.../org/apache/phoenix/schema/PTableImpl.java | 12 ++---
.../apache/phoenix/util/EncodedColumnsUtil.java | 41 ++++++++++++++--
.../java/org/apache/phoenix/util/IndexUtil.java | 3 +-
.../java/org/apache/phoenix/util/ScanUtil.java | 29 -----------
.../org/apache/phoenix/util/SchemaUtil.java | 4 +-
.../phoenix/execute/CorrelatePlanTest.java | 2 +-
.../execute/LiteralResultIteratorPlanTest.java | 2 +-
24 files changed, 109 insertions(+), 124 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
index d4ccfff..8d00996 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
@@ -788,7 +788,7 @@ public class FromCompiler {
MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM, null, null, columns, null, null,
Collections.<PTable> emptyList(), false, Collections.<PName> emptyList(), null, null, false, false,
false, null, null, null, false, false, 0, 0L, SchemaUtil
- .isNamespaceMappingEnabled(PTableType.SUBQUERY, connection.getQueryServices().getProps()), null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
+ .isNamespaceMappingEnabled(PTableType.SUBQUERY, connection.getQueryServices().getProps()), null, false, StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
String alias = subselectNode.getAlias();
TableRef tableRef = new TableRef(alias, t, MetaDataProtocol.MIN_TABLE_TIMESTAMP, false);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index bc2c7df..b72c550 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -1313,7 +1313,7 @@ public class JoinCompiler {
left.isMultiTenant(), left.getStoreNulls(), left.getViewType(), left.getViewIndexId(),
left.getIndexType(), left.rowKeyOrderOptimizable(), left.isTransactional(),
left.getUpdateCacheFrequency(), left.getIndexDisableTimestamp(), left.isNamespaceMapped(),
- left.getAutoPartitionSeqName(), left.isAppendOnlySchema(), StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
+ left.getAutoPartitionSeqName(), left.isAppendOnlySchema(), StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
index d6fd6ff..8677dc2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
@@ -83,7 +83,7 @@ public class PostLocalIndexDDLCompiler {
// However, in this case, we need to project all of the data columns that contribute to the index.
IndexMaintainer indexMaintainer = index.getIndexMaintainer(dataTable, connection);
for (ColumnReference columnRef : indexMaintainer.getAllColumns()) {
- if (index.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ if (index.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY) {
scan.addFamily(columnRef.getFamily());
} else {
scan.addColumn(columnRef.getFamily(), columnRef.getQualifier());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
index 79e2971..6663c93 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
@@ -46,8 +46,6 @@ import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTable.IndexType;
-import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
-import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.ProjectedColumn;
@@ -181,9 +179,8 @@ public class TupleProjectionCompiler {
position++, sourceColumn.isNullable(), sourceColumnRef);
projectedColumns.add(column);
}
- StorageScheme storageScheme = table.getStorageScheme();
EncodedCQCounter cqCounter = EncodedCQCounter.NULL_COUNTER;
- if (storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES) {
+ if (EncodedColumnsUtil.usesEncodedColumnNames(table)) {
cqCounter = EncodedCQCounter.copy(table.getEncodedCQCounter());
}
@@ -193,7 +190,7 @@ public class TupleProjectionCompiler {
Collections.<PTable> emptyList(), table.isImmutableRows(), Collections.<PName> emptyList(), null, null,
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(),
table.getViewIndexId(), null, table.rowKeyOrderOptimizable(), table.isTransactional(),
- table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), storageScheme, table.getEncodingScheme(), cqCounter);
+ table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), cqCounter);
}
// For extracting column references from single select statement
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
index 7f2fbb3..013169d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
@@ -100,7 +100,7 @@ public class UnionCompiler {
null, null, projectedColumns, null, null, null, true, null, null, null, true,
true, true, null, null, null, false, false, 0, 0L,
SchemaUtil.isNamespaceMappingEnabled(PTableType.SUBQUERY,
- statement.getConnection().getQueryServices().getProps()), null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
+ statement.getConnection().getQueryServices().getProps()), null, false, StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
TableRef tableRef = new TableRef(null, tempTable, 0, false);
return tableRef;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index e42ec26..6bb3563 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -173,7 +173,7 @@ public class WhereCompiler {
TableRef tableRef = ref.getTableRef();
Expression newColumnExpression = ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive());
if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(ref.getColumn())) {
- byte[] cq = tableRef.getTable().getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL
+ byte[] cq = tableRef.getTable().getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY
? ref.getColumn().getFamilyName().getBytes() : EncodedColumnsUtil.getColumnQualifier(ref.getColumn(), tableRef.getTable());
// track the where condition columns. Later we need to ensure the Scan in HRS scans these column CFs
context.addWhereCoditionColumn(ref.getColumn().getFamilyName().getBytes(), cq);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
index 66cd288..793386d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
@@ -24,7 +24,6 @@ import static org.apache.phoenix.query.QueryServices.GROUPBY_ESTIMATED_DISTINCT_
import static org.apache.phoenix.query.QueryServices.GROUPBY_SPILLABLE_ATTRIB;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_GROUPBY_ESTIMATED_DISTINCT_VALUES;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_GROUPBY_SPILLABLE;
-import static org.apache.phoenix.util.ScanUtil.getMinMaxQualifiersFromScan;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -70,6 +69,7 @@ import org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.util.Closeables;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.KeyValueUtil;
import org.apache.phoenix.util.LogUtil;
@@ -136,7 +136,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
final TupleProjector p = TupleProjector.deserializeProjectorFromScan(scan);
final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan);
- boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(ScanUtil.getMinMaxQualifiersFromScan(scan));
+ boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan));
if (ScanUtil.isLocalIndex(scan) || (j == null && p != null)) {
if (dataColumns != null) {
tupleProjector = IndexUtil.getTupleProjector(scan, dataColumns);
@@ -383,8 +383,8 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
estDistVals = Math.max(MIN_DISTINCT_VALUES,
(int) (Bytes.toInt(estDistValsBytes) * 1.5f));
}
- Pair<Integer, Integer> minMaxQualifiers = getMinMaxQualifiersFromScan(scan);
- boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(ScanUtil.getMinMaxQualifiersFromScan(scan));
+ Pair<Integer, Integer> minMaxQualifiers = EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan);
+ boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan));
final boolean spillableEnabled =
conf.getBoolean(GROUPBY_SPILLABLE_ATTRIB, DEFAULT_GROUPBY_SPILLABLE);
@@ -456,8 +456,8 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
logger.debug(LogUtil.addCustomAnnotations("Grouped aggregation over ordered rows with scan " + scan + ", group by "
+ expressions + ", aggregators " + aggregators, ScanUtil.getCustomAnnotations(scan)));
}
- final Pair<Integer, Integer> minMaxQualifiers = getMinMaxQualifiersFromScan(scan);
- final boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(minMaxQualifiers);
+ final Pair<Integer, Integer> minMaxQualifiers = EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan);
+ final boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(minMaxQualifiers);
return new BaseRegionScanner(scanner) {
private long rowCount = 0;
private ImmutableBytesPtr currentKey = null;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index c4d049b..55ee8f1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -952,7 +952,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
isAppendOnlySchemaKv.getValueOffset(), isAppendOnlySchemaKv.getValueLength()));
Cell storageSchemeKv = tableKeyValues[STORAGE_SCHEME_INDEX];
//TODO: change this once we start having other values for storage schemes
- StorageScheme storageScheme = storageSchemeKv == null ? StorageScheme.NON_ENCODED_COLUMN_NAMES : StorageScheme
+ StorageScheme storageScheme = storageSchemeKv == null ? StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN : StorageScheme
.fromSerializedValue((byte)PTinyint.INSTANCE.toObject(storageSchemeKv.getValueArray(),
storageSchemeKv.getValueOffset(), storageSchemeKv.getValueLength()));
Cell encodingSchemeKv = tableKeyValues[QUALIFIER_ENCODING_SCHEME_INDEX];
@@ -965,7 +965,9 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
List<PName> physicalTables = Lists.newArrayList();
PName parentTableName = tableType == INDEX ? dataTableName : null;
PName parentSchemaName = tableType == INDEX ? schemaName : null;
- EncodedCQCounter cqCounter = (storageScheme == StorageScheme.NON_ENCODED_COLUMN_NAMES || tableType == PTableType.VIEW) ? PTable.EncodedCQCounter.NULL_COUNTER : new EncodedCQCounter();
+ EncodedCQCounter cqCounter =
+ (!EncodedColumnsUtil.usesEncodedColumnNames(encodingScheme) || tableType == PTableType.VIEW) ? PTable.EncodedCQCounter.NULL_COUNTER
+ : new EncodedCQCounter();
while (true) {
results.clear();
scanner.next(results);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
index 8a833ac..3a61493 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
@@ -61,6 +61,7 @@ import org.apache.phoenix.schema.ValueBitSet;
import org.apache.phoenix.schema.tuple.ResultTuple;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.ScanUtil;
import org.apache.phoenix.util.ServerUtil;
@@ -125,7 +126,7 @@ public class ScanRegionObserver extends BaseScannerRegionObserver {
orderByExpression.readFields(input);
orderByExpressions.add(orderByExpression);
}
- ResultIterator inner = new RegionScannerResultIterator(s, ScanUtil.getMinMaxQualifiersFromScan(scan));
+ ResultIterator inner = new RegionScannerResultIterator(s, EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan));
return new OrderedResultIterator(inner, orderByExpressions, thresholdBytes, limit >= 0 ? limit : null, null,
estimatedRowSize);
} catch (IOException e) {
@@ -220,7 +221,7 @@ public class ScanRegionObserver extends BaseScannerRegionObserver {
final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan);
//TODO: samarth make this a client side check by looking at order by and group by expressions. Then use that to set min max qualifiers. We can then make useQualifierListAsIndex
// a member variable of BaseScannerRegionObserver.
- boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(ScanUtil.getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null;
+ boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null;
innerScanner =
getWrappedScanner(c, innerScanner, arrayKVRefs, arrayFuncRefs, offset, scan,
dataColumns, tupleProjector, dataRegion, indexMaintainer, tx,
@@ -232,7 +233,7 @@ public class ScanRegionObserver extends BaseScannerRegionObserver {
}
if (scanOffset != null) {
innerScanner = getOffsetScanner(c, innerScanner,
- new OffsetResultIterator(new RegionScannerResultIterator(innerScanner, ScanUtil.getMinMaxQualifiersFromScan(scan)), scanOffset),
+ new OffsetResultIterator(new RegionScannerResultIterator(innerScanner, EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan)), scanOffset),
scan.getAttribute(QueryConstants.LAST_SCAN) != null);
}
final OrderedResultIterator iterator = deserializeFromScan(scan, innerScanner);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
index a313dd1..671b5f8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
@@ -24,7 +24,6 @@ import static org.apache.phoenix.query.QueryConstants.UNGROUPED_AGG_ROW_KEY;
import static org.apache.phoenix.query.QueryServices.MUTATE_BATCH_SIZE_ATTRIB;
import static org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker.COMPACTION_UPDATE_STATS_ROW_COUNT;
import static org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker.CONCURRENT_UPDATE_STATS_ROW_COUNT;
-import static org.apache.phoenix.util.ScanUtil.getMinMaxQualifiersFromScan;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -108,6 +107,7 @@ import org.apache.phoenix.schema.types.PDouble;
import org.apache.phoenix.schema.types.PFloat;
import org.apache.phoenix.schema.types.PLong;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.KeyValueUtil;
import org.apache.phoenix.util.LogUtil;
@@ -332,7 +332,7 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
ColumnReference[] dataColumns = IndexUtil.deserializeDataTableColumnsToJoin(scan);
final TupleProjector p = TupleProjector.deserializeProjectorFromScan(scan);
final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan);
- boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(ScanUtil.getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null;
+ boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null;
if ((localIndexScan && !isDelete && !isDescRowKeyOrderUpgrade) || (j == null && p != null)) {
if (dataColumns != null) {
tupleProjector = IndexUtil.getTupleProjector(scan, dataColumns);
@@ -381,7 +381,7 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
Aggregator[] rowAggregators = aggregators.getAggregators();
boolean hasMore;
boolean hasAny = false;
- Pair<Integer, Integer> minMaxQualifiers = getMinMaxQualifiersFromScan(scan);
+ Pair<Integer, Integer> minMaxQualifiers = EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan);
Tuple result = useQualifierAsIndex ? new PositionBasedMultiKeyValueTuple() : new MultiKeyValueTuple();
if (logger.isDebugEnabled()) {
logger.debug(LogUtil.addCustomAnnotations("Starting ungrouped coprocessor scan " + scan + " "+region.getRegionInfo(), ScanUtil.getCustomAnnotations(scan)));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index fb5af32..cbd9bd3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -431,7 +431,7 @@ public abstract class BaseQueryPlan implements QueryPlan {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
DataOutputStream output = new DataOutputStream(stream);
- boolean storeColsInSingleCell = dataTable.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
+ boolean storeColsInSingleCell = dataTable.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY;
if (storeColsInSingleCell) {
// if storeColsInSingleCell is true all columns of a given column family are stored in a single cell
scan.setAttribute(BaseScannerRegionObserver.COLUMNS_STORED_IN_SINGLE_CELL, QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/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 a876a0b..e20c994 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
@@ -397,7 +397,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
// TODO: check whether index is immutable or not. Currently it's always false so checking
// data table is with immutable rows or not.
this.immutableRows = dataTable.isImmutableRows();
- this.storeColsInSingleCell = index.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
+ this.storeColsInSingleCell = index.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY;
int indexColByteSize = 0;
ColumnResolver resolver = null;
List<ParseNode> parseNodes = new ArrayList<ParseNode>(1);
@@ -1712,12 +1712,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
}
public StorageScheme getIndexStorageScheme() {
- if (storeColsInSingleCell) {
- return StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
- }
- if (usesEncodedColumnNames) {
- return StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS;
- }
- return StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ return storeColsInSingleCell ? StorageScheme.ONE_CELL_PER_COLUMN_FAMILY : StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN;
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
index fc6e3bf..96797a9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
@@ -23,12 +23,10 @@ import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_STAR
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_STOP_ROW_SUFFIX;
import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_FAILED_QUERY_COUNTER;
import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_QUERY_TIMEOUT_COUNTER;
-import static org.apache.phoenix.query.QueryConstants.ENCODED_EMPTY_COLUMN_NAME;
import static org.apache.phoenix.schema.PTable.IndexType.LOCAL;
import static org.apache.phoenix.schema.PTableType.INDEX;
import static org.apache.phoenix.util.ByteUtil.EMPTY_BYTE_ARRAY;
import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
-import static org.apache.phoenix.util.ScanUtil.setQualifierRanges;
import java.io.ByteArrayInputStream;
import java.io.DataInput;
@@ -91,14 +89,11 @@ import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTable.ViewType;
-import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.StaleRegionBoundaryCacheException;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.stats.GuidePostsInfo;
import org.apache.phoenix.schema.stats.GuidePostsKey;
import org.apache.phoenix.schema.stats.StatisticsUtil;
-import org.apache.phoenix.schema.types.PBoolean;
-import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.Closeables;
import org.apache.phoenix.util.EncodedColumnsUtil;
@@ -255,7 +250,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
}
// When analyzing the table, there is no look up for key values being done.
// So there is no point setting the range.
- if (setQualifierRanges(table) && !ScanUtil.isAnalyzeTable(scan)) {
+ if (EncodedColumnsUtil.setQualifierRanges(table) && !ScanUtil.isAnalyzeTable(scan)) {
Pair<Integer, Integer> range = getEncodedQualifierRange(scan, context);
if (range != null) {
scan.setAttribute(BaseScannerRegionObserver.MIN_QUALIFIER, getEncodedColumnQualifier(range.getFirst()));
@@ -272,7 +267,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
throws SQLException {
PTable table = context.getCurrentTable().getTable();
StorageScheme storageScheme = table.getStorageScheme();
- checkArgument(storageScheme == StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS,
+ checkArgument(storageScheme == StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN,
"Method should only be used for tables using encoded column names");
Pair<Integer, Integer> minMaxQualifiers = new Pair<>();
for (Pair<byte[], byte[]> whereCol : context.getWhereConditionColumns()) {
@@ -429,7 +424,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
// the ExplicitColumnTracker not to be used, though.
if (!statement.isAggregate() && filteredColumnNotInProjection) {
ScanUtil.andFilterAtEnd(scan, new ColumnProjectionFilter(SchemaUtil.getEmptyColumnFamily(table),
- columnsTracker, conditionOnlyCfs, EncodedColumnsUtil.usesEncodedColumnNames(table.getStorageScheme())));
+ columnsTracker, conditionOnlyCfs, EncodedColumnsUtil.usesEncodedColumnNames(table.getEncodingScheme())));
}
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
index 816b78c..239539f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
@@ -29,7 +29,7 @@ import org.apache.phoenix.schema.tuple.EncodedColumnQualiferCellsList;
import org.apache.phoenix.schema.tuple.MultiKeyValueTuple;
import org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple;
import org.apache.phoenix.schema.tuple.Tuple;
-import org.apache.phoenix.util.ScanUtil;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.ServerUtil;
@@ -40,7 +40,7 @@ public class RegionScannerResultIterator extends BaseResultIterator {
public RegionScannerResultIterator(RegionScanner scanner, Pair<Integer, Integer> minMaxQualifiers) {
this.scanner = scanner;
- this.useQualifierAsIndex = ScanUtil.useQualifierAsIndex(minMaxQualifiers);
+ this.useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(minMaxQualifiers);
this.minMaxQualifiers = minMaxQualifiers;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
index 88e7d77..256575c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
@@ -146,10 +146,10 @@ public class ColumnRef {
}
}
- if (table.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
- return new ArrayColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table.getStorageScheme()));
+ if (table.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY) {
+ return new ArrayColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table.getEncodingScheme()));
}
- return new KeyValueColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table.getStorageScheme()));
+ return new KeyValueColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table.getEncodingScheme()));
}
public ColumnRef cloneAtTimestamp(long timestamp) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/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 7725877..d3b9596 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
@@ -93,6 +93,10 @@ import static org.apache.phoenix.query.QueryServices.DROP_METADATA_ATTRIB;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_DROP_METADATA;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_RUN_UPDATE_STATS_ASYNC;
import static org.apache.phoenix.schema.PTable.EncodedCQCounter.NULL_COUNTER;
+import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS;
+import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
+import static org.apache.phoenix.schema.PTable.StorageScheme.ONE_CELL_PER_COLUMN_FAMILY;
+import static org.apache.phoenix.schema.PTable.StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN;
import static org.apache.phoenix.schema.PTable.ViewType.MAPPED;
import static org.apache.phoenix.schema.PTableType.TABLE;
import static org.apache.phoenix.schema.PTableType.VIEW;
@@ -2028,19 +2032,18 @@ public class MetaDataClient {
}
int pkPositionOffset = pkColumns.size();
int position = positionOffset;
- StorageScheme storageScheme = StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ StorageScheme storageScheme = ONE_CELL_PER_KEYVALUE_COLUMN;
+ QualifierEncodingScheme encodingScheme = NON_ENCODED_QUALIFIERS;
EncodedCQCounter cqCounter = NULL_COUNTER;
PTable viewPhysicalTable = null;
- if (SchemaUtil.isSystemTable(Bytes.toBytes(SchemaUtil.getTableName(schemaName, tableName)))) {
- // System tables have hard-coded column qualifiers. So we can't use column encoding for them.
- storageScheme = StorageScheme.NON_ENCODED_COLUMN_NAMES;
- } else if (tableType == PTableType.VIEW) {
+ if (tableType == PTableType.VIEW) {
/*
* We can't control what column qualifiers are used in HTable mapped to Phoenix views. So we are not
* able to encode column names.
*/
if (viewType == MAPPED) {
- storageScheme = StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ storageScheme = ONE_CELL_PER_KEYVALUE_COLUMN;
+ encodingScheme = FOUR_BYTE_QUALIFIERS;
} else {
/*
* For regular phoenix views, use the storage scheme of the physical table since they all share the
@@ -2049,11 +2052,14 @@ public class MetaDataClient {
*/
viewPhysicalTable = PhoenixRuntime.getTable(connection, physicalNames.get(0).getString());
storageScheme = viewPhysicalTable.getStorageScheme();
+ encodingScheme = viewPhysicalTable.getEncodingScheme();
if (EncodedColumnsUtil.usesEncodedColumnNames(viewPhysicalTable)) {
cqCounter = viewPhysicalTable.getEncodedCQCounter();
}
}
- } else {
+ }
+ // System tables have hard-coded column qualifiers. So we can't use column encoding for them.
+ else if (!SchemaUtil.isSystemTable(Bytes.toBytes(SchemaUtil.getTableName(schemaName, tableName)))) {
/*
* New indexes on existing tables can have encoded column names. But unfortunately, due to backward
* compatibility reasons, we aren't able to change IndexMaintainer and the state that is serialized in
@@ -2071,32 +2077,21 @@ public class MetaDataClient {
* in the client cache. If the phoenix table already doesn't exist then the non-encoded column qualifier scheme works
* because we cannot control the column qualifiers that were used when populating the hbase table.
*/
- byte[] tableNameBytes = SchemaUtil.getTableNameAsBytes(schemaName, tableName);
- boolean tableExists = true;
- try {
- connection.getQueryServices().getTableDescriptor(tableNameBytes);
- } catch (org.apache.phoenix.schema.TableNotFoundException e) {
- tableExists = false;
- }
-
if (parent != null) {
storageScheme = parent.getStorageScheme();
- } else if (tableExists) {
- storageScheme = StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ encodingScheme = parent.getEncodingScheme();
} else if (isImmutableRows) {
- storageScheme = StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
+ storageScheme = ONE_CELL_PER_COLUMN_FAMILY;
+ encodingScheme = FOUR_BYTE_QUALIFIERS;
// since we are storing all columns of a column family in a single key value we can't use deletes to store nulls
storeNulls = true;
} else {
- storageScheme = StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS;
+ storageScheme = ONE_CELL_PER_KEYVALUE_COLUMN;
+ encodingScheme = FOUR_BYTE_QUALIFIERS;
}
- cqCounter = storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES ? new EncodedCQCounter() : NULL_COUNTER;
+ cqCounter = encodingScheme != NON_ENCODED_QUALIFIERS ? new EncodedCQCounter() : NULL_COUNTER;
}
- //FIXME: samarth change this once we start having qualifier encoding scheme options
- QualifierEncodingScheme encodingScheme =
- storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES ? QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS
- : QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
Map<String, Integer> changedCqCounters = new HashMap<>(colDefs.size());
for (ColumnDef colDef : colDefs) {
rowTimeStampColumnAlreadyFound = checkAndValidateRowTimestampCol(colDef, pkConstraint, rowTimeStampColumnAlreadyFound, tableType);
@@ -2121,7 +2116,7 @@ public class MetaDataClient {
boolean isPkColumn = isPkColumn(pkConstraint, colDef, columnDefName);
String cqCounterFamily = null;
if (!isPkColumn) {
- if (storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ if (storageScheme == ONE_CELL_PER_COLUMN_FAMILY && encodingScheme != NON_ENCODED_QUALIFIERS) {
// For this scheme we track column qualifier counters at the column family level.
cqCounterFamily = colDefFamily != null ? colDefFamily : (defaultFamilyName != null ? defaultFamilyName : DEFAULT_COLUMN_FAMILY);
} else {
@@ -2259,12 +2254,12 @@ public class MetaDataClient {
Collections.<PTable>emptyList(), isImmutableRows,
Collections.<PName>emptyList(), defaultFamilyName == null ? null :
PNameFactory.newName(defaultFamilyName), null,
- Boolean.TRUE.equals(disableWAL), false, false, null, null, indexType, true, false, 0, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
+ Boolean.TRUE.equals(disableWAL), false, false, null, null, indexType, true, false, 0, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, ONE_CELL_PER_KEYVALUE_COLUMN, NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
connection.addTable(table, MetaDataProtocol.MIN_TABLE_TIMESTAMP);
}
// Update column qualifier counters
- if (EncodedColumnsUtil.usesEncodedColumnNames(storageScheme)) {
+ if (EncodedColumnsUtil.usesEncodedColumnNames(encodingScheme)) {
// Store the encoded column counter for phoenix entities that have their own hbase
// tables i.e. base tables and indexes.
String schemaNameToUse = tableType == VIEW ? viewPhysicalTable.getSchemaName().getString() : schemaName;
@@ -3159,7 +3154,7 @@ public class MetaDataClient {
if (table.getType() == PTableType.INDEX && table.getIndexType() == IndexType.LOCAL) {
defaultColumnFamily = QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX + defaultColumnFamily;
}
- if (storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ if (storageScheme == ONE_CELL_PER_COLUMN_FAMILY) {
familyName = colDefFamily != null ? colDefFamily : defaultColumnFamily;
} else {
familyName = defaultColumnFamily;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
index afe664b..b9565a1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
@@ -164,14 +164,12 @@ public interface PTable extends PMetaDataEntity {
}
public enum StorageScheme {
- COLUMNS_STORED_IN_INDIVIDUAL_CELLS((byte)1),
- NON_ENCODED_COLUMN_NAMES((byte)2),//TODO: samarth don't need this as storage scheme. Instead make it an encoding scheme
- COLUMNS_STORED_IN_SINGLE_CELL((byte)3);
+ ONE_CELL_PER_KEYVALUE_COLUMN((byte)1),
+ ONE_CELL_PER_COLUMN_FAMILY((byte)2);
private final byte[] byteValue;
private final byte serializedValue;
- private static final ByteOrder BYTE_ORDER = ByteOrder.nativeOrder();
-
+
StorageScheme(byte serializedValue) {
this.serializedValue = serializedValue;
this.byteValue = Bytes.toBytes(this.name());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/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 860163c..98c361e 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
@@ -449,7 +449,7 @@ public class PTableImpl implements PTable {
PColumn[] allColumns;
this.columnsByName = ArrayListMultimap.create(columns.size(), 1);
- this.kvColumnsByEncodedColumnNames = (EncodedColumnsUtil.usesEncodedColumnNames(storageScheme) ? ArrayListMultimap.<Pair<String, Integer>, PColumn>create(columns.size(), 1) : null);
+ this.kvColumnsByEncodedColumnNames = (EncodedColumnsUtil.usesEncodedColumnNames(qualifierEncodingScheme) ? ArrayListMultimap.<Pair<String, Integer>, PColumn>create(columns.size(), 1) : null);
int numPKColumns = 0;
if (bucketNum != null) {
// Add salt column to allColumns and pkColumns, but don't add to
@@ -558,7 +558,7 @@ public class PTableImpl implements PTable {
.orderedBy(Bytes.BYTES_COMPARATOR);
for (int i = 0; i < families.length; i++) {
Map.Entry<PName,List<PColumn>> entry = iterator.next();
- PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue(), EncodedColumnsUtil.usesEncodedColumnNames(storageScheme));
+ PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue(), EncodedColumnsUtil.usesEncodedColumnNames(qualifierEncodingScheme));
families[i] = family;
familyByString.put(family.getName().getString(), family);
familyByBytes.put(family.getName().getBytes(), family);
@@ -884,7 +884,7 @@ public class PTableImpl implements PTable {
mutations.add(deleteRow);
} else {
// store all columns for a given column family in a single cell instead of one column per cell in order to improve write performance
- if (storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ if (storageScheme == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY) {
Put put = new Put(this.key);
if (isWALDisabled()) {
put.setDurability(Durability.SKIP_WAL);
@@ -990,7 +990,7 @@ public class PTableImpl implements PTable {
removeIfPresent(unsetValues, family, qualifier);
// store all columns for a given column family in a single cell instead of one column per cell in order to improve write performance
// we don't need to do anything with unsetValues as it is only used when storeNulls is false, storeNulls is always true when storeColsInSingleCell is true
- if (storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ if (storageScheme == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY) {
columnToValueMap.put(column, ptr.get());
}
else {
@@ -1297,11 +1297,11 @@ public class PTableImpl implements PTable {
if (table.hasStorageScheme()) {
storageScheme = StorageScheme.fromSerializedValue(table.getStorageScheme().toByteArray()[0]);
}
- QualifierEncodingScheme qualifierEncodingScheme= null;
+ QualifierEncodingScheme qualifierEncodingScheme = null;
if (table.hasEncodingScheme()) {
qualifierEncodingScheme = QualifierEncodingScheme.fromSerializedValue(table.getEncodingScheme().toByteArray()[0]);
}
- EncodedCQCounter encodedColumnQualifierCounter = EncodedColumnsUtil.usesEncodedColumnNames(storageScheme) ? new EncodedCQCounter() : EncodedCQCounter.NULL_COUNTER;
+ EncodedCQCounter encodedColumnQualifierCounter = EncodedColumnsUtil.usesEncodedColumnNames(qualifierEncodingScheme) ? new EncodedCQCounter() : EncodedCQCounter.NULL_COUNTER;
if (table.getEncodedCQCountersList() != null) {
encodedColumnQualifierCounter = new EncodedCQCounter();
for (org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter cqCounterFromProto : table.getEncodedCQCountersList()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
index fee7c75..e672aa0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
@@ -22,36 +22,42 @@ import static com.google.common.base.Preconditions.checkArgument;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
public class EncodedColumnsUtil {
public static boolean usesEncodedColumnNames(PTable table) {
- return usesEncodedColumnNames(table.getStorageScheme());
+ return usesEncodedColumnNames(table.getEncodingScheme());
}
- public static boolean usesEncodedColumnNames(StorageScheme storageScheme) {
- return storageScheme != null && storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ public static boolean usesEncodedColumnNames(QualifierEncodingScheme encodingScheme) {
+ return encodingScheme != null && encodingScheme != QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
}
public static byte[] getEncodedColumnQualifier(PColumn column) {
checkArgument(!SchemaUtil.isPKColumn(column), "No column qualifiers for PK columns");
checkArgument(!column.isDynamic(), "No encoded column qualifiers for dynamic columns");
+ //TODO: samarth this would need to use encoding scheme.
return Bytes.toBytes(column.getEncodedColumnQualifier());
}
public static int getEncodedColumnQualifier(byte[] bytes, int offset, int length) {
+ //TODO: samarth this would need to use encoding scheme.
return Bytes.toInt(bytes, offset, length);
}
public static byte[] getEncodedColumnQualifier(int value) {
+ //TODO: samarth this would need to use encoding scheme.
return Bytes.toBytes(value);
}
public static int getEncodedColumnQualifier(byte[] bytes) {
+ //TODO: samarth this would need to use encoding scheme.
return Bytes.toInt(bytes);
}
@@ -60,7 +66,7 @@ public class EncodedColumnsUtil {
}
public static void setColumns(PColumn column, PTable table, Scan scan) {
- if (table.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ if (table.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY) {
// if a table storage scheme is COLUMNS_STORED_IN_SINGLE_CELL set then all columns of a column family are stored in a single cell
// (with the qualifier name being same as the family name), just project the column family here
// so that we can calculate estimatedByteSize correctly in ProjectionCompiler
@@ -103,5 +109,32 @@ public class EncodedColumnsUtil {
public static boolean hasEncodedColumnName(PColumn column){
return !SchemaUtil.isPKColumn(column) && !column.isDynamic() && column.getEncodedColumnQualifier() != null;
}
+
+ public static Pair<Integer, Integer> getMinMaxQualifiersFromScan(Scan scan) {
+ Integer minQ = null, maxQ = null;
+ byte[] minQualifier = scan.getAttribute(BaseScannerRegionObserver.MIN_QUALIFIER);
+ if (minQualifier != null) {
+ minQ = getEncodedColumnQualifier(minQualifier);
+ }
+ byte[] maxQualifier = scan.getAttribute(BaseScannerRegionObserver.MAX_QUALIFIER);
+ if (maxQualifier != null) {
+ maxQ = getEncodedColumnQualifier(maxQualifier);
+ }
+ if (minQualifier == null) {
+ return null;
+ }
+ return new Pair<>(minQ, maxQ);
+ }
+
+ public static boolean setQualifierRanges(PTable table) {
+ return table.getStorageScheme() != null
+ && table.getStorageScheme() == StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN
+ && usesEncodedColumnNames(table) && !table.isTransactional()
+ && !ScanUtil.hasDynamicColumns(table);
+ }
+
+ public static boolean useQualifierAsIndex(Pair<Integer, Integer> minMaxQualifiers) {
+ return minMaxQualifiers != null;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
index c088b25..d816e3b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
@@ -496,9 +496,8 @@ public class IndexUtil {
byte[] dataRowKey = indexMaintainer.buildDataRowKey(ptr, viewConstants);
Get get = new Get(dataRowKey);
StorageScheme storageScheme = indexMaintainer.getIndexStorageScheme();
- boolean colsStoredInSingleCell = storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
for (int i = 0; i < dataColumns.length; i++) {
- if (colsStoredInSingleCell) {
+ if (storageScheme == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY) {
get.addFamily(dataColumns[i].getFamily());
} else {
get.addColumn(dataColumns[i].getFamily(), dataColumns[i].getQualifier());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
index 787b3e8..c9e76c5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
@@ -23,7 +23,6 @@ import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.CUSTOM_AN
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_ACTUAL_START_ROW;
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_START_ROW_SUFFIX;
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_STOP_ROW_SUFFIX;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import java.io.IOException;
import java.sql.SQLException;
@@ -44,7 +43,6 @@ import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.io.TimeRange;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.io.WritableComparator;
import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
import org.apache.phoenix.compile.ScanRanges;
@@ -69,12 +67,10 @@ import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
-import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.RowKeySchema;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.ValueSchema.Field;
import org.apache.phoenix.schema.types.PDataType;
-import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PVarbinary;
import com.google.common.collect.Iterators;
@@ -900,31 +896,6 @@ public class ScanUtil {
return true;
}
- public static Pair<Integer, Integer> getMinMaxQualifiersFromScan(Scan scan) {
- Integer minQ = null, maxQ = null;
- byte[] minQualifier = scan.getAttribute(BaseScannerRegionObserver.MIN_QUALIFIER);
- if (minQualifier != null) {
- minQ = getEncodedColumnQualifier(minQualifier);
- }
- byte[] maxQualifier = scan.getAttribute(BaseScannerRegionObserver.MAX_QUALIFIER);
- if (maxQualifier != null) {
- maxQ = getEncodedColumnQualifier(maxQualifier);
- }
- if (minQualifier == null) {
- return null;
- }
- return new Pair<>(minQ, maxQ);
- }
-
- public static boolean useQualifierAsIndex(Pair<Integer, Integer> minMaxQualifiers) {
- return minMaxQualifiers != null;
- }
-
- public static boolean setQualifierRanges(PTable table) {
- return table.getStorageScheme() != null && table.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS
- && !table.isTransactional() && !hasDynamicColumns(table);
- }
-
public static boolean hasDynamicColumns(PTable table) {
for (PColumn col : table.getColumns()) {
if (col.isDynamic()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/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 f8e0cb7..6081d13 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
@@ -1096,9 +1096,9 @@ public class SchemaUtil {
}
public static Map<String, Pair<Integer, Integer>> getQualifierRanges(PTable table) {
- Preconditions.checkArgument(table.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS,
+ Preconditions.checkArgument(table.getStorageScheme() == StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN,
"Use this method only for tables with storage scheme "
- + StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS.name());
+ + StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN.name());
Map<String, Pair<Integer, Integer>> toReturn = Maps.newHashMapWithExpectedSize(table.getColumns().size());
for (PColumn column : table.getColumns()) {
if (!isPKColumn(column)) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
index 418a547..30f8970 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
@@ -261,7 +261,7 @@ public class CorrelatePlanTest {
PTableType.SUBQUERY, null, MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM,
null, null, columns, null, null, Collections.<PTable>emptyList(),
false, Collections.<PName>emptyList(), null, null, false, false, false, null,
- null, null, true, false, 0, 0L, Boolean.FALSE, null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, EncodedCQCounter.NULL_COUNTER);
+ null, null, true, false, 0, 0L, Boolean.FALSE, null, false, StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, EncodedCQCounter.NULL_COUNTER);
TableRef sourceTable = new TableRef(pTable);
List<ColumnRef> sourceColumnRefs = Lists.<ColumnRef> newArrayList();
for (PColumn column : sourceTable.getTable().getColumns()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3426262a/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
index f6ee970..0cd22ef 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
@@ -182,7 +182,7 @@ public class LiteralResultIteratorPlanTest {
PTable pTable = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME, PTableType.SUBQUERY, null,
MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM, null, null, columns, null, null,
Collections.<PTable> emptyList(), false, Collections.<PName> emptyList(), null, null, false, false,
- false, null, null, null, true, false, 0, 0L, false, null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, EncodedCQCounter.NULL_COUNTER);
+ false, null, null, null, true, false, 0, 0L, false, null, false, StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, EncodedCQCounter.NULL_COUNTER);
TableRef sourceTable = new TableRef(pTable);
List<ColumnRef> sourceColumnRefs = Lists.<ColumnRef> newArrayList();
for (PColumn column : sourceTable.getTable().getColumns()) {
[15/42] phoenix git commit: PHOENIX-3540 Fix Time data type in
Phoenix Spark integration
Posted by td...@apache.org.
PHOENIX-3540 Fix Time data type in Phoenix Spark integration
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/5706f514
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/5706f514
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/5706f514
Branch: refs/heads/encodecolumns2
Commit: 5706f514416079e9afda7c59474492a74c704473
Parents: f11d501
Author: Ankit Singhal <an...@gmail.com>
Authored: Thu Dec 22 13:18:35 2016 +0530
Committer: Ankit Singhal <an...@gmail.com>
Committed: Thu Dec 22 13:18:35 2016 +0530
----------------------------------------------------------------------
phoenix-spark/src/it/resources/globalSetup.sql | 2 ++
.../org/apache/phoenix/spark/PhoenixSparkIT.scala | 12 ++++++++++++
.../scala/org/apache/phoenix/spark/PhoenixRDD.scala | 15 ++++++++-------
3 files changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5706f514/phoenix-spark/src/it/resources/globalSetup.sql
----------------------------------------------------------------------
diff --git a/phoenix-spark/src/it/resources/globalSetup.sql b/phoenix-spark/src/it/resources/globalSetup.sql
index 852687e..72f8620 100644
--- a/phoenix-spark/src/it/resources/globalSetup.sql
+++ b/phoenix-spark/src/it/resources/globalSetup.sql
@@ -48,6 +48,8 @@ CREATE TABLE TEST_SMALL_TINY (ID BIGINT NOT NULL PRIMARY KEY, COL1 SMALLINT, COL
UPSERT INTO TEST_SMALL_TINY VALUES (1, 32767, 127)
CREATE TABLE DATE_TEST(ID BIGINT NOT NULL PRIMARY KEY, COL1 DATE)
UPSERT INTO DATE_TEST VALUES(1, CURRENT_DATE())
+CREATE TABLE TIME_TEST(ID BIGINT NOT NULL PRIMARY KEY, COL1 TIME)
+UPSERT INTO TIME_TEST VALUES(1, CURRENT_TIME())
CREATE TABLE "space" ("key" VARCHAR PRIMARY KEY, "first name" VARCHAR)
UPSERT INTO "space" VALUES ('key1', 'xyz')
CREATE TABLE "small" ("key" VARCHAR PRIMARY KEY, "first name" VARCHAR, "salary" INTEGER )
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5706f514/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkIT.scala
----------------------------------------------------------------------
diff --git a/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkIT.scala b/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkIT.scala
index 90822d4..fc8483d 100644
--- a/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkIT.scala
+++ b/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkIT.scala
@@ -620,4 +620,16 @@ class PhoenixSparkIT extends AbstractPhoenixSparkIT {
assert(Math.abs(epoch - ts) < 300000)
}
+
+ test("Can load Phoenix Time columns through DataFrame API") {
+ val sqlContext = new SQLContext(sc)
+ val df = sqlContext.read
+ .format("org.apache.phoenix.spark")
+ .options(Map("table" -> "TIME_TEST", "zkUrl" -> quorumAddress))
+ .load
+ val time = df.select("COL1").first().getTimestamp(0).getTime
+ val epoch = new Date().getTime
+ assert(Math.abs(epoch - time) < 86400000)
+ }
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5706f514/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala
----------------------------------------------------------------------
diff --git a/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala b/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala
index 505de1b..204a7ef 100644
--- a/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala
+++ b/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala
@@ -130,13 +130,14 @@ class PhoenixRDD(sc: SparkContext, table: String, columns: Seq[String],
val rowSeq = columns.map { case (name, sqlType) =>
val res = pr.resultMap(name)
- // Special handling for data types
- if(dateAsTimestamp && sqlType == 91) { // 91 is the defined type for Date
- new java.sql.Timestamp(res.asInstanceOf[java.sql.Date].getTime)
- }
- else {
- res
- }
+ // Special handling for data types
+ if (dateAsTimestamp && sqlType == 91) { // 91 is the defined type for Date
+ new java.sql.Timestamp(res.asInstanceOf[java.sql.Date].getTime)
+ } else if (sqlType == 92) { // 92 is the defined type for Time
+ new java.sql.Timestamp(res.asInstanceOf[java.sql.Time].getTime)
+ } else {
+ res
+ }
}
// Create a Spark Row from the sequence
[11/42] phoenix git commit: PHOENIX-3524 Changing the
APPEND_ONLY_SCHEMA property using an ALTER TABLE does not work
Posted by td...@apache.org.
PHOENIX-3524 Changing the APPEND_ONLY_SCHEMA property using an ALTER TABLE does not work
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/0ea97ce6
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/0ea97ce6
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/0ea97ce6
Branch: refs/heads/encodecolumns2
Commit: 0ea97ce675bbd01eef2e566aff7f5910faae4369
Parents: e202020
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Mon Dec 19 15:43:31 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Tue Dec 20 09:04:42 2016 -0800
----------------------------------------------------------------------
.../phoenix/end2end/AlterTableWithViewsIT.java | 97 +++++++++++++++-----
.../phoenix/end2end/AppendOnlySchemaIT.java | 9 +-
.../phoenix/end2end/ImmutableTablePropIT.java | 42 ++++++++-
.../coprocessor/MetaDataEndpointImpl.java | 32 +++++--
.../phoenix/exception/SQLExceptionCode.java | 2 +
.../apache/phoenix/jdbc/PhoenixConnection.java | 14 ---
.../phoenix/query/ConnectionQueryServices.java | 3 +-
.../query/ConnectionQueryServicesImpl.java | 22 +----
.../query/ConnectionlessQueryServicesImpl.java | 16 +---
.../query/DelegateConnectionQueryServices.java | 14 +--
.../apache/phoenix/query/MetaDataMutated.java | 1 -
.../apache/phoenix/schema/MetaDataClient.java | 62 ++++++++-----
.../apache/phoenix/schema/PMetaDataImpl.java | 24 -----
.../phoenix/schema/PSynchronizedMetaData.java | 17 ----
.../apache/phoenix/schema/TableProperty.java | 90 +++++++++++++++---
15 files changed, 269 insertions(+), 176 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
index 91aca4e..52dae00 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
@@ -19,7 +19,6 @@ package org.apache.phoenix.end2end;
import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE;
import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -33,7 +32,6 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Properties;
import org.apache.commons.lang.ArrayUtils;
import org.apache.hadoop.hbase.client.HTableInterface;
@@ -47,8 +45,6 @@ import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.SchemaUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -106,37 +102,52 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
try (Connection conn = DriverManager.getConnection(getUrl());
Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn ) {
String tableName = generateUniqueName();
- String viewOfTable = tableName + "_VIEW";
+ String viewOfTable1 = tableName + "_VIEW1";
+ String viewOfTable2 = tableName + "_VIEW2";
String ddlFormat = "CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ " %s ID char(1) NOT NULL,"
+ " COL1 integer NOT NULL,"
+ " COL2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
- + " ) %s";
+ + " ) UPDATE_CACHE_FREQUENCY=15 "
+ + (isMultiTenant ? ",%s" : "%s");
conn.createStatement().execute(generateDDL(ddlFormat));
- viewConn.createStatement().execute("CREATE VIEW " + viewOfTable + " ( VIEW_COL1 DECIMAL(10,2), VIEW_COL2 VARCHAR ) AS SELECT * FROM " + tableName);
+ viewConn.createStatement().execute("CREATE VIEW " + viewOfTable1 + " ( VIEW_COL1 DECIMAL(10,2), VIEW_COL2 VARCHAR ) AS SELECT * FROM " + tableName);
+ viewConn.createStatement().execute("CREATE VIEW " + viewOfTable2 + " ( VIEW_COL1 DECIMAL(10,2), VIEW_COL2 VARCHAR ) AS SELECT * FROM " + tableName);
+ viewConn.createStatement().execute("ALTER VIEW " + viewOfTable2 + " SET UPDATE_CACHE_FREQUENCY = 5");
PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
PTable table = phoenixConn.getTable(new PTableKey(null, tableName));
PName tenantId = isMultiTenant ? PNameFactory.newName("tenant1") : null;
assertFalse(table.isImmutableRows());
- assertEquals(0, table.getUpdateCacheFrequency());
- PTable viewTable = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable));
- assertFalse(viewTable.isImmutableRows());
- assertEquals(0, viewTable.getUpdateCacheFrequency());
-
- conn.createStatement().execute("ALTER TABLE " + tableName + " SET IMMUTABLE_ROWS=true, UPDATE_CACHE_FREQUENCY=123");
+ assertEquals(15, table.getUpdateCacheFrequency());
+ PTable viewTable1 = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable1));
+ assertFalse(viewTable1.isImmutableRows());
+ assertEquals(15, viewTable1.getUpdateCacheFrequency());
// query the view to force the table cache to be updated
- viewConn.createStatement().execute("SELECT * FROM "+viewOfTable);
+ viewConn.createStatement().execute("SELECT * FROM "+viewOfTable2);
+ PTable viewTable2 = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable2));
+ assertFalse(viewTable2.isImmutableRows());
+ assertEquals(5, viewTable2.getUpdateCacheFrequency());
+
+ conn.createStatement().execute("ALTER TABLE " + tableName + " SET IMMUTABLE_ROWS=true, UPDATE_CACHE_FREQUENCY=10");
+ // query the views to force the table cache to be updated
+ viewConn.createStatement().execute("SELECT * FROM "+viewOfTable1);
+ viewConn.createStatement().execute("SELECT * FROM "+viewOfTable2);
phoenixConn = conn.unwrap(PhoenixConnection.class);
table = phoenixConn.getTable(new PTableKey(null, tableName));
assertTrue(table.isImmutableRows());
- assertEquals(123, table.getUpdateCacheFrequency());
+ assertEquals(10, table.getUpdateCacheFrequency());
- viewTable = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable));
- assertTrue(viewTable.isImmutableRows());
- assertEquals(123, viewTable.getUpdateCacheFrequency());
+ viewTable1 = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable1));
+ assertTrue(viewTable1.isImmutableRows());
+ assertEquals(10, viewTable1.getUpdateCacheFrequency());
+
+ viewTable2 = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable2));
+ assertTrue(viewTable2.isImmutableRows());
+ // update cache frequency is not propagated to the view since it was altered on the view
+ assertEquals(5, viewTable2.getUpdateCacheFrequency());
}
}
@@ -731,10 +742,11 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
String viewOfTable = baseTableName + "_VIEW";
String ddl = "CREATE TABLE " + baseTableName + " (\n"
- +"ID VARCHAR(15) NOT NULL,\n"
+ +"%s ID VARCHAR(15) NOT NULL,\n"
+ + " COL1 integer NOT NULL,"
+"CREATED_DATE DATE,\n"
- +"CONSTRAINT PK PRIMARY KEY (ID))";
- conn.createStatement().execute(ddl);
+ +"CONSTRAINT PK PRIMARY KEY (%s ID, COL1)) %s";
+ conn.createStatement().execute(generateDDL(ddl));
ddl = "CREATE VIEW " + viewOfTable + " AS SELECT * FROM " + baseTableName;
viewConn.createStatement().execute(ddl);
@@ -757,7 +769,48 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW.getErrorCode(), e.getErrorCode());
}
}
-
+ }
+
+ @Test
+ public void testAlterAppendOnlySchema() throws Exception {
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn ) {
+ String baseTableName = "NONTXNTBL_" + generateUniqueName() + (isMultiTenant ? "0":"1");
+ String viewOfTable = baseTableName + "_VIEW";
+
+ String ddl = "CREATE TABLE " + baseTableName + " (\n"
+ +"%s ID VARCHAR(15) NOT NULL,\n"
+ + " COL1 integer NOT NULL,"
+ +"CREATED_DATE DATE,\n"
+ +"CONSTRAINT PK PRIMARY KEY (%s ID, COL1)) %s";
+ conn.createStatement().execute(generateDDL(ddl));
+ ddl = "CREATE VIEW " + viewOfTable + " AS SELECT * FROM " + baseTableName;
+ viewConn.createStatement().execute(ddl);
+
+ PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
+ PTable table = phoenixConn.getTable(new PTableKey(null, baseTableName));
+ PName tenantId = isMultiTenant ? PNameFactory.newName("tenant1") : null;
+ assertFalse(table.isAppendOnlySchema());
+ PTable viewTable = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable));
+ assertFalse(viewTable.isAppendOnlySchema());
+
+ try {
+ viewConn.createStatement().execute("ALTER VIEW " + viewOfTable + " SET APPEND_ONLY_SCHEMA = true");
+ fail();
+ }
+ catch(SQLException e){
+ assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW.getErrorCode(), e.getErrorCode());
+ }
+
+ conn.createStatement().execute("ALTER TABLE " + baseTableName + " SET APPEND_ONLY_SCHEMA = true");
+ viewConn.createStatement().execute("SELECT * FROM "+viewOfTable);
+
+ phoenixConn = conn.unwrap(PhoenixConnection.class);
+ table = phoenixConn.getTable(new PTableKey(null, baseTableName));
+ assertTrue(table.isAppendOnlySchema());
+ viewTable = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable));
+ assertTrue(viewTable.isAppendOnlySchema());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
index 8d40094..7ed64ff 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
@@ -133,7 +133,7 @@ public class AppendOnlySchemaIT extends ParallelStatsDisabledIT {
// if not verify exists is true one call to add column table with empty mutation list (which does not make a rpc)
// else verify no add column calls
- verify(connectionQueryServices, notExists ? times(1) : never() ).addColumn(eq(Collections.<Mutation>emptyList()), any(PTable.class), anyMap(), anySetOf(String.class));
+ verify(connectionQueryServices, notExists ? times(1) : never() ).addColumn(eq(Collections.<Mutation>emptyList()), any(PTable.class), anyMap(), anySetOf(String.class), anyListOf(PColumn.class));
// upsert one row
conn2.createStatement().execute("UPSERT INTO " + viewName + "(hostName, metricVal) VALUES('host2', 2.0)");
@@ -309,10 +309,11 @@ public class AppendOnlySchemaIT extends ParallelStatsDisabledIT {
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1))"
+ " APPEND_ONLY_SCHEMA = true, UPDATE_CACHE_FREQUENCY=1000");
conn.createStatement().execute(
- "create view IF NOT EXISTS " + viewName + " (val1 integer) AS SELECT * FROM " + tableName
- + " UPDATE_CACHE_FREQUENCY=1000");
+ "create view IF NOT EXISTS " + viewName + " (val1 integer) AS SELECT * FROM " + tableName);
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
- assertEquals(true, pconn.getTable(new PTableKey(pconn.getTenantId(), viewName)).isAppendOnlySchema());
+ PTable view = pconn.getTable(new PTableKey(pconn.getTenantId(), viewName));
+ assertEquals(true, view.isAppendOnlySchema());
+ assertEquals(1000, view.getUpdateCacheFrequency());
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/it/java/org/apache/phoenix/end2end/ImmutableTablePropIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ImmutableTablePropIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ImmutableTablePropIT.java
index 693fb81..78be892 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ImmutableTablePropIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ImmutableTablePropIT.java
@@ -18,14 +18,18 @@
package org.apache.phoenix.end2end;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.sql.Connection;
import java.sql.DriverManager;
+import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
+import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
@@ -69,13 +73,13 @@ public class ImmutableTablePropIT extends ParallelStatsDisabledIT {
String mutableDataTableFullName = SchemaUtil.getTableName("", generateUniqueName());
try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
Statement stmt = conn.createStatement();
- // create table with immutable_table property set to true
+ // create table with immutable table property set to true
String ddl = "CREATE TABLE " + immutableDataTableFullName +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string)) IMMUTABLE_ROWS=true";
stmt.execute(ddl);
- // create table with immutable_table property set to false
+ // create table with immutable table property set to false
ddl = "CREATE TABLE " + mutableDataTableFullName +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string)) IMMUTABLE_ROWS=false";
@@ -89,4 +93,38 @@ public class ImmutableTablePropIT extends ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testImmutableKeywordAndProperty() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String immutableDataTableFullName = SchemaUtil.getTableName("", generateUniqueName());
+ String mutableDataTableFullName = SchemaUtil.getTableName("", generateUniqueName());
+ try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+ Statement stmt = conn.createStatement();
+ try {
+ // create immutable table with immutable table property set to true
+ String ddl = "CREATE IMMUTABLE TABLE " + immutableDataTableFullName +
+ " (a_string varchar not null, col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string)) IMMUTABLE_ROWS=true";
+ stmt.execute(ddl);
+ fail();
+ }
+ catch (SQLException e) {
+ assertEquals(SQLExceptionCode.IMMUTABLE_TABLE_PROPERTY_INVALID.getErrorCode(), e.getErrorCode());
+ }
+
+ try {
+ // create immutable table with immutable table property set to false
+ String ddl = "CREATE IMMUTABLE TABLE " + mutableDataTableFullName +
+ " (a_string varchar not null, col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string)) IMMUTABLE_ROWS=false";
+ stmt.execute(ddl);
+ fail();
+ }
+ catch (SQLException e) {
+ assertEquals(SQLExceptionCode.IMMUTABLE_TABLE_PROPERTY_INVALID.getErrorCode(), e.getErrorCode());
+ }
+
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 9ade0f5..8afdec4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -87,6 +87,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.NavigableMap;
import java.util.Properties;
@@ -226,6 +227,7 @@ import org.slf4j.LoggerFactory;
import com.google.common.cache.Cache;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import com.google.protobuf.ByteString;
import com.google.protobuf.RpcCallback;
import com.google.protobuf.RpcController;
@@ -1899,8 +1901,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
byte[] tenantId = rowKeyMetaData[PhoenixDatabaseMetaData.TENANT_ID_INDEX];
byte[] schemaName = rowKeyMetaData[PhoenixDatabaseMetaData.SCHEMA_NAME_INDEX];
byte[] tableName = rowKeyMetaData[PhoenixDatabaseMetaData.TABLE_NAME_INDEX];
+ byte[] key = SchemaUtil.getTableKey(tenantId, schemaName, tableName);
try {
- byte[] key = SchemaUtil.getTableKey(tenantId, schemaName, tableName);
HRegion region = env.getRegion();
MetaDataMutationResult result = checkTableKeyInRegion(key, region);
if (result != null) {
@@ -1995,7 +1997,12 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
// mutateRowsWithLocks call
long currentTime = MetaDataUtil.getClientTimeStamp(tableMetadata);
// if the update mutation caused tables to be deleted just return the result which will contain the table to be deleted
- return result != null ? result : new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, currentTime, null);
+ if (result !=null) {
+ return result;
+ } else {
+ table = buildTable(key, cacheKey, region, HConstants.LATEST_TIMESTAMP);
+ return new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, currentTime, table);
+ }
} finally {
region.releaseRowLocks(locks);
}
@@ -2154,7 +2161,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
List<ImmutableBytesPtr> invalidateList, long clientTimeStamp, TableViewFinderResult childViewsResult,
HRegion region, List<RowLock> locks) throws IOException, SQLException {
List<PutWithOrdinalPosition> columnPutsForBaseTable = Lists.newArrayListWithExpectedSize(tableMetadata.size());
- List<Cell> tablePropertyCells = Lists.newArrayListWithExpectedSize(tableMetadata.size());
+ Map<TableProperty, Cell> tablePropertyCellMap = Maps.newHashMapWithExpectedSize(tableMetadata.size());
// Isolate the puts relevant to adding columns. Also figure out what kind of columns are being added.
for (Mutation m : tableMetadata) {
if (m instanceof Put) {
@@ -2178,7 +2185,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
Cell tablePropCell = CellUtil.createCell(cell.getRow(), CellUtil.cloneFamily(cell),
CellUtil.cloneQualifier(cell), cell.getTimestamp(), cell.getTypeByte(),
CellUtil.cloneValue(cell));
- tablePropertyCells.add(tablePropCell);
+ tablePropertyCellMap.put(tableProp, tablePropCell);
}
}
}
@@ -2353,12 +2360,19 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
deltaNumPkColsSoFar);
// set table properties in child view
- if (!tablePropertyCells.isEmpty()) {
+ if (!tablePropertyCellMap.isEmpty()) {
Put viewHeaderRowPut = new Put(viewKey, clientTimeStamp);
- for (Cell tablePropertyCell : tablePropertyCells) {
- viewHeaderRowPut.add(CellUtil.createCell(viewKey, CellUtil.cloneFamily(tablePropertyCell),
- CellUtil.cloneQualifier(tablePropertyCell), clientTimeStamp, tablePropertyCell.getTypeByte(),
- CellUtil.cloneValue(tablePropertyCell)));
+ for (TableProperty tableProp : TableProperty.values()) {
+ Cell tablePropertyCell = tablePropertyCellMap.get(tableProp);
+ if ( tablePropertyCell != null) {
+ // set this table property on the view if it is not mutable on a view (which means the property is always the same as the base table)
+ // or if it is mutable on a view and the property value is the same as the base table property (which means it wasn't changed on the view)
+ if (!tableProp.isMutableOnView() || tableProp.getPTableValue(view).equals(tableProp.getPTableValue(basePhysicalTable))) {
+ viewHeaderRowPut.add(CellUtil.createCell(viewKey, CellUtil.cloneFamily(tablePropertyCell),
+ CellUtil.cloneQualifier(tablePropertyCell), clientTimeStamp, tablePropertyCell.getTypeByte(),
+ CellUtil.cloneValue(tablePropertyCell)));
+ }
+ }
}
byte[] viewSequencePtr = new byte[PLong.INSTANCE.getByteSize()];
PLong.INSTANCE.getCodec().encodeLong(view.getSequenceNumber() + 1, viewSequencePtr, 0);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index 20f3974..fb4e3c3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -366,6 +366,8 @@ public enum SQLExceptionCode {
CANNOT_ALTER_IMMUTABLE_ROWS_PROPERTY(1133, "XCL33", "IMMUTABLE_ROWS property can be changed only if the table storage scheme is ONE_CELL_PER_KEYVALUE_COLUMN"),
CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW(1134, "XCL34", "Altering this table property on a view is not allowed"),
+
+ IMMUTABLE_TABLE_PROPERTY_INVALID(1135, "XCL35", "IMMUTABLE table property cannot be used with CREATE IMMUTABLE TABLE statement "),
/**
* Implementation defined class. Phoenix internal error. (errorcode 20, sqlstate INT).
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
index 7cdab20..f465176 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -919,20 +919,6 @@ public class PhoenixConnection implements Connection, MetaDataMutated, SQLClosea
}
@Override
- public void addColumn(PName tenantId, String tableName, List<PColumn> columns, long tableTimeStamp,
- long tableSeqNum, boolean isImmutableRows, boolean isWalDisabled, boolean isMultitenant, boolean storeNulls,
- boolean isTransactional, long updateCacheFrequency, boolean isNamespaceMapped, long resolvedTime)
- throws SQLException {
- metaData.addColumn(tenantId, tableName, columns, tableTimeStamp, tableSeqNum, isImmutableRows,
- isWalDisabled, isMultitenant, storeNulls, isTransactional, updateCacheFrequency, isNamespaceMapped,
- resolvedTime);
- // Cascade through to connectionQueryServices too
- getQueryServices().addColumn(tenantId, tableName, columns, tableTimeStamp, tableSeqNum, isImmutableRows,
- isWalDisabled, isMultitenant, storeNulls, isTransactional, updateCacheFrequency, isNamespaceMapped,
- resolvedTime);
- }
-
- @Override
public void removeTable(PName tenantId, String tableName, String parentTableName, long tableTimeStamp) throws SQLException {
metaData.removeTable(tenantId, tableName, parentTableName, tableTimeStamp);
//Cascade through to connectionQueryServices too
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/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 51716d0..38580e4 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
@@ -37,6 +37,7 @@ import org.apache.phoenix.execute.MutationState;
import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.parse.PFunction;
+import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableType;
@@ -83,7 +84,7 @@ public interface ConnectionQueryServices extends QueryServices, MetaDataMutated
boolean isNamespaceMapped, boolean allocateIndexId) throws SQLException;
public MetaDataMutationResult dropTable(List<Mutation> tableMetadata, PTableType tableType, boolean cascade) throws SQLException;
public MetaDataMutationResult dropFunction(List<Mutation> tableMetadata, boolean ifExists) throws SQLException;
- public MetaDataMutationResult addColumn(List<Mutation> tableMetaData, PTable table, Map<String, List<Pair<String,Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded) throws SQLException;
+ public MetaDataMutationResult addColumn(List<Mutation> tableMetaData, PTable table, Map<String, List<Pair<String,Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded, List<PColumn> columns) throws SQLException;
public MetaDataMutationResult dropColumn(List<Mutation> tableMetadata, PTableType tableType) throws SQLException;
public MetaDataMutationResult updateIndexState(List<Mutation> tableMetadata, String parentTableName) throws SQLException;
public MutationState updateData(MutationPlan plan) throws SQLException;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/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 c8cd04d..da43af7 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
@@ -641,26 +641,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
@Override
- public void addColumn(final PName tenantId, final String tableName, final List<PColumn> columns,
- final long tableTimeStamp, final long tableSeqNum, final boolean isImmutableRows,
- final boolean isWalDisabled, final boolean isMultitenant, final boolean storeNulls,
- final boolean isTransactional, final long updateCacheFrequency, final boolean isNamespaceMapped,
- final long resolvedTime) throws SQLException {
- metaDataMutated(tenantId, tableName, tableSeqNum, new Mutator() {
- @Override
- public void mutate(PMetaData metaData) throws SQLException {
- try {
- metaData.addColumn(tenantId, tableName, columns, tableTimeStamp, tableSeqNum,
- isImmutableRows, isWalDisabled, isMultitenant, storeNulls, isTransactional,
- updateCacheFrequency, isNamespaceMapped, resolvedTime);
- } catch (TableNotFoundException e) {
- // The DROP TABLE may have been processed first, so just ignore.
- }
- }
- });
- }
-
- @Override
public void removeTable(PName tenantId, final String tableName, String parentTableName, long tableTimeStamp) throws SQLException {
synchronized (latestMetaDataLock) {
throwConnectionClosedIfNullMetaData();
@@ -1707,7 +1687,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
@Override
- public MetaDataMutationResult addColumn(final List<Mutation> tableMetaData, PTable table, Map<String, List<Pair<String,Object>>> stmtProperties, Set<String> colFamiliesForPColumnsToBeAdded) throws SQLException {
+ public MetaDataMutationResult addColumn(final List<Mutation> tableMetaData, PTable table, Map<String, List<Pair<String,Object>>> stmtProperties, Set<String> colFamiliesForPColumnsToBeAdded, List<PColumn> columns) throws SQLException {
List<Pair<byte[], Map<String, Object>>> families = new ArrayList<>(stmtProperties.size());
Map<String, Object> tableProps = new HashMap<String, Object>();
Set<HTableDescriptor> tableDescriptors = Collections.emptySet();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/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 6398a23..042d7a6 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
@@ -180,16 +180,6 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices imple
}
@Override
- public void addColumn(PName tenantId, String tableName, List<PColumn> columns, long tableTimeStamp,
- long tableSeqNum, boolean isImmutableRows, boolean isWalDisabled, boolean isMultitenant, boolean storeNulls,
- boolean isTransactional, long updateCacheFrequency, boolean isNamespaceMapped, long resolvedTime)
- throws SQLException {
- metaData.addColumn(tenantId, tableName, columns, tableTimeStamp, tableSeqNum, isImmutableRows,
- isWalDisabled, isMultitenant, storeNulls, isTransactional, updateCacheFrequency, isNamespaceMapped,
- resolvedTime);
- }
-
- @Override
public void removeTable(PName tenantId, String tableName, String parentTableName, long tableTimeStamp)
throws SQLException {
metaData.removeTable(tenantId, tableName, parentTableName, tableTimeStamp);
@@ -271,8 +261,10 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices imple
}
@Override
- public MetaDataMutationResult addColumn(List<Mutation> tableMetaData, PTable table, Map<String, List<Pair<String,Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded) throws SQLException {
- return new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, 0, null);
+ public MetaDataMutationResult addColumn(List<Mutation> tableMetaData, PTable table, Map<String, List<Pair<String,Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded, List<PColumn> columnsToBeAdded) throws SQLException {
+ List<PColumn> columns = Lists.newArrayList(table.getColumns());
+ columns.addAll(columnsToBeAdded);
+ return new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, 0, PTableImpl.makePTable(table, columns));
}
@Override
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/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 685e583..4d77267 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
@@ -87,16 +87,6 @@ public class DelegateConnectionQueryServices extends DelegateQueryServices imple
}
@Override
- public void addColumn(PName tenantId, String tableName, List<PColumn> columns, long tableTimeStamp,
- long tableSeqNum, boolean isImmutableRows, boolean isWalDisabled, boolean isMultitenant, boolean storeNulls,
- boolean isTransactional, long updateCacheFrequency, boolean isNamespaceMapped, long resolvedTime)
- throws SQLException {
- getDelegate().addColumn(tenantId, tableName, columns, tableTimeStamp, tableSeqNum, isImmutableRows,
- isWalDisabled, isMultitenant, storeNulls, isTransactional, updateCacheFrequency, isNamespaceMapped,
- resolvedTime);
- }
-
- @Override
public void removeTable(PName tenantId, String tableName, String parentTableName, long tableTimeStamp)
throws SQLException {
getDelegate().removeTable(tenantId, tableName, parentTableName, tableTimeStamp);
@@ -132,8 +122,8 @@ public class DelegateConnectionQueryServices extends DelegateQueryServices imple
}
@Override
- public MetaDataMutationResult addColumn(List<Mutation> tableMetaData, PTable table, Map<String, List<Pair<String,Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded) throws SQLException {
- return getDelegate().addColumn(tableMetaData, table, properties, colFamiliesForPColumnsToBeAdded);
+ public MetaDataMutationResult addColumn(List<Mutation> tableMetaData, PTable table, Map<String, List<Pair<String,Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded, List<PColumn> columns) throws SQLException {
+ return getDelegate().addColumn(tableMetaData, table, properties, colFamiliesForPColumnsToBeAdded, columns);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java b/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java
index 0b6a644..e7ce65c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/MetaDataMutated.java
@@ -38,7 +38,6 @@ public interface MetaDataMutated {
void addTable(PTable table, long resolvedTime) throws SQLException;
void updateResolvedTimestamp(PTable table, long resolvedTimestamp) throws SQLException;
void removeTable(PName tenantId, String tableName, String parentTableName, long tableTimeStamp) throws SQLException;
- void addColumn(PName tenantId, String tableName, List<PColumn> columns, long tableTimeStamp, long tableSeqNum, boolean isImmutableRows, boolean isWalDisabled, boolean isMultitenant, boolean storeNulls, boolean isTransactional, long updateCacheFrequency, boolean isNamespaceMapped, long resolvedTime) throws SQLException;
void removeColumn(PName tenantId, String tableName, List<PColumn> columnsToRemove, long tableTimeStamp, long tableSeqNum, long resolvedTime) throws SQLException;
void addFunction(PFunction function) throws SQLException;
void removeFunction(PName tenantId, String function, long functionTimeStamp) throws SQLException;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/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 0803e89..7f183e9 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
@@ -889,19 +889,20 @@ public class MetaDataClient {
populatePropertyMaps(statement.getProps(), tableProps, commonFamilyProps);
boolean isAppendOnlySchema = false;
+ long updateCacheFrequency = 0;
if (parent==null) {
Boolean appendOnlySchemaProp = (Boolean) TableProperty.APPEND_ONLY_SCHEMA.getValue(tableProps);
if (appendOnlySchemaProp != null) {
isAppendOnlySchema = appendOnlySchemaProp;
}
+ Long updateCacheFrequencyProp = (Long) TableProperty.UPDATE_CACHE_FREQUENCY.getValue(tableProps);
+ if (updateCacheFrequencyProp != null) {
+ updateCacheFrequency = updateCacheFrequencyProp;
+ }
}
else {
isAppendOnlySchema = parent.isAppendOnlySchema();
- }
- long updateCacheFrequency = 0;
- Long updateCacheFrequencyProp = (Long) TableProperty.UPDATE_CACHE_FREQUENCY.getValue(tableProps);
- if (updateCacheFrequencyProp != null) {
- updateCacheFrequency = updateCacheFrequencyProp;
+ updateCacheFrequency = parent.getUpdateCacheFrequency();
}
// updateCacheFrequency cannot be set to ALWAYS if isAppendOnlySchema is true
if (isAppendOnlySchema && updateCacheFrequency==0) {
@@ -909,6 +910,12 @@ public class MetaDataClient {
.setSchemaName(tableName.getSchemaName()).setTableName(tableName.getTableName())
.build().buildException();
}
+ Boolean immutableProp = (Boolean) TableProperty.IMMUTABLE_ROWS.getValue(tableProps);
+ if (statement.immutableRows()!=null && immutableProp!=null) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.IMMUTABLE_TABLE_PROPERTY_INVALID)
+ .setSchemaName(tableName.getSchemaName()).setTableName(tableName.getTableName())
+ .build().buildException();
+ }
PTable table = null;
// if the APPEND_ONLY_SCHEMA attribute is true first check if the table is present in the cache
@@ -1660,6 +1667,7 @@ public class MetaDataClient {
storeNulls = parent.getStoreNulls();
isImmutableRows = parent.isImmutableRows();
isAppendOnlySchema = parent.isAppendOnlySchema();
+
// Index on view
// TODO: Can we support a multi-tenant index directly on a multi-tenant
// table instead of only a view? We don't have anywhere to put the link
@@ -1733,7 +1741,6 @@ public class MetaDataClient {
isImmutableRows = isImmutableRowsProp;
}
}
-
if (tableType == PTableType.TABLE) {
Boolean isAppendOnlySchemaProp = (Boolean) TableProperty.APPEND_ONLY_SCHEMA.getValue(tableProps);
isAppendOnlySchema = isAppendOnlySchemaProp!=null ? isAppendOnlySchemaProp : false;
@@ -1917,6 +1924,10 @@ public class MetaDataClient {
saltBucketNum = parent.getBucketNum();
isAppendOnlySchema = parent.isAppendOnlySchema();
isImmutableRows = parent.isImmutableRows();
+ if (updateCacheFrequencyProp == null) {
+ // set to the parent value if the property is not set on the view
+ updateCacheFrequency = parent.getUpdateCacheFrequency();
+ }
disableWAL = (disableWALProp == null ? parent.isWALDisabled() : disableWALProp);
defaultFamilyName = parent.getDefaultFamilyName() == null ? null : parent.getDefaultFamilyName().getString();
List<PColumn> allColumns = parent.getColumns();
@@ -2647,12 +2658,12 @@ public class MetaDataClient {
}
private long incrementTableSeqNum(PTable table, PTableType expectedType, int columnCountDelta, Boolean isTransactional, Long updateCacheFrequency) throws SQLException {
- return incrementTableSeqNum(table, expectedType, columnCountDelta, isTransactional, updateCacheFrequency, null, null, null, null, -1L);
+ return incrementTableSeqNum(table, expectedType, columnCountDelta, isTransactional, updateCacheFrequency, null, null, null, null, -1L, null);
}
private long incrementTableSeqNum(PTable table, PTableType expectedType, int columnCountDelta,
Boolean isTransactional, Long updateCacheFrequency, Boolean isImmutableRows, Boolean disableWAL,
- Boolean isMultiTenant, Boolean storeNulls, Long guidePostWidth)
+ Boolean isMultiTenant, Boolean storeNulls, Long guidePostWidth, Boolean appendOnlySchema)
throws SQLException {
String schemaName = table.getSchemaName().getString();
String tableName = table.getTableName().getString();
@@ -2693,6 +2704,9 @@ public class MetaDataClient {
if (guidePostWidth == null || guidePostWidth >= 0) {
mutateLongProperty(tenantId, schemaName, tableName, GUIDE_POSTS_WIDTH, guidePostWidth);
}
+ if (appendOnlySchema !=null) {
+ mutateBooleanProperty(tenantId, schemaName, tableName, APPEND_ONLY_SCHEMA, appendOnlySchema);
+ }
return seqNum;
}
@@ -2757,6 +2771,7 @@ public class MetaDataClient {
Boolean storeNullsProp = null;
Boolean isTransactionalProp = null;
Long updateCacheFrequencyProp = null;
+ Boolean appendOnlySchemaProp = null;
Long guidePostWidth = -1L;
Map<String, List<Pair<String, Object>>> properties = new HashMap<>(stmtProperties.size());
@@ -2818,6 +2833,8 @@ public class MetaDataClient {
updateCacheFrequencyProp = (Long)value;
} else if (propName.equals(GUIDE_POSTS_WIDTH)) {
guidePostWidth = (Long)value;
+ } else if (propName.equals(APPEND_ONLY_SCHEMA)) {
+ appendOnlySchemaProp = (Boolean) value;
}
}
// if removeTableProps is true only add the property if it is not a HTable or Phoenix Table property
@@ -2884,6 +2901,14 @@ public class MetaDataClient {
changingPhoenixTableProperty = true;
}
}
+ Boolean appendOnlySchema = null;
+ if (appendOnlySchemaProp !=null) {
+ if (appendOnlySchemaProp != table.isAppendOnlySchema()) {
+ appendOnlySchema = appendOnlySchemaProp;
+ changingPhoenixTableProperty = true;
+ }
+ }
+
if (guidePostWidth == null || guidePostWidth >= 0) {
changingPhoenixTableProperty = true;
}
@@ -3031,7 +3056,7 @@ public class MetaDataClient {
long seqNum = table.getSequenceNumber();
if (changingPhoenixTableProperty || columnDefs.size() > 0) {
seqNum = incrementTableSeqNum(table, tableType, columnDefs.size(), isTransactional, updateCacheFrequency, isImmutableRows,
- disableWAL, multiTenant, storeNulls, guidePostWidth);
+ disableWAL, multiTenant, storeNulls, guidePostWidth, appendOnlySchema);
tableMetaData.addAll(connection.getMutationState().toMutations(timeStamp).next().getSecond());
connection.rollback();
}
@@ -3059,7 +3084,7 @@ public class MetaDataClient {
}
}
- MetaDataMutationResult result = connection.getQueryServices().addColumn(tableMetaData, table, properties, colFamiliesForPColumnsToBeAdded);
+ MetaDataMutationResult result = connection.getQueryServices().addColumn(tableMetaData, table, properties, colFamiliesForPColumnsToBeAdded, columns);
try {
MutationCode code = processMutationResult(schemaName, tableName, result);
if (code == MutationCode.COLUMN_ALREADY_EXISTS) {
@@ -3076,20 +3101,7 @@ public class MetaDataClient {
String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
long resolvedTimeStamp = TransactionUtil.getResolvedTime(connection, result);
if (table.getIndexes().isEmpty() || (numPkColumnsAdded==0 && !nonTxToTx)) {
- connection.addColumn(
- tenantId,
- fullTableName,
- columns,
- result.getMutationTime(),
- seqNum,
- isImmutableRows == null ? table.isImmutableRows() : isImmutableRows,
- disableWAL == null ? table.isWALDisabled() : disableWAL,
- multiTenant == null ? table.isMultiTenant() : multiTenant,
- storeNulls == null ? table.getStoreNulls() : storeNulls,
- isTransactional == null ? table.isTransactional() : isTransactional,
- updateCacheFrequency == null ? table.getUpdateCacheFrequency() : updateCacheFrequency,
- table.isNamespaceMapped(),
- resolvedTimeStamp);
+ connection.addTable(result.getTable(), resolvedTimeStamp);
} else if (updateCacheFrequency != null) {
// Force removal from cache as the update cache frequency has changed
// Note that clients outside this JVM won't be affected.
@@ -3334,7 +3346,7 @@ public class MetaDataClient {
Collections.<Mutation>singletonList(new Put(SchemaUtil.getTableKey
(tenantIdBytes, tableContainingColumnToDrop.getSchemaName().getBytes(),
tableContainingColumnToDrop.getTableName().getBytes()))),
- tableContainingColumnToDrop, family, Sets.newHashSet(Bytes.toString(emptyCF)));
+ tableContainingColumnToDrop, family, Sets.newHashSet(Bytes.toString(emptyCF)), Collections.<PColumn>emptyList());
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
index 064137e..6ca38cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
@@ -144,30 +144,6 @@ public class PMetaDataImpl implements PMetaData {
}
@Override
- public void addColumn(PName tenantId, String tableName, List<PColumn> columnsToAdd, long tableTimeStamp,
- long tableSeqNum, boolean isImmutableRows, boolean isWalDisabled, boolean isMultitenant, boolean storeNulls,
- boolean isTransactional, long updateCacheFrequency, boolean isNamespaceMapped, long resolvedTime)
- throws SQLException {
- PTableRef oldTableRef = metaData.get(new PTableKey(tenantId, tableName));
- if (oldTableRef == null) {
- return;
- }
- List<PColumn> oldColumns = PTableImpl.getColumnsToClone(oldTableRef.getTable());
- List<PColumn> newColumns;
- if (columnsToAdd.isEmpty()) {
- newColumns = oldColumns;
- } else {
- newColumns = Lists.newArrayListWithExpectedSize(oldColumns.size() + columnsToAdd.size());
- newColumns.addAll(oldColumns);
- newColumns.addAll(columnsToAdd);
- }
- PTable newTable = PTableImpl.makePTable(oldTableRef.getTable(), tableTimeStamp, tableSeqNum, newColumns,
- isImmutableRows, isWalDisabled, isMultitenant, storeNulls, isTransactional, updateCacheFrequency,
- isNamespaceMapped);
- addTable(newTable, resolvedTime);
- }
-
- @Override
public void removeTable(PName tenantId, String tableName, String parentTableName, long tableTimeStamp) throws SQLException {
PTableRef parentTableRef = null;
PTableKey key = new PTableKey(tenantId, tableName);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/main/java/org/apache/phoenix/schema/PSynchronizedMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PSynchronizedMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PSynchronizedMetaData.java
index af4bc60..e4ccf8b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PSynchronizedMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PSynchronizedMetaData.java
@@ -161,23 +161,6 @@ public class PSynchronizedMetaData implements PMetaData {
}
@Override
- public void addColumn(PName tenantId, String tableName, List<PColumn> columns,
- long tableTimeStamp, long tableSeqNum, boolean isImmutableRows, boolean isWalDisabled,
- boolean isMultitenant, boolean storeNulls, boolean isTransactional,
- long updateCacheFrequency, boolean isNamespaceMapped, long resolvedTime)
- throws SQLException {
- readWriteLock.writeLock().lock();
- try {
- delegate.addColumn(tenantId, tableName, columns, tableTimeStamp, tableSeqNum,
- isImmutableRows, isWalDisabled, isMultitenant, storeNulls, isTransactional,
- updateCacheFrequency, isNamespaceMapped, resolvedTime);
- }
- finally {
- readWriteLock.writeLock().unlock();
- }
- }
-
- @Override
public PSchema getSchema(PTableKey key) throws SchemaNotFoundException {
readWriteLock.readLock().lock();
try {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea97ce6/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
index 69cc7ff..9962859 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
@@ -35,23 +35,63 @@ import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.util.SchemaUtil;
public enum TableProperty {
-
+
@Deprecated // use the IMMUTABLE keyword while creating the table
- IMMUTABLE_ROWS(PhoenixDatabaseMetaData.IMMUTABLE_ROWS, true, true, false),
+ IMMUTABLE_ROWS(PhoenixDatabaseMetaData.IMMUTABLE_ROWS, true, true, false) {
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.isImmutableRows();
+ }
+ },
- MULTI_TENANT(PhoenixDatabaseMetaData.MULTI_TENANT, true, false, false),
+ MULTI_TENANT(PhoenixDatabaseMetaData.MULTI_TENANT, true, false, false) {
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.isMultiTenant();
+ }
+ },
- DISABLE_WAL(PhoenixDatabaseMetaData.DISABLE_WAL, true, false, false),
+ DISABLE_WAL(PhoenixDatabaseMetaData.DISABLE_WAL, true, false, false) {
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.isWALDisabled();
+ }
+ },
- SALT_BUCKETS(PhoenixDatabaseMetaData.SALT_BUCKETS, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, SALT_ONLY_ON_CREATE_TABLE, false, false),
+ SALT_BUCKETS(PhoenixDatabaseMetaData.SALT_BUCKETS, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, SALT_ONLY_ON_CREATE_TABLE, false, false) {
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.getBucketNum();
+ }
+ },
- DEFAULT_COLUMN_FAMILY(DEFAULT_COLUMN_FAMILY_NAME, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, DEFAULT_COLUMN_FAMILY_ONLY_ON_CREATE_TABLE, false, false),
+ DEFAULT_COLUMN_FAMILY(DEFAULT_COLUMN_FAMILY_NAME, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, DEFAULT_COLUMN_FAMILY_ONLY_ON_CREATE_TABLE, false, false) {
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.getDefaultFamilyName();
+ }
+ },
- TTL(HColumnDescriptor.TTL, COLUMN_FAMILY_NOT_ALLOWED_FOR_TTL, true, CANNOT_ALTER_PROPERTY, false, false),
+ TTL(HColumnDescriptor.TTL, COLUMN_FAMILY_NOT_ALLOWED_FOR_TTL, true, CANNOT_ALTER_PROPERTY, false, false) {
+ @Override
+ public Object getPTableValue(PTable table) {
+ return null;
+ }
+ },
- STORE_NULLS(PhoenixDatabaseMetaData.STORE_NULLS, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, false, false),
+ STORE_NULLS(PhoenixDatabaseMetaData.STORE_NULLS, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, false, false) {
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.getStoreNulls();
+ }
+ },
- TRANSACTIONAL(PhoenixDatabaseMetaData.TRANSACTIONAL, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, false, false),
+ TRANSACTIONAL(PhoenixDatabaseMetaData.TRANSACTIONAL, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, false, false) {
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.isTransactional();
+ }
+ },
UPDATE_CACHE_FREQUENCY(PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY, true, true, true) {
@Override
@@ -67,26 +107,46 @@ public enum TableProperty {
return value == null ? null : ((Number) value).longValue();
}
return value;
- }
+ }
+
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.getUpdateCacheFrequency();
+ }
},
AUTO_PARTITION_SEQ(PhoenixDatabaseMetaData.AUTO_PARTITION_SEQ, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, false, false) {
@Override
public Object getValue(Object value) {
return value == null ? null : SchemaUtil.normalizeIdentifier(value.toString());
+ }
+
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.getAutoPartitionSeqName();
}
},
- APPEND_ONLY_SCHEMA(PhoenixDatabaseMetaData.APPEND_ONLY_SCHEMA, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, true, false),
+ APPEND_ONLY_SCHEMA(PhoenixDatabaseMetaData.APPEND_ONLY_SCHEMA, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, true, false) {
+ @Override
+ public Object getPTableValue(PTable table) {
+ return table.isAppendOnlySchema();
+ }
+ },
GUIDE_POSTS_WIDTH(PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH, true, false, false) {
@Override
public Object getValue(Object value) {
return value == null ? null : ((Number) value).longValue();
+ }
+
+ @Override
+ public Object getPTableValue(PTable table) {
+ return null;
}
},
;
-
+
private final String propertyName;
private final SQLExceptionCode colFamSpecifiedException;
private final boolean isMutable; // whether or not a property can be changed through statements like ALTER TABLE.
@@ -174,4 +234,10 @@ public enum TableProperty {
return isMutable;
}
+ public boolean isMutableOnView() {
+ return isMutableOnView;
+ }
+
+ abstract public Object getPTableValue(PTable table);
+
}
[20/42] phoenix git commit: Fail-fast iterators for
EncodedColumnQualifierCellsList. Use list iterators instead of get(index) for
navigating lists. Use HBase bytes utility for encoded column names. Fix test
failures for immutable tables and indexes.
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java
index 15d6d2f..c5f690b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java
@@ -44,6 +44,7 @@ import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.util.Closeables;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -89,7 +90,7 @@ public class FormatToKeyValueReducer
}
private void initColumnsMap(PhoenixConnection conn) throws SQLException {
- Map<byte[], Integer> indexMap = new TreeMap(Bytes.BYTES_COMPARATOR);
+ Map<byte[], Integer> indexMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
columnIndexes = new HashMap<>();
int columnIndex = 0;
for (int index = 0; index < logicalNames.size(); index++) {
@@ -98,12 +99,16 @@ public class FormatToKeyValueReducer
for (int i = 0; i < cls.size(); i++) {
PColumn c = cls.get(i);
byte[] family = new byte[0];
- if (c.getFamilyName() != null) {
+ byte[] cq;
+ if (!SchemaUtil.isPKColumn(c)) {
family = c.getFamilyName().getBytes();
+ cq = EncodedColumnsUtil.getColumnQualifier(c, table);
+ } else {
+ // TODO: samarth verify if this is the right thing to do here.
+ cq = c.getName().getBytes();
}
- byte[] name = c.getName().getBytes();
- byte[] cfn = Bytes.add(family, QueryConstants.NAMESPACE_SEPARATOR_BYTES, name);
- Pair<byte[], byte[]> pair = new Pair(family, name);
+ byte[] cfn = Bytes.add(family, QueryConstants.NAMESPACE_SEPARATOR_BYTES, cq);
+ Pair<byte[], byte[]> pair = new Pair<>(family, cq);
if (!indexMap.containsKey(cfn)) {
indexMap.put(cfn, new Integer(columnIndex));
columnIndexes.put(new Integer(columnIndex), pair);
@@ -111,8 +116,8 @@ public class FormatToKeyValueReducer
}
}
byte[] emptyColumnFamily = SchemaUtil.getEmptyColumnFamily(table);
- Pair<byte[], byte[]> pair = new Pair(emptyColumnFamily, QueryConstants
- .EMPTY_COLUMN_BYTES);
+ byte[] emptyKeyValue = EncodedColumnsUtil.getEmptyKeyValueInfo(table).getFirst();
+ Pair<byte[], byte[]> pair = new Pair<>(emptyColumnFamily, emptyKeyValue);
columnIndexes.put(new Integer(columnIndex), pair);
columnIndex++;
}
@@ -123,18 +128,17 @@ public class FormatToKeyValueReducer
Reducer<TableRowkeyPair, ImmutableBytesWritable, TableRowkeyPair, KeyValue>.Context context)
throws IOException, InterruptedException {
TreeSet<KeyValue> map = new TreeSet<KeyValue>(KeyValue.COMPARATOR);
- ImmutableBytesWritable rowKey = key.getRowkey();
for (ImmutableBytesWritable aggregatedArray : values) {
DataInputStream input = new DataInputStream(new ByteArrayInputStream(aggregatedArray.get()));
while (input.available() != 0) {
byte type = input.readByte();
int index = WritableUtils.readVInt(input);
ImmutableBytesWritable family;
- ImmutableBytesWritable name;
+ ImmutableBytesWritable cq;
ImmutableBytesWritable value = QueryConstants.EMPTY_COLUMN_VALUE_BYTES_PTR;
Pair<byte[], byte[]> pair = columnIndexes.get(index);
family = new ImmutableBytesWritable(pair.getFirst());
- name = new ImmutableBytesWritable(pair.getSecond());
+ cq = new ImmutableBytesWritable(pair.getSecond());
int len = WritableUtils.readVInt(input);
if (len > 0) {
byte[] array = new byte[len];
@@ -145,10 +149,10 @@ public class FormatToKeyValueReducer
KeyValue.Type kvType = KeyValue.Type.codeToType(type);
switch (kvType) {
case Put: // not null value
- kv = builder.buildPut(key.getRowkey(), family, name, value);
+ kv = builder.buildPut(key.getRowkey(), family, cq, value);
break;
case DeleteColumn: // null value
- kv = builder.buildDeleteColumns(key.getRowkey(), family, name);
+ kv = builder.buildDeleteColumns(key.getRowkey(), family, cq);
break;
default:
throw new IOException("Unsupported KeyValue type " + kvType);
@@ -164,4 +168,4 @@ public class FormatToKeyValueReducer
if (++index % 100 == 0) context.setStatus("Wrote " + index);
}
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 f1de0bd..5a00372 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
@@ -94,6 +94,7 @@ import org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory;
import org.apache.hadoop.hbase.ipc.ServerRpcController;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto;
import org.apache.hadoop.hbase.regionserver.IndexHalfStoreFileReaderGenerator;
+import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.util.ByteStringer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
@@ -574,7 +575,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
latestMetaDataLock.notifyAll();
}
}
-
@Override
public void updateResolvedTimestamp(PTable table, long resolvedTime) throws SQLException {
synchronized (latestMetaDataLock) {
@@ -4128,4 +4128,4 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
public Configuration getConfiguration() {
return config;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 042d7a6..76b69fb 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
@@ -93,7 +93,6 @@ import org.apache.tephra.inmemory.InMemoryTxSystemClient;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-
/**
*
* Implementation of ConnectionQueryServices used in testing where no connection to
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 8e2dc1a..e44d83e 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
@@ -31,6 +31,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_COUNT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_DEF;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_FAMILY;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER_COUNTER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_SIZE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CURRENT_VALUE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CYCLE_FLAG;
@@ -40,6 +41,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DECIMAL_DIGITS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAMILY_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_VALUE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FUNCTION_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH;
@@ -85,6 +87,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SOURCE_DATA_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SQL_DATA_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SQL_DATETIME_SUB;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.START_WITH;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.STORAGE_SCHEME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.STORE_NULLS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE;
@@ -104,6 +107,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_CONSTANT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_STATEMENT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import java.math.BigDecimal;
@@ -118,7 +122,8 @@ import org.apache.phoenix.schema.MetaDataSplitPolicy;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.util.EncodedColumnsUtil;
/**
@@ -149,23 +154,30 @@ public interface QueryConstants {
public final static byte[] OFFSET_ROW_KEY_BYTES = Bytes.toBytes(OFFSET_ROW_KEY);
public final static ImmutableBytesPtr OFFSET_ROW_KEY_PTR = new ImmutableBytesPtr(OFFSET_ROW_KEY_BYTES);
- public final static PName SINGLE_COLUMN_NAME = PNameFactory.newNormalizedName("s");
- public final static PName SINGLE_COLUMN_FAMILY_NAME = PNameFactory.newNormalizedName("s");
- public final static byte[] SINGLE_COLUMN = SINGLE_COLUMN_NAME.getBytes();
- public final static byte[] SINGLE_COLUMN_FAMILY = SINGLE_COLUMN_FAMILY_NAME.getBytes();
-
public static final long AGG_TIMESTAMP = HConstants.LATEST_TIMESTAMP;
/**
* Key used for a single row aggregation where there is no group by
*/
public final static byte[] UNGROUPED_AGG_ROW_KEY = Bytes.toBytes("a");
- public final static PName AGG_COLUMN_NAME = SINGLE_COLUMN_NAME;
- public final static PName AGG_COLUMN_FAMILY_NAME = SINGLE_COLUMN_FAMILY_NAME;
-
- public static final byte[] ARRAY_VALUE_COLUMN_FAMILY = Bytes.toBytes("a");
- // Use empty byte array for column qualifier so as not to accidentally conflict with any other columns
- public static final byte[] ARRAY_VALUE_COLUMN_QUALIFIER = ByteUtil.EMPTY_BYTE_ARRAY;
+
+ /** BEGIN Set of reserved column qualifiers **/
+
+ public static final String RESERVED_COLUMN_FAMILY = "_r";
+ public static final byte[] RESERVED_COLUMN_FAMILY_BYTES = Bytes.toBytes(RESERVED_COLUMN_FAMILY);
+
+ public static final byte[] VALUE_COLUMN_FAMILY = RESERVED_COLUMN_FAMILY_BYTES;
+ public static final byte[] VALUE_COLUMN_QUALIFIER = getEncodedColumnQualifier(1);
+
+ public static final byte[] ARRAY_VALUE_COLUMN_FAMILY = RESERVED_COLUMN_FAMILY_BYTES;
+ public static final byte[] ARRAY_VALUE_COLUMN_QUALIFIER = getEncodedColumnQualifier(2);
+
+ public final static PName SINGLE_COLUMN_NAME = PNameFactory.newNormalizedName("s");
+ public final static PName SINGLE_COLUMN_FAMILY_NAME = PNameFactory.newNormalizedName("s");
+ public final static byte[] SINGLE_COLUMN = getEncodedColumnQualifier(3);
+ public final static byte[] SINGLE_COLUMN_FAMILY = RESERVED_COLUMN_FAMILY_BYTES;
+ /** END Set of reserved column qualifiers **/
+
public static final byte[] TRUE = new byte[] {1};
/**
@@ -192,11 +204,18 @@ public interface QueryConstants {
public static final byte[] EMPTY_COLUMN_BYTES = Bytes.toBytes(EMPTY_COLUMN_NAME);
public static final ImmutableBytesPtr EMPTY_COLUMN_BYTES_PTR = new ImmutableBytesPtr(
EMPTY_COLUMN_BYTES);
+ public static final Integer ENCODED_EMPTY_COLUMN_NAME = 0;
+ public static final byte[] ENCODED_EMPTY_COLUMN_BYTES = getEncodedColumnQualifier(ENCODED_EMPTY_COLUMN_NAME);
+ public static final ImmutableBytesPtr ENCODED_EMPTY_COLUMN_BYTES_PTR = new ImmutableBytesPtr(
+ ENCODED_EMPTY_COLUMN_BYTES);
public final static String EMPTY_COLUMN_VALUE = "x";
public final static byte[] EMPTY_COLUMN_VALUE_BYTES = Bytes.toBytes(EMPTY_COLUMN_VALUE);
public static final ImmutableBytesPtr EMPTY_COLUMN_VALUE_BYTES_PTR = new ImmutableBytesPtr(
EMPTY_COLUMN_VALUE_BYTES);
-
+ public static final String ENCODED_EMPTY_COLUMN_VALUE = EMPTY_COLUMN_VALUE;
+ public final static byte[] ENCODED_EMPTY_COLUMN_VALUE_BYTES = Bytes.toBytes(EMPTY_COLUMN_VALUE);
+ public static final ImmutableBytesPtr ENCODED_EMPTY_COLUMN_VALUE_BYTES_PTR = new ImmutableBytesPtr(
+ ENCODED_EMPTY_COLUMN_VALUE_BYTES);
public static final String DEFAULT_COLUMN_FAMILY = "0";
public static final byte[] DEFAULT_COLUMN_FAMILY_BYTES = Bytes.toBytes(DEFAULT_COLUMN_FAMILY);
public static final ImmutableBytesPtr DEFAULT_COLUMN_FAMILY_BYTES_PTR = new ImmutableBytesPtr(
@@ -222,6 +241,12 @@ public interface QueryConstants {
public static final int NANOS_IN_SECOND = BigDecimal.valueOf(Math.pow(10, 9)).intValue();
public static final int DIVERGED_VIEW_BASE_COLUMN_COUNT = -100;
public static final int BASE_TABLE_BASE_COLUMN_COUNT = -1;
+
+ /**
+ * We mark counter values 0 to 10 as reserved. Value 0 is used by {@link #ENCODED_EMPTY_COLUMN_NAME}. Values 1-10
+ * are reserved for special column qualifiers returned by Phoenix co-processors.
+ */
+ public static final int ENCODED_CQ_COUNTER_INITIAL_VALUE = 11;
public static final String CREATE_TABLE_METADATA =
// Do not use IF NOT EXISTS as we sometimes catch the TableAlreadyExists
// exception and add columns to the SYSTEM.TABLE dynamically.
@@ -289,6 +314,9 @@ public interface QueryConstants {
AUTO_PARTITION_SEQ + " VARCHAR," +
APPEND_ONLY_SCHEMA + " BOOLEAN," +
GUIDE_POSTS_WIDTH + " BIGINT," +
+ ENCODED_COLUMN_QUALIFIER + " UNSIGNED_INT," +
+ STORAGE_SCHEME + " TINYINT, " +
+ COLUMN_QUALIFIER_COUNTER + " INTEGER, " +
"CONSTRAINT " + SYSTEM_TABLE_PK_NAME + " PRIMARY KEY (" + TENANT_ID + ","
+ TABLE_SCHEM + "," + TABLE_NAME + "," + COLUMN_NAME + "," + COLUMN_FAMILY + "))\n" +
HConstants.VERSIONS + "=" + MetaDataProtocol.DEFAULT_MAX_META_DATA_VERSIONS + ",\n" +
@@ -363,5 +391,5 @@ public interface QueryConstants {
public static final byte[] OFFSET_FAMILY = "f_offset".getBytes();
public static final byte[] OFFSET_COLUMN = "c_offset".getBytes();
public static final String LAST_SCAN = "LAST_SCAN";
-
+ public static final byte[] UPGRADE_MUTEX = "UPGRADE_MUTEX".getBytes();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 8c07ca6..3b4d9cc 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
@@ -243,7 +243,6 @@ public class QueryServicesOptions {
public static final long DEFAULT_QUERY_SERVER_UGI_CACHE_MAX_SIZE = 1000L;
public static final int DEFAULT_QUERY_SERVER_UGI_CACHE_INITIAL_SIZE = 100;
public static final int DEFAULT_QUERY_SERVER_UGI_CACHE_CONCURRENCY = 10;
-
public static final boolean DEFAULT_RENEW_LEASE_ENABLED = true;
public static final int DEFAULT_RUN_RENEW_LEASE_FREQUENCY_INTERVAL_MILLISECONDS =
DEFAULT_HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD / 2;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
index 1d772b4..88e7d77 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
@@ -17,10 +17,17 @@
*/
package org.apache.phoenix.schema;
+import static org.apache.phoenix.util.EncodedColumnsUtil.usesEncodedColumnNames;
+
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Arrays;
+
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.http.annotation.Immutable;
import org.apache.phoenix.compile.ExpressionCompiler;
import org.apache.phoenix.compile.StatementContext;
+import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.KeyValueColumnExpression;
import org.apache.phoenix.expression.ProjectedColumnExpression;
@@ -30,14 +37,12 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.ParseNode;
import org.apache.phoenix.parse.SQLParser;
+import org.apache.phoenix.schema.PTable.StorageScheme;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.ExpressionUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.SchemaUtil;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Arrays;
-
/**
*
@@ -59,7 +64,7 @@ public class ColumnRef {
}
public ColumnRef(TableRef tableRef, String familyName, String columnName) throws MetaDataEntityNotFoundException {
- this(tableRef, tableRef.getTable().getColumnFamily(familyName).getColumn(columnName).getPosition());
+ this(tableRef, tableRef.getTable().getColumnFamily(familyName).getPColumnForColumnName(columnName).getPosition());
}
public ColumnRef(TableRef tableRef, int columnPosition) {
@@ -123,7 +128,7 @@ public class ColumnRef {
return new ProjectedColumnExpression(column, table, displayName);
}
- Expression expression = new KeyValueColumnExpression(column, displayName);
+ Expression expression = new KeyValueColumnExpression(column, displayName, usesEncodedColumnNames(table));
if (column.getExpressionStr() != null) {
String url = PhoenixRuntime.JDBC_PROTOCOL
@@ -141,7 +146,10 @@ public class ColumnRef {
}
}
- return expression;
+ if (table.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ return new ArrayColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table.getStorageScheme()));
+ }
+ return new KeyValueColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table.getStorageScheme()));
}
public ColumnRef cloneAtTimestamp(long timestamp) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
index 62d2e3f..cd9c2c0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
@@ -100,4 +100,8 @@ public class DelegateColumn extends DelegateDatum implements PColumn {
public boolean equals(Object o) {
return getDelegate().equals(o);
}
+ @Override
+ public Integer getEncodedColumnQualifier() {
+ return getDelegate().getEncodedColumnQualifier();
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
index 7d39dfe..b09fc5f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
@@ -96,8 +96,8 @@ public class DelegateTable implements PTable {
}
@Override
- public PColumn getColumn(String name) throws ColumnNotFoundException, AmbiguousColumnException {
- return delegate.getColumn(name);
+ public PColumn getPColumnForColumnName(String name) throws ColumnNotFoundException, AmbiguousColumnException {
+ return delegate.getPColumnForColumnName(name);
}
@Override
@@ -290,4 +290,19 @@ public class DelegateTable implements PTable {
public boolean equals(Object obj) {
return delegate.equals(obj);
}
+
+ @Override
+ public StorageScheme getStorageScheme() {
+ return delegate.getStorageScheme();
+ }
+
+ @Override
+ public PColumn getPColumnForColumnQualifier(byte[] cf, byte[] cq) throws ColumnNotFoundException, AmbiguousColumnException {
+ return delegate.getPColumnForColumnQualifier(cf, cq);
+ }
+
+ @Override
+ public EncodedCQCounter getEncodedCQCounter() {
+ return delegate.getEncodedCQCounter();
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 7f183e9..cb20db1 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
@@ -34,6 +34,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_COUNT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_DEF;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_FAMILY;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER_COUNTER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_SIZE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DATA_TABLE_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DATA_TYPE;
@@ -41,6 +42,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DECIMAL_DIGITS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAMILY_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_VALUE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FUNCTION_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IMMUTABLE_ROWS;
@@ -68,6 +70,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PK_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.RETURN_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SALT_BUCKETS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SORT_ORDER;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.STORAGE_SCHEME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.STORE_NULLS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE;
@@ -84,9 +87,11 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_CONSTANT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_STATEMENT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE;
import static org.apache.phoenix.query.QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT;
+import static org.apache.phoenix.query.QueryConstants.DEFAULT_COLUMN_FAMILY;
import static org.apache.phoenix.query.QueryServices.DROP_METADATA_ATTRIB;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_DROP_METADATA;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_RUN_UPDATE_STATS_ASYNC;
+import static org.apache.phoenix.schema.PTable.EncodedCQCounter.NULL_COUNTER;
import static org.apache.phoenix.schema.PTable.ViewType.MAPPED;
import static org.apache.phoenix.schema.PTableType.TABLE;
import static org.apache.phoenix.schema.PTableType.VIEW;
@@ -147,7 +152,6 @@ import org.apache.phoenix.execute.MutationState;
import org.apache.phoenix.expression.Determinism;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.RowKeyColumnExpression;
-import org.apache.phoenix.hbase.index.covered.update.ColumnReference;
import org.apache.phoenix.index.IndexMaintainer;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
@@ -186,8 +190,10 @@ import org.apache.phoenix.query.ConnectionQueryServices.Feature;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTable.LinkType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTable.ViewType;
import org.apache.phoenix.schema.stats.GuidePostsKey;
import org.apache.phoenix.schema.types.PDataType;
@@ -199,6 +205,7 @@ import org.apache.phoenix.schema.types.PUnsignedLong;
import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.schema.types.PVarchar;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.LogUtil;
import org.apache.phoenix.util.MetaDataUtil;
@@ -214,6 +221,7 @@ import org.apache.tephra.TxConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Strings;
import com.google.common.collect.Iterators;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
@@ -258,8 +266,9 @@ public class MetaDataClient {
IS_NAMESPACE_MAPPED + "," +
AUTO_PARTITION_SEQ + "," +
APPEND_ONLY_SCHEMA + "," +
- GUIDE_POSTS_WIDTH +
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ GUIDE_POSTS_WIDTH + "," +
+ STORAGE_SCHEME +
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String CREATE_SCHEMA = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE
+ "\"( " + TABLE_SCHEM + "," + TABLE_NAME + ") VALUES (?,?)";
@@ -274,6 +283,7 @@ public class MetaDataClient {
TABLE_SEQ_NUM +","+ // this is actually set to the parent table's sequence number
TABLE_TYPE +
") VALUES (?, ?, ?, ?, ?, ?, ?)";
+
private static final String CREATE_VIEW_LINK =
"UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
TENANT_ID + "," +
@@ -283,7 +293,17 @@ public class MetaDataClient {
LINK_TYPE + "," +
PARENT_TENANT_ID + " " + PVarchar.INSTANCE.getSqlTypeName() + // Dynamic column for now to prevent schema change
") VALUES (?, ?, ?, ?, ?, ?)";
- private static final String INCREMENT_SEQ_NUM =
+
+ public static final String UPDATE_ENCODED_COLUMN_COUNTER =
+ "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
+ TENANT_ID + ", " +
+ TABLE_SCHEM + "," +
+ TABLE_NAME + "," +
+ COLUMN_FAMILY + "," +
+ COLUMN_QUALIFIER_COUNTER +
+ ") VALUES (?, ?, ?, ?, ?)";
+
+ public static final String INCREMENT_SEQ_NUM =
"UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
TENANT_ID + "," +
TABLE_SCHEM + "," +
@@ -336,8 +356,9 @@ public class MetaDataClient {
PK_NAME + "," + // write this both in the column and table rows for access by metadata APIs
KEY_SEQ + "," +
COLUMN_DEF + "," +
+ ENCODED_COLUMN_QUALIFIER + ", " +
IS_ROW_TIMESTAMP +
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String INSERT_COLUMN_ALTER_TABLE =
"UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
TENANT_ID + "," +
@@ -357,8 +378,9 @@ public class MetaDataClient {
IS_VIEW_REFERENCED + "," +
PK_NAME + "," + // write this both in the column and table rows for access by metadata APIs
KEY_SEQ + "," +
- COLUMN_DEF +
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ COLUMN_DEF + "," +
+ ENCODED_COLUMN_QUALIFIER +
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String UPDATE_COLUMN_POSITION =
"UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\" ( " +
TENANT_ID + "," +
@@ -703,22 +725,22 @@ public class MetaDataClient {
// since view columns may be removed.
IndexMaintainer indexMaintainer = index.getIndexMaintainer(parentTable, connection);
// Check that the columns required for the index pk are present in the view
- Set<ColumnReference> indexColRefs = indexMaintainer.getIndexedColumns();
- for (ColumnReference colRef : indexColRefs) {
+ Set<Pair<String, String>> indexedColInfos = indexMaintainer.getIndexedColumnInfo();
+ for (Pair<String, String> colInfo : indexedColInfos) {
try {
- byte[] cf= colRef.getFamily();
- byte[] cq= colRef.getQualifier();
- if (cf!=null) {
- view.getColumnFamily(cf).getColumn(cq);
- }
- else {
- view.getColumn( Bytes.toString(cq));
+ String colFamily = colInfo.getFirst();
+ String colName = colInfo.getSecond();
+ if (colFamily == null) {
+ view.getPColumnForColumnName(colName);
+ } else {
+ view.getColumnFamily(colFamily).getPColumnForColumnName(colName);
}
- } catch (ColumnNotFoundException e) { // Ignore this index and continue with others
+ } catch (ColumnNotFoundException e) {
containsAllReqdCols = false;
break;
}
}
+
// Ensure that constant columns (i.e. columns matched in the view WHERE clause)
// all exist in the index on the parent table.
for (PColumn col : view.getColumns()) {
@@ -728,17 +750,17 @@ public class MetaDataClient {
// but the WHERE clause for the view statement (which is added to the index below)
// would fail to compile.
String indexColumnName = IndexUtil.getIndexColumnName(col);
- index.getColumn(indexColumnName);
+ index.getPColumnForColumnName(indexColumnName);
} catch (ColumnNotFoundException e1) {
PColumn indexCol = null;
try {
String cf = col.getFamilyName()!=null ? col.getFamilyName().getString() : null;
- String cq = col.getName().getString();
- if (cf!=null) {
- indexCol = parentTable.getColumnFamily(cf).getColumn(cq);
+ String colName = col.getName().getString();
+ if (cf != null) {
+ indexCol = parentTable.getColumnFamily(cf).getPColumnForColumnName(colName);
}
else {
- indexCol = parentTable.getColumn(cq);
+ indexCol = parentTable.getPColumnForColumnName(colName);
}
} catch (ColumnNotFoundException e2) { // Ignore this index and continue with others
containsAllReqdCols = false;
@@ -805,8 +827,13 @@ public class MetaDataClient {
} else {
colUpsert.setString(18, column.getExpressionStr());
}
- if (colUpsert.getParameterMetaData().getParameterCount() > 18) {
- colUpsert.setBoolean(19, column.isRowTimestamp());
+ if (column.getEncodedColumnQualifier() == null) {
+ colUpsert.setNull(19, Types.INTEGER);
+ } else {
+ colUpsert.setInt(19, column.getEncodedColumnQualifier());
+ }
+ if (colUpsert.getParameterMetaData().getParameterCount() > 19) {
+ colUpsert.setBoolean(20, column.isRowTimestamp());
}
colUpsert.execute();
}
@@ -825,7 +852,7 @@ public class MetaDataClient {
argUpsert.execute();
}
- private PColumn newColumn(int position, ColumnDef def, PrimaryKeyConstraint pkConstraint, String defaultColumnFamily, boolean addingToPK) throws SQLException {
+ private PColumn newColumn(int position, ColumnDef def, PrimaryKeyConstraint pkConstraint, String defaultColumnFamily, boolean addingToPK, Integer encodedColumnQualifier) throws SQLException {
try {
ColumnName columnDefName = def.getColumnDefName();
SortOrder sortOrder = def.getSortOrder();
@@ -873,15 +900,14 @@ public class MetaDataClient {
}
isNull = false;
}
-
PColumn column = new PColumnImpl(PNameFactory.newName(columnName), familyName, def.getDataType(),
- def.getMaxLength(), def.getScale(), isNull, position, sortOrder, def.getArraySize(), null, false, def.getExpression(), isRowTimestamp, false);
+ def.getMaxLength(), def.getScale(), isNull, position, sortOrder, def.getArraySize(), null, false, def.getExpression(), isRowTimestamp, false, isPK ? null : encodedColumnQualifier);
return column;
} catch (IllegalArgumentException e) { // Based on precondition check in constructor
throw new SQLException(e);
}
}
-
+
public MutationState createTable(CreateTableStatement statement, byte[][] splits, PTable parent, String viewStatement, ViewType viewType, byte[][] viewColumnConstants, BitSet isViewColumnReferenced) throws SQLException {
TableName tableName = statement.getTableName();
Map<String,Object> tableProps = Maps.newHashMapWithExpectedSize(statement.getProps().size());
@@ -1784,7 +1810,6 @@ public class MetaDataClient {
}
String autoPartitionSeq = (String) TableProperty.AUTO_PARTITION_SEQ.getValue(tableProps);
Long guidePostsWidth = (Long) TableProperty.GUIDE_POSTS_WIDTH.getValue(tableProps);
-
Boolean storeNullsProp = (Boolean) TableProperty.STORE_NULLS.getValue(tableProps);
if (storeNullsProp == null) {
if (parent == null) {
@@ -1806,7 +1831,7 @@ public class MetaDataClient {
if (transactionalProp == null) {
transactional = connection.getQueryServices().getProps().getBoolean(
QueryServices.DEFAULT_TABLE_ISTRANSACTIONAL_ATTRIB,
- QueryServicesOptions.DEFAULT_TRANSACTIONAL);
+ QueryServicesOptions.DEFAULT_TABLE_ISTRANSACTIONAL);
} else {
transactional = transactionalProp;
}
@@ -1821,7 +1846,7 @@ public class MetaDataClient {
.build().buildException();
}
// can't create a transactional table if it has a row timestamp column
- if (pkConstraint.getNumColumnsWithRowTimestamp()>0 && transactional) {
+ if (pkConstraint.getNumColumnsWithRowTimestamp() > 0 && transactional) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP)
.setSchemaName(schemaName).setTableName(tableName)
.build().buildException();
@@ -1956,7 +1981,7 @@ public class MetaDataClient {
columns = new LinkedHashMap<PColumn,PColumn>(colDefs.size());
pkColumns = newLinkedHashSetWithExpectedSize(colDefs.size() + 1); // in case salted
}
-
+
// Don't add link for mapped view, as it just points back to itself and causes the drop to
// fail because it looks like there's always a view associated with it.
if (!physicalNames.isEmpty()) {
@@ -2000,7 +2025,72 @@ public class MetaDataClient {
}
int pkPositionOffset = pkColumns.size();
int position = positionOffset;
-
+ StorageScheme storageScheme = StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ EncodedCQCounter cqCounter = NULL_COUNTER;
+ PTable viewPhysicalTable = null;
+ if (SchemaUtil.isSystemTable(Bytes.toBytes(SchemaUtil.getTableName(schemaName, tableName)))) {
+ // System tables have hard-coded column qualifiers. So we can't use column encoding for them.
+ storageScheme = StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ } else if (tableType == PTableType.VIEW) {
+ /*
+ * We can't control what column qualifiers are used in HTable mapped to Phoenix views. So we are not
+ * able to encode column names.
+ */
+ if (viewType == MAPPED) {
+ storageScheme = StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ } else {
+ /*
+ * For regular phoenix views, use the storage scheme of the physical table since they all share the
+ * the same HTable. Views always use the base table's column qualifier counter for doling out
+ * encoded column qualifier.
+ */
+ viewPhysicalTable = PhoenixRuntime.getTable(connection, physicalNames.get(0).getString());
+ storageScheme = viewPhysicalTable.getStorageScheme();
+ if (EncodedColumnsUtil.usesEncodedColumnNames(viewPhysicalTable)) {
+ cqCounter = viewPhysicalTable.getEncodedCQCounter();
+ }
+ }
+ } else {
+ /*
+ * New indexes on existing tables can have encoded column names. But unfortunately, due to backward
+ * compatibility reasons, we aren't able to change IndexMaintainer and the state that is serialized in
+ * it. Because of this we are forced to have the indexes inherit the storage scheme of the parent data
+ * tables. Otherwise, we always attempt to create tables with encoded column names.
+ *
+ * Also of note is the case with shared indexes i.e. local indexes and view indexes. In these cases,
+ * column qualifiers for covered columns don't have to be unique because rows of the logical indexes are
+ * partitioned by the virtue of indexId present in the row key. As such, different shared indexes can use
+ * potentially overlapping column qualifiers.
+ *
+ * If the hbase table already exists, then possibly encoded or non-encoded column qualifiers already exist.
+ * In this case we pursue ahead with non-encoded column qualifier scheme. If the phoenix table already exists
+ * then we rely on the PTable, with appropriate storage scheme, returned in the MetadataMutationResult to be updated
+ * in the client cache. If the phoenix table already doesn't exist then the non-encoded column qualifier scheme works
+ * because we cannot control the column qualifiers that were used when populating the hbase table.
+ */
+ byte[] tableNameBytes = SchemaUtil.getTableNameAsBytes(schemaName, tableName);
+ boolean tableExists = true;
+ try {
+ connection.getQueryServices().getTableDescriptor(tableNameBytes);
+ } catch (org.apache.phoenix.schema.TableNotFoundException e) {
+ tableExists = false;
+ }
+
+ if (parent != null) {
+ storageScheme = parent.getStorageScheme();
+ } else if (tableExists) {
+ storageScheme = StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ } else if (isImmutableRows) {
+ storageScheme = StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
+ // since we are storing all columns of a column family in a single key value we can't use deletes to store nulls
+ storeNulls = true;
+ } else {
+ storageScheme = StorageScheme.ENCODED_COLUMN_NAMES;
+ }
+ cqCounter = storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES ? new EncodedCQCounter() : NULL_COUNTER;
+ }
+
+ Map<String, Integer> changedCqCounters = new HashMap<>(colDefs.size());
for (ColumnDef colDef : colDefs) {
rowTimeStampColumnAlreadyFound = checkAndValidateRowTimestampCol(colDef, pkConstraint, rowTimeStampColumnAlreadyFound, tableType);
if (colDef.isPK()) { // i.e. the column is declared as CREATE TABLE COLNAME DATATYPE PRIMARY KEY...
@@ -2019,7 +2109,24 @@ public class MetaDataClient {
.setColumnName(colDef.getColumnDefName().getColumnName()).build().buildException();
}
}
- PColumn column = newColumn(position++, colDef, pkConstraint, defaultFamilyName, false);
+ ColumnName columnDefName = colDef.getColumnDefName();
+ String colDefFamily = columnDefName.getFamilyName();
+ boolean isPkColumn = isPkColumn(pkConstraint, colDef, columnDefName);
+ String cqCounterFamily = null;
+ if (!isPkColumn) {
+ if (storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ // For this scheme we track column qualifier counters at the column family level.
+ cqCounterFamily = colDefFamily != null ? colDefFamily : (defaultFamilyName != null ? defaultFamilyName : DEFAULT_COLUMN_FAMILY);
+ } else {
+ // For other schemes, column qualifier counters are tracked using the default column family.
+ cqCounterFamily = defaultFamilyName != null ? defaultFamilyName : DEFAULT_COLUMN_FAMILY;
+ }
+ }
+ Integer encodedCQ = isPkColumn ? null : cqCounter.getNextQualifier(cqCounterFamily);
+ PColumn column = newColumn(position++, colDef, pkConstraint, defaultFamilyName, false, encodedCQ);
+ if (cqCounter.increment(cqCounterFamily)) {
+ changedCqCounters.put(cqCounterFamily, cqCounter.getNextQualifier(cqCounterFamily));
+ }
if (SchemaUtil.isPKColumn(column)) {
// TODO: remove this constraint?
if (pkColumnsIterator.hasNext() && !column.getName().getString().equals(pkColumnsIterator.next().getFirst().getColumnName())) {
@@ -2054,6 +2161,9 @@ public class MetaDataClient {
column.getFamilyName());
}
}
+
+
+
// We need a PK definition for a TABLE or mapped VIEW
if (!isPK && pkColumnsNames.isEmpty() && tableType != PTableType.VIEW && viewType != ViewType.MAPPED) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_MISSING)
@@ -2135,15 +2245,52 @@ public class MetaDataClient {
if (SchemaUtil.isMetaTable(schemaName,tableName)) {
// TODO: what about stats for system catalog?
PName newSchemaName = PNameFactory.newName(schemaName);
+ // Column names and qualifiers and hardcoded for system tables.
PTable table = PTableImpl.makePTable(tenantId,newSchemaName, PNameFactory.newName(tableName), tableType,
null, MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM,
PNameFactory.newName(QueryConstants.SYSTEM_TABLE_PK_NAME), null, columns.values(), null, null,
Collections.<PTable>emptyList(), isImmutableRows,
Collections.<PName>emptyList(), defaultFamilyName == null ? null :
PNameFactory.newName(defaultFamilyName), null,
- Boolean.TRUE.equals(disableWAL), false, false, null, null, indexType, true, false, 0, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema);
+ Boolean.TRUE.equals(disableWAL), false, false, null, null, indexType, true, false, 0, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, StorageScheme.NON_ENCODED_COLUMN_NAMES, PTable.EncodedCQCounter.NULL_COUNTER);
connection.addTable(table, MetaDataProtocol.MIN_TABLE_TIMESTAMP);
}
+
+ // Update column qualifier counters
+ if (EncodedColumnsUtil.usesEncodedColumnNames(storageScheme)) {
+ // Store the encoded column counter for phoenix entities that have their own hbase
+ // tables i.e. base tables and indexes.
+ String schemaNameToUse = tableType == VIEW ? viewPhysicalTable.getSchemaName().getString() : schemaName;
+ String tableNameToUse = tableType == VIEW ? viewPhysicalTable.getTableName().getString() : tableName;
+ boolean sharedIndex = tableType == PTableType.INDEX && (indexType == IndexType.LOCAL || parent.getType() == PTableType.VIEW);
+ // For local indexes and indexes on views, pass on the the tenant id since all their meta-data rows have
+ // tenant ids in there.
+ String tenantIdToUse = connection.getTenantId() != null && sharedIndex ? connection.getTenantId().getString() : null;
+ // When a view adds its own columns, then we need to increase the sequence number of the base table
+ // too since we want clients to get the latest PTable of the base table.
+ for (Entry<String, Integer> entry : changedCqCounters.entrySet()) {
+ try (PreparedStatement linkStatement = connection.prepareStatement(UPDATE_ENCODED_COLUMN_COUNTER)) {
+ linkStatement.setString(1, tenantIdToUse);
+ linkStatement.setString(2, schemaNameToUse);
+ linkStatement.setString(3, tableNameToUse);
+ linkStatement.setString(4, entry.getKey());
+ linkStatement.setInt(5, entry.getValue());
+ linkStatement.execute();
+ }
+ }
+ if (tableType == VIEW && !changedCqCounters.isEmpty()) { //TODO: samarth think about shared indexes
+ PreparedStatement incrementStatement = connection.prepareStatement(INCREMENT_SEQ_NUM);
+ incrementStatement.setString(1, null);
+ incrementStatement.setString(2, viewPhysicalTable.getSchemaName().getString());
+ incrementStatement.setString(3, viewPhysicalTable.getTableName().getString());
+ incrementStatement.setLong(4, viewPhysicalTable.getSequenceNumber() + 1);
+ incrementStatement.execute();
+ }
+ if (connection.getMutationState().toMutations(timestamp).hasNext()) {
+ tableMetaData.addAll(connection.getMutationState().toMutations(timestamp).next().getSecond());
+ connection.rollback();
+ }
+ }
short nextKeySeq = 0;
@@ -2169,14 +2316,14 @@ public class MetaDataClient {
return true;
}
});
- }
- else if (isViewColumnReferenced != null) {
+ } else if (isViewColumnReferenced != null) {
if (viewColumnConstants != null && columnPosition < viewColumnConstants.length) {
entry.setValue(column = new DelegateColumn(column) {
@Override
public byte[] getViewConstant() {
return viewColumnConstants[columnPosition];
}
+
@Override
public boolean isViewReferenced() {
return isViewColumnReferenced.get(columnPosition);
@@ -2259,6 +2406,7 @@ public class MetaDataClient {
} else {
tableUpsert.setLong(25, guidePostsWidth);
}
+ tableUpsert.setByte(26, storageScheme.getSerializedValue()); //TODO: samarth should there be a null check here?
tableUpsert.execute();
if (asyncCreatedDate != null) {
@@ -2279,7 +2427,7 @@ public class MetaDataClient {
* 3) parent table header row
*/
Collections.reverse(tableMetaData);
-
+
if (indexType != IndexType.LOCAL) {
splits = SchemaUtil.processSplits(splits, pkColumns, saltBucketNum, connection.getQueryServices().getProps().getBoolean(
QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, QueryServicesOptions.DEFAULT_FORCE_ROW_KEY_ORDER));
@@ -2352,12 +2500,18 @@ public class MetaDataClient {
}
}
PName newSchemaName = PNameFactory.newName(schemaName);
+ /*
+ * It doesn't hurt for the PTable of views to have the cqCounter. However, views always rely on the
+ * parent table's counter to dole out encoded column qualifiers. So setting the counter as NULL_COUNTER
+ * for extra safety.
+ */
+ EncodedCQCounter cqCounterToBe = tableType == PTableType.VIEW ? NULL_COUNTER : cqCounter;
PTable table = PTableImpl.makePTable(
tenantId, newSchemaName, PNameFactory.newName(tableName), tableType, indexState, timestamp!=null ? timestamp : result.getMutationTime(),
PTable.INITIAL_SEQ_NUM, pkName == null ? null : PNameFactory.newName(pkName), saltBucketNum, columns.values(),
parent == null ? null : parent.getSchemaName(), parent == null ? null : parent.getTableName(), Collections.<PTable>emptyList(), isImmutableRows,
physicalNames, defaultFamilyName == null ? null : PNameFactory.newName(defaultFamilyName), viewStatement, Boolean.TRUE.equals(disableWAL), multiTenant, storeNulls, viewType,
- result.getViewIndexId(), indexType, rowKeyOrderOptimizable, transactional, updateCacheFrequency, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema);
+ result.getViewIndexId(), indexType, rowKeyOrderOptimizable, transactional, updateCacheFrequency, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, storageScheme, cqCounterToBe);
result = new MetaDataMutationResult(code, result.getMutationTime(), table, true);
addTableToCache(result);
return table;
@@ -2367,6 +2521,10 @@ public class MetaDataClient {
}
}
+ private static boolean isPkColumn(PrimaryKeyConstraint pkConstraint, ColumnDef colDef, ColumnName columnDefName) {
+ return colDef.isPK() || (pkConstraint != null && pkConstraint.getColumnWithSortOrder(columnDefName) != null);
+ }
+
/**
* A table can be a parent table to tenant-specific tables if all of the following conditions are true:
* <p>
@@ -2764,7 +2922,6 @@ public class MetaDataClient {
PName tenantId = connection.getTenantId();
String schemaName = table.getSchemaName().getString();
String tableName = table.getTableName().getString();
-
Boolean isImmutableRowsProp = null;
Boolean multiTenantProp = null;
Boolean disableWALProp = null;
@@ -2785,7 +2942,7 @@ public class MetaDataClient {
if (familyName!=null) {
try {
PColumnFamily columnFamily = table.getColumnFamily(familyName);
- columnFamily.getColumn(columnName);
+ columnFamily.getPColumnForColumnName(columnName);
if (!ifNotExists) {
throw new ColumnAlreadyExistsException(schemaName, tableName, columnName);
}
@@ -2796,7 +2953,7 @@ public class MetaDataClient {
}
else {
try {
- table.getColumn(columnName);
+ table.getPColumnForColumnName(columnName);
if (!ifNotExists) {
throw new ColumnAlreadyExistsException(schemaName, tableName, columnName);
}
@@ -2851,7 +3008,8 @@ public class MetaDataClient {
ColumnResolver resolver = FromCompiler.getResolver(namedTableNode, connection);
table = resolver.getTables().get(0).getTable();
int nIndexes = table.getIndexes().size();
- int nNewColumns = columnDefs.size();
+ int numCols = columnDefs.size();
+ int nNewColumns = numCols;
List<Mutation> tableMetaData = Lists.newArrayListWithExpectedSize((1 + nNewColumns) * (nIndexes + 1));
List<Mutation> columnMetaData = Lists.newArrayListWithExpectedSize(nNewColumns * (nIndexes + 1));
if (logger.isDebugEnabled()) {
@@ -2952,11 +3110,15 @@ public class MetaDataClient {
Long timeStamp = TransactionUtil.getTableTimestamp(connection, table.isTransactional() || nonTxToTx);
int numPkColumnsAdded = 0;
- List<PColumn> columns = Lists.newArrayListWithExpectedSize(columnDefs.size());
+ List<PColumn> columns = Lists.newArrayListWithExpectedSize(numCols);
Set<String> colFamiliesForPColumnsToBeAdded = new LinkedHashSet<>();
Set<String> families = new LinkedHashSet<>();
- if (columnDefs.size() > 0 ) {
+ PTable tableForCQCounters = tableType == PTableType.VIEW ? PhoenixRuntime.getTable(connection, table.getPhysicalName().getString()) : table;;
+ EncodedCQCounter cqCounterToUse = tableForCQCounters.getEncodedCQCounter();
+ Map<String, Integer> changedCqCounters = new HashMap<>(numCols);
+ if (numCols > 0 ) {
StatementContext context = new StatementContext(new PhoenixStatement(connection), resolver);
+ //TODO: samarth should these be guarded by storage scheme check. Better to have the map always available. immutable empty for views and non encoded.
try (PreparedStatement colUpsert = connection.prepareStatement(INSERT_COLUMN_ALTER_TABLE)) {
short nextKeySeq = SchemaUtil.getMaxKeySeq(table);
for( ColumnDef colDef : columnDefs) {
@@ -2979,11 +3141,32 @@ public class MetaDataClient {
if (!colDef.validateDefault(context, null)) {
colDef = new ColumnDef(colDef, null); // Remove DEFAULT as it's not necessary
}
- PColumn column = newColumn(position++, colDef, PrimaryKeyConstraint.EMPTY, table.getDefaultFamilyName() == null ? null : table.getDefaultFamilyName().getString(), true);
+ Integer encodedCQ = null;
+ if (!colDef.isPK()) {
+ String colDefFamily = colDef.getColumnDefName().getFamilyName();
+ String familyName = null;
+ StorageScheme storageScheme = table.getStorageScheme();
+ String defaultColumnFamily = tableForCQCounters.getDefaultFamilyName() != null && !Strings.isNullOrEmpty(tableForCQCounters.getDefaultFamilyName().getString()) ?
+ tableForCQCounters.getDefaultFamilyName().getString() : DEFAULT_COLUMN_FAMILY;
+ if (table.getType() == PTableType.INDEX && table.getIndexType() == IndexType.LOCAL) {
+ defaultColumnFamily = QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX + defaultColumnFamily;
+ }
+ if (storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ familyName = colDefFamily != null ? colDefFamily : defaultColumnFamily;
+ } else {
+ familyName = defaultColumnFamily;
+ }
+ encodedCQ = cqCounterToUse.getNextQualifier(familyName);
+ if (cqCounterToUse.increment(familyName)) {
+ changedCqCounters.put(familyName,
+ cqCounterToUse.getNextQualifier(familyName));
+ }
+ }
+ PColumn column = newColumn(position++, colDef, PrimaryKeyConstraint.EMPTY, table.getDefaultFamilyName() == null ? null : table.getDefaultFamilyName().getString(), true, encodedCQ);
columns.add(column);
String pkName = null;
Short keySeq = null;
-
+
// TODO: support setting properties on other families?
if (column.getFamilyName() == null) {
++numPkColumnsAdded;
@@ -2995,13 +3178,13 @@ public class MetaDataClient {
colFamiliesForPColumnsToBeAdded.add(column.getFamilyName() == null ? null : column.getFamilyName().getString());
addColumnMutation(schemaName, tableName, column, colUpsert, null, pkName, keySeq, table.getBucketNum() != null);
}
-
+
// Add any new PK columns to end of index PK
- if (numPkColumnsAdded>0) {
+ if (numPkColumnsAdded > 0) {
// create PK column list that includes the newly created columns
List<PColumn> pkColumns = Lists.newArrayListWithExpectedSize(table.getPKColumns().size()+numPkColumnsAdded);
pkColumns.addAll(table.getPKColumns());
- for (int i=0; i<columnDefs.size(); ++i) {
+ for (int i=0; i<numCols; ++i) {
if (columnDefs.get(i).isPK()) {
pkColumns.add(columns.get(i));
}
@@ -3010,14 +3193,14 @@ public class MetaDataClient {
for (PTable index : table.getIndexes()) {
short nextIndexKeySeq = SchemaUtil.getMaxKeySeq(index);
int indexPosition = index.getColumns().size();
- for (int i=0; i<columnDefs.size(); ++i) {
+ for (int i=0; i<numCols; ++i) {
ColumnDef colDef = columnDefs.get(i);
if (colDef.isPK()) {
PDataType indexColDataType = IndexUtil.getIndexColumnDataType(colDef.isNull(), colDef.getDataType());
ColumnName indexColName = ColumnName.caseSensitiveColumnName(IndexUtil.getIndexColumnName(null, colDef.getColumnDefName().getColumnName()));
Expression expression = new RowKeyColumnExpression(columns.get(i), new RowKeyValueAccessor(pkColumns, ++pkSlotPosition));
ColumnDef indexColDef = FACTORY.columnDef(indexColName, indexColDataType.getSqlTypeName(), colDef.isNull(), colDef.getMaxLength(), colDef.getScale(), true, colDef.getSortOrder(), expression.toString(), colDef.isRowTimestamp());
- PColumn indexColumn = newColumn(indexPosition++, indexColDef, PrimaryKeyConstraint.EMPTY, null, true);
+ PColumn indexColumn = newColumn(indexPosition++, indexColDef, PrimaryKeyConstraint.EMPTY, null, true, null);
addColumnMutation(schemaName, index.getTableName().getString(), indexColumn, colUpsert, index.getParentTableName().getString(), index.getPKName() == null ? null : index.getPKName().getString(), ++nextIndexKeySeq, index.getBucketNum() != null);
}
}
@@ -3053,6 +3236,7 @@ public class MetaDataClient {
tableMetaData.addAll(connection.getMutationState().toMutations(timeStamp).next().getSecond());
connection.rollback();
}
+
long seqNum = table.getSequenceNumber();
if (changingPhoenixTableProperty || columnDefs.size() > 0) {
seqNum = incrementTableSeqNum(table, tableType, columnDefs.size(), isTransactional, updateCacheFrequency, isImmutableRows,
@@ -3065,6 +3249,33 @@ public class MetaDataClient {
Collections.reverse(tableMetaData);
// Add column metadata afterwards, maintaining the order so columns have more predictable ordinal position
tableMetaData.addAll(columnMetaData);
+ boolean sharedIndex = tableType == PTableType.INDEX && (table.getIndexType() == IndexType.LOCAL || table.getViewIndexId() != null);
+ String tenantIdToUse = connection.getTenantId() != null && sharedIndex ? connection.getTenantId().getString() : null;
+ if (!changedCqCounters.isEmpty()) {
+ PreparedStatement linkStatement;
+ linkStatement = connection.prepareStatement(UPDATE_ENCODED_COLUMN_COUNTER);
+ for (Entry<String, Integer> entry : changedCqCounters.entrySet()) {
+ linkStatement.setString(1, tenantIdToUse);
+ linkStatement.setString(2, tableForCQCounters.getSchemaName().getString());
+ linkStatement.setString(3, tableForCQCounters.getTableName().getString());
+ linkStatement.setString(4, entry.getKey());
+ linkStatement.setInt(5, entry.getValue());
+ linkStatement.execute();
+ }
+
+ // When a view adds its own columns, then we need to increase the sequence number of the base table
+ // too since we want clients to get the latest PTable of the base table.
+ if (tableType == VIEW) {
+ PreparedStatement incrementStatement = connection.prepareStatement(INCREMENT_SEQ_NUM);
+ incrementStatement.setString(1, null); //TODO: samarth verify that tenant id should be null here
+ incrementStatement.setString(2, tableForCQCounters.getSchemaName().getString());
+ incrementStatement.setString(3, tableForCQCounters.getTableName().getString());
+ incrementStatement.setLong(4, tableForCQCounters.getSequenceNumber() + 1);
+ incrementStatement.execute();
+ }
+ tableMetaData.addAll(connection.getMutationState().toMutations(timeStamp).next().getSecond());
+ connection.rollback();
+ }
byte[] family = families.size() > 0 ? families.iterator().next().getBytes() : null;
@@ -3094,7 +3305,6 @@ public class MetaDataClient {
}
return new MutationState(0,connection);
}
-
// Only update client side cache if we aren't adding a PK column to a table with indexes or
// transitioning a table from non transactional to transactional.
// We could update the cache manually then too, it'd just be a pain.
@@ -3102,6 +3312,7 @@ public class MetaDataClient {
long resolvedTimeStamp = TransactionUtil.getResolvedTime(connection, result);
if (table.getIndexes().isEmpty() || (numPkColumnsAdded==0 && !nonTxToTx)) {
connection.addTable(result.getTable(), resolvedTimeStamp);
+ table = result.getTable();
} else if (updateCacheFrequency != null) {
// Force removal from cache as the update cache frequency has changed
// Note that clients outside this JVM won't be affected.
@@ -3278,23 +3489,23 @@ public class MetaDataClient {
Long timeStamp = table.isTransactional() ? tableRef.getTimeStamp() : null;
for (PTable index : table.getIndexes()) {
IndexMaintainer indexMaintainer = index.getIndexMaintainer(table, connection);
- // get the columns required for the index pk
- Set<ColumnReference> indexColumns = indexMaintainer.getIndexedColumns();
- // get the covered columns
- Set<ColumnReference> coveredColumns = indexMaintainer.getCoveredColumns();
+ // get the covered columns
List<PColumn> indexColumnsToDrop = Lists.newArrayListWithExpectedSize(columnRefs.size());
+ Set<Pair<String, String>> indexedColsInfo = indexMaintainer.getIndexedColumnInfo();
+ Set<Pair<String, String>> coveredColsInfo = indexMaintainer.getCoveredColumnInfo();
for(PColumn columnToDrop : tableColumnsToDrop) {
- ColumnReference columnToDropRef = new ColumnReference(columnToDrop.getFamilyName().getBytes(), columnToDrop.getName().getBytes());
- // if the columns being dropped is indexed and the physical index table is not shared
- if (indexColumns.contains(columnToDropRef)) {
- if (index.getViewIndexId()==null)
+ Pair<String, String> columnToDropInfo = new Pair<>(columnToDrop.getFamilyName().getString(), columnToDrop.getName().getString());
+ boolean isColumnIndexed = indexedColsInfo.contains(columnToDropInfo);
+ if (isColumnIndexed) {
+ if (index.getViewIndexId() == null) {
indexesToDrop.add(new TableRef(index));
+ }
connection.removeTable(tenantId, SchemaUtil.getTableName(schemaName, index.getName().getString()), index.getParentName() == null ? null : index.getParentName().getString(), index.getTimeStamp());
removedIndexTableOrColumn = true;
}
- else if (coveredColumns.contains(columnToDropRef)) {
+ else if (coveredColsInfo.contains(columnToDropInfo)) {
String indexColumnName = IndexUtil.getIndexColumnName(columnToDrop);
- PColumn indexColumn = index.getColumn(indexColumnName);
+ PColumn indexColumn = index.getPColumnForColumnName(indexColumnName);
indexColumnsToDrop.add(indexColumn);
// add the index column to be dropped so that we actually delete the column values
columnsToDrop.add(new ColumnRef(new TableRef(index), indexColumn.getPosition()));
@@ -3384,13 +3595,15 @@ public class MetaDataClient {
// so we need to issue deletes markers for all the rows of the index
final List<TableRef> tableRefsToDrop = Lists.newArrayList();
Map<String, List<TableRef>> tenantIdTableRefMap = Maps.newHashMap();
- if (result.getSharedTablesToDelete()!=null) {
+ if (result.getSharedTablesToDelete() != null) {
for (SharedTableState sharedTableState : result.getSharedTablesToDelete()) {
+ //TODO: samarth I don't think we really care about storage scheme and cq counter at this point.
+ //Probably worthy to change the constructor here to not expect the two arguments.
PTableImpl viewIndexTable = new PTableImpl(sharedTableState.getTenantId(),
sharedTableState.getSchemaName(), sharedTableState.getTableName(), ts,
table.getColumnFamilies(), sharedTableState.getColumns(),
sharedTableState.getPhysicalNames(), sharedTableState.getViewIndexId(),
- table.isMultiTenant(), table.isNamespaceMapped());
+ table.isMultiTenant(), table.isNamespaceMapped(), table.getStorageScheme(), table.getEncodedCQCounter());
TableRef indexTableRef = new TableRef(viewIndexTable);
PName indexTableTenantId = sharedTableState.getTenantId();
if (indexTableTenantId==null) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java
index 0f5fa44..978ded7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java
@@ -27,7 +27,7 @@ package org.apache.phoenix.schema;
public interface PColumn extends PDatum {
/**
- * @return the name of the column qualifier
+ * @return the name of the column
*/
PName getName();
@@ -60,4 +60,6 @@ public interface PColumn extends PDatum {
boolean isRowTimestamp();
boolean isDynamic();
+
+ Integer getEncodedColumnQualifier();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java
index 24da14d..c4c383e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java
@@ -39,16 +39,22 @@ public interface PColumnFamily {
Collection<PColumn> getColumns();
/**
- * @return The PColumn for the specified column qualifier.
+ * @return The PColumn for the specified column name.
* @throws ColumnNotFoundException if the column cannot be found
*/
- PColumn getColumn(byte[] qualifier) throws ColumnNotFoundException;
+ PColumn getPColumnForColumnNameBytes(byte[] columnNameBytes) throws ColumnNotFoundException;
/**
- * @return The PColumn for the specified column qualifier.
+ * @return The PColumn for the specified column name.
* @throws ColumnNotFoundException if the column cannot be found
*/
- PColumn getColumn(String name) throws ColumnNotFoundException;
+ PColumn getPColumnForColumnName(String columnName) throws ColumnNotFoundException;
int getEstimatedSize();
+
+ /**
+ * @return The PColumn for the specified column qualifier.
+ * @throws ColumnNotFoundException if the column cannot be found
+ */
+ PColumn getPColumnForColumnQualifier(byte[] cq) throws ColumnNotFoundException;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
index 2e29656..c175aa2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.Map;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.SizedUtil;
import com.google.common.base.Preconditions;
@@ -31,8 +32,9 @@ import com.google.common.collect.ImmutableSortedMap;
public class PColumnFamilyImpl implements PColumnFamily {
private final PName name;
private final List<PColumn> columns;
- private final Map<String, PColumn> columnByString;
- private final Map<byte[], PColumn> columnByBytes;
+ private final Map<String, PColumn> columnNamesByStrings;
+ private final Map<byte[], PColumn> columnNamesByBytes;
+ private final Map<byte[], PColumn> encodedColumnQualifersByBytes;
private final int estimatedSize;
@Override
@@ -40,22 +42,27 @@ public class PColumnFamilyImpl implements PColumnFamily {
return estimatedSize;
}
- public PColumnFamilyImpl(PName name, List<PColumn> columns) {
+ public PColumnFamilyImpl(PName name, List<PColumn> columns, boolean useEncodedColumnNames) {
Preconditions.checkNotNull(name);
// Include guidePosts also in estimating the size
long estimatedSize = SizedUtil.OBJECT_SIZE + SizedUtil.POINTER_SIZE * 5 + SizedUtil.INT_SIZE + name.getEstimatedSize() +
SizedUtil.sizeOfMap(columns.size()) * 2 + SizedUtil.sizeOfArrayList(columns.size());
this.name = name;
this.columns = ImmutableList.copyOf(columns);
- ImmutableMap.Builder<String, PColumn> columnByStringBuilder = ImmutableMap.builder();
- ImmutableSortedMap.Builder<byte[], PColumn> columnByBytesBuilder = ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR);
+ ImmutableMap.Builder<String, PColumn> columnNamesByStringBuilder = ImmutableMap.builder();
+ ImmutableSortedMap.Builder<byte[], PColumn> columnNamesByBytesBuilder = ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR);
+ ImmutableSortedMap.Builder<byte[], PColumn> encodedColumnQualifiersByBytesBuilder = ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR);
for (PColumn column : columns) {
estimatedSize += column.getEstimatedSize();
- columnByBytesBuilder.put(column.getName().getBytes(), column);
- columnByStringBuilder.put(column.getName().getString(), column);
+ columnNamesByBytesBuilder.put(column.getName().getBytes(), column);
+ columnNamesByStringBuilder.put(column.getName().getString(), column);
+ if (useEncodedColumnNames && column.getEncodedColumnQualifier() != null) {
+ encodedColumnQualifiersByBytesBuilder.put(EncodedColumnsUtil.getEncodedColumnQualifier(column), column);
+ }
}
- this.columnByBytes = columnByBytesBuilder.build();
- this.columnByString = columnByStringBuilder.build();
+ this.columnNamesByBytes = columnNamesByBytesBuilder.build();
+ this.columnNamesByStrings = columnNamesByStringBuilder.build();
+ this.encodedColumnQualifersByBytes = encodedColumnQualifiersByBytesBuilder.build();
this.estimatedSize = (int)estimatedSize;
}
@@ -70,19 +77,32 @@ public class PColumnFamilyImpl implements PColumnFamily {
}
@Override
- public PColumn getColumn(byte[] qualifier) throws ColumnNotFoundException {
- PColumn column = columnByBytes.get(qualifier);
+ public PColumn getPColumnForColumnNameBytes(byte[] columnNameBytes) throws ColumnNotFoundException {
+ PColumn column = columnNamesByBytes.get(columnNameBytes);
if (column == null) {
- throw new ColumnNotFoundException(Bytes.toString(qualifier));
+ throw new ColumnNotFoundException(Bytes.toString(columnNameBytes));
}
return column;
}
@Override
- public PColumn getColumn(String name) throws ColumnNotFoundException {
- PColumn column = columnByString.get(name);
+ public PColumn getPColumnForColumnName(String columnName) throws ColumnNotFoundException {
+ PColumn column = columnNamesByStrings.get(columnName);
if (column == null) {
- throw new ColumnNotFoundException(name);
+ throw new ColumnNotFoundException(columnName);
+ }
+ return column;
+ }
+
+ @Override
+ public PColumn getPColumnForColumnQualifier(byte[] cq) throws ColumnNotFoundException {
+ Preconditions.checkNotNull(cq);
+ PColumn column = encodedColumnQualifersByBytes.get(cq);
+ if (column == null) {
+ // For tables with non-encoded column names, column qualifiers are
+ // column name bytes. Also dynamic columns don't have encoded column
+ // qualifiers. So they could be found in the column name by bytes map.
+ return getPColumnForColumnNameBytes(cq);
}
return column;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 ca827d8..e6f8b71 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
@@ -40,6 +40,7 @@ public class PColumnImpl implements PColumn {
private String expressionStr;
private boolean isRowTimestamp;
private boolean isDynamic;
+ private Integer columnQualifier;
public PColumnImpl() {
}
@@ -51,13 +52,13 @@ public class PColumnImpl implements PColumn {
Integer scale,
boolean nullable,
int position,
- SortOrder sortOrder, Integer arrSize, byte[] viewConstant, boolean isViewReferenced, String expressionStr, boolean isRowTimestamp, boolean isDynamic) {
- init(name, familyName, dataType, maxLength, scale, nullable, position, sortOrder, arrSize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, isDynamic);
+ SortOrder sortOrder, Integer arrSize, byte[] viewConstant, boolean isViewReferenced, String expressionStr, boolean isRowTimestamp, boolean isDynamic, Integer columnQualifier) {
+ init(name, familyName, dataType, maxLength, scale, nullable, position, sortOrder, arrSize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, isDynamic, columnQualifier);
}
public PColumnImpl(PColumn column, int position) {
this(column.getName(), column.getFamilyName(), column.getDataType(), column.getMaxLength(),
- column.getScale(), column.isNullable(), position, column.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(), column.isDynamic());
+ column.getScale(), column.isNullable(), position, column.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(), column.isDynamic(), column.getEncodedColumnQualifier());
}
private void init(PName name,
@@ -69,7 +70,7 @@ public class PColumnImpl implements PColumn {
int position,
SortOrder sortOrder,
Integer arrSize,
- byte[] viewConstant, boolean isViewReferenced, String expressionStr, boolean isRowTimestamp, boolean isDynamic) {
+ byte[] viewConstant, boolean isViewReferenced, String expressionStr, boolean isRowTimestamp, boolean isDynamic, Integer columnQualifier) {
Preconditions.checkNotNull(sortOrder);
this.dataType = dataType;
if (familyName == null) {
@@ -94,6 +95,7 @@ public class PColumnImpl implements PColumn {
this.expressionStr = expressionStr;
this.isRowTimestamp = isRowTimestamp;
this.isDynamic = isDynamic;
+ this.columnQualifier = columnQualifier;
}
@Override
@@ -205,6 +207,11 @@ public class PColumnImpl implements PColumn {
public boolean isDynamic() {
return isDynamic;
}
+
+ @Override
+ public Integer getEncodedColumnQualifier() {
+ return columnQualifier;
+ }
/**
* Create a PColumn instance from PBed PColumn instance
@@ -251,8 +258,12 @@ public class PColumnImpl implements PColumn {
if (column.hasIsDynamic()) {
isDynamic = column.getIsDynamic();
}
+ Integer columnQualifier = null;
+ if (column.hasColumnQualifier()) {
+ columnQualifier = column.getColumnQualifier();
+ }
return new PColumnImpl(columnName, familyName, dataType, maxLength, scale, nullable, position, sortOrder,
- arraySize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, isDynamic);
+ arraySize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, isDynamic, columnQualifier);
}
public static PTableProtos.PColumn toProto(PColumn column) {
@@ -283,6 +294,9 @@ public class PColumnImpl implements PColumn {
builder.setExpression(column.getExpressionStr());
}
builder.setIsRowTimestamp(column.isRowTimestamp());
+ if (column.getEncodedColumnQualifier() != null) {
+ builder.setColumnQualifier(column.getEncodedColumnQualifier());
+ }
return builder.build();
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
index 6ca38cc..0263b09 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
@@ -199,7 +199,7 @@ public class PMetaDataImpl implements PMetaData {
if (familyName == null) {
column = table.getPKColumn(columnToRemove.getName().getString());
} else {
- column = table.getColumnFamily(familyName).getColumn(columnToRemove.getName().getString());
+ column = table.getColumnFamily(familyName).getPColumnForColumnName(columnToRemove.getName().getString());
}
int positionOffset = 0;
int position = column.getPosition();
@@ -214,7 +214,7 @@ public class PMetaDataImpl implements PMetaData {
// Update position of columns that follow removed column
for (int i = position+1; i < oldColumns.size(); i++) {
PColumn oldColumn = oldColumns.get(i);
- PColumn newColumn = new PColumnImpl(oldColumn.getName(), oldColumn.getFamilyName(), oldColumn.getDataType(), oldColumn.getMaxLength(), oldColumn.getScale(), oldColumn.isNullable(), i-1+positionOffset, oldColumn.getSortOrder(), oldColumn.getArraySize(), oldColumn.getViewConstant(), oldColumn.isViewReferenced(), oldColumn.getExpressionStr(), oldColumn.isRowTimestamp(), oldColumn.isDynamic());
+ PColumn newColumn = new PColumnImpl(oldColumn.getName(), oldColumn.getFamilyName(), oldColumn.getDataType(), oldColumn.getMaxLength(), oldColumn.getScale(), oldColumn.isNullable(), i-1+positionOffset, oldColumn.getSortOrder(), oldColumn.getArraySize(), oldColumn.getViewConstant(), oldColumn.isViewReferenced(), oldColumn.getExpressionStr(), oldColumn.isRowTimestamp(), oldColumn.isDynamic(), oldColumn.getEncodedColumnQualifier());
columns.add(newColumn);
}
[28/42] phoenix git commit: Fix test failure
Posted by td...@apache.org.
Fix test failure
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/9eb690f6
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/9eb690f6
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/9eb690f6
Branch: refs/heads/encodecolumns2
Commit: 9eb690f6bcdc4f3810b59d9d666a972cc0040e9e
Parents: 2881091
Author: Samarth <sa...@salesforce.com>
Authored: Tue Nov 8 12:26:45 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../phoenix/compile/CreateTableCompiler.java | 2 +-
.../expression/ArrayColumnExpression.java | 27 +++++++++++---------
.../expression/KeyValueColumnExpression.java | 2 +-
3 files changed, 17 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/9eb690f6/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
index c986c28..fae53e2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
@@ -329,7 +329,7 @@ public class CreateTableCompiler {
@Override
public Boolean visit(ArrayColumnExpression node) {
try {
- this.position = table.getColumnFamily(node.getColumnFamily()).getPColumnForColumnQualifier(node.getEncodedColumnQualifier()).getPosition();
+ this.position = table.getColumnFamily(node.getColumnFamily()).getPColumnForColumnQualifier(node.getPositionInArray()).getPosition();
} catch (SQLException e) {
throw new RuntimeException(e);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/9eb690f6/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
index f4616da..0b5e5d7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
@@ -43,21 +43,21 @@ import org.apache.phoenix.util.SchemaUtil;
*/
public class ArrayColumnExpression extends KeyValueColumnExpression {
- private int encodedCQ;
- private String displayName;
+ private int positionInArray;
+ private String arrayColDisplayName;
public ArrayColumnExpression() {
}
public ArrayColumnExpression(PDatum column, byte[] cf, int encodedCQ) {
super(column, cf, cf);
- this.encodedCQ = encodedCQ;
+ this.positionInArray = encodedCQ;
}
public ArrayColumnExpression(PColumn column, String displayName, boolean encodedColumnName) {
super(column, column.getFamilyName().getBytes(), column.getFamilyName().getBytes());
- this.displayName = SchemaUtil.getColumnDisplayName(column.getFamilyName().getString(), column.getName().getString());
- this.encodedCQ = column.getEncodedColumnQualifier();
+ this.arrayColDisplayName = displayName;
+ this.positionInArray = column.getEncodedColumnQualifier();
}
@Override
@@ -70,20 +70,20 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
// 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, encodedCQ, PVarbinary.INSTANCE, null);
+ PArrayDataType.positionAtArrayElement(ptr, positionInArray, PVarbinary.INSTANCE, null);
return true;
}
@Override
public void readFields(DataInput input) throws IOException {
super.readFields(input);
- encodedCQ = WritableUtils.readVInt(input);
+ positionInArray = WritableUtils.readVInt(input);
}
@Override
public void write(DataOutput output) throws IOException {
super.write(output);
- WritableUtils.writeVInt(output, encodedCQ);
+ WritableUtils.writeVInt(output, positionInArray);
}
public KeyValueColumnExpression getKeyValueExpression() {
@@ -118,16 +118,19 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
public PDataType getDataType() {
return datatype;
}
- }, getColumnFamily(), getEncodedColumnQualifier());
+ }, getColumnFamily(), getPositionInArray());
}
@Override
public String toString() {
- return displayName;
+ if (arrayColDisplayName == null) {
+ arrayColDisplayName = SchemaUtil.getColumnDisplayName(getColumnFamily(), getColumnQualifier());
+ }
+ return arrayColDisplayName;
}
- public byte[] getEncodedColumnQualifier() {
- return EncodedColumnsUtil.getEncodedColumnQualifier(encodedCQ);
+ public byte[] getPositionInArray() {
+ return EncodedColumnsUtil.getEncodedColumnQualifier(positionInArray);
}
@Override
http://git-wip-us.apache.org/repos/asf/phoenix/blob/9eb690f6/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
index 6170418..5cd7433 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
@@ -42,7 +42,7 @@ import org.apache.phoenix.util.SchemaUtil;
public class KeyValueColumnExpression extends ColumnExpression {
private byte[] cf;
private byte[] cq;
- private String displayName; // client-side only. TODO: samarth see what can you do for encoded column names.
+ private String displayName; // client-side only.
public KeyValueColumnExpression() {
}
[17/42] phoenix git commit: Fail-fast iterators for
EncodedColumnQualifierCellsList. Use list iterators instead of get(index) for
navigating lists. Use HBase bytes utility for encoded column names. Fix test
failures for immutable tables and indexes.
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index 5feedb1..5409554 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -304,11 +304,11 @@ public class TestUtil {
}
public static Expression constantComparison(CompareOp op, PColumn c, Object o) {
- return new ComparisonExpression(Arrays.<Expression>asList(new KeyValueColumnExpression(c), LiteralExpression.newConstant(o)), op);
+ return new ComparisonExpression(Arrays.<Expression>asList(new KeyValueColumnExpression(c, true), LiteralExpression.newConstant(o)), op);
}
public static Expression kvColumn(PColumn c) {
- return new KeyValueColumnExpression(c);
+ return new KeyValueColumnExpression(c, true);
}
public static Expression pkColumn(PColumn c, List<PColumn> columns) {
@@ -610,7 +610,7 @@ public class TestUtil {
}
public static void analyzeTable(Connection conn, String tableName) throws IOException, SQLException {
- analyzeTable(conn, tableName, false);
+ analyzeTable(conn, tableName, false);
}
public static void analyzeTable(Connection conn, String tableName, boolean transactional) throws IOException, SQLException {
@@ -652,17 +652,17 @@ public class TestUtil {
Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * MILLIS_IN_DAY);
stmt.setDate(6, date);
}
-
+
public static void validateRowKeyColumns(ResultSet rs, int i) throws SQLException {
- assertTrue(rs.next());
- assertEquals(rs.getString(1), "varchar" + String.valueOf(i));
- assertEquals(rs.getString(2), "char" + String.valueOf(i));
- assertEquals(rs.getInt(3), i);
- assertEquals(rs.getInt(4), i);
- assertEquals(rs.getBigDecimal(5), new BigDecimal(i*0.5d));
- Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * MILLIS_IN_DAY);
- assertEquals(rs.getDate(6), date);
- }
+ assertTrue(rs.next());
+ assertEquals(rs.getString(1), "varchar" + String.valueOf(i));
+ assertEquals(rs.getString(2), "char" + String.valueOf(i));
+ assertEquals(rs.getInt(3), i);
+ assertEquals(rs.getInt(4), i);
+ assertEquals(rs.getBigDecimal(5), new BigDecimal(i*0.5d));
+ Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * MILLIS_IN_DAY);
+ assertEquals(rs.getDate(6), date);
+ }
public static String getTableName(Boolean mutable, Boolean transactional) {
StringBuilder tableNameBuilder = new StringBuilder(DEFAULT_DATA_TABLE_NAME);
@@ -694,7 +694,7 @@ public class TestUtil {
@Override
public SortOrder getSortOrder() {
- return SortOrder.getDefault();
+ return SortOrder.getDefault();
}
@Override
@@ -720,11 +720,15 @@ public class TestUtil {
public boolean isRowTimestamp() {
return false;
}
- @Override
- public boolean isDynamic() {
- return false;
- }
- })), null);
+ @Override
+ public boolean isDynamic() {
+ return false;
+ }
+ @Override
+ public Integer getEncodedColumnQualifier() {
+ return null;
+ }
+ }, false)), null);
aggregationManager.setAggregators(new ClientAggregators(Collections.<SingleAggregateFunction>singletonList(func), 1));
ClientAggregators aggregators = aggregationManager.getAggregators();
return aggregators;
@@ -821,4 +825,3 @@ public class TestUtil {
}
}
-
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-protocol/src/main/PTable.proto
----------------------------------------------------------------------
diff --git a/phoenix-protocol/src/main/PTable.proto b/phoenix-protocol/src/main/PTable.proto
index a16263f..d5df2f3 100644
--- a/phoenix-protocol/src/main/PTable.proto
+++ b/phoenix-protocol/src/main/PTable.proto
@@ -47,6 +47,7 @@ message PColumn {
optional string expression = 12;
optional bool isRowTimestamp = 13;
optional bool isDynamic = 14;
+ optional int32 columnQualifier = 15;
}
message PTableStats {
@@ -95,4 +96,11 @@ message PTable {
optional string autoParititonSeqName = 31;
optional bool isAppendOnlySchema = 32;
optional bytes parentNameBytes = 33;
+ optional bytes storageScheme = 34;
+ repeated EncodedCQCounter encodedCQCounters = 35;
+}
+
+message EncodedCQCounter {
+ required string colFamily = 1;
+ required int32 counter = 2;
}
[07/42] phoenix git commit: PHOENIX-3537 Clients not able to resolve
sequences when the SYSTEM.SEQUENCE table is salted
Posted by td...@apache.org.
PHOENIX-3537 Clients not able to resolve sequences when the SYSTEM.SEQUENCE table is salted
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e966e26a
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e966e26a
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e966e26a
Branch: refs/heads/encodecolumns2
Commit: e966e26ad90ef80ee2c9a7f074d5389baa1520a7
Parents: 9b06c60
Author: Samarth <sa...@salesforce.com>
Authored: Thu Dec 15 15:41:20 2016 -0800
Committer: Samarth <sa...@salesforce.com>
Committed: Thu Dec 15 15:41:20 2016 -0800
----------------------------------------------------------------------
.../org/apache/phoenix/query/ConnectionQueryServicesImpl.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e966e26a/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 c8d42d9..c8cd04d 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
@@ -2461,7 +2461,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
private void createOtherSystemTables(PhoenixConnection metaConnection) throws SQLException {
try {
metaConnection.createStatement().execute(QueryConstants.CREATE_SEQUENCE_METADATA);
- } catch (TableAlreadyExistsException ignore) {}
+ } catch (TableAlreadyExistsException e) {
+ nSequenceSaltBuckets = getSaltBuckets(e);
+ }
try {
metaConnection.createStatement().execute(QueryConstants.CREATE_STATS_TABLE_METADATA);
} catch (TableAlreadyExistsException ignore) {}
[38/42] phoenix git commit: PHOENIX-3445 Add a CREATE IMMUTABLE TABLE
construct to make immutable tables more explicit
Posted by td...@apache.org.
PHOENIX-3445 Add a CREATE IMMUTABLE TABLE construct to make immutable tables more explicit
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/be6861c8
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/be6861c8
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/be6861c8
Branch: refs/heads/encodecolumns2
Commit: be6861c8963d8ee05caa4c5aabc78fd05bd59605
Parents: 01ef5d5
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Mon Nov 28 17:08:27 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:03:27 2016 -0800
----------------------------------------------------------------------
.../apache/phoenix/end2end/AlterTableIT.java | 40 +++++++++++++++++++-
.../phoenix/end2end/AlterTableWithViewsIT.java | 4 ++
.../apache/phoenix/schema/MetaDataClient.java | 4 ++
3 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/be6861c8/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index 173a3be..3084a92 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -2502,6 +2502,44 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
assertFalse(rs.next());
}
}
-
+
+ @Test
+ public void testAlterImmutableRowsPropertyForOneCellPerKeyValueColumnStorageScheme() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+ +"ID VARCHAR(15) NOT NULL,\n"
+ +"CREATED_DATE DATE,\n"
+ +"CREATION_TIME BIGINT,\n"
+ +"CONSTRAINT PK PRIMARY KEY (ID))";
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute(ddl);
+ assertImmutableRows(conn, dataTableFullName, false);
+ ddl = "ALTER TABLE " + dataTableFullName + " SET IMMUTABLE_ROWS = true";
+ conn.createStatement().execute(ddl);
+ assertImmutableRows(conn, dataTableFullName, true);
+ }
+
+ @Test
+ public void testAlterImmutableRowsPropertyForOneCellPerColumnFamilyStorageScheme() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+ +"ID VARCHAR(15) NOT NULL,\n"
+ +"CREATED_DATE DATE,\n"
+ +"CREATION_TIME BIGINT,\n"
+ +"CONSTRAINT PK PRIMARY KEY (ID)) IMMUTABLE_ROWS=true";
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute(ddl);
+ assertImmutableRows(conn, dataTableFullName, true);
+ try {
+ ddl = "ALTER TABLE " + dataTableFullName + " SET IMMUTABLE_ROWS = false";
+ conn.createStatement().execute(ddl);
+ fail();
+ }
+ catch(SQLException e) {
+ assertEquals(SQLExceptionCode.CANNOT_ALTER_IMMUTABLE_ROWS_PROPERTY.getErrorCode(), e.getErrorCode());
+ }
+ assertImmutableRows(conn, dataTableFullName, true);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/be6861c8/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
index e0bbb10..310071f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.end2end;
import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE;
import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -32,6 +33,7 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Properties;
import org.apache.commons.lang.ArrayUtils;
import org.apache.hadoop.hbase.client.HTableInterface;
@@ -45,6 +47,8 @@ import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.SchemaUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/be6861c8/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 a7144bb..06aa479 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
@@ -3049,6 +3049,10 @@ public class MetaDataClient {
Boolean isImmutableRows = null;
if (isImmutableRowsProp != null) {
if (isImmutableRowsProp.booleanValue() != table.isImmutableRows()) {
+ if (table.getStorageScheme() != StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_IMMUTABLE_ROWS_PROPERTY)
+ .setSchemaName(schemaName).setTableName(tableName).build().buildException();
+ }
isImmutableRows = isImmutableRowsProp;
changingPhoenixTableProperty = true;
}
[36/42] phoenix git commit: PHOENIX-3295 Remove
ReplaceArrayColumnWithKeyValueColumnExpressionVisitor
Posted by td...@apache.org.
PHOENIX-3295 Remove ReplaceArrayColumnWithKeyValueColumnExpressionVisitor
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/aa7450fe
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/aa7450fe
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/aa7450fe
Branch: refs/heads/encodecolumns2
Commit: aa7450fe356c9ad63436fbb4a21e36f5682cd693
Parents: 37836a0
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Tue Nov 22 12:32:34 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../apache/phoenix/compile/WhereCompiler.java | 3 ++-
.../expression/ArrayColumnExpression.java | 28 +++++++++++++-------
.../apache/phoenix/index/IndexMaintainer.java | 11 ++++----
.../apache/phoenix/query/QueryConstants.java | 7 +++--
.../org/apache/phoenix/schema/PTableImpl.java | 4 +--
5 files changed, 32 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/aa7450fe/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 6bb3563..598b433 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -46,6 +46,7 @@ import org.apache.phoenix.parse.ParseNodeFactory;
import org.apache.phoenix.parse.SelectStatement;
import org.apache.phoenix.parse.StatelessTraverseAllParseNodeVisitor;
import org.apache.phoenix.parse.SubqueryParseNode;
+import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.AmbiguousColumnException;
import org.apache.phoenix.schema.ColumnNotFoundException;
import org.apache.phoenix.schema.ColumnRef;
@@ -174,7 +175,7 @@ public class WhereCompiler {
Expression newColumnExpression = ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive());
if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(ref.getColumn())) {
byte[] cq = tableRef.getTable().getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY
- ? ref.getColumn().getFamilyName().getBytes() : EncodedColumnsUtil.getColumnQualifier(ref.getColumn(), tableRef.getTable());
+ ? QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES : EncodedColumnsUtil.getColumnQualifier(ref.getColumn(), tableRef.getTable());
// track the where condition columns. Later we need to ensure the Scan in HRS scans these column CFs
context.addWhereCoditionColumn(ref.getColumn().getFamilyName().getBytes(), cq);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/aa7450fe/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
index 0b5e5d7..f09fb62 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.WritableUtils;
import org.apache.phoenix.compile.CreateTableCompiler.ViewWhereExpressionVisitor;
import org.apache.phoenix.expression.visitor.ExpressionVisitor;
+import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PDatum;
import org.apache.phoenix.schema.SortOrder;
@@ -45,19 +46,22 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
private int positionInArray;
private String arrayColDisplayName;
+ private KeyValueColumnExpression keyValueColumnExpression;
public ArrayColumnExpression() {
}
public ArrayColumnExpression(PDatum column, byte[] cf, int encodedCQ) {
- super(column, cf, cf);
+ super(column, cf, QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES);
this.positionInArray = encodedCQ;
+ setKeyValueExpression();
}
public ArrayColumnExpression(PColumn column, String displayName, boolean encodedColumnName) {
- super(column, column.getFamilyName().getBytes(), column.getFamilyName().getBytes());
+ super(column, column.getFamilyName().getBytes(), QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES);
this.arrayColDisplayName = displayName;
this.positionInArray = column.getEncodedColumnQualifier();
+ setKeyValueExpression();
}
@Override
@@ -77,7 +81,8 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
@Override
public void readFields(DataInput input) throws IOException {
super.readFields(input);
- positionInArray = WritableUtils.readVInt(input);
+ this.positionInArray = WritableUtils.readVInt(input);
+ setKeyValueExpression();
}
@Override
@@ -87,13 +92,16 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
}
public KeyValueColumnExpression getKeyValueExpression() {
- final boolean isNullable = isNullable();
- final SortOrder sortOrder = getSortOrder();
- final Integer scale = getScale();
- final Integer maxLength = getMaxLength();
- final PDataType datatype = getDataType();
- return new KeyValueColumnExpression(new PDatum() {
-
+ return keyValueColumnExpression;
+ }
+
+ private void setKeyValueExpression() {
+ final boolean isNullable = isNullable();
+ final SortOrder sortOrder = getSortOrder();
+ final Integer scale = getScale();
+ final Integer maxLength = getMaxLength();
+ final PDataType datatype = getDataType();
+ this.keyValueColumnExpression = new KeyValueColumnExpression(new PDatum() {
@Override
public boolean isNullable() {
return isNullable;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/aa7450fe/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 e20c994..2ab3730 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
@@ -25,7 +25,6 @@ import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
-import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -938,18 +937,18 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
ImmutableBytesPtr rowKey = new ImmutableBytesPtr(indexRowKey);
if (storeColsInSingleCell) {
// map from index column family to list of pair of index column and data column (for covered columns)
- Map<ByteBuffer, List<Pair<ColumnReference, ColumnReference>>> familyToColListMap = Maps.newHashMap();
+ Map<ImmutableBytesPtr, List<Pair<ColumnReference, ColumnReference>>> familyToColListMap = Maps.newHashMap();
for (ColumnReference ref : this.getCoveredColumns()) {
ColumnReference indexColRef = this.coveredColumnsMap.get(ref);
- ByteBuffer cf = ByteBuffer.wrap(indexColRef.getFamily());
+ ImmutableBytesPtr cf = new ImmutableBytesPtr(indexColRef.getFamily());
if (!familyToColListMap.containsKey(cf)) {
familyToColListMap.put(cf, Lists.<Pair<ColumnReference, ColumnReference>>newArrayList());
}
familyToColListMap.get(cf).add(Pair.newPair(indexColRef, ref));
}
// iterate over each column family and create a byte[] containing all the columns
- for (Entry<ByteBuffer, List<Pair<ColumnReference, ColumnReference>>> entry : familyToColListMap.entrySet()) {
- byte[] columnFamily = entry.getKey().array();
+ for (Entry<ImmutableBytesPtr, List<Pair<ColumnReference, ColumnReference>>> entry : familyToColListMap.entrySet()) {
+ byte[] columnFamily = entry.getKey().copyBytesIfNecessary();
List<Pair<ColumnReference, ColumnReference>> colRefPairs = entry.getValue();
int maxIndex = Integer.MIN_VALUE;
// find the max col qualifier
@@ -1014,7 +1013,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
}
ImmutableBytesPtr colFamilyPtr = new ImmutableBytesPtr(columnFamily);
//this is a little bit of extra work for installations that are running <0.94.14, but that should be rare and is a short-term set of wrappers - it shouldn't kill GC
- put.add(kvBuilder.buildPut(rowKey, colFamilyPtr, colFamilyPtr, ts, ptr));
+ put.add(kvBuilder.buildPut(rowKey, colFamilyPtr, QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES_PTR, ts, ptr));
}
}
else {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/aa7450fe/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 954e78a..fe0d9cb 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
@@ -123,8 +123,6 @@ import org.apache.phoenix.schema.MetaDataSplitPolicy;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.types.PInteger;
-import org.apache.phoenix.util.EncodedColumnsUtil;
/**
@@ -221,6 +219,11 @@ public interface QueryConstants {
public static final byte[] DEFAULT_COLUMN_FAMILY_BYTES = Bytes.toBytes(DEFAULT_COLUMN_FAMILY);
public static final ImmutableBytesPtr DEFAULT_COLUMN_FAMILY_BYTES_PTR = new ImmutableBytesPtr(
DEFAULT_COLUMN_FAMILY_BYTES);
+ // column qualifier of the single key value used to store all columns for the COLUMNS_STORED_IN_SINGLE_CELL storage scheme
+ public static final String SINGLE_KEYVALUE_COLUMN_QUALIFIER = "0";
+ public final static byte[] SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES = Bytes.toBytes(SINGLE_KEYVALUE_COLUMN_QUALIFIER);
+ public static final ImmutableBytesPtr SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES_PTR = new ImmutableBytesPtr(
+ SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES);
public static final String LOCAL_INDEX_COLUMN_FAMILY_PREFIX = "L#";
public static final byte[] LOCAL_INDEX_COLUMN_FAMILY_PREFIX_BYTES = Bytes.toBytes(LOCAL_INDEX_COLUMN_FAMILY_PREFIX);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/aa7450fe/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 e225940..8522c13 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
@@ -914,7 +914,7 @@ public class PTableImpl implements PTable {
arrayExpression.evaluate(new BaseTuple() {}, ptr);
ImmutableBytesPtr colFamilyPtr = new ImmutableBytesPtr(columnFamily);
addQuietly(put, kvBuilder, kvBuilder.buildPut(keyPtr,
- colFamilyPtr, colFamilyPtr, ts, ptr));
+ colFamilyPtr, QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES_PTR, ts, ptr));
}
setValues = put;
}
@@ -988,7 +988,7 @@ public class PTableImpl implements PTable {
ptr.set(byteValue);
type.pad(ptr, maxLength, sortOrder);
removeIfPresent(unsetValues, family, qualifier);
- // store all columns for a given column family in a single cell instead of one column per cell in order to improve write performance
+ // store all columns for a given column family in a single cell instead of one column per cell in order to improve write performance
// we don't need to do anything with unsetValues as it is only used when storeNulls is false, storeNulls is always true when storeColsInSingleCell is true
if (storageScheme == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY) {
columnToValueMap.put(column, ptr.get());
[34/42] phoenix git commit: Fix some more test failures
Posted by td...@apache.org.
Fix some more test failures
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/ffb984f4
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ffb984f4
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ffb984f4
Branch: refs/heads/encodecolumns2
Commit: ffb984f44f4841314ad2ea2328a9d5b284174929
Parents: 4128b56
Author: Samarth <sa...@salesforce.com>
Authored: Wed Nov 23 00:52:04 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../phoenix/iterate/BaseResultIterators.java | 2 +-
.../apache/phoenix/schema/MetaDataClient.java | 1 +
.../java/org/apache/phoenix/schema/PTable.java | 27 ++++++++++++++++-
.../org/apache/phoenix/schema/PTableImpl.java | 3 ++
.../apache/phoenix/util/EncodedColumnsUtil.java | 31 ++++++++++++++++++++
.../org/apache/phoenix/util/SchemaUtil.java | 27 +----------------
6 files changed, 63 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffb984f4/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
index 96797a9..6357e52 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
@@ -279,7 +279,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
}
Map<byte[], NavigableSet<byte[]>> familyMap = scan.getFamilyMap();
- Map<String, Pair<Integer, Integer>> qualifierRanges = SchemaUtil.getQualifierRanges(table);
+ Map<String, Pair<Integer, Integer>> qualifierRanges = EncodedColumnsUtil.getQualifierRanges(table);
for (Entry<byte[], NavigableSet<byte[]>> entry : familyMap.entrySet()) {
if (entry.getValue() != null) {
for (byte[] cq : entry.getValue()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffb984f4/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 d3b9596..8936b9b 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
@@ -2076,6 +2076,7 @@ public class MetaDataClient {
* then we rely on the PTable, with appropriate storage scheme, returned in the MetadataMutationResult to be updated
* in the client cache. If the phoenix table already doesn't exist then the non-encoded column qualifier scheme works
* because we cannot control the column qualifiers that were used when populating the hbase table.
+ * TODO: samarth add a test case for this
*/
if (parent != null) {
storageScheme = parent.getStorageScheme();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffb984f4/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
index b9565a1..1ee2320 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
@@ -213,6 +213,11 @@ public interface PTable extends PMetaDataEntity {
public boolean isEncodeable(String value) {
return true;
}
+
+ @Override
+ public String toString() {
+ return "NON_ENCODED_QUALIFIERS";
+ }
};
public static final QualifierEncodingScheme ONE_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)1, "ONE_BYTE_QUALIFIERS", 255l) {
@Override
@@ -234,6 +239,11 @@ public interface PTable extends PMetaDataEntity {
public boolean isEncodeable(Long value) {
return true;
}
+
+ @Override
+ public String toString() {
+ return "ONE_BYTE_QUALIFIERS";
+ }
};
public static final QualifierEncodingScheme TWO_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)2, "TWO_BYTE_QUALIFIERS", 65535l) {
@Override
@@ -255,6 +265,11 @@ public interface PTable extends PMetaDataEntity {
public boolean isEncodeable(Long value) {
return true;
}
+
+ @Override
+ public String toString() {
+ return "TWO_BYTE_QUALIFIERS";
+ }
};
public static final QualifierEncodingScheme THREE_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)3, "THREE_BYTE_QUALIFIERS", 16777215l) {
@Override
@@ -276,6 +291,11 @@ public interface PTable extends PMetaDataEntity {
public boolean isEncodeable(Long value) {
return true;
}
+
+ @Override
+ public String toString() {
+ return "THREE_BYTE_QUALIFIERS";
+ }
};
public static final QualifierEncodingScheme FOUR_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)4, "FOUR_BYTE_QUALIFIERS", 4294967295l) {
@Override
@@ -297,6 +317,11 @@ public interface PTable extends PMetaDataEntity {
public boolean isEncodeable(Long value) {
return true;
}
+
+ @Override
+ public String toString() {
+ return "FOUR_BYTE_QUALIFIERS";
+ }
};
public static final QualifierEncodingScheme[] schemes = {NON_ENCODED_QUALIFIERS, ONE_BYTE_QUALIFIERS, TWO_BYTE_QUALIFIERS, THREE_BYTE_QUALIFIERS, FOUR_BYTE_QUALIFIERS};
private final byte[] metadataBytes;
@@ -318,7 +343,7 @@ public interface PTable extends PMetaDataEntity {
}
public static QualifierEncodingScheme fromSerializedValue(byte serializedValue) {
- if (serializedValue < 0 || serializedValue > schemes.length - 1) {
+ if (serializedValue < 0 || serializedValue >= schemes.length) {
return null;
}
return schemes[serializedValue];
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffb984f4/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 98c361e..e225940 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
@@ -1414,6 +1414,9 @@ public class PTableImpl implements PTable {
builder.addEncodedCQCounters(cqBuilder.build());
}
}
+ if (table.getEncodingScheme() != null) {
+ builder.setEncodingScheme(ByteStringer.wrap(new byte[]{table.getEncodingScheme().getSerializedMetadataValue()}));
+ }
return builder.build();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffb984f4/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
index e672aa0..c73e5b0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
@@ -18,6 +18,9 @@
package org.apache.phoenix.util;
import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
+
+import java.util.Map;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
@@ -29,6 +32,9 @@ import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+
public class EncodedColumnsUtil {
public static boolean usesEncodedColumnNames(PTable table) {
@@ -136,5 +142,30 @@ public class EncodedColumnsUtil {
public static boolean useQualifierAsIndex(Pair<Integer, Integer> minMaxQualifiers) {
return minMaxQualifiers != null;
}
+
+ public static Map<String, Pair<Integer, Integer>> getQualifierRanges(PTable table) {
+ Preconditions.checkArgument(table.getEncodingScheme() != NON_ENCODED_QUALIFIERS,
+ "Use this method only for tables with encoding scheme "
+ + NON_ENCODED_QUALIFIERS);
+ Map<String, Pair<Integer, Integer>> toReturn = Maps.newHashMapWithExpectedSize(table.getColumns().size());
+ for (PColumn column : table.getColumns()) {
+ if (!SchemaUtil.isPKColumn(column)) {
+ String colFamily = column.getFamilyName().getString();
+ Pair<Integer, Integer> minMaxQualifiers = toReturn.get(colFamily);
+ Integer encodedColumnQualifier = column.getEncodedColumnQualifier();
+ if (minMaxQualifiers == null) {
+ minMaxQualifiers = new Pair<>(encodedColumnQualifier, encodedColumnQualifier);
+ toReturn.put(colFamily, minMaxQualifiers);
+ } else {
+ if (encodedColumnQualifier < minMaxQualifiers.getFirst()) {
+ minMaxQualifiers.setFirst(encodedColumnQualifier);
+ } else if (encodedColumnQualifier > minMaxQualifiers.getSecond()) {
+ minMaxQualifiers.setSecond(encodedColumnQualifier);
+ }
+ }
+ }
+ }
+ return toReturn;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ffb984f4/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 6081d13..964bacc 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
@@ -47,7 +47,6 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.Pair;
import org.apache.phoenix.exception.DataExceedsCapacityException;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
@@ -71,6 +70,7 @@ import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.RowKeySchema;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
import org.apache.phoenix.schema.SaltingUtil;
@@ -1094,29 +1094,4 @@ public class SchemaUtil {
}
}
}
-
- public static Map<String, Pair<Integer, Integer>> getQualifierRanges(PTable table) {
- Preconditions.checkArgument(table.getStorageScheme() == StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN,
- "Use this method only for tables with storage scheme "
- + StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN.name());
- Map<String, Pair<Integer, Integer>> toReturn = Maps.newHashMapWithExpectedSize(table.getColumns().size());
- for (PColumn column : table.getColumns()) {
- if (!isPKColumn(column)) {
- String colFamily = column.getFamilyName().getString();
- Pair<Integer, Integer> minMaxQualifiers = toReturn.get(colFamily);
- Integer encodedColumnQualifier = column.getEncodedColumnQualifier();
- if (minMaxQualifiers == null) {
- minMaxQualifiers = new Pair<>(encodedColumnQualifier, encodedColumnQualifier);
- toReturn.put(colFamily, minMaxQualifiers);
- } else {
- if (encodedColumnQualifier < minMaxQualifiers.getFirst()) {
- minMaxQualifiers.setFirst(encodedColumnQualifier);
- } else if (encodedColumnQualifier > minMaxQualifiers.getSecond()) {
- minMaxQualifiers.setSecond(encodedColumnQualifier);
- }
- }
- }
- }
- return toReturn;
- }
}
[26/42] phoenix git commit: Bring back check for existing HBase table
Posted by td...@apache.org.
Bring back check for existing HBase table
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1bddaa0b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1bddaa0b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1bddaa0b
Branch: refs/heads/encodecolumns2
Commit: 1bddaa0b45d96c9cf974b48b0d2ae1fc988d8882
Parents: ffb984f
Author: Samarth <sa...@salesforce.com>
Authored: Wed Nov 23 10:10:01 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../org/apache/phoenix/schema/MetaDataClient.java | 18 +++++++++++++-----
.../apache/phoenix/compile/WhereCompilerTest.java | 4 ++--
.../apache/phoenix/execute/MutationStateTest.java | 4 ++--
.../apache/phoenix/query/ConnectionlessTest.java | 14 ++++++++------
4 files changed, 25 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/1bddaa0b/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 8936b9b..53c1c86 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
@@ -2041,10 +2041,7 @@ public class MetaDataClient {
* We can't control what column qualifiers are used in HTable mapped to Phoenix views. So we are not
* able to encode column names.
*/
- if (viewType == MAPPED) {
- storageScheme = ONE_CELL_PER_KEYVALUE_COLUMN;
- encodingScheme = FOUR_BYTE_QUALIFIERS;
- } else {
+ if (viewType != MAPPED) {
/*
* For regular phoenix views, use the storage scheme of the physical table since they all share the
* the same HTable. Views always use the base table's column qualifier counter for doling out
@@ -2078,7 +2075,18 @@ public class MetaDataClient {
* because we cannot control the column qualifiers that were used when populating the hbase table.
* TODO: samarth add a test case for this
*/
- if (parent != null) {
+
+ byte[] tableNameBytes = SchemaUtil.getTableNameAsBytes(schemaName, tableName);
+ boolean tableExists = true;
+ try {
+ connection.getQueryServices().getTableDescriptor(tableNameBytes);
+ } catch (org.apache.phoenix.schema.TableNotFoundException e) {
+ tableExists = false;
+ }
+ if (tableExists) {
+ storageScheme = ONE_CELL_PER_KEYVALUE_COLUMN;
+ encodingScheme = NON_ENCODED_QUALIFIERS;
+ } else if (parent != null) {
storageScheme = parent.getStorageScheme();
encodingScheme = parent.getEncodingScheme();
} else if (isImmutableRows) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/1bddaa0b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
index 06c20d3..c65408e 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
@@ -121,7 +121,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
Filter filter = scan.getFilter();
Expression idExpression = new ColumnRef(plan.getTableRef(), plan.getTableRef().getTable().getPColumnForColumnName("ID").getPosition()).newColumnExpression();
Expression id = new RowKeyColumnExpression(idExpression,new RowKeyValueAccessor(plan.getTableRef().getTable().getPKColumns(),0));
- Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getPColumnForColumnName("COMPANY"), true);
+ Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getPColumnForColumnName("COMPANY"), false);
// FilterList has no equals implementation
assertTrue(filter instanceof FilterList);
FilterList filterList = (FilterList)filter;
@@ -153,7 +153,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
assertEquals(
singleKVFilter(constantComparison(
CompareOp.EQUAL,
- new KeyValueColumnExpression(column, true),
+ new KeyValueColumnExpression(column, false),
"c3")),
filter);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/1bddaa0b/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
index 8553b73..276d946 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
@@ -127,11 +127,11 @@ public class MutationStateTest {
private void assertTable(String tableName1,List<KeyValue> keyValues1,String tableName2,List<KeyValue> keyValues2) {
assertTrue("MUTATION_TEST1".equals(tableName1));
assertTrue(Bytes.equals(PUnsignedInt.INSTANCE.toBytes(111),CellUtil.cloneRow(keyValues1.get(0))));
- assertTrue("app1".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues1.get(1)))));
+ assertTrue("app1".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues1.get(0)))));
assertTrue("MUTATION_TEST2".equals(tableName2));
assertTrue(Bytes.equals(PUnsignedInt.INSTANCE.toBytes(222),CellUtil.cloneRow(keyValues2.get(0))));
- assertTrue("app2".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues2.get(1)))));
+ assertTrue("app2".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues2.get(0)))));
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/1bddaa0b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
index 84cc65c..089c5f1 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
@@ -141,21 +141,19 @@ public class ConnectionlessTest {
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey1, kv.getRow());
- assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
- kv = iterator.next();
- assertArrayEquals(expectedRowKey1, kv.getRow());
assertEquals(name1, PVarchar.INSTANCE.toObject(kv.getValue()));
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey1, kv.getRow());
assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
+ assertTrue(iterator.hasNext());
+ kv = iterator.next();
+ assertArrayEquals(expectedRowKey1, kv.getRow());
+ assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
}
private static void assertRow2(Iterator<KeyValue> iterator, byte[] expectedRowKey2) {
KeyValue kv;
- kv = iterator.next();
- assertArrayEquals(expectedRowKey2, kv.getRow());
- assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey2, kv.getRow());
@@ -164,6 +162,10 @@ public class ConnectionlessTest {
kv = iterator.next();
assertArrayEquals(expectedRowKey2, kv.getRow());
assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
+ assertTrue(iterator.hasNext());
+ kv = iterator.next();
+ assertArrayEquals(expectedRowKey2, kv.getRow());
+ assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
}
@Test
[02/42] phoenix git commit: Set version to 4.10.0-HBase-0.98-SNAPSHOT
after release
Posted by td...@apache.org.
Set version to 4.10.0-HBase-0.98-SNAPSHOT after release
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/af202f2e
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/af202f2e
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/af202f2e
Branch: refs/heads/encodecolumns2
Commit: af202f2efe001a6167f85692cfd865e69064d083
Parents: f18e780
Author: Mujtaba <mu...@apache.org>
Authored: Mon Nov 28 15:56:17 2016 -0800
Committer: Mujtaba <mu...@apache.org>
Committed: Mon Nov 28 15:56:17 2016 -0800
----------------------------------------------------------------------
phoenix-assembly/pom.xml | 2 +-
phoenix-client/pom.xml | 2 +-
phoenix-core/pom.xml | 2 +-
phoenix-flume/pom.xml | 2 +-
phoenix-hive/pom.xml | 2 +-
phoenix-pherf/pom.xml | 2 +-
phoenix-pig/pom.xml | 2 +-
phoenix-queryserver-client/pom.xml | 2 +-
phoenix-queryserver/pom.xml | 2 +-
phoenix-server/pom.xml | 2 +-
phoenix-spark/pom.xml | 2 +-
phoenix-tracing-webapp/pom.xml | 2 +-
pom.xml | 2 +-
13 files changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-assembly/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-assembly/pom.xml b/phoenix-assembly/pom.xml
index e8a1900..a221dca 100644
--- a/phoenix-assembly/pom.xml
+++ b/phoenix-assembly/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-assembly</artifactId>
<name>Phoenix Assembly</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-client/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-client/pom.xml b/phoenix-client/pom.xml
index a21303c..f5ce71c 100644
--- a/phoenix-client/pom.xml
+++ b/phoenix-client/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-client</artifactId>
<name>Phoenix Client</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-core/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-core/pom.xml b/phoenix-core/pom.xml
index 9396882..5984dec 100644
--- a/phoenix-core/pom.xml
+++ b/phoenix-core/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-core</artifactId>
<name>Phoenix Core</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-flume/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-flume/pom.xml b/phoenix-flume/pom.xml
index b013518..0b21357 100644
--- a/phoenix-flume/pom.xml
+++ b/phoenix-flume/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-flume</artifactId>
<name>Phoenix - Flume</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-hive/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-hive/pom.xml b/phoenix-hive/pom.xml
index 6aa2f61..c0cc6fd 100644
--- a/phoenix-hive/pom.xml
+++ b/phoenix-hive/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-hive</artifactId>
<name>Phoenix - Hive</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-pherf/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-pherf/pom.xml b/phoenix-pherf/pom.xml
index 20fc1cc..d7b66bf 100644
--- a/phoenix-pherf/pom.xml
+++ b/phoenix-pherf/pom.xml
@@ -15,7 +15,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-pherf</artifactId>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-pig/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-pig/pom.xml b/phoenix-pig/pom.xml
index 1e7ca4e..945aa2d 100644
--- a/phoenix-pig/pom.xml
+++ b/phoenix-pig/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-pig</artifactId>
<name>Phoenix - Pig</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-queryserver-client/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-queryserver-client/pom.xml b/phoenix-queryserver-client/pom.xml
index 88e6eff..e2621ef 100644
--- a/phoenix-queryserver-client/pom.xml
+++ b/phoenix-queryserver-client/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-queryserver-client</artifactId>
<name>Phoenix Query Server Client</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-queryserver/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-queryserver/pom.xml b/phoenix-queryserver/pom.xml
index 2f81069..1f4106a 100644
--- a/phoenix-queryserver/pom.xml
+++ b/phoenix-queryserver/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-queryserver</artifactId>
<name>Phoenix Query Server</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-server/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-server/pom.xml b/phoenix-server/pom.xml
index 9b6f28b..67355a7 100644
--- a/phoenix-server/pom.xml
+++ b/phoenix-server/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-server</artifactId>
<name>Phoenix Server</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-spark/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-spark/pom.xml b/phoenix-spark/pom.xml
index ee15c25..f525525 100644
--- a/phoenix-spark/pom.xml
+++ b/phoenix-spark/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-spark</artifactId>
<name>Phoenix - Spark</name>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/phoenix-tracing-webapp/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-tracing-webapp/pom.xml b/phoenix-tracing-webapp/pom.xml
index 21c6381..f8dd8e1 100755
--- a/phoenix-tracing-webapp/pom.xml
+++ b/phoenix-tracing-webapp/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
</parent>
<artifactId>phoenix-tracing-webapp</artifactId>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/af202f2e/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index eede19d..ff682ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
- <version>5.0.0-HBase-0.98-SNAPSHOT</version>
+ <version>4.10.0-HBase-0.98-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Apache Phoenix</name>
<description>A SQL layer over HBase</description>
[08/42] phoenix git commit: PHOENIX-3445 Add a CREATE IMMUTABLE TABLE
construct to make immutable tables more explicit
Posted by td...@apache.org.
PHOENIX-3445 Add a CREATE IMMUTABLE TABLE construct to make immutable tables more explicit
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/d2a22418
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d2a22418
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d2a22418
Branch: refs/heads/encodecolumns2
Commit: d2a224186ffbd605a028ac99d14bf3ac9436a5c5
Parents: e966e26
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Mon Nov 28 17:08:27 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Fri Dec 16 11:27:26 2016 -0800
----------------------------------------------------------------------
.../apache/phoenix/end2end/AlterTableIT.java | 16 ++--
.../phoenix/end2end/AlterTableWithViewsIT.java | 41 +++++++++
.../phoenix/end2end/AppendOnlySchemaIT.java | 21 ++---
.../phoenix/end2end/ImmutableTablePropIT.java | 92 ++++++++++++++++++++
.../end2end/QueryDatabaseMetaDataIT.java | 3 +-
phoenix-core/src/main/antlr3/PhoenixSQL.g | 7 +-
.../phoenix/exception/SQLExceptionCode.java | 4 +-
.../apache/phoenix/jdbc/PhoenixStatement.java | 8 +-
.../phoenix/parse/CreateTableStatement.java | 14 ++-
.../apache/phoenix/parse/ParseNodeFactory.java | 4 +-
.../org/apache/phoenix/query/QueryServices.java | 1 +
.../apache/phoenix/schema/MetaDataClient.java | 23 ++---
.../apache/phoenix/schema/TableProperty.java | 50 ++++++-----
13 files changed, 219 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index 5da0ee7..155b6c2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -1168,9 +1168,8 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
assertImmutableRows(conn, dataTableFullName, true);
ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, VERSIONS = 10";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, CF1.MIN_VERSIONS = 1, CF2.MIN_VERSIONS = 3, MIN_VERSIONS = 8, IMMUTABLE_ROWS=false, CF1.KEEP_DELETED_CELLS = true, KEEP_DELETED_CELLS = false";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, CF1.MIN_VERSIONS = 1, CF2.MIN_VERSIONS = 3, MIN_VERSIONS = 8, CF1.KEEP_DELETED_CELLS = true, KEEP_DELETED_CELLS = false";
conn.createStatement().execute(ddl);
- assertImmutableRows(conn, dataTableFullName, false);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
@@ -1346,11 +1345,16 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
String viewFullName = SchemaUtil.getTableName(schemaName, generateUniqueName());
ddl = "CREATE VIEW " + viewFullName + " AS SELECT * FROM " + dataTableFullName + " WHERE CREATION_TIME = 1";
conn1.createStatement().execute(ddl);
- ddl = "ALTER VIEW " + viewFullName + " SET IMMUTABLE_ROWS = TRUE";
+ ddl = "ALTER VIEW " + viewFullName + " SET UPDATE_CACHE_FREQUENCY = 10";
conn1.createStatement().execute(ddl);
- assertImmutableRows(conn1, viewFullName, true);
- ddl = "ALTER VIEW " + viewFullName + " SET IMMUTABLE_ROWS = FALSE";
+ conn1.createStatement().execute("SELECT * FROM " + viewFullName);
+ PhoenixConnection pconn = conn1.unwrap(PhoenixConnection.class);
+ assertEquals(10, pconn.getTable(new PTableKey(pconn.getTenantId(), viewFullName)).getUpdateCacheFrequency());
+ ddl = "ALTER VIEW " + viewFullName + " SET UPDATE_CACHE_FREQUENCY = 20";
conn1.createStatement().execute(ddl);
+ conn1.createStatement().execute("SELECT * FROM " + viewFullName);
+ pconn = conn1.unwrap(PhoenixConnection.class);
+ assertEquals(20, pconn.getTable(new PTableKey(pconn.getTenantId(), viewFullName)).getUpdateCacheFrequency());
assertImmutableRows(conn1, viewFullName, false);
ddl = "ALTER VIEW " + viewFullName + " SET DISABLE_WAL = TRUE";
try {
@@ -2230,6 +2234,6 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
}
}
}
-
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
index 6e4f5c0..91aca4e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.end2end;
import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE;
import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -32,6 +33,7 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Properties;
import org.apache.commons.lang.ArrayUtils;
import org.apache.hadoop.hbase.client.HTableInterface;
@@ -45,6 +47,8 @@ import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.SchemaUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -719,4 +723,41 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testAlterTablePropertyOnView() throws Exception {
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn ) {
+ String baseTableName = "NONTXNTBL_" + generateUniqueName() + (isMultiTenant ? "0":"1");
+ String viewOfTable = baseTableName + "_VIEW";
+
+ String ddl = "CREATE TABLE " + baseTableName + " (\n"
+ +"ID VARCHAR(15) NOT NULL,\n"
+ +"CREATED_DATE DATE,\n"
+ +"CONSTRAINT PK PRIMARY KEY (ID))";
+ conn.createStatement().execute(ddl);
+ ddl = "CREATE VIEW " + viewOfTable + " AS SELECT * FROM " + baseTableName;
+ viewConn.createStatement().execute(ddl);
+
+ try {
+ viewConn.createStatement().execute("ALTER VIEW " + viewOfTable + " SET IMMUTABLE_ROWS = true");
+ fail();
+ } catch (SQLException e) {
+ assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW.getErrorCode(), e.getErrorCode());
+ }
+
+ viewConn.createStatement().execute("ALTER VIEW " + viewOfTable + " SET UPDATE_CACHE_FREQUENCY = 100");
+ viewConn.createStatement().execute("SELECT * FROM "+ viewOfTable);
+ PName tenantId = isMultiTenant ? PNameFactory.newName("tenant1") : null;
+ assertEquals(100, viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable)).getUpdateCacheFrequency());
+
+ try {
+ viewConn.createStatement().execute("ALTER VIEW " + viewOfTable + " SET APPEND_ONLY_SCHEMA = true");
+ fail();
+ } catch (SQLException e) {
+ assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW.getErrorCode(), e.getErrorCode());
+ }
+ }
+
+ }
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
index 93341b7..8d40094 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
@@ -89,7 +89,7 @@ public class AppendOnlySchemaIT extends ParallelStatsDisabledIT {
+ viewName + " ( hostName varchar NOT NULL, tagName varChar"
+ " CONSTRAINT HOSTNAME_PK PRIMARY KEY (hostName))"
+ " AS SELECT * FROM " + metricTableName
- + " APPEND_ONLY_SCHEMA = true, UPDATE_CACHE_FREQUENCY=300000";
+ + " UPDATE_CACHE_FREQUENCY=300000";
conn1.createStatement().execute(ddl);
conn1.createStatement().execute("UPSERT INTO " + viewName + "(hostName, metricVal) VALUES('host1', 1.0)");
conn1.commit();
@@ -201,7 +201,7 @@ public class AppendOnlySchemaIT extends ParallelStatsDisabledIT {
+ viewName + "( hostName varchar NOT NULL,"
+ " CONSTRAINT HOSTNAME_PK PRIMARY KEY (hostName))"
+ " AS SELECT * FROM " + metricTableName
- + " APPEND_ONLY_SCHEMA = true, UPDATE_CACHE_FREQUENCY=300000";
+ + " UPDATE_CACHE_FREQUENCY=300000";
conn1.createStatement().execute(ddl);
conn1.createStatement().execute("UPSERT INTO " + viewName + "(hostName, metricVal1) VALUES('host1', 1.0)");
@@ -215,7 +215,7 @@ public class AppendOnlySchemaIT extends ParallelStatsDisabledIT {
+ viewName + "( instanceName varchar, hostName varchar, metricVal2 double, metricVal1 double"
+ " CONSTRAINT HOSTNAME_PK PRIMARY KEY (instancename, hostName))"
+ " AS SELECT * FROM " + metricTableName
- + " APPEND_ONLY_SCHEMA = true, UPDATE_CACHE_FREQUENCY=300000";
+ + " UPDATE_CACHE_FREQUENCY=300000";
conn2.createStatement().execute(ddl);
conn2.createStatement().execute(
@@ -308,16 +308,11 @@ public class AppendOnlySchemaIT extends ParallelStatsDisabledIT {
+ " col1 integer NOT NULL"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1))"
+ " APPEND_ONLY_SCHEMA = true, UPDATE_CACHE_FREQUENCY=1000");
- try {
- conn.createStatement().execute(
- "create view IF NOT EXISTS " + viewName + " (val1 integer NOT NULL) AS SELECT * FROM " + tableName
- + " UPDATE_CACHE_FREQUENCY=1000");
- fail("APPEND_ONLY_SCHEMA must be true for a view if it is true for the base table ");
- }
- catch (SQLException e) {
- assertEquals(SQLExceptionCode.VIEW_APPEND_ONLY_SCHEMA.getErrorCode(),
- e.getErrorCode());
- }
+ conn.createStatement().execute(
+ "create view IF NOT EXISTS " + viewName + " (val1 integer) AS SELECT * FROM " + tableName
+ + " UPDATE_CACHE_FREQUENCY=1000");
+ PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
+ assertEquals(true, pconn.getTable(new PTableKey(pconn.getTenantId(), viewName)).isAppendOnlySchema());
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/it/java/org/apache/phoenix/end2end/ImmutableTablePropIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ImmutableTablePropIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ImmutableTablePropIT.java
new file mode 100644
index 0000000..693fb81
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ImmutableTablePropIT.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTableKey;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.Test;
+
+public class ImmutableTablePropIT extends ParallelStatsDisabledIT {
+
+ @Test
+ public void testImmutableKeyword() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String immutableDataTableFullName = SchemaUtil.getTableName("", generateUniqueName());
+ String mutableDataTableFullName = SchemaUtil.getTableName("", generateUniqueName());
+ try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+ Statement stmt = conn.createStatement();
+ // create table with immutable keyword
+ String ddl = "CREATE IMMUTABLE TABLE " + immutableDataTableFullName +
+ " (a_string varchar not null, col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string)) STORE_NULLS=true";
+ stmt.execute(ddl);
+
+ // create table without immutable keyword
+ ddl = "CREATE TABLE " + mutableDataTableFullName +
+ " (a_string varchar not null, col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string)) STORE_NULLS=true";
+ stmt.execute(ddl);
+
+ PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
+ PTable immutableTable = phxConn.getTable(new PTableKey(null, immutableDataTableFullName));
+ assertTrue("IMMUTABLE_ROWS should be set to true", immutableTable.isImmutableRows());
+ PTable mutableTable = phxConn.getTable(new PTableKey(null, mutableDataTableFullName));
+ assertFalse("IMMUTABLE_ROWS should be set to false", mutableTable.isImmutableRows());
+ }
+ }
+
+ @Test
+ public void testImmutableProperty() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String immutableDataTableFullName = SchemaUtil.getTableName("", generateUniqueName());
+ String mutableDataTableFullName = SchemaUtil.getTableName("", generateUniqueName());
+ try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+ Statement stmt = conn.createStatement();
+ // create table with immutable_table property set to true
+ String ddl = "CREATE TABLE " + immutableDataTableFullName +
+ " (a_string varchar not null, col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string)) IMMUTABLE_ROWS=true";
+ stmt.execute(ddl);
+
+ // create table with immutable_table property set to false
+ ddl = "CREATE TABLE " + mutableDataTableFullName +
+ " (a_string varchar not null, col1 integer" +
+ " CONSTRAINT pk PRIMARY KEY (a_string)) IMMUTABLE_ROWS=false";
+ stmt.execute(ddl);
+
+ PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
+ PTable immutableTable = phxConn.getTable(new PTableKey(null, immutableDataTableFullName));
+ assertTrue("IMMUTABLE_ROWS should be set to true", immutableTable.isImmutableRows());
+ PTable mutableTable = phxConn.getTable(new PTableKey(null, mutableDataTableFullName));
+ assertFalse("IMMUTABLE_ROWS should be set to false", mutableTable.isImmutableRows());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
index 805691d..ec9f32f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
@@ -842,7 +842,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
createStmt = "create view " + MDTEST_NAME +
" (id char(1) not null primary key,\n" +
" b.col1 integer,\n" +
- " \"c\".col2 bigint) \n";
+ " \"c\".col2 bigint) IMMUTABLE_ROWS=true \n";
// should be ok now
conn1.createStatement().execute(createStmt);
conn1.close();
@@ -875,7 +875,6 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
} catch (ReadOnlyTableException e) {
// expected to fail b/c table is read-only
}
- conn2.createStatement().execute("ALTER VIEW " + MDTEST_NAME + " SET IMMUTABLE_ROWS=TRUE");
HTableInterface htable = conn2.getQueryServices().getTable(SchemaUtil.getTableNameAsBytes(MDTEST_SCHEMA_NAME,MDTEST_NAME));
Put put = new Put(Bytes.toBytes("0"));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/main/antlr3/PhoenixSQL.g
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/antlr3/PhoenixSQL.g b/phoenix-core/src/main/antlr3/PhoenixSQL.g
index 1d1a873..a5e46dc 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -137,6 +137,7 @@ tokens
DEFAULT = 'default';
DUPLICATE = 'duplicate';
IGNORE = 'ignore';
+ IMMUTABLE = 'immutable';
}
@@ -433,11 +434,11 @@ explain_node returns [BindableStatement ret]
// Parse a create table statement.
create_table_node returns [CreateTableStatement ret]
- : CREATE TABLE (IF NOT ex=EXISTS)? t=from_table_name
+ : CREATE (im=IMMUTABLE)? TABLE (IF NOT ex=EXISTS)? t=from_table_name
(LPAREN c=column_defs (pk=pk_constraint)? RPAREN)
(p=fam_properties)?
(SPLIT ON s=value_expression_list)?
- {ret = factory.createTable(t, p, c, pk, s, PTableType.TABLE, ex!=null, null, null, getBindCount()); }
+ {ret = factory.createTable(t, p, c, pk, s, PTableType.TABLE, ex!=null, null, null, getBindCount(), im!=null ? true : null); }
;
// Parse a create schema statement.
@@ -454,7 +455,7 @@ create_view_node returns [CreateTableStatement ret]
FROM bt=from_table_name
(WHERE w=expression)? )?
(p=fam_properties)?
- { ret = factory.createTable(t, p, c, pk, null, PTableType.VIEW, ex!=null, bt==null ? t : bt, w, getBindCount()); }
+ { ret = factory.createTable(t, p, c, pk, null, PTableType.VIEW, ex!=null, bt==null ? t : bt, w, getBindCount(), null); }
;
// Parse a create index statement.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index ac5619f..20f3974 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -363,7 +363,9 @@ public enum SQLExceptionCode {
UPDATE_CACHE_FREQUENCY_INVALID(1130, "XCL30", "UPDATE_CACHE_FREQUENCY cannot be set to ALWAYS if APPEND_ONLY_SCHEMA is true."),
CANNOT_DROP_COL_APPEND_ONLY_SCHEMA(1131, "XCL31", "Cannot drop column from table that with append only schema."),
- VIEW_APPEND_ONLY_SCHEMA(1132, "XCL32", "APPEND_ONLY_SCHEMA property of view must match the base table"),
+
+ CANNOT_ALTER_IMMUTABLE_ROWS_PROPERTY(1133, "XCL33", "IMMUTABLE_ROWS property can be changed only if the table storage scheme is ONE_CELL_PER_KEYVALUE_COLUMN"),
+ CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW(1134, "XCL34", "Altering this table property on a view is not allowed"),
/**
* Implementation defined class. Phoenix internal error. (errorcode 20, sqlstate INT).
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/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 2a7cd0e..54bef29 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
@@ -632,8 +632,8 @@ public class PhoenixStatement implements Statement, SQLCloseable {
private static class ExecutableCreateTableStatement extends CreateTableStatement implements CompilableStatement {
ExecutableCreateTableStatement(TableName tableName, ListMultimap<String,Pair<String,Object>> props, List<ColumnDef> columnDefs,
PrimaryKeyConstraint pkConstraint, List<ParseNode> splitNodes, PTableType tableType, boolean ifNotExists,
- TableName baseTableName, ParseNode tableTypeIdNode, int bindCount) {
- super(tableName, props, columnDefs, pkConstraint, splitNodes, tableType, ifNotExists, baseTableName, tableTypeIdNode, bindCount);
+ TableName baseTableName, ParseNode tableTypeIdNode, int bindCount, Boolean immutableRows) {
+ super(tableName, props, columnDefs, pkConstraint, splitNodes, tableType, ifNotExists, baseTableName, tableTypeIdNode, bindCount, immutableRows);
}
@SuppressWarnings("unchecked")
@@ -1170,8 +1170,8 @@ public class PhoenixStatement implements Statement, SQLCloseable {
@Override
public CreateTableStatement createTable(TableName tableName, ListMultimap<String,Pair<String,Object>> props, List<ColumnDef> columns, PrimaryKeyConstraint pkConstraint,
- List<ParseNode> splits, PTableType tableType, boolean ifNotExists, TableName baseTableName, ParseNode tableTypeIdNode, int bindCount) {
- return new ExecutableCreateTableStatement(tableName, props, columns, pkConstraint, splits, tableType, ifNotExists, baseTableName, tableTypeIdNode, bindCount);
+ List<ParseNode> splits, PTableType tableType, boolean ifNotExists, TableName baseTableName, ParseNode tableTypeIdNode, int bindCount, Boolean immutableRows) {
+ return new ExecutableCreateTableStatement(tableName, props, columns, pkConstraint, splits, tableType, ifNotExists, baseTableName, tableTypeIdNode, bindCount, immutableRows);
}
@Override
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateTableStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateTableStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateTableStatement.java
index 3c84cd0..73b7a11 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateTableStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateTableStatement.java
@@ -17,12 +17,16 @@
*/
package org.apache.phoenix.parse;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.TableProperty;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
@@ -39,6 +43,8 @@ public class CreateTableStatement extends MutableStatement {
private final boolean ifNotExists;
private final TableName baseTableName;
private final ParseNode whereClause;
+ // TODO change this to boolean at the next major release and remove TableProperty.IMMUTABLE_ROWS and QueryServiceOptions.IMMUTABLE_ROWS_ATTRIB
+ private final Boolean immutableRows;
public CreateTableStatement(CreateTableStatement createTable, List<ColumnDef> columns) {
this.tableName = createTable.tableName;
@@ -51,11 +57,12 @@ public class CreateTableStatement extends MutableStatement {
this.ifNotExists = createTable.ifNotExists;
this.baseTableName = createTable.baseTableName;
this.whereClause = createTable.whereClause;
+ this.immutableRows = createTable.immutableRows;
}
protected CreateTableStatement(TableName tableName, ListMultimap<String,Pair<String,Object>> props, List<ColumnDef> columns, PrimaryKeyConstraint pkConstraint,
List<ParseNode> splitNodes, PTableType tableType, boolean ifNotExists,
- TableName baseTableName, ParseNode whereClause, int bindCount) {
+ TableName baseTableName, ParseNode whereClause, int bindCount, Boolean immutableRows) {
this.tableName = tableName;
this.props = props == null ? ImmutableListMultimap.<String,Pair<String,Object>>of() : props;
this.tableType = PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA.equals(tableName.getSchemaName()) ? PTableType.SYSTEM : tableType;
@@ -66,6 +73,7 @@ public class CreateTableStatement extends MutableStatement {
this.ifNotExists = ifNotExists;
this.baseTableName = baseTableName;
this.whereClause = whereClause;
+ this.immutableRows = immutableRows;
}
public ParseNode getWhereClause() {
@@ -108,4 +116,8 @@ public class CreateTableStatement extends MutableStatement {
public PrimaryKeyConstraint getPrimaryKeyConstraint() {
return pkConstraint;
}
+
+ public Boolean immutableRows() {
+ return immutableRows;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
index 232a91e..0376877 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
@@ -293,8 +293,8 @@ public class ParseNodeFactory {
return new IndexKeyConstraint(parseNodeAndSortOrder);
}
- public CreateTableStatement createTable(TableName tableName, ListMultimap<String,Pair<String,Object>> props, List<ColumnDef> columns, PrimaryKeyConstraint pkConstraint, List<ParseNode> splits, PTableType tableType, boolean ifNotExists, TableName baseTableName, ParseNode tableTypeIdNode, int bindCount) {
- return new CreateTableStatement(tableName, props, columns, pkConstraint, splits, tableType, ifNotExists, baseTableName, tableTypeIdNode, bindCount);
+ public CreateTableStatement createTable(TableName tableName, ListMultimap<String,Pair<String,Object>> props, List<ColumnDef> columns, PrimaryKeyConstraint pkConstraint, List<ParseNode> splits, PTableType tableType, boolean ifNotExists, TableName baseTableName, ParseNode tableTypeIdNode, int bindCount, Boolean immutableRows) {
+ return new CreateTableStatement(tableName, props, columns, pkConstraint, splits, tableType, ifNotExists, baseTableName, tableTypeIdNode, bindCount, immutableRows);
}
public CreateSchemaStatement createSchema(String schemaName, boolean ifNotExists) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
index f5ee612..65d385e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
@@ -92,6 +92,7 @@ public interface QueryServices extends SQLCloseable {
public static final String ROW_KEY_ORDER_SALTED_TABLE_ATTRIB = "phoenix.query.rowKeyOrderSaltedTable";
public static final String USE_INDEXES_ATTRIB = "phoenix.query.useIndexes";
+ @Deprecated // use the IMMUTABLE keyword while creating the table
public static final String IMMUTABLE_ROWS_ATTRIB = "phoenix.mutate.immutableRows";
public static final String INDEX_MUTATE_BATCH_SIZE_THRESHOLD_ATTRIB = "phoenix.index.mutableBatchSizeThreshold";
public static final String DROP_METADATA_ATTRIB = "phoenix.schema.dropMetaData";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/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 ecd5f7a..0803e89 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
@@ -889,9 +889,14 @@ public class MetaDataClient {
populatePropertyMaps(statement.getProps(), tableProps, commonFamilyProps);
boolean isAppendOnlySchema = false;
- Boolean appendOnlySchemaProp = (Boolean) TableProperty.APPEND_ONLY_SCHEMA.getValue(tableProps);
- if (appendOnlySchemaProp != null) {
- isAppendOnlySchema = appendOnlySchemaProp;
+ if (parent==null) {
+ Boolean appendOnlySchemaProp = (Boolean) TableProperty.APPEND_ONLY_SCHEMA.getValue(tableProps);
+ if (appendOnlySchemaProp != null) {
+ isAppendOnlySchema = appendOnlySchemaProp;
+ }
+ }
+ else {
+ isAppendOnlySchema = parent.isAppendOnlySchema();
}
long updateCacheFrequency = 0;
Long updateCacheFrequencyProp = (Long) TableProperty.UPDATE_CACHE_FREQUENCY.getValue(tableProps);
@@ -904,12 +909,6 @@ public class MetaDataClient {
.setSchemaName(tableName.getSchemaName()).setTableName(tableName.getTableName())
.build().buildException();
}
- // view isAppendOnlySchema property must match the parent table
- if (parent!=null && isAppendOnlySchema!= parent.isAppendOnlySchema()) {
- throw new SQLExceptionInfo.Builder(SQLExceptionCode.VIEW_APPEND_ONLY_SCHEMA)
- .setSchemaName(tableName.getSchemaName()).setTableName(tableName.getTableName())
- .build().buildException();
- }
PTable table = null;
// if the APPEND_ONLY_SCHEMA attribute is true first check if the table is present in the cache
@@ -1424,7 +1423,7 @@ public class MetaDataClient {
statement.getProps().put("", new Pair<String,Object>(DEFAULT_COLUMN_FAMILY_NAME,dataTable.getDefaultFamilyName().getString()));
}
PrimaryKeyConstraint pk = FACTORY.primaryKey(null, allPkColumns);
- CreateTableStatement tableStatement = FACTORY.createTable(indexTableName, statement.getProps(), columnDefs, pk, statement.getSplitNodes(), PTableType.INDEX, statement.ifNotExists(), null, null, statement.getBindCount());
+ CreateTableStatement tableStatement = FACTORY.createTable(indexTableName, statement.getProps(), columnDefs, pk, statement.getSplitNodes(), PTableType.INDEX, statement.ifNotExists(), null, null, statement.getBindCount(), null);
table = createTableInternal(tableStatement, splits, dataTable, null, null, null, null, allocateIndexId, statement.getIndexType(), asyncCreatedDate, tableProps, commonFamilyProps);
break;
} catch (ConcurrentTableMutationException e) { // Can happen if parent data table changes while above is in progress
@@ -1725,7 +1724,9 @@ public class MetaDataClient {
// Although unusual, it's possible to set a mapped VIEW as having immutable rows.
// This tells Phoenix that you're managing the index maintenance yourself.
if (tableType != PTableType.INDEX && (tableType != PTableType.VIEW || viewType == ViewType.MAPPED)) {
- Boolean isImmutableRowsProp = (Boolean) TableProperty.IMMUTABLE_ROWS.getValue(tableProps);
+ // TODO remove TableProperty.IMMUTABLE_ROWS at the next major release
+ Boolean isImmutableRowsProp = statement.immutableRows()!=null? statement.immutableRows() :
+ (Boolean) TableProperty.IMMUTABLE_ROWS.getValue(tableProps);
if (isImmutableRowsProp == null) {
isImmutableRows = connection.getQueryServices().getProps().getBoolean(QueryServices.IMMUTABLE_ROWS_ATTRIB, QueryServicesOptions.DEFAULT_IMMUTABLE_ROWS);
} else {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2a22418/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
index 4f24c92..69cc7ff 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
@@ -36,23 +36,24 @@ import org.apache.phoenix.util.SchemaUtil;
public enum TableProperty {
- IMMUTABLE_ROWS(PhoenixDatabaseMetaData.IMMUTABLE_ROWS, true, true),
+ @Deprecated // use the IMMUTABLE keyword while creating the table
+ IMMUTABLE_ROWS(PhoenixDatabaseMetaData.IMMUTABLE_ROWS, true, true, false),
- MULTI_TENANT(PhoenixDatabaseMetaData.MULTI_TENANT, true, false),
+ MULTI_TENANT(PhoenixDatabaseMetaData.MULTI_TENANT, true, false, false),
- DISABLE_WAL(PhoenixDatabaseMetaData.DISABLE_WAL, true, false),
+ DISABLE_WAL(PhoenixDatabaseMetaData.DISABLE_WAL, true, false, false),
- SALT_BUCKETS(PhoenixDatabaseMetaData.SALT_BUCKETS, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, SALT_ONLY_ON_CREATE_TABLE, false),
+ SALT_BUCKETS(PhoenixDatabaseMetaData.SALT_BUCKETS, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, SALT_ONLY_ON_CREATE_TABLE, false, false),
- DEFAULT_COLUMN_FAMILY(DEFAULT_COLUMN_FAMILY_NAME, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, DEFAULT_COLUMN_FAMILY_ONLY_ON_CREATE_TABLE, false),
+ DEFAULT_COLUMN_FAMILY(DEFAULT_COLUMN_FAMILY_NAME, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, DEFAULT_COLUMN_FAMILY_ONLY_ON_CREATE_TABLE, false, false),
- TTL(HColumnDescriptor.TTL, COLUMN_FAMILY_NOT_ALLOWED_FOR_TTL, true, CANNOT_ALTER_PROPERTY, false),
+ TTL(HColumnDescriptor.TTL, COLUMN_FAMILY_NOT_ALLOWED_FOR_TTL, true, CANNOT_ALTER_PROPERTY, false, false),
- STORE_NULLS(PhoenixDatabaseMetaData.STORE_NULLS, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, false),
+ STORE_NULLS(PhoenixDatabaseMetaData.STORE_NULLS, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, false, false),
- TRANSACTIONAL(PhoenixDatabaseMetaData.TRANSACTIONAL, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, false),
-
- UPDATE_CACHE_FREQUENCY(PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY, true, true) {
+ TRANSACTIONAL(PhoenixDatabaseMetaData.TRANSACTIONAL, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, false, false),
+
+ UPDATE_CACHE_FREQUENCY(PhoenixDatabaseMetaData.UPDATE_CACHE_FREQUENCY, true, true, true) {
@Override
public Object getValue(Object value) {
if (value instanceof String) {
@@ -69,15 +70,15 @@ public enum TableProperty {
}
},
- AUTO_PARTITION_SEQ(PhoenixDatabaseMetaData.AUTO_PARTITION_SEQ, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, false) {
+ AUTO_PARTITION_SEQ(PhoenixDatabaseMetaData.AUTO_PARTITION_SEQ, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, false, false, false) {
@Override
public Object getValue(Object value) {
return value == null ? null : SchemaUtil.normalizeIdentifier(value.toString());
}
},
- APPEND_ONLY_SCHEMA(PhoenixDatabaseMetaData.APPEND_ONLY_SCHEMA, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, true),
- GUIDE_POSTS_WIDTH(PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH, true, false) {
+ APPEND_ONLY_SCHEMA(PhoenixDatabaseMetaData.APPEND_ONLY_SCHEMA, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, true, true, false),
+ GUIDE_POSTS_WIDTH(PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH, true, false, false) {
@Override
public Object getValue(Object value) {
return value == null ? null : ((Number) value).longValue();
@@ -91,25 +92,27 @@ public enum TableProperty {
private final boolean isMutable; // whether or not a property can be changed through statements like ALTER TABLE.
private final SQLExceptionCode mutatingImmutablePropException;
private final boolean isValidOnView;
+ private final boolean isMutableOnView;
- private TableProperty(String propertyName, boolean isMutable, boolean isValidOnView) {
- this(propertyName, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, isMutable, CANNOT_ALTER_PROPERTY, isValidOnView);
+ private TableProperty(String propertyName, boolean isMutable, boolean isValidOnView, boolean isMutableOnView) {
+ this(propertyName, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, isMutable, CANNOT_ALTER_PROPERTY, isValidOnView, isMutableOnView);
}
- private TableProperty(String propertyName, SQLExceptionCode colFamilySpecifiedException, boolean isMutable, boolean isValidOnView) {
- this(propertyName, colFamilySpecifiedException, isMutable, CANNOT_ALTER_PROPERTY, isValidOnView);
+ private TableProperty(String propertyName, SQLExceptionCode colFamilySpecifiedException, boolean isMutable, boolean isValidOnView, boolean isMutableOnView) {
+ this(propertyName, colFamilySpecifiedException, isMutable, CANNOT_ALTER_PROPERTY, isValidOnView, isMutableOnView);
}
- private TableProperty(String propertyName, boolean isMutable, boolean isValidOnView, SQLExceptionCode isMutatingException) {
- this(propertyName, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, isMutable, isMutatingException, isValidOnView);
+ private TableProperty(String propertyName, boolean isMutable, boolean isValidOnView, boolean isMutableOnView, SQLExceptionCode isMutatingException) {
+ this(propertyName, COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY, isMutable, isMutatingException, isValidOnView, isMutableOnView);
}
- private TableProperty(String propertyName, SQLExceptionCode colFamSpecifiedException, boolean isMutable, SQLExceptionCode mutatingException, boolean isValidOnView) {
+ private TableProperty(String propertyName, SQLExceptionCode colFamSpecifiedException, boolean isMutable, SQLExceptionCode mutatingException, boolean isValidOnView, boolean isMutableOnView) {
this.propertyName = propertyName;
this.colFamSpecifiedException = colFamSpecifiedException;
this.isMutable = isMutable;
this.mutatingImmutablePropException = mutatingException;
this.isValidOnView = isValidOnView;
+ this.isMutableOnView = isMutableOnView;
}
public static boolean isPhoenixTableProperty(String property) {
@@ -132,8 +135,8 @@ public enum TableProperty {
// isQualified is true if column family name is specified in property name
public void validate(boolean isMutating, boolean isQualified, PTableType tableType) throws SQLException {
checkForColumnFamily(isQualified);
- checkForMutability(isMutating);
checkIfApplicableForView(tableType);
+ checkForMutability(isMutating,tableType);
}
private void checkForColumnFamily(boolean isQualified) throws SQLException {
@@ -142,10 +145,13 @@ public enum TableProperty {
}
}
- private void checkForMutability(boolean isMutating) throws SQLException {
+ private void checkForMutability(boolean isMutating, PTableType tableType) throws SQLException {
if (isMutating && !isMutable) {
throw new SQLExceptionInfo.Builder(mutatingImmutablePropException).setMessage(". Property: " + propertyName).build().buildException();
}
+ if (isMutating && tableType == PTableType.VIEW && !isMutableOnView) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW).setMessage(". Property: " + propertyName).build().buildException();
+ }
}
private void checkIfApplicableForView(PTableType tableType)
[40/42] phoenix git commit: Refactor code to store and use column
qualifiers in SYSTEM.CATALOG
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
index 6357e52..3cca2de 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
@@ -26,7 +26,6 @@ import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_QUERY_TIM
import static org.apache.phoenix.schema.PTable.IndexType.LOCAL;
import static org.apache.phoenix.schema.PTableType.INDEX;
import static org.apache.phoenix.util.ByteUtil.EMPTY_BYTE_ARRAY;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import java.io.ByteArrayInputStream;
import java.io.DataInput;
@@ -87,6 +86,7 @@ import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.schema.PColumnFamily;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTable.ViewType;
import org.apache.phoenix.schema.StaleRegionBoundaryCacheException;
@@ -248,13 +248,14 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
ScanUtil.andFilterAtEnd(scan, new PageFilter(plan.getLimit()));
}
}
+ scan.setAttribute(BaseScannerRegionObserver.QUALIFIER_ENCODING_SCHEME, new byte[]{table.getEncodingScheme().getSerializedMetadataValue()});
// When analyzing the table, there is no look up for key values being done.
// So there is no point setting the range.
if (EncodedColumnsUtil.setQualifierRanges(table) && !ScanUtil.isAnalyzeTable(scan)) {
Pair<Integer, Integer> range = getEncodedQualifierRange(scan, context);
if (range != null) {
- scan.setAttribute(BaseScannerRegionObserver.MIN_QUALIFIER, getEncodedColumnQualifier(range.getFirst()));
- scan.setAttribute(BaseScannerRegionObserver.MAX_QUALIFIER, getEncodedColumnQualifier(range.getSecond()));
+ scan.setAttribute(BaseScannerRegionObserver.MIN_QUALIFIER, Bytes.toBytes(range.getFirst()));
+ scan.setAttribute(BaseScannerRegionObserver.MAX_QUALIFIER, Bytes.toBytes(range.getSecond()));
}
}
if (optimizeProjection) {
@@ -266,25 +267,25 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
private static Pair<Integer, Integer> getEncodedQualifierRange(Scan scan, StatementContext context)
throws SQLException {
PTable table = context.getCurrentTable().getTable();
- StorageScheme storageScheme = table.getStorageScheme();
- checkArgument(storageScheme == StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN,
+ QualifierEncodingScheme encodingScheme = table.getEncodingScheme();
+ checkArgument(encodingScheme != QualifierEncodingScheme.NON_ENCODED_QUALIFIERS,
"Method should only be used for tables using encoded column names");
Pair<Integer, Integer> minMaxQualifiers = new Pair<>();
for (Pair<byte[], byte[]> whereCol : context.getWhereConditionColumns()) {
byte[] cq = whereCol.getSecond();
if (cq != null) {
- int qualifier = getEncodedColumnQualifier(cq);
+ int qualifier = table.getEncodingScheme().getDecodedValue(cq);
determineQualifierRange(qualifier, minMaxQualifiers);
}
}
Map<byte[], NavigableSet<byte[]>> familyMap = scan.getFamilyMap();
- Map<String, Pair<Integer, Integer>> qualifierRanges = EncodedColumnsUtil.getQualifierRanges(table);
+ Map<String, Pair<Integer, Integer>> qualifierRanges = EncodedColumnsUtil.getFamilyQualifierRanges(table);
for (Entry<byte[], NavigableSet<byte[]>> entry : familyMap.entrySet()) {
if (entry.getValue() != null) {
for (byte[] cq : entry.getValue()) {
if (cq != null) {
- int qualifier = getEncodedColumnQualifier(cq);
+ int qualifier = table.getEncodingScheme().getDecodedValue(cq);
determineQualifierRange(qualifier, minMaxQualifiers);
}
}
@@ -299,8 +300,10 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
family = IndexUtil.getLocalIndexColumnFamily(family);
}
Pair<Integer, Integer> range = qualifierRanges.get(family);
- determineQualifierRange(range.getFirst(), minMaxQualifiers);
- determineQualifierRange(range.getSecond(), minMaxQualifiers);
+ if (range != null) {
+ determineQualifierRange(range.getFirst(), minMaxQualifiers);
+ determineQualifierRange(range.getSecond(), minMaxQualifiers);
+ }
}
}
if (minMaxQualifiers.getFirst() == null) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
index 239539f..4b89133 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
@@ -25,6 +25,7 @@ import java.util.List;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.regionserver.RegionScanner;
import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.tuple.EncodedColumnQualiferCellsList;
import org.apache.phoenix.schema.tuple.MultiKeyValueTuple;
import org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple;
@@ -37,11 +38,13 @@ public class RegionScannerResultIterator extends BaseResultIterator {
private final RegionScanner scanner;
private final Pair<Integer, Integer> minMaxQualifiers;
private final boolean useQualifierAsIndex;
+ private final QualifierEncodingScheme encodingScheme;
- public RegionScannerResultIterator(RegionScanner scanner, Pair<Integer, Integer> minMaxQualifiers) {
+ public RegionScannerResultIterator(RegionScanner scanner, Pair<Integer, Integer> minMaxQualifiers, QualifierEncodingScheme encodingScheme) {
this.scanner = scanner;
this.useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(minMaxQualifiers);
this.minMaxQualifiers = minMaxQualifiers;
+ this.encodingScheme = encodingScheme;
}
@Override
@@ -51,7 +54,7 @@ public class RegionScannerResultIterator extends BaseResultIterator {
synchronized (scanner) {
try {
// TODO: size
- List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond()) : new ArrayList<Cell>();
+ List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond(), encodingScheme) : new ArrayList<Cell>();
// Results are potentially returned even when the return value of s.next is false
// since this is an indication of whether or not there are more values after the
// ones returned
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/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 40952cd..fd8ac8b 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
@@ -324,8 +324,8 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData {
public static final byte[] STORAGE_SCHEME_BYTES = Bytes.toBytes(STORAGE_SCHEME);
public static final String ENCODING_SCHEME = "ENCODING_SCHEME";
public static final byte[] ENCODING_SCHEME_BYTES = Bytes.toBytes(ENCODING_SCHEME);
- public static final String ENCODED_COLUMN_QUALIFIER = "COLUMN_QUALIFIER";
- public static final byte[] ENCODED_COLUMN_QUALIFIER_BYTES = Bytes.toBytes(ENCODED_COLUMN_QUALIFIER);
+ public static final String COLUMN_QUALIFIER = "COLUMN_QUALIFIER";
+ public static final byte[] COLUMN_QUALIFIER_BYTES = Bytes.toBytes(COLUMN_QUALIFIER);
public static final String COLUMN_QUALIFIER_COUNTER = "QUALIFIER_COUNTER";
public static final byte[] COLUMN_QUALIFIER_COUNTER_BYTES = Bytes.toBytes(COLUMN_QUALIFIER_COUNTER);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
index a6a57c7..2ef2127 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
@@ -220,7 +220,7 @@ public abstract class FormatToBytesWritableMapper<RECORD> extends Mapper<LongWri
byte[] cq;
if (!SchemaUtil.isPKColumn(c)) {
family = c.getFamilyName().getBytes();
- cq = EncodedColumnsUtil.getColumnQualifier(c, table);
+ cq = c.getColumnQualifierBytes();
} else {
// TODO: samarth verify if this is the right thing to do here.
cq = c.getName().getBytes();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java
index c5f690b..c529afe 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToKeyValueReducer.java
@@ -102,7 +102,7 @@ public class FormatToKeyValueReducer
byte[] cq;
if (!SchemaUtil.isPKColumn(c)) {
family = c.getFamilyName().getBytes();
- cq = EncodedColumnsUtil.getColumnQualifier(c, table);
+ cq = c.getColumnQualifierBytes();
} else {
// TODO: samarth verify if this is the right thing to do here.
cq = c.getName().getBytes();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/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 fe0d9cb..54d9c74 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
@@ -31,6 +31,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_COUNT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_DEF;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_FAMILY;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER_COUNTER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_SIZE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CURRENT_VALUE;
@@ -41,7 +42,6 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DECIMAL_DIGITS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAMILY_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_VALUE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODING_SCHEME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FUNCTION_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT;
@@ -108,7 +108,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_CONSTANT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_STATEMENT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
+import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS;
import java.math.BigDecimal;
@@ -165,14 +165,18 @@ public interface QueryConstants {
public static final byte[] RESERVED_COLUMN_FAMILY_BYTES = Bytes.toBytes(RESERVED_COLUMN_FAMILY);
public static final byte[] VALUE_COLUMN_FAMILY = RESERVED_COLUMN_FAMILY_BYTES;
- public static final byte[] VALUE_COLUMN_QUALIFIER = getEncodedColumnQualifier(1);
+ //TODO: samarth think about the implication of using the four byte scheme here. Can we just
+ // get away with storing them in a single byte? We would need to make our encoding scheme
+ // cognizant of the fact that all bytes may not be available making them interoperable.
+ // In other words allow upper casting but not downcasting.
+ public static final byte[] VALUE_COLUMN_QUALIFIER = FOUR_BYTE_QUALIFIERS.getEncodedBytes(1);
public static final byte[] ARRAY_VALUE_COLUMN_FAMILY = RESERVED_COLUMN_FAMILY_BYTES;
- public static final byte[] ARRAY_VALUE_COLUMN_QUALIFIER = getEncodedColumnQualifier(2);
+ public static final byte[] ARRAY_VALUE_COLUMN_QUALIFIER = FOUR_BYTE_QUALIFIERS.getEncodedBytes(2);
public final static PName SINGLE_COLUMN_NAME = PNameFactory.newNormalizedName("s");
public final static PName SINGLE_COLUMN_FAMILY_NAME = PNameFactory.newNormalizedName("s");
- public final static byte[] SINGLE_COLUMN = getEncodedColumnQualifier(3);
+ public final static byte[] SINGLE_COLUMN = FOUR_BYTE_QUALIFIERS.getEncodedBytes(3);
public final static byte[] SINGLE_COLUMN_FAMILY = RESERVED_COLUMN_FAMILY_BYTES;
/** END Set of reserved column qualifiers **/
@@ -204,7 +208,7 @@ public interface QueryConstants {
public static final ImmutableBytesPtr EMPTY_COLUMN_BYTES_PTR = new ImmutableBytesPtr(
EMPTY_COLUMN_BYTES);
public static final Integer ENCODED_EMPTY_COLUMN_NAME = 0;
- public static final byte[] ENCODED_EMPTY_COLUMN_BYTES = getEncodedColumnQualifier(ENCODED_EMPTY_COLUMN_NAME);
+ public static final byte[] ENCODED_EMPTY_COLUMN_BYTES = FOUR_BYTE_QUALIFIERS.getEncodedBytes(ENCODED_EMPTY_COLUMN_NAME);
public static final ImmutableBytesPtr ENCODED_EMPTY_COLUMN_BYTES_PTR = new ImmutableBytesPtr(
ENCODED_EMPTY_COLUMN_BYTES);
public final static String EMPTY_COLUMN_VALUE = "x";
@@ -318,7 +322,7 @@ public interface QueryConstants {
AUTO_PARTITION_SEQ + " VARCHAR," +
APPEND_ONLY_SCHEMA + " BOOLEAN," +
GUIDE_POSTS_WIDTH + " BIGINT," +
- ENCODED_COLUMN_QUALIFIER + " UNSIGNED_INT," +
+ COLUMN_QUALIFIER + " VARBINARY," +
STORAGE_SCHEME + " TINYINT, " +
ENCODING_SCHEME + " TINYINT, " +
COLUMN_QUALIFIER_COUNTER + " INTEGER, " +
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
index d757322..c997074 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
@@ -17,8 +17,6 @@
*/
package org.apache.phoenix.schema;
-import static org.apache.phoenix.util.EncodedColumnsUtil.usesEncodedColumnNames;
-
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Arrays;
@@ -38,7 +36,6 @@ import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.ParseNode;
import org.apache.phoenix.parse.SQLParser;
import org.apache.phoenix.schema.PTable.StorageScheme;
-import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.ExpressionUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.SchemaUtil;
@@ -129,7 +126,7 @@ public class ColumnRef {
}
Expression expression = table.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY ?
- new ArrayColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table)) : new KeyValueColumnExpression(column, displayName, usesEncodedColumnNames(table));
+ new ArrayColumnExpression(column, displayName, table.getEncodingScheme()) : new KeyValueColumnExpression(column, displayName);
if (column.getExpressionStr() != null) {
String url = PhoenixRuntime.JDBC_PROTOCOL
@@ -146,7 +143,6 @@ public class ColumnRef {
return new DefaultValueExpression(Arrays.asList(expression, defaultExpression));
}
}
-
return expression;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
index cd9c2c0..c220ed0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
@@ -101,7 +101,7 @@ public class DelegateColumn extends DelegateDatum implements PColumn {
return getDelegate().equals(o);
}
@Override
- public Integer getEncodedColumnQualifier() {
- return getDelegate().getEncodedColumnQualifier();
+ public byte[] getColumnQualifierBytes() {
+ return getDelegate().getColumnQualifierBytes();
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/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 06aa479..495969f 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
@@ -34,6 +34,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_COUNT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_DEF;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_FAMILY;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER_COUNTER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_SIZE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DATA_TABLE_NAME;
@@ -42,7 +43,6 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DECIMAL_DIGITS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAMILY_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_VALUE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODING_SCHEME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FUNCTION_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH;
@@ -363,7 +363,7 @@ public class MetaDataClient {
PK_NAME + "," + // write this both in the column and table rows for access by metadata APIs
KEY_SEQ + "," +
COLUMN_DEF + "," +
- ENCODED_COLUMN_QUALIFIER + ", " +
+ COLUMN_QUALIFIER + ", " +
IS_ROW_TIMESTAMP +
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String INSERT_COLUMN_ALTER_TABLE =
@@ -386,7 +386,7 @@ public class MetaDataClient {
PK_NAME + "," + // write this both in the column and table rows for access by metadata APIs
KEY_SEQ + "," +
COLUMN_DEF + "," +
- ENCODED_COLUMN_QUALIFIER +
+ COLUMN_QUALIFIER +
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String UPDATE_COLUMN_POSITION =
"UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\" ( " +
@@ -834,10 +834,10 @@ public class MetaDataClient {
} else {
colUpsert.setString(18, column.getExpressionStr());
}
- if (column.getEncodedColumnQualifier() == null) {
- colUpsert.setNull(19, Types.INTEGER);
+ if (column.getColumnQualifierBytes() == null) {
+ colUpsert.setNull(19, Types.VARBINARY);
} else {
- colUpsert.setInt(19, column.getEncodedColumnQualifier());
+ colUpsert.setBytes(19, column.getColumnQualifierBytes());
}
if (colUpsert.getParameterMetaData().getParameterCount() > 19) {
colUpsert.setBoolean(20, column.isRowTimestamp());
@@ -859,7 +859,7 @@ public class MetaDataClient {
argUpsert.execute();
}
- private PColumn newColumn(int position, ColumnDef def, PrimaryKeyConstraint pkConstraint, String defaultColumnFamily, boolean addingToPK, Integer encodedColumnQualifier) throws SQLException {
+ private PColumn newColumn(int position, ColumnDef def, PrimaryKeyConstraint pkConstraint, String defaultColumnFamily, boolean addingToPK, byte[] columnQualifierBytes) throws SQLException {
try {
ColumnName columnDefName = def.getColumnDefName();
SortOrder sortOrder = def.getSortOrder();
@@ -908,7 +908,7 @@ public class MetaDataClient {
isNull = false;
}
PColumn column = new PColumnImpl(PNameFactory.newName(columnName), familyName, def.getDataType(),
- def.getMaxLength(), def.getScale(), isNull, position, sortOrder, def.getArraySize(), null, false, def.getExpression(), isRowTimestamp, false, isPK ? null : encodedColumnQualifier);
+ def.getMaxLength(), def.getScale(), isNull, position, sortOrder, def.getArraySize(), null, false, def.getExpression(), isRowTimestamp, false, columnQualifierBytes);
return column;
} catch (IllegalArgumentException e) { // Based on precondition check in constructor
throw new SQLException(e);
@@ -2068,10 +2068,10 @@ public class MetaDataClient {
* partitioned by the virtue of indexId present in the row key. As such, different shared indexes can use
* potentially overlapping column qualifiers.
*
- * If the hbase table already exists, then possibly encoded or non-encoded column qualifiers already exist.
- * In this case we pursue ahead with non-encoded column qualifier scheme. If the phoenix table already exists
+ * If the hbase table already exists, then possibly encoded or non-encoded column qualifiers were used.
+ * In this case we pursue ahead with non-encoded column qualifier scheme. If the phoenix metadata for this table already exists
* then we rely on the PTable, with appropriate storage scheme, returned in the MetadataMutationResult to be updated
- * in the client cache. If the phoenix table already doesn't exist then the non-encoded column qualifier scheme works
+ * in the client cache. If the phoenix table metadata already doesn't exist then the non-encoded column qualifier scheme works
* because we cannot control the column qualifiers that were used when populating the hbase table.
* TODO: samarth add a test case for this
*/
@@ -2136,8 +2136,9 @@ public class MetaDataClient {
cqCounterFamily = defaultFamilyName != null ? defaultFamilyName : DEFAULT_COLUMN_FAMILY;
}
}
- Integer encodedCQ = isPkColumn ? null : cqCounter.getNextQualifier(cqCounterFamily);
- PColumn column = newColumn(position++, colDef, pkConstraint, defaultFamilyName, false, encodedCQ);
+ Integer encodedCQ = isPkColumn ? null : cqCounter.getNextQualifier(cqCounterFamily);
+ byte[] columnQualifierBytes = EncodedColumnsUtil.getColumnQualifierBytes(columnDefName.getColumnName(), encodedCQ, encodingScheme);
+ PColumn column = newColumn(position++, colDef, pkConstraint, defaultFamilyName, false, columnQualifierBytes);
if (cqCounter.increment(cqCounterFamily)) {
changedCqCounters.put(cqCounterFamily, cqCounter.getNextQualifier(cqCounterFamily));
}
@@ -2710,7 +2711,7 @@ public class MetaDataClient {
PTable viewIndexTable = new PTableImpl(null,
SchemaUtil.getSchemaNameFromFullName(viewIndexPhysicalName),
SchemaUtil.getTableNameFromFullName(viewIndexPhysicalName), ts,
- table.getColumnFamilies(),table.isNamespaceMapped());
+ table.getColumnFamilies(),table.isNamespaceMapped(), table.getStorageScheme(), table.getEncodingScheme());
tableRefs.add(new TableRef(null, viewIndexTable, ts, false));
}
}
@@ -3181,7 +3182,8 @@ public class MetaDataClient {
cqCounterToUse.getNextQualifier(familyName));
}
}
- PColumn column = newColumn(position++, colDef, PrimaryKeyConstraint.EMPTY, table.getDefaultFamilyName() == null ? null : table.getDefaultFamilyName().getString(), true, encodedCQ);
+ byte[] columnQualifierBytes = EncodedColumnsUtil.getColumnQualifierBytes(colDef.getColumnDefName().getColumnName(), encodedCQ, table);
+ PColumn column = newColumn(position++, colDef, PrimaryKeyConstraint.EMPTY, table.getDefaultFamilyName() == null ? null : table.getDefaultFamilyName().getString(), true, columnQualifierBytes);
columns.add(column);
String pkName = null;
Short keySeq = null;
@@ -3356,7 +3358,7 @@ public class MetaDataClient {
PTable viewIndexTable = new PTableImpl(null,
SchemaUtil.getSchemaNameFromFullName(viewIndexPhysicalName),
SchemaUtil.getTableNameFromFullName(viewIndexPhysicalName), ts,
- table.getColumnFamilies(), table.isNamespaceMapped());
+ table.getColumnFamilies(), table.isNamespaceMapped(), table.getStorageScheme(), table.getEncodingScheme());
List<TableRef> tableRefs = Collections.singletonList(new TableRef(null, viewIndexTable, ts, false));
MutationPlan plan = new PostDDLCompiler(connection).compile(tableRefs, null, null,
Collections.<PColumn> emptyList(), ts);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java
index 978ded7..9e26227 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumn.java
@@ -61,5 +61,5 @@ public interface PColumn extends PDatum {
boolean isDynamic();
- Integer getEncodedColumnQualifier();
+ byte[] getColumnQualifierBytes();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
index c175aa2..d1a35cf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
@@ -17,11 +17,14 @@
*/
package org.apache.phoenix.schema;
+import static org.apache.phoenix.util.EncodedColumnsUtil.usesEncodedColumnNames;
+
import java.util.List;
import java.util.Map;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.util.EncodedColumnsUtil;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
+import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.SizedUtil;
import com.google.common.base.Preconditions;
@@ -34,7 +37,7 @@ public class PColumnFamilyImpl implements PColumnFamily {
private final List<PColumn> columns;
private final Map<String, PColumn> columnNamesByStrings;
private final Map<byte[], PColumn> columnNamesByBytes;
- private final Map<byte[], PColumn> encodedColumnQualifersByBytes;
+ private final Map<byte[], PColumn> columnsByQualifiers;
private final int estimatedSize;
@Override
@@ -42,7 +45,7 @@ public class PColumnFamilyImpl implements PColumnFamily {
return estimatedSize;
}
- public PColumnFamilyImpl(PName name, List<PColumn> columns, boolean useEncodedColumnNames) {
+ public PColumnFamilyImpl(PName name, List<PColumn> columns) {
Preconditions.checkNotNull(name);
// Include guidePosts also in estimating the size
long estimatedSize = SizedUtil.OBJECT_SIZE + SizedUtil.POINTER_SIZE * 5 + SizedUtil.INT_SIZE + name.getEstimatedSize() +
@@ -51,18 +54,21 @@ public class PColumnFamilyImpl implements PColumnFamily {
this.columns = ImmutableList.copyOf(columns);
ImmutableMap.Builder<String, PColumn> columnNamesByStringBuilder = ImmutableMap.builder();
ImmutableSortedMap.Builder<byte[], PColumn> columnNamesByBytesBuilder = ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR);
- ImmutableSortedMap.Builder<byte[], PColumn> encodedColumnQualifiersByBytesBuilder = ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR);
+ ImmutableSortedMap.Builder<byte[], PColumn> columnsByQualifiersBuilder = ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR);
for (PColumn column : columns) {
estimatedSize += column.getEstimatedSize();
columnNamesByBytesBuilder.put(column.getName().getBytes(), column);
columnNamesByStringBuilder.put(column.getName().getString(), column);
- if (useEncodedColumnNames && column.getEncodedColumnQualifier() != null) {
- encodedColumnQualifiersByBytesBuilder.put(EncodedColumnsUtil.getEncodedColumnQualifier(column), column);
+ // In certain cases like JOIN, PK columns are assigned a column family. So they
+ // are not evaluated as a PK column. However, their column qualifier bytes are
+ // still null.
+ if (!SchemaUtil.isPKColumn(column) && column.getColumnQualifierBytes() != null) {
+ columnsByQualifiersBuilder.put(column.getColumnQualifierBytes(), column);
}
}
this.columnNamesByBytes = columnNamesByBytesBuilder.build();
this.columnNamesByStrings = columnNamesByStringBuilder.build();
- this.encodedColumnQualifersByBytes = encodedColumnQualifiersByBytesBuilder.build();
+ this.columnsByQualifiers = columnsByQualifiersBuilder.build();
this.estimatedSize = (int)estimatedSize;
}
@@ -94,16 +100,21 @@ public class PColumnFamilyImpl implements PColumnFamily {
return column;
}
+
+ //TODO: FIXME: samarth think about backward compatibility here since older tables won't have column qualifiers in their metadata
@Override
public PColumn getPColumnForColumnQualifier(byte[] cq) throws ColumnNotFoundException {
Preconditions.checkNotNull(cq);
- PColumn column = encodedColumnQualifersByBytes.get(cq);
- if (column == null) {
- // For tables with non-encoded column names, column qualifiers are
- // column name bytes. Also dynamic columns don't have encoded column
- // qualifiers. So they could be found in the column name by bytes map.
- return getPColumnForColumnNameBytes(cq);
- }
- return column;
+ return columnsByQualifiers.get(cq);
+// if (encodedColumnQualifiers) {
+// return columnsByQualifiers.get(cq);
+// }
+// /*
+// * For tables with non-encoded column names, column qualifiers are
+// * column name bytes. Also dynamic columns don't have encoded column
+// * qualifiers. So they could be found in the column name by bytes map.
+// */
+// return getPColumnForColumnNameBytes(cq);
+
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/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 dbb96d5..16054b4 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
@@ -40,7 +40,7 @@ public class PColumnImpl implements PColumn {
private String expressionStr;
private boolean isRowTimestamp;
private boolean isDynamic;
- private Integer columnQualifier;
+ private byte[] columnQualifierBytes;
public PColumnImpl() {
}
@@ -52,13 +52,13 @@ public class PColumnImpl implements PColumn {
Integer scale,
boolean nullable,
int position,
- SortOrder sortOrder, Integer arrSize, byte[] viewConstant, boolean isViewReferenced, String expressionStr, boolean isRowTimestamp, boolean isDynamic, Integer columnQualifier) {
- init(name, familyName, dataType, maxLength, scale, nullable, position, sortOrder, arrSize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, isDynamic, columnQualifier);
+ SortOrder sortOrder, Integer arrSize, byte[] viewConstant, boolean isViewReferenced, String expressionStr, boolean isRowTimestamp, boolean isDynamic, byte[] columnQualifierBytes) {
+ init(name, familyName, dataType, maxLength, scale, nullable, position, sortOrder, arrSize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, isDynamic, columnQualifierBytes);
}
public PColumnImpl(PColumn column, int position) {
this(column.getName(), column.getFamilyName(), column.getDataType(), column.getMaxLength(),
- column.getScale(), column.isNullable(), position, column.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(), column.isDynamic(), column.getEncodedColumnQualifier());
+ column.getScale(), column.isNullable(), position, column.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(), column.isDynamic(), column.getColumnQualifierBytes());
}
private void init(PName name,
@@ -70,7 +70,7 @@ public class PColumnImpl implements PColumn {
int position,
SortOrder sortOrder,
Integer arrSize,
- byte[] viewConstant, boolean isViewReferenced, String expressionStr, boolean isRowTimestamp, boolean isDynamic, Integer columnQualifier) {
+ byte[] viewConstant, boolean isViewReferenced, String expressionStr, boolean isRowTimestamp, boolean isDynamic, byte[] columnQualifierBytes) {
Preconditions.checkNotNull(sortOrder);
this.dataType = dataType;
if (familyName == null) {
@@ -95,7 +95,7 @@ public class PColumnImpl implements PColumn {
this.expressionStr = expressionStr;
this.isRowTimestamp = isRowTimestamp;
this.isDynamic = isDynamic;
- this.columnQualifier = columnQualifier;
+ this.columnQualifierBytes = columnQualifierBytes;
}
@Override
@@ -209,8 +209,8 @@ public class PColumnImpl implements PColumn {
}
@Override
- public Integer getEncodedColumnQualifier() {
- return columnQualifier;
+ public byte[] getColumnQualifierBytes() {
+ return columnQualifierBytes;
}
/**
@@ -258,12 +258,12 @@ public class PColumnImpl implements PColumn {
if (column.hasIsDynamic()) {
isDynamic = column.getIsDynamic();
}
- Integer columnQualifier = null;
- if (column.hasEncodedColumnQualifier()) {
- columnQualifier = column.getEncodedColumnQualifier();
+ byte[] columnQualifierBytes = null;
+ if (column.hasColumnQualifierBytes()) {
+ columnQualifierBytes = column.getColumnQualifierBytes().toByteArray();
}
return new PColumnImpl(columnName, familyName, dataType, maxLength, scale, nullable, position, sortOrder,
- arraySize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, isDynamic, columnQualifier);
+ arraySize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, isDynamic, columnQualifierBytes);
}
public static PTableProtos.PColumn toProto(PColumn column) {
@@ -294,8 +294,8 @@ public class PColumnImpl implements PColumn {
builder.setExpression(column.getExpressionStr());
}
builder.setIsRowTimestamp(column.isRowTimestamp());
- if (column.getEncodedColumnQualifier() != null) {
- builder.setEncodedColumnQualifier(column.getEncodedColumnQualifier());
+ if (column.getColumnQualifierBytes() != null) {
+ builder.setColumnQualifierBytes(ByteStringer.wrap(column.getColumnQualifierBytes()));
}
return builder.build();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
index 0263b09..169e78d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
@@ -214,7 +214,7 @@ public class PMetaDataImpl implements PMetaData {
// Update position of columns that follow removed column
for (int i = position+1; i < oldColumns.size(); i++) {
PColumn oldColumn = oldColumns.get(i);
- PColumn newColumn = new PColumnImpl(oldColumn.getName(), oldColumn.getFamilyName(), oldColumn.getDataType(), oldColumn.getMaxLength(), oldColumn.getScale(), oldColumn.isNullable(), i-1+positionOffset, oldColumn.getSortOrder(), oldColumn.getArraySize(), oldColumn.getViewConstant(), oldColumn.isViewReferenced(), oldColumn.getExpressionStr(), oldColumn.isRowTimestamp(), oldColumn.isDynamic(), oldColumn.getEncodedColumnQualifier());
+ PColumn newColumn = new PColumnImpl(oldColumn.getName(), oldColumn.getFamilyName(), oldColumn.getDataType(), oldColumn.getMaxLength(), oldColumn.getScale(), oldColumn.isNullable(), i-1+positionOffset, oldColumn.getSortOrder(), oldColumn.getArraySize(), oldColumn.getViewConstant(), oldColumn.isViewReferenced(), oldColumn.getExpressionStr(), oldColumn.isRowTimestamp(), oldColumn.isDynamic(), oldColumn.getColumnQualifierBytes());
columns.add(newColumn);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
index 184a588..4c85e48 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
@@ -190,194 +190,167 @@ public interface PTable extends PMetaDataEntity {
}
}
- public static class QualifierEncodingScheme<E> implements QualifierEncoderDecoder<E> {
-
- public static final QualifierEncodingScheme NON_ENCODED_QUALIFIERS = new QualifierEncodingScheme<String>((byte)0, "NON_ENCODED_QUALIFIERS", null) {
+ public enum QualifierEncodingScheme implements QualifierEncoderDecoder {
+ NON_ENCODED_QUALIFIERS((byte)0, null) {
@Override
- public byte[] getEncodedBytes(String value) {
- return Bytes.toBytes(value);
+ public byte[] getEncodedBytes(int value) {
+ throw new UnsupportedOperationException();
}
@Override
- public String getDecodedValue(byte[] bytes) {
- return Bytes.toString(bytes);
+ public int getDecodedValue(byte[] bytes) {
+ throw new UnsupportedOperationException();
}
@Override
- public String getDecodedValue(byte[] bytes, int offset, int length) {
- return Bytes.toString(bytes, offset, length);
+ public int getDecodedValue(byte[] bytes, int offset, int length) {
+ throw new UnsupportedOperationException();
}
@Override
- public boolean isEncodeable(String value) {
+ public boolean isEncodeable() {
return true;
}
@Override
public String toString() {
- return "NON_ENCODED_QUALIFIERS";
+ return name();
}
- };
- public static final QualifierEncodingScheme ONE_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)1, "ONE_BYTE_QUALIFIERS", 255l) {
+ },
+ ONE_BYTE_QUALIFIERS((byte)1, 255) {
@Override
- public byte[] getEncodedBytes(Long value) {
+ public byte[] getEncodedBytes(int value) {
throw new UnsupportedOperationException();
}
@Override
- public Long getDecodedValue(byte[] bytes) {
+ public int getDecodedValue(byte[] bytes) {
throw new UnsupportedOperationException();
}
@Override
- public Long getDecodedValue(byte[] bytes, int offset, int length) {
+ public int getDecodedValue(byte[] bytes, int offset, int length) {
throw new UnsupportedOperationException();
}
@Override
- public boolean isEncodeable(Long value) {
+ public boolean isEncodeable() {
return true;
}
@Override
public String toString() {
- return "ONE_BYTE_QUALIFIERS";
+ return name();
}
- };
- public static final QualifierEncodingScheme TWO_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)2, "TWO_BYTE_QUALIFIERS", 65535l) {
+ },
+ TWO_BYTE_QUALIFIERS((byte)2, 65535) {
@Override
- public byte[] getEncodedBytes(Long value) {
+ public byte[] getEncodedBytes(int value) {
throw new UnsupportedOperationException();
}
@Override
- public Long getDecodedValue(byte[] bytes) {
+ public int getDecodedValue(byte[] bytes) {
throw new UnsupportedOperationException();
}
@Override
- public Long getDecodedValue(byte[] bytes, int offset, int length) {
+ public int getDecodedValue(byte[] bytes, int offset, int length) {
throw new UnsupportedOperationException();
}
@Override
- public boolean isEncodeable(Long value) {
+ public boolean isEncodeable() {
return true;
}
@Override
public String toString() {
- return "TWO_BYTE_QUALIFIERS";
+ return name();
}
- };
- public static final QualifierEncodingScheme THREE_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)3, "THREE_BYTE_QUALIFIERS", 16777215l) {
+ },
+ THREE_BYTE_QUALIFIERS((byte)3, 16777215) {
@Override
- public byte[] getEncodedBytes(Long value) {
+ public byte[] getEncodedBytes(int value) {
throw new UnsupportedOperationException();
}
@Override
- public Long getDecodedValue(byte[] bytes) {
+ public int getDecodedValue(byte[] bytes) {
throw new UnsupportedOperationException();
}
@Override
- public Long getDecodedValue(byte[] bytes, int offset, int length) {
+ public int getDecodedValue(byte[] bytes, int offset, int length) {
throw new UnsupportedOperationException();
}
@Override
- public boolean isEncodeable(Long value) {
+ public boolean isEncodeable() {
return true;
}
@Override
public String toString() {
- return "THREE_BYTE_QUALIFIERS";
+ return name();
}
- };
- public static final QualifierEncodingScheme FOUR_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)4, "FOUR_BYTE_QUALIFIERS", 4294967295l) {
+ },
+ FOUR_BYTE_QUALIFIERS((byte)4, Integer.MAX_VALUE) {
@Override
- public byte[] getEncodedBytes(Long value) {
+ public byte[] getEncodedBytes(int value) {
return Bytes.toBytes(value);
}
@Override
- public Long getDecodedValue(byte[] bytes) {
- return Bytes.toLong(bytes);
+ public int getDecodedValue(byte[] bytes) {
+ return Bytes.toInt(bytes);
}
@Override
- public Long getDecodedValue(byte[] bytes, int offset, int length) {
- return Bytes.toLong(bytes, offset, length);
+ public int getDecodedValue(byte[] bytes, int offset, int length) {
+ return Bytes.toInt(bytes, offset, length);
}
@Override
- public boolean isEncodeable(Long value) {
+ public boolean isEncodeable() {
return true;
}
@Override
public String toString() {
- return "FOUR_BYTE_QUALIFIERS";
+ return name();
}
};
- public static final QualifierEncodingScheme[] schemes = {NON_ENCODED_QUALIFIERS, ONE_BYTE_QUALIFIERS, TWO_BYTE_QUALIFIERS, THREE_BYTE_QUALIFIERS, FOUR_BYTE_QUALIFIERS};
- private final byte[] metadataBytes;
+
private final byte metadataValue;
- private final Long maxQualifier;
-
- private QualifierEncodingScheme(byte serializedMetadataValue, String name, Long maxQualifier) {
- this.metadataValue = serializedMetadataValue;
- this.metadataBytes = Bytes.toBytes(name);
- this.maxQualifier = maxQualifier;
- }
-
- public byte[] getMetadataBytes() {
- return metadataBytes;
- }
-
+ private final Integer maxQualifier;
+
public byte getSerializedMetadataValue() {
return this.metadataValue;
}
public static QualifierEncodingScheme fromSerializedValue(byte serializedValue) {
- if (serializedValue < 0 || serializedValue >= schemes.length) {
+ if (serializedValue < 0 || serializedValue >= QualifierEncodingScheme.values().length) {
return null;
}
- return schemes[serializedValue];
+ return QualifierEncodingScheme.values()[serializedValue];
}
- public Long getMaxQualifier() {
+ public Integer getMaxQualifier() {
return maxQualifier;
}
- @Override
- public byte[] getEncodedBytes(E value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public E getDecodedValue(byte[] bytes) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public E getDecodedValue(byte[] bytes, int offset, int length) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isEncodeable(E value) {
- throw new UnsupportedOperationException();
+ private QualifierEncodingScheme(byte serializedMetadataValue, Integer maxQualifier) {
+ this.metadataValue = serializedMetadataValue;
+ this.maxQualifier = maxQualifier;
}
}
- interface QualifierEncoderDecoder<E> {
- byte[] getEncodedBytes(E value);
- E getDecodedValue(byte[] bytes);
- E getDecodedValue(byte[] bytes, int offset, int length);
- boolean isEncodeable(E value);
+ interface QualifierEncoderDecoder {
+ byte[] getEncodedBytes(int value);
+ int getDecodedValue(byte[] bytes);
+ int getDecodedValue(byte[] bytes, int offset, int length);
+ boolean isEncodeable();
}
long getTimeStamp();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/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 7e6f35b..7f11faf 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
@@ -20,7 +20,7 @@ package org.apache.phoenix.schema;
import static org.apache.phoenix.hbase.index.util.KeyValueBuilder.addQuietly;
import static org.apache.phoenix.hbase.index.util.KeyValueBuilder.deleteQuietly;
import static org.apache.phoenix.schema.SaltingUtil.SALTING_COLUMN;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
+import static org.apache.phoenix.util.EncodedColumnsUtil.usesEncodedColumnNames;
import java.io.IOException;
import java.sql.DriverManager;
@@ -34,6 +34,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import javax.annotation.Nonnull;
+
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.client.Delete;
@@ -119,7 +121,7 @@ public class PTableImpl implements PTable {
private Map<byte[], PColumnFamily> familyByBytes;
private Map<String, PColumnFamily> familyByString;
private ListMultimap<String, PColumn> columnsByName;
- private ListMultimap<Pair<String, Integer>, PColumn> kvColumnsByEncodedColumnNames;
+ private ListMultimap<KVColumnFamilyQualifier, PColumn> kvColumnsByEncodedQualifiers;
private PName pkName;
private Integer bucketNum;
private RowKeySchema rowKeySchema;
@@ -160,8 +162,33 @@ public class PTableImpl implements PTable {
this.physicalNames = Collections.emptyList();
this.rowKeySchema = RowKeySchema.EMPTY_SCHEMA;
}
-
- public PTableImpl(PName tenantId, String schemaName, String tableName, long timestamp, List<PColumnFamily> families, boolean isNamespaceMapped) { // For base table of mapped VIEW
+
+ // Constructor used at table creation time
+ public PTableImpl(PName tenantId, String schemaName, String tableName, long timestamp, List<PColumnFamily> families, boolean isNamespaceMapped) {
+ Preconditions.checkArgument(tenantId==null || tenantId.getBytes().length > 0); // tenantId should be null or not empty
+ this.tenantId = tenantId;
+ this.name = PNameFactory.newName(SchemaUtil.getTableName(schemaName, tableName));
+ this.key = new PTableKey(tenantId, name.getString());
+ this.schemaName = PNameFactory.newName(schemaName);
+ this.tableName = PNameFactory.newName(tableName);
+ this.type = PTableType.VIEW;
+ this.viewType = ViewType.MAPPED;
+ this.timeStamp = timestamp;
+ this.pkColumns = this.allColumns = Collections.emptyList();
+ this.rowKeySchema = RowKeySchema.EMPTY_SCHEMA;
+ this.indexes = Collections.emptyList();
+ this.familyByBytes = Maps.newHashMapWithExpectedSize(families.size());
+ this.familyByString = Maps.newHashMapWithExpectedSize(families.size());
+ for (PColumnFamily family : families) {
+ familyByBytes.put(family.getName().getBytes(), family);
+ familyByString.put(family.getName().getString(), family);
+ }
+ this.families = families;
+ this.physicalNames = Collections.emptyList();
+ this.isNamespaceMapped = isNamespaceMapped;
+ }
+
+ public PTableImpl(PName tenantId, String schemaName, String tableName, long timestamp, List<PColumnFamily> families, boolean isNamespaceMapped, StorageScheme storageScheme, QualifierEncodingScheme encodingScheme) { // For base table of mapped VIEW
Preconditions.checkArgument(tenantId==null || tenantId.getBytes().length > 0); // tenantId should be null or not empty
this.tenantId = tenantId;
this.name = PNameFactory.newName(SchemaUtil.getTableName(schemaName, tableName));
@@ -183,6 +210,8 @@ public class PTableImpl implements PTable {
this.families = families;
this.physicalNames = Collections.emptyList();
this.isNamespaceMapped = isNamespaceMapped;
+ this.storageScheme = storageScheme;
+ this.qualifierEncodingScheme = encodingScheme;
}
// For indexes stored in shared physical tables
@@ -452,7 +481,7 @@ public class PTableImpl implements PTable {
PColumn[] allColumns;
this.columnsByName = ArrayListMultimap.create(columns.size(), 1);
- this.kvColumnsByEncodedColumnNames = (EncodedColumnsUtil.usesEncodedColumnNames(qualifierEncodingScheme) ? ArrayListMultimap.<Pair<String, Integer>, PColumn>create(columns.size(), 1) : null);
+ this.kvColumnsByEncodedQualifiers = ArrayListMultimap.<KVColumnFamilyQualifier, PColumn>create(columns.size(), 1);
int numPKColumns = 0;
if (bucketNum != null) {
// Add salt column to allColumns and pkColumns, but don't add to
@@ -465,6 +494,7 @@ public class PTableImpl implements PTable {
allColumns = new PColumn[columns.size()];
pkColumns = Lists.newArrayListWithExpectedSize(columns.size());
}
+ boolean encodedColumnQualifiers = usesEncodedColumnNames(qualifierEncodingScheme);
for (PColumn column : columns) {
allColumns[column.getPosition()] = column;
PName familyName = column.getFamilyName();
@@ -483,20 +513,18 @@ public class PTableImpl implements PTable {
}
}
}
- //TODO: samarth understand the implication of this.
- if (kvColumnsByEncodedColumnNames != null) {
- Integer cq = column.getEncodedColumnQualifier();
- String cf = column.getFamilyName() != null ? column.getFamilyName().getString() : null;
- if (cf != null && cq != null) {
- Pair<String, Integer> pair = new Pair<>(cf, cq);
- if (kvColumnsByEncodedColumnNames.put(pair, column)) {
- int count = 0;
- for (PColumn dupColumn : kvColumnsByEncodedColumnNames.get(pair)) {
- if (Objects.equal(familyName, dupColumn.getFamilyName())) {
- count++;
- if (count > 1) {
- throw new ColumnAlreadyExistsException(schemaName.getString(), name.getString(), columnName);
- }
+ byte[] cq = column.getColumnQualifierBytes();
+ String cf = column.getFamilyName() != null ? column.getFamilyName().getString() : null;
+ if (cf != null && cq != null && encodedColumnQualifiers) {
+ KVColumnFamilyQualifier info = new KVColumnFamilyQualifier(cf, cq);
+ if (kvColumnsByEncodedQualifiers.put(info, column)) {
+ int count = 0;
+ for (PColumn dupColumn : kvColumnsByEncodedQualifiers.get(info)) {
+ if (Objects.equal(familyName, dupColumn.getFamilyName())) {
+ count++;
+ if (count > 1) {
+ throw new ColumnAlreadyExistsException(schemaName.getString(),
+ name.getString(), columnName);
}
}
}
@@ -561,7 +589,7 @@ public class PTableImpl implements PTable {
.orderedBy(Bytes.BYTES_COMPARATOR);
for (int i = 0; i < families.length; i++) {
Map.Entry<PName,List<PColumn>> entry = iterator.next();
- PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue(), EncodedColumnsUtil.usesEncodedColumnNames(qualifierEncodingScheme));
+ PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue());//, qualifierEncodingScheme);
families[i] = family;
familyByString.put(family.getName().getString(), family);
familyByBytes.put(family.getName().getBytes(), family);
@@ -806,9 +834,8 @@ public class PTableImpl implements PTable {
String columnName = (String)PVarchar.INSTANCE.toObject(cq);
return getPColumnForColumnName(columnName);
} else {
- Integer qualifier = getEncodedColumnQualifier(cq);
String family = (String)PVarchar.INSTANCE.toObject(cf);
- List<PColumn> columns = kvColumnsByEncodedColumnNames.get(new Pair<>(family, qualifier));
+ List<PColumn> columns = kvColumnsByEncodedQualifiers.get(new KVColumnFamilyQualifier(family, cq));
int size = columns.size();
if (size == 0) {
//TODO: samarth should we have a column qualifier not found exception?
@@ -898,7 +925,8 @@ public class PTableImpl implements PTable {
Collection<PColumn> columns = family.getColumns();
int maxEncodedColumnQualifier = Integer.MIN_VALUE;
for (PColumn column : columns) {
- maxEncodedColumnQualifier = Math.max(maxEncodedColumnQualifier, column.getEncodedColumnQualifier());
+ int qualifier = qualifierEncodingScheme.getDecodedValue(column.getColumnQualifierBytes());
+ maxEncodedColumnQualifier = Math.max(maxEncodedColumnQualifier, qualifier);
}
Expression[] colValues = new Expression[maxEncodedColumnQualifier+1];
Arrays.fill(colValues, new DelegateExpression(LiteralExpression.newConstant(null)) {
@@ -911,7 +939,8 @@ public class PTableImpl implements PTable {
colValues[0]=LiteralExpression.newConstant(QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
for (PColumn column : columns) {
if (columnToValueMap.containsKey(column)) {
- colValues[column.getEncodedColumnQualifier()] = new LiteralExpression(columnToValueMap.get(column));
+ int qualifier = qualifierEncodingScheme.getDecodedValue(column.getColumnQualifierBytes());
+ colValues[qualifier] = new LiteralExpression(columnToValueMap.get(column));
}
}
@@ -963,7 +992,7 @@ public class PTableImpl implements PTable {
public void setValue(PColumn column, byte[] byteValue) {
deleteRow = null;
byte[] family = column.getFamilyName().getBytes();
- byte[] qualifier = getColumnQualifier(column);
+ byte[] qualifier = column.getColumnQualifierBytes();
ImmutableBytesPtr qualifierPtr = new ImmutableBytesPtr(qualifier);
PDataType<?> type = column.getDataType();
// Check null, since some types have no byte representation for null
@@ -1041,10 +1070,6 @@ public class PTableImpl implements PTable {
}
}
- private byte[] getColumnQualifier(PColumn column) {
- return EncodedColumnsUtil.getColumnQualifier(column, PTableImpl.this);
- }
-
}
@Override
@@ -1510,4 +1535,39 @@ public class PTableImpl implements PTable {
public QualifierEncodingScheme getEncodingScheme() {
return qualifierEncodingScheme;
}
+
+ private static final class KVColumnFamilyQualifier {
+ @Nonnull
+ private final String colFamilyName;
+ @Nonnull
+ private final byte[] colQualifier;
+
+ public KVColumnFamilyQualifier(String colFamilyName, byte[] colQualifier) {
+ Preconditions.checkArgument(colFamilyName != null && colQualifier != null,
+ "None of the arguments, column family name or column qualifier can be null");
+ this.colFamilyName = colFamilyName;
+ this.colQualifier = colQualifier;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + colFamilyName.hashCode();
+ result = prime * result + Arrays.hashCode(colQualifier);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ KVColumnFamilyQualifier other = (KVColumnFamilyQualifier) obj;
+ if (!colFamilyName.equals(other.colFamilyName)) return false;
+ if (!Arrays.equals(colQualifier, other.colQualifier)) return false;
+ return true;
+ }
+
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java
index 9336938..d875982 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java
@@ -24,14 +24,16 @@ public class ProjectedColumn extends DelegateColumn {
private final int position;
private final boolean nullable;
private final ColumnRef sourceColumnRef;
+ private final byte[] cq;
- public ProjectedColumn(PName name, PName familyName, int position, boolean nullable, ColumnRef sourceColumnRef) {
+ public ProjectedColumn(PName name, PName familyName, int position, boolean nullable, ColumnRef sourceColumnRef, byte[] cq) {
super(sourceColumnRef.getColumn());
this.name = name;
this.familyName = familyName;
this.position = position;
this.nullable = nullable;
this.sourceColumnRef = sourceColumnRef;
+ this.cq = cq;
}
@Override
@@ -53,7 +55,12 @@ public class ProjectedColumn extends DelegateColumn {
public boolean isNullable() {
return nullable;
}
-
+
+ @Override
+ public byte[] getColumnQualifierBytes() {
+ return cq;
+ }
+
public ColumnRef getSourceColumnRef() {
return sourceColumnRef;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java
index f39bb1f..dcafd84 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java
@@ -20,7 +20,6 @@ package org.apache.phoenix.schema.tuple;
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.phoenix.query.QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE;
import static org.apache.phoenix.query.QueryConstants.ENCODED_EMPTY_COLUMN_NAME;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import java.util.Collection;
import java.util.ConcurrentModificationException;
@@ -32,6 +31,7 @@ import java.util.NoSuchElementException;
import javax.annotation.concurrent.NotThreadSafe;
import org.apache.hadoop.hbase.Cell;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
/**
@@ -64,8 +64,9 @@ public class EncodedColumnQualiferCellsList implements List<Cell> {
private static final int RESERVED_RANGE_SIZE = ENCODED_CQ_COUNTER_INITIAL_VALUE - ENCODED_EMPTY_COLUMN_NAME;
// Used by iterators to figure out if the list was structurally modified.
private int modCount = 0;
+ private final QualifierEncodingScheme encodingScheme;
- public EncodedColumnQualiferCellsList(int minQ, int maxQ) {
+ public EncodedColumnQualiferCellsList(int minQ, int maxQ, QualifierEncodingScheme encodingScheme) {
checkArgument(minQ <= maxQ, "Invalid arguments. Min: " + minQ
+ ". Max: " + maxQ);
this.minQualifier = minQ;
@@ -80,6 +81,7 @@ public class EncodedColumnQualiferCellsList implements List<Cell> {
}
this.array = new Cell[size];
this.nonReservedRangeOffset = minQ > ENCODED_CQ_COUNTER_INITIAL_VALUE ? minQ - ENCODED_CQ_COUNTER_INITIAL_VALUE : 0;
+ this.encodingScheme = encodingScheme;
}
@Override
@@ -131,7 +133,7 @@ public class EncodedColumnQualiferCellsList implements List<Cell> {
if (e == null) {
throw new NullPointerException();
}
- int columnQualifier = getEncodedColumnQualifier(e.getQualifierArray(), e.getQualifierOffset(), e.getQualifierLength());
+ int columnQualifier = encodingScheme.getDecodedValue(e.getQualifierArray(), e.getQualifierOffset(), e.getQualifierLength());
checkQualifierRange(columnQualifier);
int idx = getArrayIndex(columnQualifier);
@@ -231,7 +233,7 @@ public class EncodedColumnQualiferCellsList implements List<Cell> {
ListIterator<Cell> listItr = this.listIterator();
while (listItr.hasNext()) {
Cell cellInThis = listItr.next();
- int qualifier = getEncodedColumnQualifier(cellInThis.getQualifierArray(),
+ int qualifier = encodingScheme.getDecodedValue(cellInThis.getQualifierArray(),
cellInThis.getQualifierOffset(), cellInThis.getQualifierLength());
try {
Cell cellInParam = list.getCellForColumnQualifier(qualifier);
@@ -354,7 +356,12 @@ public class EncodedColumnQualiferCellsList implements List<Cell> {
return new Itr();
}
- public Cell getCellForColumnQualifier(int columnQualifier) {
+ public Cell getCellForColumnQualifier(byte[] qualifierBytes) {
+ int columnQualifier = encodingScheme.getDecodedValue(qualifierBytes);
+ return getCellForColumnQualifier(columnQualifier);
+ }
+
+ private Cell getCellForColumnQualifier(int columnQualifier) {
checkQualifierRange(columnQualifier);
int idx = getArrayIndex(columnQualifier);
Cell c = array[idx];
@@ -510,7 +517,7 @@ public class EncodedColumnQualiferCellsList implements List<Cell> {
if (lastRet == -1) {
throw new IllegalStateException();
}
- int columnQualifier = getEncodedColumnQualifier(e.getQualifierArray(), e.getQualifierOffset(), e.getQualifierLength());
+ int columnQualifier = encodingScheme.getDecodedValue(e.getQualifierArray(), e.getQualifierOffset(), e.getQualifierLength());
int idx = getArrayIndex(columnQualifier);
if (idx != lastRet) {
throw new IllegalArgumentException("Cell " + e + " with column qualifier "
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedMultiKeyValueTuple.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedMultiKeyValueTuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedMultiKeyValueTuple.java
index 08cafe0..01a5e4d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedMultiKeyValueTuple.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedMultiKeyValueTuple.java
@@ -18,7 +18,6 @@
package org.apache.phoenix.schema.tuple;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import java.util.List;
@@ -58,7 +57,7 @@ public class PositionBasedMultiKeyValueTuple extends BaseTuple {
@Override
public Cell getValue(byte[] family, byte[] qualifier) {
- return values.getCellForColumnQualifier(getEncodedColumnQualifier(qualifier));
+ return values.getCellForColumnQualifier(qualifier);
}
@Override
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedResultTuple.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedResultTuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedResultTuple.java
index 109cfc3..63ba101 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedResultTuple.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedResultTuple.java
@@ -49,8 +49,7 @@ public class PositionBasedResultTuple extends BaseTuple {
@Override
public KeyValue getValue(byte[] family, byte[] qualifier) {
- int columnQualifier = EncodedColumnsUtil.getEncodedColumnQualifier(qualifier);
- return org.apache.hadoop.hbase.KeyValueUtil.ensureKeyValue(cells.getCellForColumnQualifier(columnQualifier));
+ return org.apache.hadoop.hbase.KeyValueUtil.ensureKeyValue(cells.getCellForColumnQualifier(qualifier));
}
@Override
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
index a9addf0..26ffe82 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
@@ -17,7 +17,7 @@
*/
package org.apache.phoenix.util;
-import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
import java.util.Map;
@@ -44,32 +44,6 @@ public class EncodedColumnsUtil {
public static boolean usesEncodedColumnNames(QualifierEncodingScheme encodingScheme) {
return encodingScheme != null && encodingScheme != QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
}
-
- public static byte[] getEncodedColumnQualifier(PColumn column) {
- checkArgument(!SchemaUtil.isPKColumn(column), "No column qualifiers for PK columns");
- checkArgument(!column.isDynamic(), "No encoded column qualifiers for dynamic columns");
- //TODO: samarth this would need to use encoding scheme.
- return Bytes.toBytes(column.getEncodedColumnQualifier());
- }
-
- public static int getEncodedColumnQualifier(byte[] bytes, int offset, int length) {
- //TODO: samarth this would need to use encoding scheme.
- return Bytes.toInt(bytes, offset, length);
- }
-
- public static byte[] getEncodedColumnQualifier(int value) {
- //TODO: samarth this would need to use encoding scheme.
- return Bytes.toBytes(value);
- }
-
- public static int getEncodedColumnQualifier(byte[] bytes) {
- //TODO: samarth this would need to use encoding scheme.
- return Bytes.toInt(bytes);
- }
-
- public static byte[] getColumnQualifier(PColumn column, PTable table) {
- return EncodedColumnsUtil.getColumnQualifier(column, usesEncodedColumnNames(table));
- }
public static void setColumns(PColumn column, PTable table, Scan scan) {
if (table.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY) {
@@ -79,16 +53,14 @@ public class EncodedColumnsUtil {
scan.addFamily(column.getFamilyName().getBytes());
}
else {
- scan.addColumn(column.getFamilyName().getBytes(), EncodedColumnsUtil.getColumnQualifier(column, table));
+ if (column.getColumnQualifierBytes() != null) {
+ scan.addColumn(column.getFamilyName().getBytes(), column.getColumnQualifierBytes());
+ }
}
}
- public static byte[] getColumnQualifier(PColumn column, boolean encodedColumnName) {
- checkArgument(!SchemaUtil.isPKColumn(column), "No column qualifiers for PK columns");
- if (column.isDynamic()) { // Dynamic column names don't have encoded column names
- return column.getName().getBytes();
- }
- return encodedColumnName ? getEncodedColumnQualifier(column) : column.getName().getBytes();
+ public static QualifierEncodingScheme getEncodingScheme(Scan s) {
+ return QualifierEncodingScheme.fromSerializedValue(s.getAttribute(BaseScannerRegionObserver.QUALIFIER_ENCODING_SCHEME)[0]);
}
/**
@@ -110,20 +82,26 @@ public class EncodedColumnsUtil {
QueryConstants.ENCODED_EMPTY_COLUMN_VALUE_BYTES) : new Pair<>(QueryConstants.EMPTY_COLUMN_BYTES,
QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
}
-
- public static boolean hasEncodedColumnName(PColumn column){
- return !SchemaUtil.isPKColumn(column) && !column.isDynamic() && column.getEncodedColumnQualifier() != null;
+
+ /**
+ * @return pair of byte arrays. The first part of the pair is the empty key value's column qualifier, and the second
+ * part is the value to use for it.
+ */
+ public static Pair<byte[], byte[]> getEmptyKeyValueInfo(QualifierEncodingScheme encodingScheme) {
+ return usesEncodedColumnNames(encodingScheme) ? new Pair<>(QueryConstants.ENCODED_EMPTY_COLUMN_BYTES,
+ QueryConstants.ENCODED_EMPTY_COLUMN_VALUE_BYTES) : new Pair<>(QueryConstants.EMPTY_COLUMN_BYTES,
+ QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
}
public static Pair<Integer, Integer> getMinMaxQualifiersFromScan(Scan scan) {
Integer minQ = null, maxQ = null;
byte[] minQualifier = scan.getAttribute(BaseScannerRegionObserver.MIN_QUALIFIER);
if (minQualifier != null) {
- minQ = getEncodedColumnQualifier(minQualifier);
+ minQ = Bytes.toInt(minQualifier);
}
byte[] maxQualifier = scan.getAttribute(BaseScannerRegionObserver.MAX_QUALIFIER);
if (maxQualifier != null) {
- maxQ = getEncodedColumnQualifier(maxQualifier);
+ maxQ = Bytes.toInt(maxQualifier);
}
if (minQualifier == null) {
return null;
@@ -142,8 +120,10 @@ public class EncodedColumnsUtil {
return minMaxQualifiers != null;
}
- public static Map<String, Pair<Integer, Integer>> getQualifierRanges(PTable table) {
- Preconditions.checkArgument(table.getEncodingScheme() != NON_ENCODED_QUALIFIERS,
+ public static Map<String, Pair<Integer, Integer>> getFamilyQualifierRanges(PTable table) {
+ checkNotNull(table);
+ QualifierEncodingScheme encodingScheme = table.getEncodingScheme();
+ Preconditions.checkArgument(encodingScheme != NON_ENCODED_QUALIFIERS,
"Use this method only for tables with encoding scheme "
+ NON_ENCODED_QUALIFIERS);
Map<String, Pair<Integer, Integer>> toReturn = Maps.newHashMapWithExpectedSize(table.getColumns().size());
@@ -151,7 +131,7 @@ public class EncodedColumnsUtil {
if (!SchemaUtil.isPKColumn(column)) {
String colFamily = column.getFamilyName().getString();
Pair<Integer, Integer> minMaxQualifiers = toReturn.get(colFamily);
- Integer encodedColumnQualifier = column.getEncodedColumnQualifier();
+ Integer encodedColumnQualifier = encodingScheme.getDecodedValue(column.getColumnQualifierBytes());
if (minMaxQualifiers == null) {
minMaxQualifiers = new Pair<>(encodedColumnQualifier, encodedColumnQualifier);
toReturn.put(colFamily, minMaxQualifiers);
@@ -167,4 +147,17 @@ public class EncodedColumnsUtil {
return toReturn;
}
+ public static byte[] getColumnQualifierBytes(String columnName, Integer numberBasedQualifier, PTable table) {
+ QualifierEncodingScheme encodingScheme = table.getEncodingScheme();
+ return getColumnQualifierBytes(columnName, numberBasedQualifier, encodingScheme);
+ }
+
+ public static byte[] getColumnQualifierBytes(String columnName, Integer numberBasedQualifier, QualifierEncodingScheme encodingScheme) {
+ if (encodingScheme == NON_ENCODED_QUALIFIERS) {
+ return Bytes.toBytes(columnName);
+ } else if (numberBasedQualifier != null) {
+ return encodingScheme.getEncodedBytes(numberBasedQualifier);
+ }
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
index d816e3b..00d355c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
@@ -20,7 +20,6 @@ package org.apache.phoenix.util;
import static org.apache.phoenix.query.QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX;
import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_FAMILY;
import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_QUALIFIER;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
@@ -84,9 +83,9 @@ import org.apache.phoenix.schema.KeyValueSchema;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnFamily;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableType;
-import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.ValueSchema.Field;
@@ -95,7 +94,6 @@ import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PBinary;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PDecimal;
-import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.schema.types.PVarchar;
import org.apache.tephra.TxConstants;
@@ -435,14 +433,15 @@ public class IndexUtil {
public static TupleProjector getTupleProjector(Scan scan, ColumnReference[] dataColumns) {
if (dataColumns != null && dataColumns.length != 0) {
KeyValueSchema keyValueSchema = deserializeLocalIndexJoinSchemaFromScan(scan);
- boolean storeColsInSingleCell = scan.getAttribute(BaseScannerRegionObserver.COLUMNS_STORED_IN_SINGLE_CELL)!=null;
+ boolean storeColsInSingleCell = scan.getAttribute(BaseScannerRegionObserver.COLUMNS_STORED_IN_SINGLE_CELL) != null;
+ QualifierEncodingScheme scheme = EncodedColumnsUtil.getEncodingScheme(scan);
Expression[] colExpressions = storeColsInSingleCell ? new ArrayColumnExpression[dataColumns.length] : new KeyValueColumnExpression[dataColumns.length];
for (int i = 0; i < dataColumns.length; i++) {
byte[] family = dataColumns[i].getFamily();
byte[] qualifier = dataColumns[i].getQualifier();
Field field = keyValueSchema.getField(i);
Expression dataColumnExpr =
- storeColsInSingleCell ? new ArrayColumnExpression(field, family, getEncodedColumnQualifier(qualifier))
+ storeColsInSingleCell ? new ArrayColumnExpression(field, family, qualifier, scheme)
: new KeyValueColumnExpression(field, family, qualifier);
colExpressions[i] = dataColumnExpr;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
index 06c20d3..e10b940 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
@@ -121,7 +121,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
Filter filter = scan.getFilter();
Expression idExpression = new ColumnRef(plan.getTableRef(), plan.getTableRef().getTable().getPColumnForColumnName("ID").getPosition()).newColumnExpression();
Expression id = new RowKeyColumnExpression(idExpression,new RowKeyValueAccessor(plan.getTableRef().getTable().getPKColumns(),0));
- Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getPColumnForColumnName("COMPANY"), true);
+ Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getPColumnForColumnName("COMPANY"));
// FilterList has no equals implementation
assertTrue(filter instanceof FilterList);
FilterList filterList = (FilterList)filter;
@@ -153,7 +153,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
assertEquals(
singleKVFilter(constantComparison(
CompareOp.EQUAL,
- new KeyValueColumnExpression(column, true),
+ new KeyValueColumnExpression(column),
"c3")),
filter);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
index 30f8970..c2d02ec 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
@@ -252,9 +252,10 @@ public class CorrelatePlanTest {
for (int i = 0; i < row.length; i++) {
String name = ParseNodeFactory.createTempAlias();
Expression expr = LiteralExpression.newConstant(row[i]);
+ PName colName = PNameFactory.newName(name);
columns.add(new PColumnImpl(PNameFactory.newName(name), PNameFactory.newName(VALUE_COLUMN_FAMILY),
expr.getDataType(), expr.getMaxLength(), expr.getScale(), expr.isNullable(),
- i, expr.getSortOrder(), null, null, false, name, false, false, null));
+ i, expr.getSortOrder(), null, null, false, name, false, false, colName.getBytes()));
}
try {
PTable pTable = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME,
[13/42] phoenix git commit: PHOENIX-3355 Register Phoenix built-in
functions as Calcite functions
Posted by td...@apache.org.
PHOENIX-3355 Register Phoenix built-in functions as Calcite functions
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/90d27be5
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/90d27be5
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/90d27be5
Branch: refs/heads/encodecolumns2
Commit: 90d27be5b469f66e346539f5c273623a39f1c6c0
Parents: 18cb85e
Author: Eric Lomore <er...@gmail.com>
Authored: Wed Dec 21 17:23:02 2016 -0800
Committer: maryannxue <ma...@gmail.com>
Committed: Wed Dec 21 17:23:02 2016 -0800
----------------------------------------------------------------------
.../org/apache/phoenix/end2end/DateTimeIT.java | 48 ++++++++++----------
.../phoenix/end2end/DefaultColumnValueIT.java | 6 +--
.../phoenix/end2end/ToDateFunctionIT.java | 2 +-
.../phoenix/end2end/index/LocalIndexIT.java | 6 +--
.../ByteBasedRegexpReplaceFunction.java | 11 +++++
.../function/ByteBasedRegexpSplitFunction.java | 10 ++++
.../function/ByteBasedRegexpSubstrFunction.java | 16 +++++++
.../expression/function/CeilDateExpression.java | 14 ++++++
.../function/CeilDecimalExpression.java | 13 ++++++
.../expression/function/CeilFunction.java | 10 +++-
.../function/CeilTimestampExpression.java | 13 ++++++
.../function/CurrentDateFunction.java | 9 ++++
.../function/CurrentTimeFunction.java | 9 ++++
.../expression/function/FirstValueFunction.java | 4 ++
.../function/FloorDateExpression.java | 13 ++++++
.../function/FloorDecimalExpression.java | 13 ++++++
.../expression/function/FloorFunction.java | 5 +-
.../expression/function/LastValueFunction.java | 4 ++
.../function/MaxAggregateFunction.java | 4 ++
.../function/MinAggregateFunction.java | 4 ++
.../expression/function/NowFunction.java | 5 +-
.../expression/function/NthValueFunction.java | 4 ++
.../function/RegexpReplaceFunction.java | 5 +-
.../function/RegexpSplitFunction.java | 4 +-
.../function/RegexpSubstrFunction.java | 5 +-
.../function/RoundDateExpression.java | 12 +++++
.../function/RoundDecimalExpression.java | 12 +++++
.../expression/function/RoundFunction.java | 5 +-
.../function/RoundTimestampExpression.java | 14 +++++-
.../StringBasedRegexpReplaceFunction.java | 12 +++++
.../StringBasedRegexpSplitFunction.java | 10 ++++
.../StringBasedRegexpSubstrFunction.java | 12 +++++
.../expression/function/ToCharFunction.java | 34 ++++++++++++++
.../expression/function/ToDateFunction.java | 14 ++++++
.../expression/function/ToNumberFunction.java | 34 ++++++++++++++
.../expression/function/ToTimeFunction.java | 6 +++
.../function/ToTimestampFunction.java | 5 ++
.../expression/function/TruncFunction.java | 5 +-
.../apache/phoenix/parse/FunctionParseNode.java | 31 +++++++++++++
.../apache/phoenix/parse/ParseNodeFactory.java | 38 +++++++++++-----
40 files changed, 429 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
index ffcb472..74cc068 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
@@ -411,45 +411,45 @@ public class DateTimeIT extends ParallelStatsDisabledIT {
@Test
public void testYearFunctionDate() throws SQLException {
- assertEquals(2008, callYearFunction("YEAR(TO_DATE('2008-01-01', 'yyyy-MM-dd', 'local'))"));
+ assertEquals(2008, callYearFunction("\"YEAR\"(TO_DATE('2008-01-01', 'yyyy-MM-dd', 'local'))"));
assertEquals(2004,
- callYearFunction("YEAR(TO_DATE('2004-12-13 10:13:18', 'yyyy-MM-dd hh:mm:ss'))"));
+ callYearFunction("\"YEAR\"(TO_DATE('2004-12-13 10:13:18', 'yyyy-MM-dd hh:mm:ss'))"));
- assertEquals(2015, callYearFunction("YEAR(TO_DATE('2015-01-27T16:17:57+00:00'))"));
+ assertEquals(2015, callYearFunction("\"YEAR\"(TO_DATE('2015-01-27T16:17:57+00:00'))"));
- assertEquals(2005, callYearFunction("YEAR(TO_DATE('2005-12-13 10:13:18'))"));
+ assertEquals(2005, callYearFunction("\"YEAR\"(TO_DATE('2005-12-13 10:13:18'))"));
- assertEquals(2006, callYearFunction("YEAR(TO_DATE('2006-12-13'))"));
+ assertEquals(2006, callYearFunction("\"YEAR\"(TO_DATE('2006-12-13'))"));
- assertEquals(2015, callYearFunction("YEAR(TO_DATE('2015-W05'))"));
+ assertEquals(2015, callYearFunction("\"YEAR\"(TO_DATE('2015-W05'))"));
assertEquals(
2008,
- callYearFunction("YEAR(TO_DATE('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'))"));
+ callYearFunction("\"YEAR\"(TO_DATE('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'))"));
}
@Test
public void testYearFunctionTimestamp() throws SQLException {
- assertEquals(2015, callYearFunction("YEAR(TO_TIMESTAMP('2015-01-27T16:17:57+00:00'))"));
+ assertEquals(2015, callYearFunction("\"YEAR\"(TO_TIMESTAMP('2015-01-27T16:17:57+00:00'))"));
- assertEquals(2015, callYearFunction("YEAR(TO_TIMESTAMP('2015-01-27T16:17:57Z'))"));
+ assertEquals(2015, callYearFunction("\"YEAR\"(TO_TIMESTAMP('2015-01-27T16:17:57Z'))"));
- assertEquals(2015, callYearFunction("YEAR(TO_TIMESTAMP('2015-W10-3'))"));
+ assertEquals(2015, callYearFunction("\"YEAR\"(TO_TIMESTAMP('2015-W10-3'))"));
- assertEquals(2015, callYearFunction("YEAR(TO_TIMESTAMP('2015-W05'))"));
+ assertEquals(2015, callYearFunction("\"YEAR\"(TO_TIMESTAMP('2015-W05'))"));
- assertEquals(2015, callYearFunction("YEAR(TO_TIMESTAMP('2015-063'))"));
+ assertEquals(2015, callYearFunction("\"YEAR\"(TO_TIMESTAMP('2015-063'))"));
- assertEquals(2006, callYearFunction("YEAR(TO_TIMESTAMP('2006-12-13'))"));
+ assertEquals(2006, callYearFunction("\"YEAR\"(TO_TIMESTAMP('2006-12-13'))"));
assertEquals(2004,
- callYearFunction("YEAR(TO_TIMESTAMP('2004-12-13 10:13:18', 'yyyy-MM-dd hh:mm:ss'))"));
+ callYearFunction("\"YEAR\"(TO_TIMESTAMP('2004-12-13 10:13:18', 'yyyy-MM-dd hh:mm:ss'))"));
assertEquals(
2008,
- callYearFunction("YEAR(TO_TIMESTAMP('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'))"));
+ callYearFunction("\"YEAR\"(TO_TIMESTAMP('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'))"));
}
@Test
@@ -470,8 +470,8 @@ public class DateTimeIT extends ParallelStatsDisabledIT {
conn.createStatement().execute(dml);
conn.commit();
- ResultSet rs = conn.createStatement().executeQuery("SELECT k1, YEAR(timestamps), YEAR(times), Year(unsignedDates), YEAR(unsignedTimestamps), " +
- "YEAR(unsignedTimes) FROM " + tableName + " where YEAR(dates) = 2004");
+ ResultSet rs = conn.createStatement().executeQuery("SELECT k1, \"YEAR\"(timestamps), \"YEAR\"(times), \"YEAR\"(unsignedDates), \"YEAR\"(unsignedTimestamps), " +
+ "\"YEAR\"(unsignedTimes) FROM " + tableName + " where \"YEAR\"(dates) = 2004");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals(2006, rs.getInt(2));
@@ -500,8 +500,8 @@ public class DateTimeIT extends ParallelStatsDisabledIT {
conn.createStatement().execute(dml);
conn.commit();
- ResultSet rs = conn.createStatement().executeQuery("SELECT k1, MONTH(timestamps), MONTH(times), MONTH(unsignedDates), MONTH(unsignedTimestamps), " +
- "MONTH(unsignedTimes) FROM " + tableName + " where MONTH(dates) = 3");
+ ResultSet rs = conn.createStatement().executeQuery("SELECT k1, \"MONTH\"(timestamps), \"MONTH\"(times), \"MONTH\"(unsignedDates), \"MONTH\"(unsignedTimestamps), " +
+ "\"MONTH\"(unsignedTimes) FROM " + tableName + " where \"MONTH\"(dates) = 3");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals(4, rs.getInt(2));
@@ -577,7 +577,7 @@ public class DateTimeIT extends ParallelStatsDisabledIT {
conn.createStatement().execute(dml);
conn.commit();
- ResultSet rs = conn.createStatement().executeQuery("SELECT k1, WEEK(dates), WEEK(times) FROM " + tableName + " where WEEK(timestamps)=15");
+ ResultSet rs = conn.createStatement().executeQuery("SELECT k1, \"WEEK\"(dates), \"WEEK\"(times) FROM " + tableName + " where \"WEEK\"(timestamps)=15");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals(2, rs.getInt(2));
@@ -602,7 +602,7 @@ public class DateTimeIT extends ParallelStatsDisabledIT {
conn.createStatement().execute(dml);
conn.commit();
- ResultSet rs = conn.createStatement().executeQuery("SELECT k1, HOUR(dates), HOUR(times) FROM " + tableName + " where HOUR(timestamps)=15");
+ ResultSet rs = conn.createStatement().executeQuery("SELECT k1, \"HOUR\"(dates), \"HOUR\"(times) FROM " + tableName + " where \"HOUR\"(timestamps)=15");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals(3, rs.getInt(2));
@@ -649,8 +649,8 @@ public class DateTimeIT extends ParallelStatsDisabledIT {
conn.createStatement().execute(dml);
conn.commit();
- ResultSet rs = conn.createStatement().executeQuery("SELECT k1, MINUTE(dates), MINUTE(times), MINUTE(unsignedDates), MINUTE(unsignedTimestamps), " +
- "MINUTE(unsignedTimes) FROM " + tableName + " where MINUTE(timestamps)=20");
+ ResultSet rs = conn.createStatement().executeQuery("SELECT k1, \"MINUTE\"(dates), \"MINUTE\"(times), \"MINUTE\"(unsignedDates), \"MINUTE\"(unsignedTimestamps), " +
+ "\"MINUTE\"(unsignedTimes) FROM " + tableName + " where \"MINUTE\"(timestamps)=20");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals(10, rs.getInt(2));
@@ -835,7 +835,7 @@ public class DateTimeIT extends ParallelStatsDisabledIT {
@Test
public void testFunctionOnNullDate() throws Exception {
- ResultSet rs = conn.createStatement().executeQuery("SELECT YEAR(a_date), entity_id from " + this.tableName + " WHERE entity_id = '" + ROW10 + "'");
+ ResultSet rs = conn.createStatement().executeQuery("SELECT \"YEAR\"(a_date), entity_id from " + this.tableName + " WHERE entity_id = '" + ROW10 + "'");
assertNotNull(rs);
assertTrue(rs.next());
assertEquals(ROW10, rs.getString(2));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
index 783dd75..62d79bc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
@@ -586,7 +586,7 @@ public class DefaultColumnValueIT extends ParallelStatsDisabledIT {
+ "c3 DECIMAL DEFAULT TO_NUMBER('$123.33', '\u00A4###.##'),"
+ "c4 VARCHAR DEFAULT 'AB' || 'CD',"
+ "c5 CHAR(5) DEFAULT 'E' || 'F',"
- + "c6 INTEGER DEFAULT MONTH(TO_TIMESTAMP('2015-6-05'))"
+ + "c6 INTEGER DEFAULT \"MONTH\"(TO_TIMESTAMP('2015-6-05'))"
+ ")";
verifyDefaultExpression(sharedTable2, ddl);
@@ -602,7 +602,7 @@ public class DefaultColumnValueIT extends ParallelStatsDisabledIT {
+ "c3 DECIMAL NOT NULL DEFAULT TO_NUMBER('$123.33', '\u00A4###.##'),"
+ "c4 VARCHAR NOT NULL DEFAULT 'AB' || 'CD',"
+ "c5 CHAR(5) NOT NULL DEFAULT 'E' || 'F',"
- + "c6 INTEGER NOT NULL DEFAULT MONTH(TO_TIMESTAMP('2015-6-05')),"
+ + "c6 INTEGER NOT NULL DEFAULT \"MONTH\"(TO_TIMESTAMP('2015-6-05')),"
+ "CONSTRAINT pk_key PRIMARY KEY (pk,c1,c2,c3,c4,c5,c6)"
+ ")";
@@ -1048,7 +1048,7 @@ public class DefaultColumnValueIT extends ParallelStatsDisabledIT {
+ "c3 DECIMAL DEFAULT TO_NUMBER('$123.33', '\u00A4###.##'),"
+ "c4 VARCHAR DEFAULT 'AB' || 'CD',"
+ "c5 CHAR(5) DEFAULT 'E' || 'F',"
- + "c6 INTEGER DEFAULT MONTH(TO_TIMESTAMP('2015-6-05'))"
+ + "c6 INTEGER DEFAULT \"MONTH\"(TO_TIMESTAMP('2015-6-05'))"
+ ")";
Connection conn = DriverManager.getConnection(getUrl());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java
index 6053ef5..fe86a22 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToDateFunctionIT.java
@@ -48,7 +48,7 @@ public class ToDateFunctionIT extends ParallelStatsDisabledIT {
private static java.util.Date callToDateFunction(Connection conn, String invocation) throws SQLException {
Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(String.format("SELECT %s FROM SYSTEM.CATALOG LIMIT 1", invocation));
+ ResultSet rs = stmt.executeQuery(String.format("SELECT %s FROM \"SYSTEM\".CATALOG LIMIT 1", invocation));
assertTrue(rs.next());
java.util.Date returnValue = (java.util.Date)rs.getObject(1);
rs.close();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
index 785a324..278f4cf 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -89,16 +89,16 @@ public class LocalIndexIT extends BaseLocalIndexIT {
conn1.createStatement().execute(createTable);
conn1.createStatement().execute(
"CREATE local INDEX IF NOT EXISTS " + indexName2 + " on " + tableName2
- + "(HOUR(user_time))");
+ + "(\"HOUR\"(user_time))");
conn1.createStatement().execute(
"upsert into " + tableName2 + " values(TO_TIME('2005-10-01 14:03:22.559'), 'foo')");
conn1.commit();
ResultSet rs =
conn1.createStatement()
.executeQuery(
- "select substr(to_char(user_time), 0, 10) as ddate, hour(user_time) as hhour, user_id, col1,col2 from "
+ "select substr(to_char(user_time), 0, 10) as ddate, \"HOUR\"(user_time) as hhour, user_id, col1,col2 from "
+ tableName2
- + " where hour(user_time)=14 group by user_id, col1, col2, ddate, hhour limit 1");
+ + " where \"HOUR\"(user_time)=14 group by user_id, col1, col2, ddate, hhour limit 1");
assertTrue(rs.next());
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpReplaceFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpReplaceFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpReplaceFunction.java
index c815190..45ab5b0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpReplaceFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpReplaceFunction.java
@@ -23,7 +23,18 @@ import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.util.regex.AbstractBasePattern;
import org.apache.phoenix.expression.util.regex.JONIPattern;
import org.joni.Option;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
+@BuiltInFunction(name=RegexpReplaceFunction.NAME,
+ args= {
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PVarchar.class},defaultValue="null")},
+ classType = FunctionClassType.DERIVED
+)
public class ByteBasedRegexpReplaceFunction extends RegexpReplaceFunction {
public ByteBasedRegexpReplaceFunction() {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSplitFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSplitFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSplitFunction.java
index 1a74975..3ed100a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSplitFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSplitFunction.java
@@ -23,7 +23,17 @@ import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.util.regex.AbstractBaseSplitter;
import org.apache.phoenix.expression.util.regex.JONIPattern;
import org.joni.Option;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
+@BuiltInFunction(name=RegexpSplitFunction.NAME,
+ args= {
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PVarchar.class})},
+ classType = FunctionClassType.DERIVED
+)
public class ByteBasedRegexpSplitFunction extends RegexpSplitFunction {
public ByteBasedRegexpSplitFunction() {
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSubstrFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSubstrFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSubstrFunction.java
index 96e5353..ea4ea2a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSubstrFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ByteBasedRegexpSubstrFunction.java
@@ -23,7 +23,23 @@ import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.util.regex.AbstractBasePattern;
import org.apache.phoenix.expression.util.regex.JONIPattern;
import org.joni.Option;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.expression.util.regex.AbstractBasePattern;
+import org.apache.phoenix.expression.util.regex.JONIPattern;
+import org.joni.Option;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
+@BuiltInFunction(name=RegexpSubstrFunction.NAME,
+ args= {
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PLong.class}, defaultValue="1")},
+ classType = FunctionClassType.DERIVED
+)
public class ByteBasedRegexpSubstrFunction extends RegexpSubstrFunction {
public ByteBasedRegexpSubstrFunction() {
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
index 7629409..1b41cb3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
@@ -26,6 +26,12 @@ import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
import com.google.common.collect.Lists;
@@ -36,6 +42,14 @@ import com.google.common.collect.Lists;
*
* @since 3.0.0
*/
+@BuiltInFunction(name = CeilFunction.NAME,
+ args = {
+ @Argument(allowedTypes={PDate.class}),
+ @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+ @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
+ },
+ classType = FunctionClassType.DERIVED
+)
public class CeilDateExpression extends RoundDateExpression {
public CeilDateExpression() {}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java
index 9c64896..d561b48 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java
@@ -29,6 +29,11 @@ import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.schema.types.PDecimal;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
import com.google.common.collect.Lists;
@@ -39,6 +44,14 @@ import com.google.common.collect.Lists;
*
* @since 3.0.0
*/
+@BuiltInFunction(name = CeilFunction.NAME,
+ args = {
+ @Argument(allowedTypes={PDecimal.class}),
+ @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+ @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
+ },
+ classType = FunctionClassType.DERIVED
+)
public class CeilDecimalExpression extends RoundDecimalExpression {
public CeilDecimalExpression() {}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
index b65010a..28fdc15 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
@@ -17,15 +17,21 @@
*/
package org.apache.phoenix.expression.function;
+import java.sql.SQLException;
import java.util.List;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.CeilParseNode;
+import org.apache.phoenix.parse.FunctionParseNode;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.schema.TypeMismatchException;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDate;
import org.apache.phoenix.schema.types.PDecimal;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
import org.apache.phoenix.schema.types.PVarchar;
/**
@@ -41,7 +47,9 @@ import org.apache.phoenix.schema.types.PVarchar;
@Argument(allowedTypes={PTimestamp.class, PDecimal.class}),
@Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
@Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
- }
+ },
+ classType = FunctionParseNode.FunctionClassType.ABSTRACT,
+ derivedFunctions = {CeilDateExpression.class, CeilTimestampExpression.class, CeilDecimalExpression.class}
)
public abstract class CeilFunction extends ScalarFunction {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
index b3a2a97..c2b0b9a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
@@ -33,6 +33,11 @@ import org.apache.phoenix.schema.types.PDate;
import org.apache.phoenix.schema.types.PTimestamp;
import org.apache.phoenix.schema.types.PUnsignedDate;
import org.apache.phoenix.schema.types.PUnsignedTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
import com.google.common.collect.Lists;
@@ -45,6 +50,14 @@ import com.google.common.collect.Lists;
*
* @since 3.0.0
*/
+@BuiltInFunction(name = CeilFunction.NAME,
+ args = {
+ @Argument(allowedTypes={PTimestamp.class}),
+ @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+ @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
+ },
+ classType = FunctionClassType.DERIVED
+)
public class CeilTimestampExpression extends CeilDateExpression {
public CeilTimestampExpression() {}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java
index 57b82e4..eb1fe01 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java
@@ -19,13 +19,18 @@ package org.apache.phoenix.expression.function;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.expression.CurrentDateTimeFunction;
+import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.CurrentDateParseNode;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.schema.types.PDate;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.tuple.Tuple;
+import java.sql.SQLException;
+import java.util.List;
+
/**
*
@@ -46,6 +51,10 @@ public class CurrentDateFunction extends CurrentDateTimeFunction {
this(System.currentTimeMillis());
}
+ public CurrentDateFunction(List<Expression> children, StatementContext context) throws SQLException {
+ this(context.getCurrentTime());
+ }
+
public CurrentDateFunction(long timeStamp) {
getDataType().getCodec().encodeLong(timeStamp, currentDate);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java
index 12abb3b..f6f17a6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java
@@ -19,13 +19,18 @@ package org.apache.phoenix.expression.function;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.expression.CurrentDateTimeFunction;
+import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.CurrentTimeParseNode;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PTime;
import org.apache.phoenix.schema.tuple.Tuple;
+import java.sql.SQLException;
+import java.util.List;
+
/**
*
@@ -46,6 +51,10 @@ public class CurrentTimeFunction extends CurrentDateTimeFunction {
this(System.currentTimeMillis());
}
+ public CurrentTimeFunction(List<Expression> children, StatementContext context) throws SQLException {
+ this(context.getCurrentTime());
+ }
+
public CurrentTimeFunction(long timeStamp) {
getDataType().getCodec().encodeLong(timeStamp, currentDate);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java
index df9d26b..c19d053 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java
@@ -44,6 +44,10 @@ public class FirstValueFunction extends FirstLastValueBaseFunction {
public FirstValueFunction() {
}
+ public FirstValueFunction(List<Expression> childExpressions) {
+ this(childExpressions, null);
+ }
+
public FirstValueFunction(List<Expression> childExpressions, CountAggregateFunction delegate) {
super(childExpressions, delegate);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java
index c0eca8a..9c0b874 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java
@@ -31,6 +31,11 @@ import org.apache.phoenix.schema.types.PDate;
import org.apache.phoenix.schema.types.PTimestamp;
import org.apache.phoenix.schema.types.PUnsignedDate;
import org.apache.phoenix.schema.types.PUnsignedTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
import com.google.common.collect.Lists;
@@ -42,6 +47,14 @@ import com.google.common.collect.Lists;
*
* @since 3.0.0
*/
+@BuiltInFunction(name = FloorFunction.NAME,
+ args = {
+ @Argument(allowedTypes={PTimestamp.class}),
+ @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+ @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
+ },
+ classType = FunctionClassType.DERIVED
+ )
public class FloorDateExpression extends RoundDateExpression {
public FloorDateExpression() {}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java
index 7351cca..1ecedc9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java
@@ -29,6 +29,11 @@ import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.schema.types.PDecimal;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
import com.google.common.collect.Lists;
@@ -40,6 +45,14 @@ import com.google.common.collect.Lists;
*
* @since 3.0.0
*/
+@BuiltInFunction(name = FloorFunction.NAME,
+ args = {
+ @Argument(allowedTypes={PDecimal.class}),
+ @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+ @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
+ },
+ classType = FunctionClassType.DERIVED
+)
public class FloorDecimalExpression extends RoundDecimalExpression {
public FloorDecimalExpression() {}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
index f6baa09..2072a4a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.FloorParseNode;
+import org.apache.phoenix.parse.FunctionParseNode;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.schema.types.PDecimal;
@@ -39,7 +40,9 @@ import org.apache.phoenix.schema.types.PVarchar;
@Argument(allowedTypes={PTimestamp.class, PDecimal.class}),
@Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
@Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
- }
+ },
+ classType = FunctionParseNode.FunctionClassType.ABSTRACT,
+ derivedFunctions = {FloorDateExpression.class, FloorDecimalExpression.class}
)
public abstract class FloorFunction extends ScalarFunction {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java
index 9f01c61..ab6ebe3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java
@@ -44,6 +44,10 @@ public class LastValueFunction extends FirstLastValueBaseFunction {
public LastValueFunction() {
}
+ public LastValueFunction(List<Expression> childExpressions) {
+ this(childExpressions, null);
+ }
+
public LastValueFunction(List<Expression> childExpressions, CountAggregateFunction delegate) {
super(childExpressions, delegate);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
index 4913f91..63252d7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
@@ -43,6 +43,10 @@ public class MaxAggregateFunction extends MinAggregateFunction {
public MaxAggregateFunction() {
}
+
+ public MaxAggregateFunction(List<Expression> childExpressions) {
+ this(childExpressions, null);
+ }
public MaxAggregateFunction(List<Expression> childExpressions, CountAggregateFunction delegate) {
super(childExpressions, delegate);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
index 5b99e13..b26a886 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
@@ -45,6 +45,10 @@ public class MinAggregateFunction extends DelegateConstantToCountAggregateFuncti
public MinAggregateFunction() {
}
+
+ public MinAggregateFunction(List<Expression> childExpressions) {
+ super(childExpressions, null);
+ }
public MinAggregateFunction(List<Expression> childExpressions, CountAggregateFunction delegate) {
super(childExpressions, delegate);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java
index 83a5e53..3b7aebb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java
@@ -20,9 +20,12 @@ package org.apache.phoenix.expression.function;
import java.sql.SQLException;
import java.util.List;
+import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.CurrentDateParseNode;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
+
/**
*
@@ -31,7 +34,7 @@ import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
*
*/
@BuiltInFunction(name = NowFunction.NAME,
-nodeClass=CurrentDateParseNode.class, args= {})
+ nodeClass=CurrentDateParseNode.class, args= {}, classType = FunctionClassType.ALIAS, derivedFunctions = {CurrentDateFunction.class})
public abstract class NowFunction extends ScalarFunction {
public static final String NAME = "NOW";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java
index 969fda9..39a09e7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java
@@ -47,6 +47,10 @@ public class NthValueFunction extends FirstLastValueBaseFunction {
public NthValueFunction() {
}
+ public NthValueFunction(List<Expression> childExpressions) {
+ this(childExpressions, null);
+ }
+
public NthValueFunction(List<Expression> childExpressions, CountAggregateFunction delegate) {
super(childExpressions, delegate);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
index b5a3d39..f2ab8f3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.phoenix.expression.Determinism;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.util.regex.AbstractBasePattern;
+import org.apache.phoenix.parse.FunctionParseNode;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.parse.RegexpReplaceParseNode;
@@ -53,7 +54,9 @@ import org.apache.phoenix.schema.types.PVarchar;
nodeClass = RegexpReplaceParseNode.class, args= {
@Argument(allowedTypes={PVarchar.class}),
@Argument(allowedTypes={PVarchar.class}),
- @Argument(allowedTypes={PVarchar.class},defaultValue="null")} )
+ @Argument(allowedTypes={PVarchar.class},defaultValue="null")},
+ classType = FunctionParseNode.FunctionClassType.ABSTRACT,
+ derivedFunctions = {ByteBasedRegexpReplaceFunction.class, StringBasedRegexpReplaceFunction.class})
public abstract class RegexpReplaceFunction extends ScalarFunction {
public static final String NAME = "REGEXP_REPLACE";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
index c663188..e86fe3b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
@@ -48,7 +48,9 @@ import org.apache.phoenix.util.ByteUtil;
@FunctionParseNode.BuiltInFunction(name=RegexpSplitFunction.NAME,
nodeClass = RegexpSplitParseNode.class, args= {
@FunctionParseNode.Argument(allowedTypes={PVarchar.class}),
- @FunctionParseNode.Argument(allowedTypes={PVarchar.class})})
+ @FunctionParseNode.Argument(allowedTypes={PVarchar.class})},
+ classType = FunctionParseNode.FunctionClassType.ABSTRACT,
+ derivedFunctions = {ByteBasedRegexpSplitFunction.class, StringBasedRegexpSplitFunction.class})
public abstract class RegexpSplitFunction extends ScalarFunction {
public static final String NAME = "REGEXP_SPLIT";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/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 ea80b11..466fd1a 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
@@ -25,6 +25,7 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.phoenix.expression.Determinism;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.util.regex.AbstractBasePattern;
+import org.apache.phoenix.parse.FunctionParseNode;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.parse.RegexpSubstrParseNode;
@@ -52,7 +53,9 @@ import org.apache.phoenix.schema.types.PVarchar;
nodeClass = RegexpSubstrParseNode.class, args={
@Argument(allowedTypes={PVarchar.class}),
@Argument(allowedTypes={PVarchar.class}),
- @Argument(allowedTypes={PLong.class}, defaultValue="1")} )
+ @Argument(allowedTypes={PLong.class}, defaultValue="1")},
+ classType = FunctionParseNode.FunctionClassType.ABSTRACT,
+ derivedFunctions = {ByteBasedRegexpSubstrFunction.class, StringBasedRegexpSubstrFunction.class})
public abstract class RegexpSubstrFunction extends PrefixFunction {
public static final String NAME = "REGEXP_SUBSTR";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/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 a80d745..9327fbb 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
@@ -42,6 +42,10 @@ import org.apache.phoenix.schema.types.PDataType.PDataCodec;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PVarchar;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
import com.google.common.collect.Lists;
@@ -55,6 +59,14 @@ import com.google.common.collect.Lists;
*
* @since 0.1
*/
+@BuiltInFunction(name = RoundFunction.NAME,
+ args = {
+ @Argument(allowedTypes={PDate.class}),
+ @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+ @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
+ },
+ classType = FunctionClassType.DERIVED
+)
public class RoundDateExpression extends ScalarFunction {
long divBy;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
index 055535e..324d655 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
@@ -42,6 +42,10 @@ import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PDecimal;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
import com.google.common.collect.Lists;
@@ -53,6 +57,14 @@ import com.google.common.collect.Lists;
*
* @since 3.0.0
*/
+@BuiltInFunction(name = RoundFunction.NAME,
+ args = {
+ @Argument(allowedTypes={PDecimal.class}),
+ @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+ @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
+ },
+ classType = FunctionClassType.DERIVED
+)
public class RoundDecimalExpression extends ScalarFunction {
private int scale;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
index 7d0306c..d95a396 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
@@ -20,6 +20,7 @@ package org.apache.phoenix.expression.function;
import java.util.List;
import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.parse.FunctionParseNode;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.parse.RoundParseNode;
@@ -38,7 +39,9 @@ import org.apache.phoenix.schema.types.PVarchar;
@Argument(allowedTypes={PTimestamp.class, PDecimal.class}),
@Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
@Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
- }
+ },
+ classType = FunctionParseNode.FunctionClassType.ABSTRACT,
+ derivedFunctions = {RoundDateExpression.class, RoundTimestampExpression.class, RoundDecimalExpression.class}
)
public abstract class RoundFunction extends ScalarFunction {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java
index 7b5ba93..51537b4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java
@@ -33,6 +33,11 @@ import org.apache.phoenix.schema.types.PDate;
import org.apache.phoenix.schema.types.PTimestamp;
import org.apache.phoenix.schema.types.PUnsignedDate;
import org.apache.phoenix.schema.types.PUnsignedTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
import com.google.common.collect.Lists;
@@ -47,7 +52,14 @@ import com.google.common.collect.Lists;
*
* @since 3.0.0
*/
-
+@BuiltInFunction(name = RoundFunction.NAME,
+ args = {
+ @Argument(allowedTypes={PTimestamp.class}),
+ @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+ @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
+ },
+ classType = FunctionClassType.DERIVED
+)
public class RoundTimestampExpression extends RoundDateExpression {
private static final long HALF_OF_NANOS_IN_MILLI = java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(1)/2;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpReplaceFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpReplaceFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpReplaceFunction.java
index 1e4943f..89f8bea 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpReplaceFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpReplaceFunction.java
@@ -24,6 +24,18 @@ import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.util.regex.AbstractBasePattern;
import org.apache.phoenix.expression.util.regex.JavaPattern;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
+
+@BuiltInFunction(name=RegexpReplaceFunction.NAME,
+ args= {
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PVarchar.class},defaultValue="null")},
+ classType = FunctionClassType.DERIVED
+)
public class StringBasedRegexpReplaceFunction extends RegexpReplaceFunction {
public StringBasedRegexpReplaceFunction() {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSplitFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSplitFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSplitFunction.java
index 77321c2..029a5d3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSplitFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSplitFunction.java
@@ -22,7 +22,17 @@ import java.util.List;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.util.regex.AbstractBaseSplitter;
import org.apache.phoenix.expression.util.regex.GuavaSplitter;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
+@BuiltInFunction(name=RegexpSplitFunction.NAME,
+ args= {
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PVarchar.class})},
+ classType = FunctionClassType.DERIVED
+)
public class StringBasedRegexpSplitFunction extends RegexpSplitFunction {
public StringBasedRegexpSplitFunction() {
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSubstrFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSubstrFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSubstrFunction.java
index 5e82a32..de2e0d4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSubstrFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StringBasedRegexpSubstrFunction.java
@@ -23,7 +23,19 @@ import java.util.regex.Pattern;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.util.regex.AbstractBasePattern;
import org.apache.phoenix.expression.util.regex.JavaPattern;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
+@BuiltInFunction(name=RegexpSubstrFunction.NAME,
+ args= {
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PVarchar.class}),
+ @Argument(allowedTypes={PLong.class}, defaultValue="1")},
+ classType = FunctionClassType.DERIVED
+)
public class StringBasedRegexpSubstrFunction extends RegexpSubstrFunction {
public StringBasedRegexpSubstrFunction() {
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
index be40723..317620f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
@@ -26,7 +26,9 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.WritableUtils;
import com.google.common.base.Preconditions;
+import org.apache.phoenix.compile.StatementContext;
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.parse.*;
@@ -57,6 +59,38 @@ public class ToCharFunction extends ScalarFunction {
public ToCharFunction() {
}
+ public ToCharFunction(List<Expression> children, StatementContext context) throws SQLException {
+ super(children.subList(0, 1));
+ PDataType dataType = children.get(0).getDataType();
+ String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
+ Format formatter;
+ FunctionArgumentType type;
+ if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
+ if (formatString == null) {
+ formatString = context.getDateFormat();
+ formatter = context.getDateFormatter();
+ } else {
+ formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
+ }
+ type = FunctionArgumentType.TEMPORAL;
+ }
+ else if (dataType.isCoercibleTo(PDecimal.INSTANCE)) {
+ if (formatString == null)
+ formatString = context.getNumberFormat();
+ formatter = FunctionArgumentType.NUMERIC.getFormatter(formatString);
+ type = FunctionArgumentType.NUMERIC;
+ }
+ else {
+ throw new SQLException(dataType + " type is unsupported for TO_CHAR(). Numeric and temporal types are supported.");
+ }
+ Preconditions.checkNotNull(formatString);
+ Preconditions.checkNotNull(formatter);
+ Preconditions.checkNotNull(type);
+ this.type = type;
+ this.formatString = formatString;
+ this.formatter = formatter;
+ }
+
public ToCharFunction(List<Expression> children, FunctionArgumentType type, String formatString, Format formatter) throws SQLException {
super(children.subList(0, 1));
Preconditions.checkNotNull(formatString);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
index 1930d92..3df09bf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
@@ -25,6 +25,7 @@ import java.util.List;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.WritableUtils;
+import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
@@ -61,6 +62,19 @@ public class ToDateFunction extends ScalarFunction {
public ToDateFunction() {
}
+ public ToDateFunction(List<Expression> children, StatementContext context) throws SQLException {
+ super(children);
+ String dateFormat = (String) ((LiteralExpression) children.get(1)).getValue();
+ String timeZoneId = (String) ((LiteralExpression) children.get(2)).getValue();
+ if (dateFormat == null) {
+ dateFormat = context.getDateFormat();
+ }
+ if (timeZoneId == null) {
+ timeZoneId = context.getDateFormatTimeZone().getID();
+ }
+ init(dateFormat, timeZoneId);
+ }
+
public ToDateFunction(List<Expression> children, String dateFormat, String timeZoneId) throws SQLException {
super(children);
init(dateFormat, timeZoneId);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
index c43062f..24e8d73 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
@@ -31,10 +31,13 @@ import org.apache.hadoop.io.WritableUtils;
import com.google.common.base.Preconditions;
+import org.apache.phoenix.compile.StatementContext;
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.parse.*;
+import org.apache.phoenix.schema.types.PChar;
import org.apache.phoenix.schema.types.PDecimal;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PTimestamp;
@@ -61,6 +64,37 @@ public class ToNumberFunction extends ScalarFunction {
public ToNumberFunction() {}
+ public ToNumberFunction(List<Expression> children, StatementContext context) throws SQLException {
+ super(children.subList(0, 1));
+ PDataType dataType = children.get(0).getDataType();
+ String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
+ Format formatter = null;
+ FunctionArgumentType type;
+
+ if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
+ if (formatString == null) {
+ formatString = context.getDateFormat();
+ formatter = context.getDateFormatter();
+ } else {
+ formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
+ }
+ type = FunctionArgumentType.TEMPORAL;
+ }
+ else if (dataType.isCoercibleTo(PChar.INSTANCE)) {
+ if (formatString != null) {
+ formatter = FunctionArgumentType.CHAR.getFormatter(formatString);
+ }
+ type = FunctionArgumentType.CHAR;
+ }
+ else {
+ throw new SQLException(dataType + " type is unsupported for TO_NUMBER(). Numeric and temporal types are supported.");
+ }
+ Preconditions.checkNotNull(type);
+ this.type = type;
+ this.formatString = formatString;
+ this.format = formatter;
+ }
+
public ToNumberFunction(List<Expression> children, FunctionArgumentType type, String formatString, Format formatter) throws SQLException {
super(children.subList(0, 1));
Preconditions.checkNotNull(type);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java
index 588cb92..905d955 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java
@@ -20,7 +20,9 @@ package org.apache.phoenix.expression.function;
import java.sql.SQLException;
import java.util.List;
+import org.apache.phoenix.compile.StatementContext;
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.parse.ToTimeParseNode;
@@ -47,6 +49,10 @@ public class ToTimeFunction extends ToDateFunction {
public ToTimeFunction() {
}
+ public ToTimeFunction(List<Expression> children, StatementContext context) throws SQLException {
+ super(children, context);
+ }
+
public ToTimeFunction(List<Expression> children, String dateFormat, String timeZoneId) throws SQLException {
super(children, dateFormat, timeZoneId);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java
index 6c14595..a727d0e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java
@@ -20,6 +20,7 @@ package org.apache.phoenix.expression.function;
import java.sql.SQLException;
import java.util.List;
+import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
@@ -47,6 +48,10 @@ public class ToTimestampFunction extends ToDateFunction {
public ToTimestampFunction() {
}
+ public ToTimestampFunction(List<Expression> children, StatementContext context) throws SQLException {
+ super(children, context);
+ }
+
public ToTimestampFunction(List<Expression> children, String dateFormat, String timeZoneId) throws SQLException {
super(children, dateFormat, timeZoneId);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
index 3b9616c..83297a1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
@@ -22,6 +22,7 @@ import java.util.List;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.parse.FloorParseNode;
+import org.apache.phoenix.parse.FunctionParseNode;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.schema.types.PDecimal;
@@ -46,7 +47,9 @@ args = {
@Argument(allowedTypes={PTimestamp.class, PDecimal.class}),
@Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
@Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
- }
+ },
+classType = FunctionParseNode.FunctionClassType.ALIAS,
+derivedFunctions = {FloorFunction.class}
)
public abstract class TruncFunction extends ScalarFunction {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
index 952d0d3..df9ad86 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
@@ -283,6 +283,8 @@ public class FunctionParseNode extends CompoundParseNode {
String name();
Argument[] args() default {};
Class<? extends FunctionParseNode> nodeClass() default FunctionParseNode.class;
+ Class<? extends FunctionExpression>[] derivedFunctions() default {};
+ FunctionClassType classType() default FunctionClassType.NONE;
}
@Retention(RetentionPolicy.RUNTIME)
@@ -297,20 +299,32 @@ public class FunctionParseNode extends CompoundParseNode {
String maxValue() default "";
}
+ public enum FunctionClassType {
+ NONE,
+ ABSTRACT,
+ DERIVED,
+ ALIAS,
+ UDF
+ }
+
/**
* Structure used to hold parse-time information about Function implementation classes
*/
@Immutable
public static final class BuiltInFunctionInfo {
private final String name;
+ private final Class<? extends FunctionExpression> func;
private final Constructor<? extends FunctionExpression> funcCtor;
private final Constructor<? extends FunctionParseNode> nodeCtor;
private final BuiltInFunctionArgInfo[] args;
private final boolean isAggregate;
private final int requiredArgCount;
+ private final FunctionClassType classType;
+ private final Class<? extends FunctionExpression>[] derivedFunctions;
public BuiltInFunctionInfo(Class<? extends FunctionExpression> f, BuiltInFunction d) {
this.name = SchemaUtil.normalizeIdentifier(d.name());
+ this.func = f;
this.funcCtor = d.nodeClass() == FunctionParseNode.class ? getExpressionCtor(f, null) : null;
this.nodeCtor = d.nodeClass() == FunctionParseNode.class ? null : getParseNodeCtor(d.nodeClass());
this.args = new BuiltInFunctionArgInfo[d.args().length];
@@ -323,10 +337,13 @@ public class FunctionParseNode extends CompoundParseNode {
}
this.requiredArgCount = requiredArgCount;
this.isAggregate = AggregateFunction.class.isAssignableFrom(f);
+ this.classType = d.classType();
+ this.derivedFunctions = d.derivedFunctions();
}
public BuiltInFunctionInfo(PFunction function) {
this.name = SchemaUtil.normalizeIdentifier(function.getFunctionName());
+ this.func = null;
this.funcCtor = getExpressionCtor(UDFExpression.class, function);
this.nodeCtor = getParseNodeCtor(UDFParseNode.class);
this.args = new BuiltInFunctionArgInfo[function.getFunctionArguments().size()];
@@ -339,6 +356,8 @@ public class FunctionParseNode extends CompoundParseNode {
}
this.requiredArgCount = requiredArgCount;
this.isAggregate = AggregateFunction.class.isAssignableFrom(UDFExpression.class);
+ this.classType = FunctionClassType.UDF;
+ this.derivedFunctions = null;
}
public int getRequiredArgCount() {
@@ -349,6 +368,10 @@ public class FunctionParseNode extends CompoundParseNode {
return name;
}
+ public Class<? extends FunctionExpression> getFunc() {
+ return func;
+ }
+
public Constructor<? extends FunctionExpression> getFuncCtor() {
return funcCtor;
}
@@ -364,6 +387,14 @@ public class FunctionParseNode extends CompoundParseNode {
public BuiltInFunctionArgInfo[] getArgs() {
return args;
}
+
+ public FunctionClassType getClassType() {
+ return classType;
+ }
+
+ public Class<? extends FunctionExpression>[] getDerivedFunctions() {
+ return derivedFunctions;
+ }
}
@Immutable
http://git-wip-us.apache.org/repos/asf/phoenix/blob/90d27be5/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
index 0376877..ce49911 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
@@ -25,8 +25,10 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
+import com.google.common.collect.ArrayListMultimap;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.phoenix.expression.Expression;
@@ -55,6 +57,7 @@ import org.apache.phoenix.util.SchemaUtil;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
/**
*
@@ -73,6 +76,7 @@ public class ParseNodeFactory {
AvgAggregateFunction.class
);
private static final Map<BuiltInFunctionKey, BuiltInFunctionInfo> BUILT_IN_FUNCTION_MAP = Maps.newHashMap();
+ private static final Multimap<String, BuiltInFunctionInfo> BUILT_IN_FUNCTION_MULTIMAP = ArrayListMultimap.create();
private static final BigDecimal MAX_LONG = BigDecimal.valueOf(Long.MAX_VALUE);
@@ -127,19 +131,24 @@ public class ParseNodeFactory {
}
int nArgs = d.args().length;
BuiltInFunctionInfo value = new BuiltInFunctionInfo(f, d);
- do {
- // Add function to function map, throwing if conflicts found
- // Add entry for each possible version of function based on arguments that are not required to be present (i.e. arg with default value)
- BuiltInFunctionKey key = new BuiltInFunctionKey(value.getName(), nArgs);
- if (BUILT_IN_FUNCTION_MAP.put(key, value) != null) {
- throw new IllegalStateException("Multiple " + value.getName() + " functions with " + nArgs + " arguments");
- }
- } while (--nArgs >= 0 && d.args()[nArgs].defaultValue().length() > 0);
+ if (d.classType() != FunctionParseNode.FunctionClassType.ABSTRACT) {
+ BUILT_IN_FUNCTION_MULTIMAP.put(value.getName(), value);
+ }
+ if (d.classType() != FunctionParseNode.FunctionClassType.DERIVED) {
+ do {
+ // Add function to function map, throwing if conflicts found
+ // Add entry for each possible version of function based on arguments that are not required to be present (i.e. arg with default value)
+ BuiltInFunctionKey key = new BuiltInFunctionKey(value.getName(), nArgs);
+ if (BUILT_IN_FUNCTION_MAP.put(key, value) != null) {
+ throw new IllegalStateException("Multiple " + value.getName() + " functions with " + nArgs + " arguments");
+ }
+ } while (--nArgs >= 0 && d.args()[nArgs].defaultValue().length() > 0);
- // Look for default values that aren't at the end and throw
- while (--nArgs >= 0) {
- if (d.args()[nArgs].defaultValue().length() > 0) {
- throw new IllegalStateException("Function " + value.getName() + " has non trailing default value of '" + d.args()[nArgs].defaultValue() + "'. Only trailing arguments may have default values");
+ // Look for default values that aren't at the end and throw
+ while (--nArgs >= 0) {
+ if (d.args()[nArgs].defaultValue().length() > 0) {
+ throw new IllegalStateException("Function " + value.getName() + " has non trailing default value of '" + d.args()[nArgs].defaultValue() + "'. Only trailing arguments may have default values");
+ }
}
}
}
@@ -181,6 +190,11 @@ public class ParseNodeFactory {
return info;
}
+ public static Multimap<String, BuiltInFunctionInfo> getBuiltInFunctionMultimap(){
+ initBuiltInFunctionMap();
+ return BUILT_IN_FUNCTION_MULTIMAP;
+ }
+
public ParseNodeFactory() {
}
[31/42] phoenix git commit: Introduce the notion of encoding schemes
and storage schemes
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/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 1134e06..860163c 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
@@ -149,6 +149,7 @@ public class PTableImpl implements PTable {
private String autoPartitionSeqName;
private boolean isAppendOnlySchema;
private StorageScheme storageScheme;
+ private QualifierEncodingScheme qualifierEncodingScheme;
private EncodedCQCounter encodedCQCounter;
public PTableImpl() {
@@ -183,7 +184,8 @@ public class PTableImpl implements PTable {
// For indexes stored in shared physical tables
public PTableImpl(PName tenantId, PName schemaName, PName tableName, long timestamp, List<PColumnFamily> families,
- List<PColumn> columns, List<PName> physicalNames, Short viewIndexId, boolean multiTenant, boolean isNamespaceMpped, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
+ List<PColumn> columns, List<PName> physicalNames, Short viewIndexId, boolean multiTenant, boolean isNamespaceMpped, StorageScheme storageScheme, QualifierEncodingScheme qualifierEncodingScheme,
+ EncodedCQCounter encodedCQCounter) throws SQLException {
this.pkColumns = this.allColumns = Collections.emptyList();
this.rowKeySchema = RowKeySchema.EMPTY_SCHEMA;
this.indexes = Collections.emptyList();
@@ -197,7 +199,7 @@ public class PTableImpl implements PTable {
init(tenantId, this.schemaName, this.tableName, PTableType.INDEX, state, timeStamp, sequenceNumber, pkName, bucketNum, columns,
this.schemaName, parentTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName,
null, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType, baseColumnCount, rowKeyOrderOptimizable,
- isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMpped, null, false, storageScheme, encodedCQCounter);
+ isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMpped, null, false, storageScheme, qualifierEncodingScheme, encodedCQCounter);
}
public PTableImpl(long timeStamp) { // For delete marker
@@ -241,7 +243,7 @@ public class PTableImpl implements PTable {
indexes, table.isImmutableRows(), physicalNames, table.getDefaultFamilyName(), viewStatement,
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), updateCacheFrequency,
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, long timeStamp, List<PTable> indexes, PName parentSchemaName, String viewStatement) throws SQLException {
@@ -251,7 +253,7 @@ public class PTableImpl implements PTable {
indexes, table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), viewStatement,
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(),
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, Collection<PColumn> columns) throws SQLException {
@@ -261,7 +263,7 @@ public class PTableImpl implements PTable {
table.getIndexes(), table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(),
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, long timeStamp, long sequenceNumber, Collection<PColumn> columns) throws SQLException {
@@ -271,7 +273,7 @@ public class PTableImpl implements PTable {
table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(),
table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(),
- table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, long timeStamp, long sequenceNumber, Collection<PColumn> columns, boolean isImmutableRows) throws SQLException {
@@ -281,7 +283,7 @@ public class PTableImpl implements PTable {
table.getIndexes(), isImmutableRows, table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(),
table.getIndexType(), table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(),
- table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, long timeStamp, long sequenceNumber, Collection<PColumn> columns, boolean isImmutableRows, boolean isWalDisabled,
@@ -292,7 +294,7 @@ public class PTableImpl implements PTable {
table.getIndexes(), isImmutableRows, table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
isWalDisabled, isMultitenant, storeNulls, table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), isTransactional, updateCacheFrequency, table.getIndexDisableTimestamp(),
- isNamespaceMapped, table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ isNamespaceMapped, table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, PIndexState state) throws SQLException {
@@ -303,7 +305,7 @@ public class PTableImpl implements PTable {
table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(),
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, boolean rowKeyOrderOptimizable) throws SQLException {
@@ -314,7 +316,7 @@ public class PTableImpl implements PTable {
table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), rowKeyOrderOptimizable, table.isTransactional(), table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(),
- table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table) throws SQLException {
@@ -325,7 +327,7 @@ public class PTableImpl implements PTable {
table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(),
- table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PName tenantId, PName schemaName, PName tableName, PTableType type,
@@ -334,12 +336,12 @@ public class PTableImpl implements PTable {
boolean isImmutableRows, List<PName> physicalNames, PName defaultFamilyName, String viewExpression,
boolean disableWAL, boolean multiTenant, boolean storeNulls, ViewType viewType, Short viewIndexId,
IndexType indexType, boolean rowKeyOrderOptimizable, boolean isTransactional, long updateCacheFrequency,
- long indexDisableTimestamp, boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
+ long indexDisableTimestamp, boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, QualifierEncodingScheme qualifierEncodingScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
return new PTableImpl(tenantId, schemaName, tableName, type, state, timeStamp, sequenceNumber, pkName, bucketNum, columns, dataSchemaName,
dataTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName,
viewExpression, disableWAL, multiTenant, storeNulls, viewType, viewIndexId,
indexType, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, rowKeyOrderOptimizable, isTransactional,
- updateCacheFrequency,indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema, storageScheme, encodedCQCounter);
+ updateCacheFrequency,indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema, storageScheme, qualifierEncodingScheme, encodedCQCounter);
}
public static PTableImpl makePTable(PName tenantId, PName schemaName, PName tableName, PTableType type,
@@ -349,13 +351,13 @@ public class PTableImpl implements PTable {
boolean disableWAL, boolean multiTenant, boolean storeNulls, ViewType viewType, Short viewIndexId,
IndexType indexType, boolean rowKeyOrderOptimizable, boolean isTransactional, long updateCacheFrequency,
int baseColumnCount, long indexDisableTimestamp, boolean isNamespaceMapped,
- String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter)
+ String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, QualifierEncodingScheme qualifierEncodingScheme, EncodedCQCounter encodedCQCounter)
throws SQLException {
return new PTableImpl(tenantId, schemaName, tableName, type, state, timeStamp, sequenceNumber, pkName,
bucketNum, columns, dataSchemaName, dataTableName, indexes, isImmutableRows, physicalNames,
defaultFamilyName, viewExpression, disableWAL, multiTenant, storeNulls, viewType, viewIndexId,
indexType, baseColumnCount, rowKeyOrderOptimizable, isTransactional, updateCacheFrequency,
- indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema, storageScheme, encodedCQCounter);
+ indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema, storageScheme, qualifierEncodingScheme, encodedCQCounter);
}
private PTableImpl(PName tenantId, PName schemaName, PName tableName, PTableType type, PIndexState state,
@@ -364,11 +366,13 @@ public class PTableImpl implements PTable {
List<PName> physicalNames, PName defaultFamilyName, String viewExpression, boolean disableWAL, boolean multiTenant,
boolean storeNulls, ViewType viewType, Short viewIndexId, IndexType indexType,
int baseColumnCount, boolean rowKeyOrderOptimizable, boolean isTransactional, long updateCacheFrequency,
- long indexDisableTimestamp, boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
+ long indexDisableTimestamp, boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme,
+ QualifierEncodingScheme qualifierEncodingScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
init(tenantId, schemaName, tableName, type, state, timeStamp, sequenceNumber, pkName, bucketNum, columns,
parentSchemaName, parentTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName,
viewExpression, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType, baseColumnCount, rowKeyOrderOptimizable,
- isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema, storageScheme, encodedCQCounter);
+ isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema, storageScheme,
+ qualifierEncodingScheme, encodedCQCounter);
}
@Override
@@ -402,7 +406,8 @@ public class PTableImpl implements PTable {
List<PTable> indexes, boolean isImmutableRows, List<PName> physicalNames, PName defaultFamilyName, String viewExpression, boolean disableWAL,
boolean multiTenant, boolean storeNulls, ViewType viewType, Short viewIndexId,
IndexType indexType , int baseColumnCount, boolean rowKeyOrderOptimizable, boolean isTransactional, long updateCacheFrequency, long indexDisableTimestamp,
- boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
+ boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, QualifierEncodingScheme qualifierEncodingScheme,
+ EncodedCQCounter encodedCQCounter) throws SQLException {
Preconditions.checkNotNull(schemaName);
Preconditions.checkArgument(tenantId==null || tenantId.getBytes().length > 0); // tenantId should be null or not empty
int estimatedSize = SizedUtil.OBJECT_SIZE * 2 + 23 * SizedUtil.POINTER_SIZE + 4 * SizedUtil.INT_SIZE + 2 * SizedUtil.LONG_SIZE + 2 * SizedUtil.INT_OBJECT_SIZE +
@@ -439,6 +444,7 @@ public class PTableImpl implements PTable {
this.autoPartitionSeqName = autoPartitionSeqName;
this.isAppendOnlySchema = isAppendOnlySchema;
this.storageScheme = storageScheme;
+ this.qualifierEncodingScheme = qualifierEncodingScheme;
List<PColumn> pkColumns;
PColumn[] allColumns;
@@ -1291,6 +1297,10 @@ public class PTableImpl implements PTable {
if (table.hasStorageScheme()) {
storageScheme = StorageScheme.fromSerializedValue(table.getStorageScheme().toByteArray()[0]);
}
+ QualifierEncodingScheme qualifierEncodingScheme= null;
+ if (table.hasEncodingScheme()) {
+ qualifierEncodingScheme = QualifierEncodingScheme.fromSerializedValue(table.getEncodingScheme().toByteArray()[0]);
+ }
EncodedCQCounter encodedColumnQualifierCounter = EncodedColumnsUtil.usesEncodedColumnNames(storageScheme) ? new EncodedCQCounter() : EncodedCQCounter.NULL_COUNTER;
if (table.getEncodedCQCountersList() != null) {
encodedColumnQualifierCounter = new EncodedCQCounter();
@@ -1305,7 +1315,8 @@ public class PTableImpl implements PTable {
(bucketNum == NO_SALTING) ? null : bucketNum, columns, parentSchemaName, parentTableName, indexes,
isImmutableRows, physicalNames, defaultFamilyName, viewStatement, disableWAL,
multiTenant, storeNulls, viewType, viewIndexId, indexType, baseColumnCount, rowKeyOrderOptimizable,
- isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoParititonSeqName, isAppendOnlySchema, storageScheme, encodedColumnQualifierCounter);
+ isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoParititonSeqName,
+ isAppendOnlySchema, storageScheme, qualifierEncodingScheme, encodedColumnQualifierCounter);
return result;
} catch (SQLException e) {
throw new RuntimeException(e); // Impossible
@@ -1392,7 +1403,7 @@ public class PTableImpl implements PTable {
}
builder.setIsAppendOnlySchema(table.isAppendOnlySchema());
if (table.getStorageScheme() != null) {
- builder.setStorageScheme(ByteStringer.wrap(new byte[]{table.getStorageScheme().getSerializedValue()}));
+ builder.setStorageScheme(ByteStringer.wrap(new byte[]{table.getStorageScheme().getSerializedMetadataValue()}));
}
if (table.getEncodedCQCounter() != null) {
Map<String, Integer> values = table.getEncodedCQCounter().values();
@@ -1482,4 +1493,9 @@ public class PTableImpl implements PTable {
public EncodedCQCounter getEncodedCQCounter() {
return encodedCQCounter;
}
+
+ @Override
+ public QualifierEncodingScheme getEncodingScheme() {
+ return qualifierEncodingScheme;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
index aeb4e46..fee7c75 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
@@ -26,7 +26,6 @@ import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.StorageScheme;
-import org.apache.phoenix.schema.types.PInteger;
public class EncodedColumnsUtil {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
index 8c2f58d..787b3e8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
@@ -921,7 +921,7 @@ public class ScanUtil {
}
public static boolean setQualifierRanges(PTable table) {
- return table.getStorageScheme() != null && table.getStorageScheme() == StorageScheme.ENCODED_COLUMN_NAMES
+ return table.getStorageScheme() != null && table.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS
&& !table.isTransactional() && !hasDynamicColumns(table);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/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 1a4502e..f8e0cb7 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
@@ -1096,9 +1096,9 @@ public class SchemaUtil {
}
public static Map<String, Pair<Integer, Integer>> getQualifierRanges(PTable table) {
- Preconditions.checkArgument(table.getStorageScheme() == StorageScheme.ENCODED_COLUMN_NAMES,
+ Preconditions.checkArgument(table.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS,
"Use this method only for tables with storage scheme "
- + StorageScheme.ENCODED_COLUMN_NAMES.name());
+ + StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS.name());
Map<String, Pair<Integer, Integer>> toReturn = Maps.newHashMapWithExpectedSize(table.getColumns().size());
for (PColumn column : table.getColumns()) {
if (!isPKColumn(column)) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
index ca6a471..418a547 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
@@ -64,6 +64,7 @@ import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.EncodedCQCounter;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
@@ -260,7 +261,7 @@ public class CorrelatePlanTest {
PTableType.SUBQUERY, null, MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM,
null, null, columns, null, null, Collections.<PTable>emptyList(),
false, Collections.<PName>emptyList(), null, null, false, false, false, null,
- null, null, true, false, 0, 0L, Boolean.FALSE, null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, EncodedCQCounter.NULL_COUNTER);
+ null, null, true, false, 0, 0L, Boolean.FALSE, null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, EncodedCQCounter.NULL_COUNTER);
TableRef sourceTable = new TableRef(pTable);
List<ColumnRef> sourceColumnRefs = Lists.<ColumnRef> newArrayList();
for (PColumn column : sourceTable.getTable().getColumns()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
index 7fff2c4..f6ee970 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
@@ -58,6 +58,7 @@ import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.EncodedCQCounter;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.TableRef;
@@ -181,7 +182,7 @@ public class LiteralResultIteratorPlanTest {
PTable pTable = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME, PTableType.SUBQUERY, null,
MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM, null, null, columns, null, null,
Collections.<PTable> emptyList(), false, Collections.<PName> emptyList(), null, null, false, false,
- false, null, null, null, true, false, 0, 0L, false, null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, EncodedCQCounter.NULL_COUNTER);
+ false, null, null, null, true, false, 0, 0L, false, null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, EncodedCQCounter.NULL_COUNTER);
TableRef sourceTable = new TableRef(pTable);
List<ColumnRef> sourceColumnRefs = Lists.<ColumnRef> newArrayList();
for (PColumn column : sourceTable.getTable().getColumns()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
index 430c20b..3ce9809 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
@@ -26,6 +26,8 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
@@ -37,6 +39,7 @@ import java.util.List;
import java.util.Properties;
import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.phoenix.compile.QueryPlan;
import org.apache.phoenix.expression.Expression;
@@ -342,5 +345,12 @@ public class PhoenixRuntimeTest extends BaseConnectionlessQueryTest {
long skewedTs = ts + QueryConstants.MILLIS_IN_DAY; // skew of a day
// Even with a day of skew, we won't consider the ts a nanos timestamp
assertEquals(skewedTs, PhoenixRuntime.getWallClockTimeFromCellTimeStamp(skewedTs));
- }
+ }
+
+ public static void main(String args[]) throws Exception {
+ byte[] bytes = Bytes.toBytes(4294967295l);
+ long value = ByteBuffer.wrap(bytes)
+ .order(ByteOrder.LITTLE_ENDIAN).getInt() & 0xFFFFFFFFL;
+ System.out.print(value);
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-protocol/src/main/PTable.proto
----------------------------------------------------------------------
diff --git a/phoenix-protocol/src/main/PTable.proto b/phoenix-protocol/src/main/PTable.proto
index d5df2f3..3eac63b 100644
--- a/phoenix-protocol/src/main/PTable.proto
+++ b/phoenix-protocol/src/main/PTable.proto
@@ -47,7 +47,7 @@ message PColumn {
optional string expression = 12;
optional bool isRowTimestamp = 13;
optional bool isDynamic = 14;
- optional int32 columnQualifier = 15;
+ optional int32 encodedColumnQualifier = 15;
}
message PTableStats {
@@ -97,7 +97,8 @@ message PTable {
optional bool isAppendOnlySchema = 32;
optional bytes parentNameBytes = 33;
optional bytes storageScheme = 34;
- repeated EncodedCQCounter encodedCQCounters = 35;
+ optional bytes encodingScheme = 35;
+ repeated EncodedCQCounter encodedCQCounters = 36;
}
message EncodedCQCounter {
[42/42] phoenix git commit: Fix test failure
Posted by td...@apache.org.
Fix test failure
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/11c0c3b7
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/11c0c3b7
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/11c0c3b7
Branch: refs/heads/encodecolumns2
Commit: 11c0c3b7b40f34f130554363a85ef0de7edd31a3
Parents: a41074a
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Thu Dec 22 17:23:04 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 17:23:04 2016 -0800
----------------------------------------------------------------------
.../org/apache/phoenix/schema/PTableImpl.java | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/11c0c3b7/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 7f11faf..8ae1988 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
@@ -64,6 +64,7 @@ import org.apache.phoenix.parse.ParseNode;
import org.apache.phoenix.parse.SQLParser;
import org.apache.phoenix.protobuf.ProtobufUtil;
import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PArrayDataType;
@@ -1335,12 +1336,17 @@ public class PTableImpl implements PTable {
if (table.hasEncodingScheme()) {
qualifierEncodingScheme = QualifierEncodingScheme.fromSerializedValue(table.getEncodingScheme().toByteArray()[0]);
}
- EncodedCQCounter encodedColumnQualifierCounter = EncodedColumnsUtil.usesEncodedColumnNames(qualifierEncodingScheme) ? new EncodedCQCounter() : EncodedCQCounter.NULL_COUNTER;
- if (table.getEncodedCQCountersList() != null) {
- encodedColumnQualifierCounter = new EncodedCQCounter();
- for (org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter cqCounterFromProto : table.getEncodedCQCountersList()) {
- encodedColumnQualifierCounter.setValue(cqCounterFromProto.getColFamily(), cqCounterFromProto.getCounter());
- }
+ EncodedCQCounter encodedColumnQualifierCounter = null;
+ if ((!EncodedColumnsUtil.usesEncodedColumnNames(qualifierEncodingScheme) || tableType == PTableType.VIEW)) {
+ encodedColumnQualifierCounter = PTable.EncodedCQCounter.NULL_COUNTER;
+ }
+ else {
+ encodedColumnQualifierCounter = new EncodedCQCounter();
+ if (table.getEncodedCQCountersList() != null) {
+ for (org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter cqCounterFromProto : table.getEncodedCQCountersList()) {
+ encodedColumnQualifierCounter.setValue(cqCounterFromProto.getColFamily(), cqCounterFromProto.getCounter());
+ }
+ }
}
try {
[41/42] phoenix git commit: Refactor code to store and use column
qualifiers in SYSTEM.CATALOG
Posted by td...@apache.org.
Refactor code to store and use column qualifiers in SYSTEM.CATALOG
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/a41074a9
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a41074a9
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a41074a9
Branch: refs/heads/encodecolumns2
Commit: a41074a9601901c80ac4c37a69ef606bffe51171
Parents: be6861c
Author: Samarth <sa...@salesforce.com>
Authored: Wed Dec 21 13:15:02 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:03:52 2016 -0800
----------------------------------------------------------------------
.../apache/phoenix/end2end/AlterTableIT.java | 7 +-
.../apache/phoenix/end2end/StoreNullsIT.java | 10 +-
.../phoenix/end2end/index/DropMetadataIT.java | 4 +-
.../apache/phoenix/compile/FromCompiler.java | 19 ++-
.../apache/phoenix/compile/JoinCompiler.java | 9 +-
.../phoenix/compile/ListJarsQueryPlan.java | 6 +-
.../apache/phoenix/compile/PostDDLCompiler.java | 2 +-
.../phoenix/compile/ProjectionCompiler.java | 14 +-
.../apache/phoenix/compile/TraceQueryPlan.java | 4 +-
.../compile/TupleProjectionCompiler.java | 8 +-
.../apache/phoenix/compile/UnionCompiler.java | 3 +-
.../apache/phoenix/compile/WhereCompiler.java | 2 +-
.../coprocessor/BaseScannerRegionObserver.java | 1 +
.../GroupedAggregateRegionObserver.java | 6 +-
.../coprocessor/MetaDataEndpointImpl.java | 26 +--
.../phoenix/coprocessor/ScanRegionObserver.java | 11 +-
.../UngroupedAggregateRegionObserver.java | 3 +-
.../coprocessor/generated/PTableProtos.java | 157 ++++++++++---------
.../apache/phoenix/execute/BaseQueryPlan.java | 2 +-
.../expression/ArrayColumnExpression.java | 30 +++-
.../expression/KeyValueColumnExpression.java | 30 ++--
.../apache/phoenix/index/IndexMaintainer.java | 29 ++--
.../phoenix/iterate/BaseResultIterators.java | 23 +--
.../iterate/RegionScannerResultIterator.java | 7 +-
.../phoenix/jdbc/PhoenixDatabaseMetaData.java | 4 +-
.../mapreduce/FormatToBytesWritableMapper.java | 2 +-
.../mapreduce/FormatToKeyValueReducer.java | 2 +-
.../apache/phoenix/query/QueryConstants.java | 18 ++-
.../org/apache/phoenix/schema/ColumnRef.java | 6 +-
.../apache/phoenix/schema/DelegateColumn.java | 4 +-
.../apache/phoenix/schema/MetaDataClient.java | 34 ++--
.../java/org/apache/phoenix/schema/PColumn.java | 2 +-
.../phoenix/schema/PColumnFamilyImpl.java | 41 +++--
.../org/apache/phoenix/schema/PColumnImpl.java | 28 ++--
.../apache/phoenix/schema/PMetaDataImpl.java | 2 +-
.../java/org/apache/phoenix/schema/PTable.java | 135 +++++++---------
.../org/apache/phoenix/schema/PTableImpl.java | 118 ++++++++++----
.../apache/phoenix/schema/ProjectedColumn.java | 11 +-
.../tuple/EncodedColumnQualiferCellsList.java | 19 ++-
.../tuple/PositionBasedMultiKeyValueTuple.java | 3 +-
.../schema/tuple/PositionBasedResultTuple.java | 3 +-
.../apache/phoenix/util/EncodedColumnsUtil.java | 77 +++++----
.../java/org/apache/phoenix/util/IndexUtil.java | 9 +-
.../phoenix/compile/WhereCompilerTest.java | 4 +-
.../phoenix/execute/CorrelatePlanTest.java | 3 +-
.../execute/LiteralResultIteratorPlanTest.java | 3 +-
.../phoenix/execute/UnnestArrayPlanTest.java | 7 +-
.../expression/ColumnExpressionTest.java | 35 +++--
.../EncodedColumnQualifierCellsListTest.java | 98 ++++++------
.../java/org/apache/phoenix/util/TestUtil.java | 10 +-
phoenix-protocol/src/main/PTable.proto | 2 +-
51 files changed, 601 insertions(+), 492 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index 3084a92..91e9964 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -20,8 +20,8 @@ package org.apache.phoenix.end2end;
import static org.apache.hadoop.hbase.HColumnDescriptor.DEFAULT_REPLICATION_SCOPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_FAMILY;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER_COUNTER;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SEQ_NUM;
@@ -65,6 +65,7 @@ import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.EncodedCQCounter;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.util.IndexUtil;
@@ -2454,7 +2455,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
}
private void assertEncodedCQValue(String columnFamily, String columnName, String schemaName, String tableName, int expectedValue) throws Exception {
- String query = "SELECT " + ENCODED_COLUMN_QUALIFIER + " FROM SYSTEM.CATALOG WHERE " + TABLE_SCHEM + " = ? AND " + TABLE_NAME
+ String query = "SELECT " + COLUMN_QUALIFIER + " FROM SYSTEM.CATALOG WHERE " + TABLE_SCHEM + " = ? AND " + TABLE_NAME
+ " = ? " + " AND " + COLUMN_FAMILY + " = ?" + " AND " + COLUMN_NAME + " = ?";
try (Connection conn = DriverManager.getConnection(getUrl())) {
PreparedStatement stmt = conn.prepareStatement(query);
@@ -2464,7 +2465,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
stmt.setString(4, columnName);
ResultSet rs = stmt.executeQuery();
assertTrue(rs.next());
- assertEquals(expectedValue, rs.getInt(1));
+ assertTrue(Bytes.equals(QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS.getEncodedBytes(expectedValue), rs.getBytes(1)));
assertFalse(rs.next());
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
index 07fc4e9..8e1db17 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
@@ -17,14 +17,11 @@
*/
package org.apache.phoenix.end2end;
-import static org.apache.phoenix.query.QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
-import static org.apache.phoenix.query.QueryConstants.ENCODED_EMPTY_COLUMN_BYTES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
@@ -34,24 +31,21 @@ import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
-import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PColumn;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.tuple.ResultTuple;
import org.apache.phoenix.schema.types.PVarchar;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.PhoenixRuntime;
-import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.After;
import org.junit.Before;
@@ -127,7 +121,7 @@ public class StoreNullsIT extends ParallelStatsDisabledIT {
Result rs = scanner.next();
assertTrue(rs.size() == 2); // 2 because it also includes the empty key value column
PColumn nameColumn = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, tableName)).getPColumnForColumnName("NAME");
- ArrayColumnExpression colExpression = new ArrayColumnExpression(nameColumn, "NAME", true);
+ ArrayColumnExpression colExpression = new ArrayColumnExpression(nameColumn, "NAME", QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS);
ImmutableBytesPtr ptr = new ImmutableBytesPtr();
colExpression.evaluate(new ResultTuple(rs), ptr);
assertEquals(new ImmutableBytesPtr(PVarchar.INSTANCE.toBytes("v1")), ptr);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
index b892c4d..c769fdd 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
@@ -187,7 +187,7 @@ public class DropMetadataIT extends ParallelStatsDisabledIT {
Result result = results.next();
assertNotNull(result);
assertNotNull("localIndexTableName2 row is missing", result.getValue(QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES,
- EncodedColumnsUtil.getColumnQualifier(localIndex2.getPColumnForColumnName(IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, "V1")), localIndex2)));
+ localIndex2.getPColumnForColumnName(IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, "V1")).getColumnQualifierBytes()));
assertNull(results.next());
}
}
@@ -300,7 +300,7 @@ public class DropMetadataIT extends ParallelStatsDisabledIT {
assertNotNull(result);
PTable viewIndexPTable = pconn.getTable(new PTableKey(pconn.getTenantId(), viewIndex2));
PColumn column = viewIndexPTable.getPColumnForColumnName(IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, "V4"));
- byte[] cq = EncodedColumnsUtil.getColumnQualifier(column, viewIndexPTable);
+ byte[] cq = column.getColumnQualifierBytes();
// there should be a single row belonging to VIEWINDEX2
assertNotNull(viewIndex2 + " row is missing", result.getValue(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, cq));
assertNull(results.next());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
index 8d00996..1a14c7f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
@@ -17,6 +17,8 @@
*/
package org.apache.phoenix.compile;
+import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
+
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ArrayList;
@@ -28,6 +30,7 @@ import java.util.Map;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.coprocessor.MetaDataProtocol;
import org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult;
import org.apache.phoenix.expression.Expression;
@@ -189,7 +192,7 @@ public class FromCompiler {
if (htable != null) Closeables.closeQuietly(htable);
}
tableNode = NamedTableNode.create(null, baseTable, statement.getColumnDefs());
- return new SingleTableColumnResolver(connection, tableNode, e.getTimeStamp(), new HashMap<String, UDFParseNode>(1), false, false);
+ return new SingleTableColumnResolver(connection, tableNode, e.getTimeStamp(), new HashMap<String, UDFParseNode>(1), false);
}
throw e;
}
@@ -261,7 +264,7 @@ public class FromCompiler {
Expression sourceExpression = projector.getColumnProjector(column.getPosition()).getExpression();
PColumnImpl projectedColumn = new PColumnImpl(column.getName(), column.getFamilyName(),
sourceExpression.getDataType(), sourceExpression.getMaxLength(), sourceExpression.getScale(), sourceExpression.isNullable(),
- column.getPosition(), sourceExpression.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(), column.isDynamic(), column.getEncodedColumnQualifier());
+ column.getPosition(), sourceExpression.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(), column.isDynamic(), column.getColumnQualifierBytes());
projectedColumns.add(projectedColumn);
}
PTable t = PTableImpl.makePTable(table, projectedColumns);
@@ -336,12 +339,12 @@ public class FromCompiler {
private final String alias;
private final List<PSchema> schemas;
- public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode table, long timeStamp, Map<String, UDFParseNode> udfParseNodes, boolean isNamespaceMapped, boolean useEncodedColumnNames) throws SQLException {
+ public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode table, long timeStamp, Map<String, UDFParseNode> udfParseNodes, boolean isNamespaceMapped) throws SQLException {
super(connection, 0, false, udfParseNodes);
List<PColumnFamily> families = Lists.newArrayListWithExpectedSize(table.getDynamicColumns().size());
for (ColumnDef def : table.getDynamicColumns()) {
if (def.getColumnDefName().getFamilyName() != null) {
- families.add(new PColumnFamilyImpl(PNameFactory.newName(def.getColumnDefName().getFamilyName()),Collections.<PColumn>emptyList(), useEncodedColumnNames));
+ families.add(new PColumnFamilyImpl(PNameFactory.newName(def.getColumnDefName().getFamilyName()),Collections.<PColumn>emptyList()));//, NON_ENCODED_QUALIFIERS));
}
}
Long scn = connection.getSCN();
@@ -349,6 +352,8 @@ public class FromCompiler {
if (connection.getSchema() != null) {
schema = schema != null ? schema : connection.getSchema();
}
+ // Storage scheme and encoding scheme don't matter here since the PTable is being used only for the purposes of create table.
+ // The actual values of these two will be determined by the metadata client.
PTable theTable = new PTableImpl(connection.getTenantId(), schema, table.getName().getTableName(),
scn == null ? HConstants.LATEST_TIMESTAMP : scn, families, isNamespaceMapped);
theTable = this.addDynamicColumns(table.getDynamicColumns(), theTable);
@@ -675,9 +680,8 @@ public class FromCompiler {
theTable.getColumnFamily(family); // Verifies that column family exists
familyName = PNameFactory.newName(family);
}
- // Dynamic columns don't have an encoded column name
allcolumns.add(new PColumnImpl(name, familyName, dynColumn.getDataType(), dynColumn.getMaxLength(),
- dynColumn.getScale(), dynColumn.isNull(), position, dynColumn.getSortOrder(), dynColumn.getArraySize(), null, false, dynColumn.getExpression(), false, true, null));
+ dynColumn.getScale(), dynColumn.isNull(), position, dynColumn.getSortOrder(), dynColumn.getArraySize(), null, false, dynColumn.getExpression(), false, true, Bytes.toBytes(dynColumn.getColumnDefName().getColumnName())));
position++;
}
theTable = PTableImpl.makePTable(theTable, allcolumns);
@@ -779,9 +783,10 @@ public class FromCompiler {
// referenced by an outer wild-card select.
alias = String.valueOf(position);
}
+ PName name = PNameFactory.newName(alias);
PColumnImpl column = new PColumnImpl(PNameFactory.newName(alias),
PNameFactory.newName(QueryConstants.DEFAULT_COLUMN_FAMILY),
- null, 0, 0, true, position++, SortOrder.ASC, null, null, false, null, false, false, null);
+ null, 0, 0, true, position++, SortOrder.ASC, null, null, false, null, false, false, name.getBytes());
columns.add(column);
}
PTable t = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME, PTableType.SUBQUERY, null,
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index b72c550..1db28f5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -17,6 +17,9 @@
*/
package org.apache.phoenix.compile;
+import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
+import static org.apache.phoenix.schema.PTable.StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN;
+
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
@@ -1287,7 +1290,7 @@ public class JoinCompiler {
if (type == JoinType.Full) {
for (PColumn c : left.getColumns()) {
merged.add(new ProjectedColumn(c.getName(), c.getFamilyName(),
- c.getPosition(), true, ((ProjectedColumn) c).getSourceColumnRef()));
+ c.getPosition(), true, ((ProjectedColumn) c).getSourceColumnRef(), SchemaUtil.isPKColumn(c) ? null : c.getName().getBytes()));
}
} else {
merged.addAll(left.getColumns());
@@ -1297,7 +1300,7 @@ public class JoinCompiler {
if (!SchemaUtil.isPKColumn(c)) {
PColumn column = new ProjectedColumn(c.getName(), c.getFamilyName(),
position++, type == JoinType.Inner ? c.isNullable() : true,
- ((ProjectedColumn) c).getSourceColumnRef());
+ ((ProjectedColumn) c).getSourceColumnRef(), c.getName().getBytes());
merged.add(column);
}
}
@@ -1313,7 +1316,7 @@ public class JoinCompiler {
left.isMultiTenant(), left.getStoreNulls(), left.getViewType(), left.getViewIndexId(),
left.getIndexType(), left.rowKeyOrderOptimizable(), left.isTransactional(),
left.getUpdateCacheFrequency(), left.getIndexDisableTimestamp(), left.isNamespaceMapped(),
- left.getAutoPartitionSeqName(), left.isAppendOnlySchema(), StorageScheme.ONE_CELL_PER_KEYVALUE_COLUMN, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
+ left.getAutoPartitionSeqName(), left.isAppendOnlySchema(), ONE_CELL_PER_KEYVALUE_COLUMN, NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
index 436e69b..8265de8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
@@ -57,6 +57,7 @@ import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnImpl;
+import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.RowKeyValueAccessor;
import org.apache.phoenix.schema.SortOrder;
@@ -77,10 +78,11 @@ public class ListJarsQueryPlan implements QueryPlan {
static {
List<ExpressionProjector> projectedColumns = new ArrayList<ExpressionProjector>();
+ PName colName = PNameFactory.newName("jar_location");
PColumn column =
- new PColumnImpl(PNameFactory.newName("jar_location"), null,
+ new PColumnImpl(colName, null,
PVarchar.INSTANCE, null, null, false, 0, SortOrder.getDefault(), 0, null,
- false, null, false, false, null);
+ false, null, false, false, colName.getBytes());
List<PColumn> columns = new ArrayList<PColumn>();
columns.add(column);
Expression expression =
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
index 3820ee5..e4ef25f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
@@ -238,7 +238,7 @@ public class PostDDLCompiler {
// data empty column family to stay the same, while the index empty column family
// changes.
PColumn column = deleteList.get(0);
- byte[] cq = EncodedColumnsUtil.getColumnQualifier(column, tableRef.getTable());
+ byte[] cq = column.getColumnQualifierBytes();
if (emptyCF == null) {
scan.addColumn(column.getFamilyName().getBytes(), cq);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/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 25aee35..e2e7573 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
@@ -485,11 +485,13 @@ public class ProjectionCompiler {
}
} else {
for (byte[] cq : entry.getValue()) {
- PColumn column = family.getPColumnForColumnQualifier(cq);
- 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;
- }
+ //if (!Bytes.equals(cq, ByteUtil.EMPTY_BYTE_ARRAY) || cq.length > 0) {
+ PColumn column = family.getPColumnForColumnQualifier(cq);
+ 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;
+ }
+ //}
}
}
boolean isProjectEmptyKeyValue = false;
@@ -665,7 +667,7 @@ public class ProjectionCompiler {
if (expression.getDataType().isArrayType()) {
indexProjectedColumns.add(expression);
PColumn col = expression.getColumn();
- KeyValueColumnExpression keyValueColumnExpression = new KeyValueColumnExpression(col, EncodedColumnsUtil.hasEncodedColumnName(col));
+ KeyValueColumnExpression keyValueColumnExpression = new KeyValueColumnExpression(col);
indexKVs.add(keyValueColumnExpression);
copyOfChildren.set(0, keyValueColumnExpression);
Integer count = arrayExpressionCounts.get(expression);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
index 10260cb..8fb435d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
@@ -51,6 +51,7 @@ import org.apache.phoenix.parse.TraceStatement;
import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnImpl;
+import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.RowKeyValueAccessor;
import org.apache.phoenix.schema.SortOrder;
@@ -75,10 +76,11 @@ public class TraceQueryPlan implements QueryPlan {
private static final RowProjector TRACE_PROJECTOR;
static {
List<ExpressionProjector> projectedColumns = new ArrayList<ExpressionProjector>();
+ PName colName = PNameFactory.newName(MetricInfo.TRACE.columnName);
PColumn column =
new PColumnImpl(PNameFactory.newName(MetricInfo.TRACE.columnName), null,
PLong.INSTANCE, null, null, false, 0, SortOrder.getDefault(), 0, null,
- false, null, false, false, null);
+ false, null, false, false, colName.getBytes());
List<PColumn> columns = new ArrayList<PColumn>();
columns.add(column);
Expression expression =
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
index 6663c93..b0e715c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
@@ -123,7 +123,7 @@ public class TupleProjectionCompiler {
PColumn sourceColumn = table.getPKColumns().get(i);
ColumnRef sourceColumnRef = new ColumnRef(tableRef, sourceColumn.getPosition());
PColumn column = new ProjectedColumn(sourceColumn.getName(), sourceColumn.getFamilyName(),
- position++, sourceColumn.isNullable(), sourceColumnRef);
+ position++, sourceColumn.isNullable(), sourceColumnRef, null);
projectedColumns.add(column);
}
for (PColumn sourceColumn : table.getColumns()) {
@@ -135,7 +135,7 @@ public class TupleProjectionCompiler {
&& !families.contains(sourceColumn.getFamilyName().getString()))
continue;
PColumn column = new ProjectedColumn(sourceColumn.getName(), sourceColumn.getFamilyName(),
- position++, sourceColumn.isNullable(), sourceColumnRef);
+ position++, sourceColumn.isNullable(), sourceColumnRef, sourceColumn.getColumnQualifierBytes());
projectedColumns.add(column);
// Wildcard or FamilyWildcard will be handled by ProjectionCompiler.
if (!isWildcard && !families.contains(sourceColumn.getFamilyName())) {
@@ -146,7 +146,7 @@ public class TupleProjectionCompiler {
for (LocalIndexDataColumnRef sourceColumnRef : visitor.localIndexColumnRefSet) {
PColumn column = new ProjectedColumn(sourceColumnRef.getColumn().getName(),
sourceColumnRef.getColumn().getFamilyName(), position++,
- sourceColumnRef.getColumn().isNullable(), sourceColumnRef);
+ sourceColumnRef.getColumn().isNullable(), sourceColumnRef, sourceColumnRef.getColumn().getColumnQualifierBytes());
projectedColumns.add(column);
}
@@ -176,7 +176,7 @@ public class TupleProjectionCompiler {
PColumn column = new ProjectedColumn(PNameFactory.newName(aliasedName),
retainPKColumns && SchemaUtil.isPKColumn(sourceColumn) ?
null : PNameFactory.newName(VALUE_COLUMN_FAMILY),
- position++, sourceColumn.isNullable(), sourceColumnRef);
+ position++, sourceColumn.isNullable(), sourceColumnRef, sourceColumn.getColumnQualifierBytes());
projectedColumns.add(column);
}
EncodedCQCounter cqCounter = EncodedCQCounter.NULL_COUNTER;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
index 013169d..13b58d1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
@@ -86,11 +86,12 @@ public class UnionCompiler {
for (int i = 0; i < plan.getProjector().getColumnCount(); i++) {
ColumnProjector colProj = plan.getProjector().getColumnProjector(i);
String name = selectNodes == null ? colProj.getName() : selectNodes.get(i).getAlias();
+ PName colName = PNameFactory.newName(name);
PColumnImpl projectedColumn = new PColumnImpl(PNameFactory.newName(name),
UNION_FAMILY_NAME, targetTypes.get(i).getType(), targetTypes.get(i).getMaxLength(),
targetTypes.get(i).getScale(), colProj.getExpression().isNullable(), i,
targetTypes.get(i).getSortOrder(), 500, null, false,
- colProj.getExpression().toString(), false, false, null);
+ colProj.getExpression().toString(), false, false, colName.getBytes());
projectedColumns.add(projectedColumn);
}
Long scn = statement.getConnection().getSCN();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 598b433..a6ff1c5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -175,7 +175,7 @@ public class WhereCompiler {
Expression newColumnExpression = ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive());
if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(ref.getColumn())) {
byte[] cq = tableRef.getTable().getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY
- ? QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES : EncodedColumnsUtil.getColumnQualifier(ref.getColumn(), tableRef.getTable());
+ ? QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES : ref.getColumn().getColumnQualifierBytes();
// track the where condition columns. Later we need to ensure the Scan in HRS scans these column CFs
context.addWhereCoditionColumn(ref.getColumn().getFamilyName().getBytes(), cq);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
index 9589c37..a64ed64 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
@@ -107,6 +107,7 @@ abstract public class BaseScannerRegionObserver extends BaseRegionObserver {
public static final String SCAN_STOP_ROW_SUFFIX = "_ScanStopRowSuffix";
public final static String MIN_QUALIFIER = "_MinQualifier";
public final static String MAX_QUALIFIER = "_MaxQualifier";
+ public final static String QUALIFIER_ENCODING_SCHEME = "_QualifierEncodingScheme";
/**
* Attribute name used to pass custom annotations in Scans and Mutations (later). Custom annotations
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
index 793386d..ee79586 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
@@ -24,6 +24,7 @@ import static org.apache.phoenix.query.QueryServices.GROUPBY_ESTIMATED_DISTINCT_
import static org.apache.phoenix.query.QueryServices.GROUPBY_SPILLABLE_ATTRIB;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_GROUPBY_ESTIMATED_DISTINCT_VALUES;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_GROUPBY_SPILLABLE;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodingScheme;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -383,6 +384,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
estDistVals = Math.max(MIN_DISTINCT_VALUES,
(int) (Bytes.toInt(estDistValsBytes) * 1.5f));
}
+
Pair<Integer, Integer> minMaxQualifiers = EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan);
boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan));
final boolean spillableEnabled =
@@ -406,7 +408,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
acquiredLock = true;
synchronized (scanner) {
do {
- List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond()) : new ArrayList<Cell>();
+ List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond(), getEncodingScheme(scan)) : new ArrayList<Cell>();
// Results are potentially returned even when the return
// value of s.next is false
// since this is an indication of whether or not there are
@@ -480,7 +482,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
acquiredLock = true;
synchronized (scanner) {
do {
- List<Cell> kvs = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond()) : new ArrayList<Cell>();
+ List<Cell> kvs = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond(), getEncodingScheme(scan)) : new ArrayList<Cell>();
// Results are potentially returned even when the return
// value of s.next is false
// since this is an indication of whether or not there
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 55ee8f1..b46cb26 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -27,6 +27,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLASS_NAME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_COUNT_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_DEF_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_NAME_INDEX;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER_COUNTER_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_SIZE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DATA_TABLE_NAME_BYTES;
@@ -35,7 +36,6 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DECIMAL_DIGITS_BYT
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAMILY_NAME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_VALUE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL_BYTES;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODING_SCHEME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FAMILY_NAME_INDEX;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IMMUTABLE_ROWS_BYTES;
@@ -78,7 +78,6 @@ import static org.apache.phoenix.query.QueryConstants.DIVERGED_VIEW_BASE_COLUMN_
import static org.apache.phoenix.query.QueryConstants.SEPARATOR_BYTE_ARRAY;
import static org.apache.phoenix.schema.PTableType.INDEX;
import static org.apache.phoenix.util.ByteUtil.EMPTY_BYTE_ARRAY;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import static org.apache.phoenix.util.SchemaUtil.getVarCharLength;
import static org.apache.phoenix.util.SchemaUtil.getVarChars;
@@ -367,7 +366,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private static final KeyValue IS_VIEW_REFERENCED_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, IS_VIEW_REFERENCED_BYTES);
private static final KeyValue COLUMN_DEF_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, COLUMN_DEF_BYTES);
private static final KeyValue IS_ROW_TIMESTAMP_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, IS_ROW_TIMESTAMP_BYTES);
- private static final KeyValue ENCODED_COLUMN_QUALIFIER_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, ENCODED_COLUMN_QUALIFIER_BYTES);
+ private static final KeyValue COLUMN_QUALIFIER_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, COLUMN_QUALIFIER_BYTES);
private static final List<KeyValue> COLUMN_KV_COLUMNS = Arrays.<KeyValue>asList(
DECIMAL_DIGITS_KV,
COLUMN_SIZE_KV,
@@ -381,7 +380,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
IS_VIEW_REFERENCED_KV,
COLUMN_DEF_KV,
IS_ROW_TIMESTAMP_KV,
- ENCODED_COLUMN_QUALIFIER_KV
+ COLUMN_QUALIFIER_KV
);
static {
Collections.sort(COLUMN_KV_COLUMNS, KeyValue.COMPARATOR);
@@ -398,7 +397,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private static final int IS_VIEW_REFERENCED_INDEX = COLUMN_KV_COLUMNS.indexOf(IS_VIEW_REFERENCED_KV);
private static final int COLUMN_DEF_INDEX = COLUMN_KV_COLUMNS.indexOf(COLUMN_DEF_KV);
private static final int IS_ROW_TIMESTAMP_INDEX = COLUMN_KV_COLUMNS.indexOf(IS_ROW_TIMESTAMP_KV);
- private static final int ENCODED_COLUMN_QUALIFIER_INDEX = COLUMN_KV_COLUMNS.indexOf(ENCODED_COLUMN_QUALIFIER_KV);
+ private static final int COLUMN_QUALIFIER_INDEX = COLUMN_KV_COLUMNS.indexOf(COLUMN_QUALIFIER_KV);
private static final int LINK_TYPE_INDEX = 0;
@@ -737,12 +736,17 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
isRowTimestampKV == null ? false : Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(
isRowTimestampKV.getValueArray(), isRowTimestampKV.getValueOffset(),
isRowTimestampKV.getValueLength()));
- Cell columnQualifierKV = colKeyValues[ENCODED_COLUMN_QUALIFIER_INDEX];
- Integer columnQualifier =
- columnQualifierKV == null ? null : getEncodedColumnQualifier(
- columnQualifierKV.getValueArray(), columnQualifierKV.getValueOffset(),
- columnQualifierKV.getValueLength());
- PColumn column = new PColumnImpl(colName, famName, dataType, maxLength, scale, isNullable, position-1, sortOrder, arraySize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, false, columnQualifier);
+
+ //TODO: samarth verify which case is the right one to use.
+ boolean isPkColumn = famName == null || famName.getString() == null;
+ Cell columnQualifierKV = colKeyValues[COLUMN_QUALIFIER_INDEX];
+ // Older tables won't have column qualifier metadata present. To make things simpler, just set the
+ // column qualifier bytes by using the column name.
+ byte[] columnQualifierBytes = columnQualifierKV != null ?
+ Arrays.copyOfRange(columnQualifierKV.getValueArray(),
+ columnQualifierKV.getValueOffset(), columnQualifierKV.getValueOffset()
+ + columnQualifierKV.getValueLength()) : (isPkColumn ? null : colName.getBytes());
+ PColumn column = new PColumnImpl(colName, famName, dataType, maxLength, scale, isNullable, position-1, sortOrder, arraySize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, false, columnQualifierBytes);
columns.add(column);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
index 3a61493..a35d53a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ScanRegionObserver.java
@@ -17,6 +17,9 @@
*/
package org.apache.phoenix.coprocessor;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodingScheme;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getMinMaxQualifiersFromScan;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
@@ -57,6 +60,7 @@ import org.apache.phoenix.memory.MemoryManager.MemoryChunk;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.KeyValueSchema;
import org.apache.phoenix.schema.KeyValueSchema.KeyValueSchemaBuilder;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.ValueBitSet;
import org.apache.phoenix.schema.tuple.ResultTuple;
import org.apache.phoenix.schema.tuple.Tuple;
@@ -126,7 +130,8 @@ public class ScanRegionObserver extends BaseScannerRegionObserver {
orderByExpression.readFields(input);
orderByExpressions.add(orderByExpression);
}
- ResultIterator inner = new RegionScannerResultIterator(s, EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan));
+ QualifierEncodingScheme encodingScheme = getEncodingScheme(scan);
+ ResultIterator inner = new RegionScannerResultIterator(s, EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan), encodingScheme);
return new OrderedResultIterator(inner, orderByExpressions, thresholdBytes, limit >= 0 ? limit : null, null,
estimatedRowSize);
} catch (IOException e) {
@@ -221,7 +226,7 @@ public class ScanRegionObserver extends BaseScannerRegionObserver {
final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan);
//TODO: samarth make this a client side check by looking at order by and group by expressions. Then use that to set min max qualifiers. We can then make useQualifierListAsIndex
// a member variable of BaseScannerRegionObserver.
- boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null;
+ boolean useQualifierAsIndex = EncodedColumnsUtil.useQualifierAsIndex(getMinMaxQualifiersFromScan(scan)) && scan.getAttribute(BaseScannerRegionObserver.TOPN) != null;
innerScanner =
getWrappedScanner(c, innerScanner, arrayKVRefs, arrayFuncRefs, offset, scan,
dataColumns, tupleProjector, dataRegion, indexMaintainer, tx,
@@ -233,7 +238,7 @@ public class ScanRegionObserver extends BaseScannerRegionObserver {
}
if (scanOffset != null) {
innerScanner = getOffsetScanner(c, innerScanner,
- new OffsetResultIterator(new RegionScannerResultIterator(innerScanner, EncodedColumnsUtil.getMinMaxQualifiersFromScan(scan)), scanOffset),
+ new OffsetResultIterator(new RegionScannerResultIterator(innerScanner, getMinMaxQualifiersFromScan(scan), getEncodingScheme(scan)), scanOffset),
scan.getAttribute(QueryConstants.LAST_SCAN) != null);
}
final OrderedResultIterator iterator = deserializeFromScan(scan, innerScanner);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
index 671b5f8..dadfaeb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
@@ -24,6 +24,7 @@ import static org.apache.phoenix.query.QueryConstants.UNGROUPED_AGG_ROW_KEY;
import static org.apache.phoenix.query.QueryServices.MUTATE_BATCH_SIZE_ATTRIB;
import static org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker.COMPACTION_UPDATE_STATS_ROW_COUNT;
import static org.apache.phoenix.schema.stats.StatisticsCollectionRunTracker.CONCURRENT_UPDATE_STATS_ROW_COUNT;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodingScheme;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -400,7 +401,7 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
acquiredLock = true;
synchronized (innerScanner) {
do {
- List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond()) : new ArrayList<Cell>();
+ List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond(), getEncodingScheme(scan)) : new ArrayList<Cell>();
// Results are potentially returned even when the return value of s.next is false
// since this is an indication of whether or not there are more values after the
// ones returned
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
index ead928f..b7ca46f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
@@ -270,15 +270,15 @@ public final class PTableProtos {
*/
boolean getIsDynamic();
- // optional int32 encodedColumnQualifier = 15;
+ // optional bytes columnQualifierBytes = 15;
/**
- * <code>optional int32 encodedColumnQualifier = 15;</code>
+ * <code>optional bytes columnQualifierBytes = 15;</code>
*/
- boolean hasEncodedColumnQualifier();
+ boolean hasColumnQualifierBytes();
/**
- * <code>optional int32 encodedColumnQualifier = 15;</code>
+ * <code>optional bytes columnQualifierBytes = 15;</code>
*/
- int getEncodedColumnQualifier();
+ com.google.protobuf.ByteString getColumnQualifierBytes();
}
/**
* Protobuf type {@code PColumn}
@@ -401,9 +401,9 @@ public final class PTableProtos {
isDynamic_ = input.readBool();
break;
}
- case 120: {
+ case 122: {
bitField0_ |= 0x00004000;
- encodedColumnQualifier_ = input.readInt32();
+ columnQualifierBytes_ = input.readBytes();
break;
}
}
@@ -724,20 +724,20 @@ public final class PTableProtos {
return isDynamic_;
}
- // optional int32 encodedColumnQualifier = 15;
- public static final int ENCODEDCOLUMNQUALIFIER_FIELD_NUMBER = 15;
- private int encodedColumnQualifier_;
+ // optional bytes columnQualifierBytes = 15;
+ public static final int COLUMNQUALIFIERBYTES_FIELD_NUMBER = 15;
+ private com.google.protobuf.ByteString columnQualifierBytes_;
/**
- * <code>optional int32 encodedColumnQualifier = 15;</code>
+ * <code>optional bytes columnQualifierBytes = 15;</code>
*/
- public boolean hasEncodedColumnQualifier() {
+ public boolean hasColumnQualifierBytes() {
return ((bitField0_ & 0x00004000) == 0x00004000);
}
/**
- * <code>optional int32 encodedColumnQualifier = 15;</code>
+ * <code>optional bytes columnQualifierBytes = 15;</code>
*/
- public int getEncodedColumnQualifier() {
- return encodedColumnQualifier_;
+ public com.google.protobuf.ByteString getColumnQualifierBytes() {
+ return columnQualifierBytes_;
}
private void initFields() {
@@ -755,7 +755,7 @@ public final class PTableProtos {
expression_ = "";
isRowTimestamp_ = false;
isDynamic_ = false;
- encodedColumnQualifier_ = 0;
+ columnQualifierBytes_ = com.google.protobuf.ByteString.EMPTY;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -832,7 +832,7 @@ public final class PTableProtos {
output.writeBool(14, isDynamic_);
}
if (((bitField0_ & 0x00004000) == 0x00004000)) {
- output.writeInt32(15, encodedColumnQualifier_);
+ output.writeBytes(15, columnQualifierBytes_);
}
getUnknownFields().writeTo(output);
}
@@ -901,7 +901,7 @@ public final class PTableProtos {
}
if (((bitField0_ & 0x00004000) == 0x00004000)) {
size += com.google.protobuf.CodedOutputStream
- .computeInt32Size(15, encodedColumnQualifier_);
+ .computeBytesSize(15, columnQualifierBytes_);
}
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
@@ -996,10 +996,10 @@ public final class PTableProtos {
result = result && (getIsDynamic()
== other.getIsDynamic());
}
- result = result && (hasEncodedColumnQualifier() == other.hasEncodedColumnQualifier());
- if (hasEncodedColumnQualifier()) {
- result = result && (getEncodedColumnQualifier()
- == other.getEncodedColumnQualifier());
+ result = result && (hasColumnQualifierBytes() == other.hasColumnQualifierBytes());
+ if (hasColumnQualifierBytes()) {
+ result = result && getColumnQualifierBytes()
+ .equals(other.getColumnQualifierBytes());
}
result = result &&
getUnknownFields().equals(other.getUnknownFields());
@@ -1070,9 +1070,9 @@ public final class PTableProtos {
hash = (37 * hash) + ISDYNAMIC_FIELD_NUMBER;
hash = (53 * hash) + hashBoolean(getIsDynamic());
}
- if (hasEncodedColumnQualifier()) {
- hash = (37 * hash) + ENCODEDCOLUMNQUALIFIER_FIELD_NUMBER;
- hash = (53 * hash) + getEncodedColumnQualifier();
+ if (hasColumnQualifierBytes()) {
+ hash = (37 * hash) + COLUMNQUALIFIERBYTES_FIELD_NUMBER;
+ hash = (53 * hash) + getColumnQualifierBytes().hashCode();
}
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
@@ -1211,7 +1211,7 @@ public final class PTableProtos {
bitField0_ = (bitField0_ & ~0x00001000);
isDynamic_ = false;
bitField0_ = (bitField0_ & ~0x00002000);
- encodedColumnQualifier_ = 0;
+ columnQualifierBytes_ = com.google.protobuf.ByteString.EMPTY;
bitField0_ = (bitField0_ & ~0x00004000);
return this;
}
@@ -1300,7 +1300,7 @@ public final class PTableProtos {
if (((from_bitField0_ & 0x00004000) == 0x00004000)) {
to_bitField0_ |= 0x00004000;
}
- result.encodedColumnQualifier_ = encodedColumnQualifier_;
+ result.columnQualifierBytes_ = columnQualifierBytes_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -1363,8 +1363,8 @@ public final class PTableProtos {
if (other.hasIsDynamic()) {
setIsDynamic(other.getIsDynamic());
}
- if (other.hasEncodedColumnQualifier()) {
- setEncodedColumnQualifier(other.getEncodedColumnQualifier());
+ if (other.hasColumnQualifierBytes()) {
+ setColumnQualifierBytes(other.getColumnQualifierBytes());
}
this.mergeUnknownFields(other.getUnknownFields());
return this;
@@ -1966,35 +1966,38 @@ public final class PTableProtos {
return this;
}
- // optional int32 encodedColumnQualifier = 15;
- private int encodedColumnQualifier_ ;
+ // optional bytes columnQualifierBytes = 15;
+ private com.google.protobuf.ByteString columnQualifierBytes_ = com.google.protobuf.ByteString.EMPTY;
/**
- * <code>optional int32 encodedColumnQualifier = 15;</code>
+ * <code>optional bytes columnQualifierBytes = 15;</code>
*/
- public boolean hasEncodedColumnQualifier() {
+ public boolean hasColumnQualifierBytes() {
return ((bitField0_ & 0x00004000) == 0x00004000);
}
/**
- * <code>optional int32 encodedColumnQualifier = 15;</code>
+ * <code>optional bytes columnQualifierBytes = 15;</code>
*/
- public int getEncodedColumnQualifier() {
- return encodedColumnQualifier_;
+ public com.google.protobuf.ByteString getColumnQualifierBytes() {
+ return columnQualifierBytes_;
}
/**
- * <code>optional int32 encodedColumnQualifier = 15;</code>
+ * <code>optional bytes columnQualifierBytes = 15;</code>
*/
- public Builder setEncodedColumnQualifier(int value) {
- bitField0_ |= 0x00004000;
- encodedColumnQualifier_ = value;
+ public Builder setColumnQualifierBytes(com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00004000;
+ columnQualifierBytes_ = value;
onChanged();
return this;
}
/**
- * <code>optional int32 encodedColumnQualifier = 15;</code>
+ * <code>optional bytes columnQualifierBytes = 15;</code>
*/
- public Builder clearEncodedColumnQualifier() {
+ public Builder clearColumnQualifierBytes() {
bitField0_ = (bitField0_ & ~0x00004000);
- encodedColumnQualifier_ = 0;
+ columnQualifierBytes_ = getDefaultInstance().getColumnQualifierBytes();
onChanged();
return this;
}
@@ -8482,7 +8485,7 @@ public final class PTableProtos {
descriptor;
static {
java.lang.String[] descriptorData = {
- "\n\014PTable.proto\032\021PGuidePosts.proto\"\306\002\n\007PC" +
+ "\n\014PTable.proto\032\021PGuidePosts.proto\"\304\002\n\007PC" +
"olumn\022\027\n\017columnNameBytes\030\001 \002(\014\022\027\n\017family" +
"NameBytes\030\002 \001(\014\022\020\n\010dataType\030\003 \002(\t\022\021\n\tmax" +
"Length\030\004 \001(\005\022\r\n\005scale\030\005 \001(\005\022\020\n\010nullable\030" +
@@ -8490,38 +8493,38 @@ public final class PTableProtos {
"(\005\022\021\n\tarraySize\030\t \001(\005\022\024\n\014viewConstant\030\n " +
"\001(\014\022\026\n\016viewReferenced\030\013 \001(\010\022\022\n\nexpressio" +
"n\030\014 \001(\t\022\026\n\016isRowTimestamp\030\r \001(\010\022\021\n\tisDyn" +
- "amic\030\016 \001(\010\022\036\n\026encodedColumnQualifier\030\017 \001" +
- "(\005\"\232\001\n\013PTableStats\022\013\n\003key\030\001 \002(\014\022\016\n\006value",
- "s\030\002 \003(\014\022\033\n\023guidePostsByteCount\030\003 \001(\003\022\025\n\r" +
- "keyBytesCount\030\004 \001(\003\022\027\n\017guidePostsCount\030\005" +
- " \001(\005\022!\n\013pGuidePosts\030\006 \001(\0132\014.PGuidePosts\"" +
- "\354\006\n\006PTable\022\027\n\017schemaNameBytes\030\001 \002(\014\022\026\n\016t" +
- "ableNameBytes\030\002 \002(\014\022\036\n\ttableType\030\003 \002(\0162\013" +
- ".PTableType\022\022\n\nindexState\030\004 \001(\t\022\026\n\016seque" +
- "nceNumber\030\005 \002(\003\022\021\n\ttimeStamp\030\006 \002(\003\022\023\n\013pk" +
- "NameBytes\030\007 \001(\014\022\021\n\tbucketNum\030\010 \002(\005\022\031\n\007co" +
- "lumns\030\t \003(\0132\010.PColumn\022\030\n\007indexes\030\n \003(\0132\007" +
- ".PTable\022\027\n\017isImmutableRows\030\013 \002(\010\022\032\n\022data",
- "TableNameBytes\030\r \001(\014\022\031\n\021defaultFamilyNam" +
- "e\030\016 \001(\014\022\022\n\ndisableWAL\030\017 \002(\010\022\023\n\013multiTena" +
- "nt\030\020 \002(\010\022\020\n\010viewType\030\021 \001(\014\022\025\n\rviewStatem" +
- "ent\030\022 \001(\014\022\025\n\rphysicalNames\030\023 \003(\014\022\020\n\010tena" +
- "ntId\030\024 \001(\014\022\023\n\013viewIndexId\030\025 \001(\005\022\021\n\tindex" +
- "Type\030\026 \001(\014\022\026\n\016statsTimeStamp\030\027 \001(\003\022\022\n\nst" +
- "oreNulls\030\030 \001(\010\022\027\n\017baseColumnCount\030\031 \001(\005\022" +
- "\036\n\026rowKeyOrderOptimizable\030\032 \001(\010\022\025\n\rtrans" +
- "actional\030\033 \001(\010\022\034\n\024updateCacheFrequency\030\034" +
- " \001(\003\022\035\n\025indexDisableTimestamp\030\035 \001(\003\022\031\n\021i",
- "sNamespaceMapped\030\036 \001(\010\022\034\n\024autoParititonS" +
- "eqName\030\037 \001(\t\022\032\n\022isAppendOnlySchema\030 \001(\010" +
- "\022\027\n\017parentNameBytes\030! \001(\014\022\025\n\rstorageSche" +
- "me\030\" \001(\014\022\026\n\016encodingScheme\030# \001(\014\022,\n\021enco" +
- "dedCQCounters\030$ \003(\0132\021.EncodedCQCounter\"6" +
- "\n\020EncodedCQCounter\022\021\n\tcolFamily\030\001 \002(\t\022\017\n" +
- "\007counter\030\002 \002(\005*A\n\nPTableType\022\n\n\006SYSTEM\020\000" +
- "\022\010\n\004USER\020\001\022\010\n\004VIEW\020\002\022\t\n\005INDEX\020\003\022\010\n\004JOIN\020" +
- "\004B@\n(org.apache.phoenix.coprocessor.gene" +
- "ratedB\014PTableProtosH\001\210\001\001\240\001\001"
+ "amic\030\016 \001(\010\022\034\n\024columnQualifierBytes\030\017 \001(\014" +
+ "\"\232\001\n\013PTableStats\022\013\n\003key\030\001 \002(\014\022\016\n\006values\030",
+ "\002 \003(\014\022\033\n\023guidePostsByteCount\030\003 \001(\003\022\025\n\rke" +
+ "yBytesCount\030\004 \001(\003\022\027\n\017guidePostsCount\030\005 \001" +
+ "(\005\022!\n\013pGuidePosts\030\006 \001(\0132\014.PGuidePosts\"\354\006" +
+ "\n\006PTable\022\027\n\017schemaNameBytes\030\001 \002(\014\022\026\n\016tab" +
+ "leNameBytes\030\002 \002(\014\022\036\n\ttableType\030\003 \002(\0162\013.P" +
+ "TableType\022\022\n\nindexState\030\004 \001(\t\022\026\n\016sequenc" +
+ "eNumber\030\005 \002(\003\022\021\n\ttimeStamp\030\006 \002(\003\022\023\n\013pkNa" +
+ "meBytes\030\007 \001(\014\022\021\n\tbucketNum\030\010 \002(\005\022\031\n\007colu" +
+ "mns\030\t \003(\0132\010.PColumn\022\030\n\007indexes\030\n \003(\0132\007.P" +
+ "Table\022\027\n\017isImmutableRows\030\013 \002(\010\022\032\n\022dataTa",
+ "bleNameBytes\030\r \001(\014\022\031\n\021defaultFamilyName\030" +
+ "\016 \001(\014\022\022\n\ndisableWAL\030\017 \002(\010\022\023\n\013multiTenant" +
+ "\030\020 \002(\010\022\020\n\010viewType\030\021 \001(\014\022\025\n\rviewStatemen" +
+ "t\030\022 \001(\014\022\025\n\rphysicalNames\030\023 \003(\014\022\020\n\010tenant" +
+ "Id\030\024 \001(\014\022\023\n\013viewIndexId\030\025 \001(\005\022\021\n\tindexTy" +
+ "pe\030\026 \001(\014\022\026\n\016statsTimeStamp\030\027 \001(\003\022\022\n\nstor" +
+ "eNulls\030\030 \001(\010\022\027\n\017baseColumnCount\030\031 \001(\005\022\036\n" +
+ "\026rowKeyOrderOptimizable\030\032 \001(\010\022\025\n\rtransac" +
+ "tional\030\033 \001(\010\022\034\n\024updateCacheFrequency\030\034 \001" +
+ "(\003\022\035\n\025indexDisableTimestamp\030\035 \001(\003\022\031\n\021isN",
+ "amespaceMapped\030\036 \001(\010\022\034\n\024autoParititonSeq" +
+ "Name\030\037 \001(\t\022\032\n\022isAppendOnlySchema\030 \001(\010\022\027" +
+ "\n\017parentNameBytes\030! \001(\014\022\025\n\rstorageScheme" +
+ "\030\" \001(\014\022\026\n\016encodingScheme\030# \001(\014\022,\n\021encode" +
+ "dCQCounters\030$ \003(\0132\021.EncodedCQCounter\"6\n\020" +
+ "EncodedCQCounter\022\021\n\tcolFamily\030\001 \002(\t\022\017\n\007c" +
+ "ounter\030\002 \002(\005*A\n\nPTableType\022\n\n\006SYSTEM\020\000\022\010" +
+ "\n\004USER\020\001\022\010\n\004VIEW\020\002\022\t\n\005INDEX\020\003\022\010\n\004JOIN\020\004B" +
+ "@\n(org.apache.phoenix.coprocessor.genera" +
+ "tedB\014PTableProtosH\001\210\001\001\240\001\001"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -8533,7 +8536,7 @@ public final class PTableProtos {
internal_static_PColumn_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_PColumn_descriptor,
- new java.lang.String[] { "ColumnNameBytes", "FamilyNameBytes", "DataType", "MaxLength", "Scale", "Nullable", "Position", "SortOrder", "ArraySize", "ViewConstant", "ViewReferenced", "Expression", "IsRowTimestamp", "IsDynamic", "EncodedColumnQualifier", });
+ new java.lang.String[] { "ColumnNameBytes", "FamilyNameBytes", "DataType", "MaxLength", "Scale", "Nullable", "Position", "SortOrder", "ArraySize", "ViewConstant", "ViewReferenced", "Expression", "IsRowTimestamp", "IsDynamic", "ColumnQualifierBytes", });
internal_static_PTableStats_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_PTableStats_fieldAccessorTable = new
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index cbd9bd3..6c7d05b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -439,7 +439,7 @@ public abstract class BaseQueryPlan implements QueryPlan {
WritableUtils.writeVInt(output, dataColumns.size());
for (PColumn column : dataColumns) {
byte[] cf = column.getFamilyName().getBytes();
- byte[] cq = EncodedColumnsUtil.getColumnQualifier(column, dataTable);
+ byte[] cq = column.getColumnQualifierBytes();
Bytes.writeByteArray(output, cf);
Bytes.writeByteArray(output, cq);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
index 747d7e6..b693ded 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
@@ -17,6 +17,9 @@
*/
package org.apache.phoenix.expression;
+import static org.apache.phoenix.query.QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES;
+import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
+
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@@ -25,9 +28,9 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.WritableUtils;
import org.apache.phoenix.compile.CreateTableCompiler.ViewWhereExpressionVisitor;
import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PArrayDataType;
@@ -36,6 +39,8 @@ import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.SchemaUtil;
+import com.google.common.base.Preconditions;
+
/**
*
* Class to access a column that is stored in a KeyValue that contains all
@@ -47,20 +52,27 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
private int positionInArray;
private String arrayColDisplayName;
private KeyValueColumnExpression keyValueColumnExpression;
+ private QualifierEncodingScheme encodingScheme;
public ArrayColumnExpression() {
}
- public ArrayColumnExpression(PDatum column, byte[] cf, int encodedCQ) {
- super(column, cf, QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES);
- this.positionInArray = encodedCQ;
+ public ArrayColumnExpression(PDatum column, byte[] cf, byte[] cq, QualifierEncodingScheme encodingScheme) {
+ super(column, cf, SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES);
+ Preconditions.checkNotNull(encodingScheme);
+ Preconditions.checkArgument(encodingScheme != NON_ENCODED_QUALIFIERS);
+ this.positionInArray = encodingScheme.getDecodedValue(cq);
+ this.encodingScheme = encodingScheme;
setKeyValueExpression();
}
- public ArrayColumnExpression(PColumn column, String displayName, boolean encodedColumnName) {
- super(column, column.getFamilyName().getBytes(), QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES);
+ public ArrayColumnExpression(PColumn column, String displayName, QualifierEncodingScheme encodingScheme) {
+ super(column, column.getFamilyName().getBytes(), SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES);
+ Preconditions.checkNotNull(encodingScheme);
+ Preconditions.checkArgument(encodingScheme != NON_ENCODED_QUALIFIERS);
this.arrayColDisplayName = displayName;
- this.positionInArray = column.getEncodedColumnQualifier();
+ this.positionInArray = encodingScheme.getDecodedValue(column.getColumnQualifierBytes());
+ this.encodingScheme = encodingScheme;
setKeyValueExpression();
}
@@ -81,6 +93,7 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
public void readFields(DataInput input) throws IOException {
super.readFields(input);
this.positionInArray = WritableUtils.readVInt(input);
+ this.encodingScheme = WritableUtils.readEnum(input, QualifierEncodingScheme.class);
setKeyValueExpression();
}
@@ -88,6 +101,7 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
public void write(DataOutput output) throws IOException {
super.write(output);
WritableUtils.writeVInt(output, positionInArray);
+ WritableUtils.writeEnum(output, encodingScheme);
}
public KeyValueColumnExpression getKeyValueExpression() {
@@ -137,7 +151,7 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
}
public byte[] getPositionInArray() {
- return EncodedColumnsUtil.getEncodedColumnQualifier(positionInArray);
+ return encodingScheme.getEncodedBytes(positionInArray);
}
@Override
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
index 5cd7433..5c0be57 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
@@ -28,7 +28,6 @@ import org.apache.phoenix.expression.visitor.ExpressionVisitor;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PDatum;
import org.apache.phoenix.schema.tuple.Tuple;
-import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -46,9 +45,21 @@ public class KeyValueColumnExpression extends ColumnExpression {
public KeyValueColumnExpression() {
}
-
- public KeyValueColumnExpression(PColumn column, boolean encodedColumnName) {
- this(column, null, encodedColumnName);
+
+ public KeyValueColumnExpression(PColumn column) {
+ super(column);
+ this.cf = column.getFamilyName().getBytes();
+ // for backward compatibility since older tables won't have columnQualifierBytes in their metadata
+ this.cq = column.getColumnQualifierBytes() != null ? column.getColumnQualifierBytes() : column.getName().getBytes();
+ this.displayName = column.getName().getString();
+ }
+
+ public KeyValueColumnExpression(PColumn column, String displayName) {
+ super(column);
+ this.cf = column.getFamilyName().getBytes();
+ // for backward compatibility since older tables won't have columnQualifierBytes in their metadata
+ this.cq = column.getColumnQualifierBytes() != null ? column.getColumnQualifierBytes() : column.getName().getBytes();
+ this.displayName = displayName;
}
public KeyValueColumnExpression(PDatum column, byte[] cf, byte[] cq) {
@@ -57,13 +68,6 @@ public class KeyValueColumnExpression extends ColumnExpression {
this.cq = cq;
}
- public KeyValueColumnExpression(PColumn column, String displayName, boolean encodedColumnName) {
- super(column);
- this.cf = column.getFamilyName().getBytes();
- this.cq = EncodedColumnsUtil.getColumnQualifier(column, encodedColumnName);
- this.displayName = displayName;
- }
-
public byte[] getColumnFamily() {
return cf;
}
@@ -124,4 +128,8 @@ public class KeyValueColumnExpression extends ColumnExpression {
public <T> T accept(ExpressionVisitor<T> visitor) {
return visitor.visit(this);
}
+
+// public void setDisplayName(String displayName) {
+// this.displayName = displayName;
+// }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/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 2ab3730..f19af6c 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
@@ -17,8 +17,6 @@
*/
package org.apache.phoenix.index;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
-
import java.io.ByteArrayInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
@@ -83,6 +81,7 @@ import org.apache.phoenix.schema.PDatum;
import org.apache.phoenix.schema.PIndexState;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.RowKeySchema;
@@ -322,8 +321,8 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
private int maxTrailingNulls;
private ColumnReference dataEmptyKeyValueRef;
private boolean rowKeyOrderOptimizable;
- private boolean usesEncodedColumnNames;
private ImmutableBytesPtr emptyKeyValueQualifierPtr;
+ private QualifierEncodingScheme encodingScheme;
private IndexMaintainer(RowKeySchema dataRowKeySchema, boolean isDataTableSalted) {
this.dataRowKeySchema = dataRowKeySchema;
@@ -337,7 +336,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
this.isMultiTenant = dataTable.isMultiTenant();
this.viewIndexId = index.getViewIndexId() == null ? null : MetaDataUtil.getViewIndexIdDataType().toBytes(index.getViewIndexId());
this.isLocalIndex = index.getIndexType() == IndexType.LOCAL;
- this.usesEncodedColumnNames = EncodedColumnsUtil.usesEncodedColumnNames(index);
+ this.encodingScheme = index.getEncodingScheme();
byte[] indexTableName = index.getPhysicalName().getBytes();
// Use this for the nDataSaltBuckets as we need this for local indexes
// TODO: persist nDataSaltBuckets separately, but maintain b/w compat.
@@ -508,8 +507,8 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
PColumnFamily family = index.getColumnFamilies().get(i);
for (PColumn indexColumn : family.getColumns()) {
PColumn dataColumn = IndexUtil.getDataColumn(dataTable, indexColumn.getName().getString());
- byte[] dataColumnCq = EncodedColumnsUtil.getColumnQualifier(dataColumn, dataTable);
- byte[] indexColumnCq = EncodedColumnsUtil.getColumnQualifier(indexColumn, index);
+ byte[] dataColumnCq = dataColumn.getColumnQualifierBytes();
+ byte[] indexColumnCq = indexColumn.getColumnQualifierBytes();
this.coveredColumns.add(new ColumnReference(dataColumn.getFamilyName().getBytes(), dataColumnCq));
this.coveredColumnsMap.put(new ColumnReference(dataColumn.getFamilyName().getBytes(), dataColumnCq),
new ColumnReference(indexColumn.getFamilyName().getBytes(), indexColumnCq));
@@ -953,7 +952,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
int maxIndex = Integer.MIN_VALUE;
// find the max col qualifier
for (Pair<ColumnReference, ColumnReference> colRefPair : colRefPairs) {
- int qualifier = getEncodedColumnQualifier(colRefPair.getFirst().getQualifier());
+ int qualifier = encodingScheme.getDecodedValue(colRefPair.getFirst().getQualifier());
maxIndex = Math.max(maxIndex, qualifier);
}
byte[][] colValues = new byte[maxIndex+1][];
@@ -961,7 +960,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
for (Pair<ColumnReference, ColumnReference> colRefPair : colRefPairs) {
ColumnReference indexColRef = colRefPair.getFirst();
ColumnReference dataColRef = colRefPair.getSecond();
- int dataArrayPos = getEncodedColumnQualifier(dataColRef.getQualifier());
Expression expression = new ArrayColumnExpression(new PDatum() {
@Override
public boolean isNullable() {
@@ -987,12 +985,12 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
public PDataType getDataType() {
return null;
}
- }, dataColRef.getFamily(), dataArrayPos);
+ }, dataColRef.getFamily(), dataColRef.getQualifier(), encodingScheme);
ImmutableBytesPtr ptr = new ImmutableBytesPtr();
expression.evaluate(new ValueGetterTuple(valueGetter), ptr);
byte[] value = ptr.copyBytesIfNecessary();
if (value != null) {
- int indexArrayPos = getEncodedColumnQualifier(indexColRef.getQualifier());
+ int indexArrayPos = encodingScheme.getDecodedValue(indexColRef.getQualifier());
colValues[indexArrayPos] = value;
}
}
@@ -1241,8 +1239,6 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
if (isNewClient) {
int numIndexedExpressions = WritableUtils.readVInt(input);
- usesEncodedColumnNames = numIndexedExpressions > 0;
- numIndexedExpressions = Math.abs(numIndexedExpressions) - 1;
indexedExpressions = Lists.newArrayListWithExpectedSize(numIndexedExpressions);
for (int i = 0; i < numIndexedExpressions; i++) {
Expression expression = ExpressionType.values()[WritableUtils.readVInt(input)].newInstance();
@@ -1311,6 +1307,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
byte[] dataTableCq = Bytes.readByteArray(input);
coveredColumnsInfo.add(new Pair<>(Bytes.toString(dataTableCf), Bytes.toString(dataTableCq)));
}
+ encodingScheme = WritableUtils.readEnum(input, QualifierEncodingScheme.class);
storeColsInSingleCell = WritableUtils.readVInt(input) > 0;
initCachedState();
}
@@ -1351,10 +1348,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
// when indexedColumnTypes is removed, remove this
WritableUtils.writeVInt(output,-emptyKeyValueCFPtr.getLength());
output.write(emptyKeyValueCFPtr.get(),emptyKeyValueCFPtr.getOffset(), emptyKeyValueCFPtr.getLength());
-
- // Hack to encode usesEncodedColumnNames in indexedExpressions size.
- int indexedExpressionsSize = (indexedExpressions.size() + 1) * (usesEncodedColumnNames ? 1 : -1);
- WritableUtils.writeVInt(output, indexedExpressionsSize);
+ WritableUtils.writeVInt(output, indexedExpressions.size());
for (Expression expression : indexedExpressions) {
WritableUtils.writeVInt(output, ExpressionType.valueOf(expression).ordinal());
expression.write(output);
@@ -1375,6 +1369,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
Bytes.writeByteArray(output, colInfo.getFirst() == null ? null : colInfo.getFirst().getBytes());
Bytes.writeByteArray(output, colInfo.getSecond().getBytes());
}
+ WritableUtils.writeEnum(output, encodingScheme);
WritableUtils.writeVInt(output, storeColsInSingleCell ? 1 : -1);
}
@@ -1422,7 +1417,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
* Init calculated state reading/creating
*/
private void initCachedState() {
- byte[] emptyKvQualifier = EncodedColumnsUtil.getEmptyKeyValueInfo(usesEncodedColumnNames).getFirst();
+ byte[] emptyKvQualifier = EncodedColumnsUtil.getEmptyKeyValueInfo(encodingScheme).getFirst();
dataEmptyKeyValueRef = new ColumnReference(emptyKeyValueCFPtr.copyBytesIfNecessary(), emptyKvQualifier);
emptyKeyValueQualifierPtr = new ImmutableBytesPtr(emptyKvQualifier);
this.allColumns = Sets.newLinkedHashSetWithExpectedSize(indexedExpressions.size() + coveredColumns.size());
[12/42] phoenix git commit: PHOENIX-3535 Fix race condition in
ConnectionQueryServicesImpl#acquireUpgradeMutex
Posted by td...@apache.org.
PHOENIX-3535 Fix race condition in ConnectionQueryServicesImpl#acquireUpgradeMutex
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/18cb85e6
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/18cb85e6
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/18cb85e6
Branch: refs/heads/encodecolumns2
Commit: 18cb85e69580ede3bdb391c2134c6f12effefabe
Parents: 0ea97ce
Author: Samarth <sa...@salesforce.com>
Authored: Wed Dec 21 15:10:09 2016 -0800
Committer: Samarth <sa...@salesforce.com>
Committed: Wed Dec 21 15:10:09 2016 -0800
----------------------------------------------------------------------
.../org/apache/phoenix/end2end/UpgradeIT.java | 43 ++++++++----------
.../query/ConnectionQueryServicesImpl.java | 46 +++++++++++---------
2 files changed, 44 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/18cb85e6/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
index 733dab0..49fdba6 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
@@ -19,6 +19,9 @@ package org.apache.phoenix.end2end;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.phoenix.query.ConnectionQueryServicesImpl.UPGRADE_MUTEX;
+import static org.apache.phoenix.query.ConnectionQueryServicesImpl.UPGRADE_MUTEX_LOCKED;
+import static org.apache.phoenix.query.ConnectionQueryServicesImpl.UPGRADE_MUTEX_UNLOCKED;
import static org.apache.phoenix.query.QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT;
import static org.apache.phoenix.query.QueryConstants.DIVERGED_VIEW_BASE_COLUMN_COUNT;
import static org.apache.phoenix.util.UpgradeUtil.SELECT_BASE_COLUMN_COUNT_FROM_HEADER_ROW;
@@ -694,17 +697,30 @@ public class UpgradeIT extends ParallelStatsDisabledIT {
}
}
+ private void putUnlockKVInSysMutex(byte[] row) throws Exception {
+ try (Connection conn = getConnection(false, null)) {
+ ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
+ try (HTableInterface sysMutexTable = services.getTable(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES)) {
+ byte[] family = PhoenixDatabaseMetaData.SYSTEM_MUTEX_FAMILY_NAME_BYTES;
+ byte[] qualifier = UPGRADE_MUTEX;
+ Put put = new Put(row);
+ put.add(family, qualifier, UPGRADE_MUTEX_UNLOCKED);
+ sysMutexTable.put(put);
+ sysMutexTable.flushCommits();
+ }
+ }
+ }
+
@Test
public void testAcquiringAndReleasingUpgradeMutex() throws Exception {
ConnectionQueryServices services = null;
byte[] mutexRowKey = SchemaUtil.getTableKey(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA,
generateUniqueName());
- boolean dropSysMutexTable = false;
try (Connection conn = getConnection(false, null)) {
services = conn.unwrap(PhoenixConnection.class).getQueryServices();
+ putUnlockKVInSysMutex(mutexRowKey);
assertTrue(((ConnectionQueryServicesImpl)services)
.acquireUpgradeMutex(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0, mutexRowKey));
- dropSysMutexTable = true;
try {
((ConnectionQueryServicesImpl)services)
.acquireUpgradeMutex(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_7_0, mutexRowKey);
@@ -714,16 +730,6 @@ public class UpgradeIT extends ParallelStatsDisabledIT {
}
assertTrue(((ConnectionQueryServicesImpl)services).releaseUpgradeMutex(mutexRowKey));
assertFalse(((ConnectionQueryServicesImpl)services).releaseUpgradeMutex(mutexRowKey));
- } finally {
- // We need to drop the SYSTEM.MUTEX table else other tests calling acquireUpgradeMutex will unexpectedly fail because they
- // won't see the UNLOCKED cell present for their key. This cell is inserted into the table the first time we create the
- // SYSTEM.MUTEX table.
- if (services != null && dropSysMutexTable) {
- try (HBaseAdmin admin = services.getAdmin()) {
- admin.disableTable(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES);
- admin.deleteTable(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES);
- }
- }
}
}
@@ -735,9 +741,9 @@ public class UpgradeIT extends ParallelStatsDisabledIT {
final AtomicInteger numExceptions = new AtomicInteger(0);
ConnectionQueryServices services = null;
final byte[] mutexKey = Bytes.toBytes(generateUniqueName());
- boolean dropSysMutexTable = false;
try (Connection conn = getConnection(false, null)) {
services = conn.unwrap(PhoenixConnection.class).getQueryServices();
+ putUnlockKVInSysMutex(mutexKey);
FutureTask<Void> task1 = new FutureTask<>(new AcquireMutexRunnable(mutexStatus1, services, latch, numExceptions, mutexKey));
FutureTask<Void> task2 = new FutureTask<>(new AcquireMutexRunnable(mutexStatus2, services, latch, numExceptions, mutexKey));
Thread t1 = new Thread(task1);
@@ -751,20 +757,9 @@ public class UpgradeIT extends ParallelStatsDisabledIT {
task1.get();
task2.get();
assertTrue("One of the threads should have acquired the mutex", mutexStatus1.get() || mutexStatus2.get());
- dropSysMutexTable = true;
assertNotEquals("One and only one thread should have acquired the mutex ", mutexStatus1.get(),
mutexStatus2.get());
assertEquals("One and only one thread should have caught UpgradeRequiredException ", 1, numExceptions.get());
- } finally {
- // We need to drop the SYSTEM.MUTEX table else other tests calling acquireUpgradeMutex will unexpectedly fail because they
- // won't see the UNLOCKED cell present for their key. This cell is inserted into the table the first time we create the
- // SYSTEM.MUTEX table.
- if (services != null && dropSysMutexTable) {
- try (HBaseAdmin admin = services.getAdmin()) {
- admin.disableTable(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES);
- admin.deleteTable(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES);
- }
- }
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/18cb85e6/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 da43af7..9d7a3d2 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
@@ -276,9 +276,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
private final boolean renewLeaseEnabled;
private final boolean isAutoUpgradeEnabled;
private final AtomicBoolean upgradeRequired = new AtomicBoolean(false);
- private static final byte[] UPGRADE_MUTEX = "UPGRADE_MUTEX".getBytes();
- private static final byte[] UPGRADE_MUTEX_LOCKED = "UPGRADE_MUTEX_LOCKED".getBytes();
- private static final byte[] UPGRADE_MUTEX_UNLOCKED = "UPGRADE_MUTEX_UNLOCKED".getBytes();
+ public static final byte[] UPGRADE_MUTEX = "UPGRADE_MUTEX".getBytes();
+ public static final byte[] UPGRADE_MUTEX_LOCKED = "UPGRADE_MUTEX_LOCKED".getBytes();
+ public static final byte[] UPGRADE_MUTEX_UNLOCKED = "UPGRADE_MUTEX_UNLOCKED".getBytes();
private static interface FeatureSupported {
boolean isSupported(ConnectionQueryServices services);
@@ -2352,6 +2352,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
hConnectionEstablished = true;
boolean isDoNotUpgradePropSet = UpgradeUtil.isNoUpgradeSet(props);
try (HBaseAdmin admin = getAdmin()) {
+ createSysMutexTable(admin);
boolean mappedSystemCatalogExists = admin
.tableExists(SchemaUtil.getPhysicalTableName(SYSTEM_CATALOG_NAME_BYTES, true));
if (SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM,
@@ -2438,6 +2439,27 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
}
+ private void createSysMutexTable(HBaseAdmin admin) throws IOException, SQLException {
+ try {
+ HTableDescriptor tableDesc = new HTableDescriptor(
+ TableName.valueOf(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES));
+ HColumnDescriptor columnDesc = new HColumnDescriptor(
+ PhoenixDatabaseMetaData.SYSTEM_MUTEX_FAMILY_NAME_BYTES);
+ columnDesc.setTimeToLive(TTL_FOR_MUTEX); // Let mutex expire after some time
+ tableDesc.addFamily(columnDesc);
+ admin.createTable(tableDesc);
+ try (HTableInterface sysMutexTable = getTable(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES)) {
+ byte[] mutexRowKey = SchemaUtil.getTableKey(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA,
+ PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE);
+ Put put = new Put(mutexRowKey);
+ put.add(PhoenixDatabaseMetaData.SYSTEM_MUTEX_FAMILY_NAME_BYTES, UPGRADE_MUTEX, UPGRADE_MUTEX_UNLOCKED);
+ sysMutexTable.put(put);
+ }
+ } catch (TableExistsException e) {
+ // Ignore
+ }
+ }
+
private void createOtherSystemTables(PhoenixConnection metaConnection) throws SQLException {
try {
metaConnection.createStatement().execute(QueryConstants.CREATE_SEQUENCE_METADATA);
@@ -2953,24 +2975,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
public boolean acquireUpgradeMutex(long currentServerSideTableTimestamp, byte[] rowToLock) throws IOException,
SQLException {
Preconditions.checkArgument(currentServerSideTableTimestamp < MIN_SYSTEM_TABLE_TIMESTAMP);
- try (HBaseAdmin admin = getAdmin()) {
- try {
- HTableDescriptor tableDesc = new HTableDescriptor(
- TableName.valueOf(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES));
- HColumnDescriptor columnDesc = new HColumnDescriptor(
- PhoenixDatabaseMetaData.SYSTEM_MUTEX_FAMILY_NAME_BYTES);
- columnDesc.setTimeToLive(TTL_FOR_MUTEX); // Let mutex expire after some time
- tableDesc.addFamily(columnDesc);
- admin.createTable(tableDesc);
- try (HTableInterface sysMutexTable = getTable(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES)) {
- Put put = new Put(rowToLock);
- put.add(PhoenixDatabaseMetaData.SYSTEM_MUTEX_FAMILY_NAME_BYTES, UPGRADE_MUTEX, UPGRADE_MUTEX_UNLOCKED);
- sysMutexTable.put(put);
- }
- } catch (TableExistsException e) {
- // Ignore
- }
- }
try (HTableInterface sysMutexTable = getTable(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME_BYTES)) {
byte[] family = PhoenixDatabaseMetaData.SYSTEM_MUTEX_FAMILY_NAME_BYTES;
byte[] qualifier = UPGRADE_MUTEX;
[32/42] phoenix git commit: Introduce the notion of encoding schemes
and storage schemes
Posted by td...@apache.org.
Introduce the notion of encoding schemes and storage schemes
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/8a1de1cb
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8a1de1cb
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8a1de1cb
Branch: refs/heads/encodecolumns2
Commit: 8a1de1cbc2ec9e0a9d309e05e38fb37e4d78ba08
Parents: 2b3265e
Author: Samarth <sa...@salesforce.com>
Authored: Tue Nov 22 17:01:15 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../apache/phoenix/compile/FromCompiler.java | 3 +-
.../apache/phoenix/compile/JoinCompiler.java | 3 +-
.../compile/TupleProjectionCompiler.java | 6 +-
.../apache/phoenix/compile/UnionCompiler.java | 3 +-
.../coprocessor/MetaDataEndpointImpl.java | 15 +-
.../coprocessor/generated/PTableProtos.java | 336 ++++++++++++-------
.../apache/phoenix/index/IndexMaintainer.java | 2 +-
.../phoenix/iterate/BaseResultIterators.java | 2 +-
.../phoenix/jdbc/PhoenixDatabaseMetaData.java | 2 +
.../apache/phoenix/query/QueryConstants.java | 4 +-
.../apache/phoenix/schema/DelegateTable.java | 5 +
.../apache/phoenix/schema/MetaDataClient.java | 22 +-
.../org/apache/phoenix/schema/PColumnImpl.java | 6 +-
.../java/org/apache/phoenix/schema/PTable.java | 176 +++++++++-
.../org/apache/phoenix/schema/PTableImpl.java | 56 ++--
.../apache/phoenix/util/EncodedColumnsUtil.java | 1 -
.../java/org/apache/phoenix/util/ScanUtil.java | 2 +-
.../org/apache/phoenix/util/SchemaUtil.java | 4 +-
.../phoenix/execute/CorrelatePlanTest.java | 3 +-
.../execute/LiteralResultIteratorPlanTest.java | 3 +-
.../apache/phoenix/util/PhoenixRuntimeTest.java | 12 +-
phoenix-protocol/src/main/PTable.proto | 5 +-
22 files changed, 496 insertions(+), 175 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
index f5df980..d4ccfff 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
@@ -71,6 +71,7 @@ import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableKey;
@@ -787,7 +788,7 @@ public class FromCompiler {
MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM, null, null, columns, null, null,
Collections.<PTable> emptyList(), false, Collections.<PName> emptyList(), null, null, false, false,
false, null, null, null, false, false, 0, 0L, SchemaUtil
- .isNamespaceMappingEnabled(PTableType.SUBQUERY, connection.getQueryServices().getProps()), null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, PTable.EncodedCQCounter.NULL_COUNTER);
+ .isNamespaceMappingEnabled(PTableType.SUBQUERY, connection.getQueryServices().getProps()), null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
String alias = subselectNode.getAlias();
TableRef tableRef = new TableRef(alias, t, MetaDataProtocol.MIN_TABLE_TIMESTAMP, false);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index 489b993..bc2c7df 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -76,6 +76,7 @@ import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
@@ -1312,7 +1313,7 @@ public class JoinCompiler {
left.isMultiTenant(), left.getStoreNulls(), left.getViewType(), left.getViewIndexId(),
left.getIndexType(), left.rowKeyOrderOptimizable(), left.isTransactional(),
left.getUpdateCacheFrequency(), left.getIndexDisableTimestamp(), left.isNamespaceMapped(),
- left.getAutoPartitionSeqName(), left.isAppendOnlySchema(), StorageScheme.NON_ENCODED_COLUMN_NAMES, PTable.EncodedCQCounter.NULL_COUNTER);
+ left.getAutoPartitionSeqName(), left.isAppendOnlySchema(), StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
index c472039..79e2971 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
@@ -46,6 +46,7 @@ import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
@@ -158,7 +159,7 @@ public class TupleProjectionCompiler {
null, null, table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(),
table.getViewIndexId(),
table.getIndexType(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(),
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
}
public static PTable createProjectedTable(TableRef tableRef, List<ColumnRef> sourceColumnRefs, boolean retainPKColumns) throws SQLException {
@@ -185,13 +186,14 @@ public class TupleProjectionCompiler {
if (storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES) {
cqCounter = EncodedCQCounter.copy(table.getEncodedCQCounter());
}
+
return PTableImpl.makePTable(table.getTenantId(), PROJECTED_TABLE_SCHEMA, table.getName(), PTableType.PROJECTED,
null, table.getTimeStamp(), table.getSequenceNumber(), table.getPKName(),
retainPKColumns ? table.getBucketNum() : null, projectedColumns, null, null,
Collections.<PTable> emptyList(), table.isImmutableRows(), Collections.<PName> emptyList(), null, null,
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(),
table.getViewIndexId(), null, table.rowKeyOrderOptimizable(), table.isTransactional(),
- table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), storageScheme, cqCounter);
+ table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), storageScheme, table.getEncodingScheme(), cqCounter);
}
// For extracting column references from single select statement
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
index d779df1..7f2fbb3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
@@ -39,6 +39,7 @@ import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableRef;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.util.SchemaUtil;
@@ -99,7 +100,7 @@ public class UnionCompiler {
null, null, projectedColumns, null, null, null, true, null, null, null, true,
true, true, null, null, null, false, false, 0, 0L,
SchemaUtil.isNamespaceMappingEnabled(PTableType.SUBQUERY,
- statement.getConnection().getQueryServices().getProps()), null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, PTable.EncodedCQCounter.NULL_COUNTER);
+ statement.getConnection().getQueryServices().getProps()), null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
TableRef tableRef = new TableRef(null, tempTable, 0, false);
return tableRef;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index a9acb63..c4d049b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -36,6 +36,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAM
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_VALUE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER_BYTES;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODING_SCHEME_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FAMILY_NAME_INDEX;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IMMUTABLE_ROWS_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP_BYTES;
@@ -195,6 +196,7 @@ import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTable.LinkType;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTable.ViewType;
import org.apache.phoenix.schema.PTableImpl;
@@ -291,6 +293,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private static final KeyValue AUTO_PARTITION_SEQ_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, AUTO_PARTITION_SEQ_BYTES);
private static final KeyValue APPEND_ONLY_SCHEMA_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, APPEND_ONLY_SCHEMA_BYTES);
private static final KeyValue STORAGE_SCHEME_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, STORAGE_SCHEME_BYTES);
+ private static final KeyValue ENCODING_SCHEME_KV = createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, ENCODING_SCHEME_BYTES);
private static final List<KeyValue> TABLE_KV_COLUMNS = Arrays.<KeyValue>asList(
EMPTY_KEYVALUE_KV,
@@ -318,7 +321,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
IS_NAMESPACE_MAPPED_KV,
AUTO_PARTITION_SEQ_KV,
APPEND_ONLY_SCHEMA_KV,
- STORAGE_SCHEME_KV
+ STORAGE_SCHEME_KV,
+ ENCODING_SCHEME_KV
);
static {
Collections.sort(TABLE_KV_COLUMNS, KeyValue.COMPARATOR);
@@ -349,6 +353,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private static final int AUTO_PARTITION_SEQ_INDEX = TABLE_KV_COLUMNS.indexOf(AUTO_PARTITION_SEQ_KV);
private static final int APPEND_ONLY_SCHEMA_INDEX = TABLE_KV_COLUMNS.indexOf(APPEND_ONLY_SCHEMA_KV);
private static final int STORAGE_SCHEME_INDEX = TABLE_KV_COLUMNS.indexOf(STORAGE_SCHEME_KV);
+ private static final int QUALIFIER_ENCODING_SCHEME_INDEX = TABLE_KV_COLUMNS.indexOf(ENCODING_SCHEME_KV);
// KeyValues for Column
private static final KeyValue DECIMAL_DIGITS_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, DECIMAL_DIGITS_BYTES);
@@ -950,7 +955,11 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
StorageScheme storageScheme = storageSchemeKv == null ? StorageScheme.NON_ENCODED_COLUMN_NAMES : StorageScheme
.fromSerializedValue((byte)PTinyint.INSTANCE.toObject(storageSchemeKv.getValueArray(),
storageSchemeKv.getValueOffset(), storageSchemeKv.getValueLength()));
-
+ Cell encodingSchemeKv = tableKeyValues[QUALIFIER_ENCODING_SCHEME_INDEX];
+ QualifierEncodingScheme encodingScheme = encodingSchemeKv == null ? QualifierEncodingScheme.NON_ENCODED_QUALIFIERS : QualifierEncodingScheme
+ .fromSerializedValue((byte)PTinyint.INSTANCE.toObject(encodingSchemeKv.getValueArray(),
+ encodingSchemeKv.getValueOffset(), encodingSchemeKv.getValueLength()));
+
List<PColumn> columns = Lists.newArrayListWithExpectedSize(columnCount);
List<PTable> indexes = Lists.newArrayList();
List<PName> physicalTables = Lists.newArrayList();
@@ -995,7 +1004,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
pkName, saltBucketNum, columns, parentSchemaName, parentTableName, indexes, isImmutableRows, physicalTables, defaultFamilyName,
viewStatement, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType,
rowKeyOrderOptimizable, transactional, updateCacheFrequency, baseColumnCount,
- indexDisableTimestamp, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, storageScheme, cqCounter);
+ indexDisableTimestamp, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, storageScheme, encodingScheme, cqCounter);
}
private boolean isQualifierCounterKV(Cell kv) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
index 2f0c00b..ead928f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
@@ -270,15 +270,15 @@ public final class PTableProtos {
*/
boolean getIsDynamic();
- // optional int32 columnQualifier = 15;
+ // optional int32 encodedColumnQualifier = 15;
/**
- * <code>optional int32 columnQualifier = 15;</code>
+ * <code>optional int32 encodedColumnQualifier = 15;</code>
*/
- boolean hasColumnQualifier();
+ boolean hasEncodedColumnQualifier();
/**
- * <code>optional int32 columnQualifier = 15;</code>
+ * <code>optional int32 encodedColumnQualifier = 15;</code>
*/
- int getColumnQualifier();
+ int getEncodedColumnQualifier();
}
/**
* Protobuf type {@code PColumn}
@@ -403,7 +403,7 @@ public final class PTableProtos {
}
case 120: {
bitField0_ |= 0x00004000;
- columnQualifier_ = input.readInt32();
+ encodedColumnQualifier_ = input.readInt32();
break;
}
}
@@ -724,20 +724,20 @@ public final class PTableProtos {
return isDynamic_;
}
- // optional int32 columnQualifier = 15;
- public static final int COLUMNQUALIFIER_FIELD_NUMBER = 15;
- private int columnQualifier_;
+ // optional int32 encodedColumnQualifier = 15;
+ public static final int ENCODEDCOLUMNQUALIFIER_FIELD_NUMBER = 15;
+ private int encodedColumnQualifier_;
/**
- * <code>optional int32 columnQualifier = 15;</code>
+ * <code>optional int32 encodedColumnQualifier = 15;</code>
*/
- public boolean hasColumnQualifier() {
+ public boolean hasEncodedColumnQualifier() {
return ((bitField0_ & 0x00004000) == 0x00004000);
}
/**
- * <code>optional int32 columnQualifier = 15;</code>
+ * <code>optional int32 encodedColumnQualifier = 15;</code>
*/
- public int getColumnQualifier() {
- return columnQualifier_;
+ public int getEncodedColumnQualifier() {
+ return encodedColumnQualifier_;
}
private void initFields() {
@@ -755,7 +755,7 @@ public final class PTableProtos {
expression_ = "";
isRowTimestamp_ = false;
isDynamic_ = false;
- columnQualifier_ = 0;
+ encodedColumnQualifier_ = 0;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -832,7 +832,7 @@ public final class PTableProtos {
output.writeBool(14, isDynamic_);
}
if (((bitField0_ & 0x00004000) == 0x00004000)) {
- output.writeInt32(15, columnQualifier_);
+ output.writeInt32(15, encodedColumnQualifier_);
}
getUnknownFields().writeTo(output);
}
@@ -901,7 +901,7 @@ public final class PTableProtos {
}
if (((bitField0_ & 0x00004000) == 0x00004000)) {
size += com.google.protobuf.CodedOutputStream
- .computeInt32Size(15, columnQualifier_);
+ .computeInt32Size(15, encodedColumnQualifier_);
}
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
@@ -996,10 +996,10 @@ public final class PTableProtos {
result = result && (getIsDynamic()
== other.getIsDynamic());
}
- result = result && (hasColumnQualifier() == other.hasColumnQualifier());
- if (hasColumnQualifier()) {
- result = result && (getColumnQualifier()
- == other.getColumnQualifier());
+ result = result && (hasEncodedColumnQualifier() == other.hasEncodedColumnQualifier());
+ if (hasEncodedColumnQualifier()) {
+ result = result && (getEncodedColumnQualifier()
+ == other.getEncodedColumnQualifier());
}
result = result &&
getUnknownFields().equals(other.getUnknownFields());
@@ -1070,9 +1070,9 @@ public final class PTableProtos {
hash = (37 * hash) + ISDYNAMIC_FIELD_NUMBER;
hash = (53 * hash) + hashBoolean(getIsDynamic());
}
- if (hasColumnQualifier()) {
- hash = (37 * hash) + COLUMNQUALIFIER_FIELD_NUMBER;
- hash = (53 * hash) + getColumnQualifier();
+ if (hasEncodedColumnQualifier()) {
+ hash = (37 * hash) + ENCODEDCOLUMNQUALIFIER_FIELD_NUMBER;
+ hash = (53 * hash) + getEncodedColumnQualifier();
}
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
@@ -1211,7 +1211,7 @@ public final class PTableProtos {
bitField0_ = (bitField0_ & ~0x00001000);
isDynamic_ = false;
bitField0_ = (bitField0_ & ~0x00002000);
- columnQualifier_ = 0;
+ encodedColumnQualifier_ = 0;
bitField0_ = (bitField0_ & ~0x00004000);
return this;
}
@@ -1300,7 +1300,7 @@ public final class PTableProtos {
if (((from_bitField0_ & 0x00004000) == 0x00004000)) {
to_bitField0_ |= 0x00004000;
}
- result.columnQualifier_ = columnQualifier_;
+ result.encodedColumnQualifier_ = encodedColumnQualifier_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -1363,8 +1363,8 @@ public final class PTableProtos {
if (other.hasIsDynamic()) {
setIsDynamic(other.getIsDynamic());
}
- if (other.hasColumnQualifier()) {
- setColumnQualifier(other.getColumnQualifier());
+ if (other.hasEncodedColumnQualifier()) {
+ setEncodedColumnQualifier(other.getEncodedColumnQualifier());
}
this.mergeUnknownFields(other.getUnknownFields());
return this;
@@ -1966,35 +1966,35 @@ public final class PTableProtos {
return this;
}
- // optional int32 columnQualifier = 15;
- private int columnQualifier_ ;
+ // optional int32 encodedColumnQualifier = 15;
+ private int encodedColumnQualifier_ ;
/**
- * <code>optional int32 columnQualifier = 15;</code>
+ * <code>optional int32 encodedColumnQualifier = 15;</code>
*/
- public boolean hasColumnQualifier() {
+ public boolean hasEncodedColumnQualifier() {
return ((bitField0_ & 0x00004000) == 0x00004000);
}
/**
- * <code>optional int32 columnQualifier = 15;</code>
+ * <code>optional int32 encodedColumnQualifier = 15;</code>
*/
- public int getColumnQualifier() {
- return columnQualifier_;
+ public int getEncodedColumnQualifier() {
+ return encodedColumnQualifier_;
}
/**
- * <code>optional int32 columnQualifier = 15;</code>
+ * <code>optional int32 encodedColumnQualifier = 15;</code>
*/
- public Builder setColumnQualifier(int value) {
+ public Builder setEncodedColumnQualifier(int value) {
bitField0_ |= 0x00004000;
- columnQualifier_ = value;
+ encodedColumnQualifier_ = value;
onChanged();
return this;
}
/**
- * <code>optional int32 columnQualifier = 15;</code>
+ * <code>optional int32 encodedColumnQualifier = 15;</code>
*/
- public Builder clearColumnQualifier() {
+ public Builder clearEncodedColumnQualifier() {
bitField0_ = (bitField0_ & ~0x00004000);
- columnQualifier_ = 0;
+ encodedColumnQualifier_ = 0;
onChanged();
return this;
}
@@ -3473,27 +3473,37 @@ public final class PTableProtos {
*/
com.google.protobuf.ByteString getStorageScheme();
- // repeated .EncodedCQCounter encodedCQCounters = 35;
+ // optional bytes encodingScheme = 35;
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>optional bytes encodingScheme = 35;</code>
+ */
+ boolean hasEncodingScheme();
+ /**
+ * <code>optional bytes encodingScheme = 35;</code>
+ */
+ com.google.protobuf.ByteString getEncodingScheme();
+
+ // repeated .EncodedCQCounter encodedCQCounters = 36;
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter>
getEncodedCQCountersList();
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter getEncodedCQCounters(int index);
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
int getEncodedCQCountersCount();
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
java.util.List<? extends org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder>
getEncodedCQCountersOrBuilderList();
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder getEncodedCQCountersOrBuilder(
int index);
@@ -3731,9 +3741,14 @@ public final class PTableProtos {
break;
}
case 282: {
- if (!((mutable_bitField1_ & 0x00000002) == 0x00000002)) {
+ bitField0_ |= 0x40000000;
+ encodingScheme_ = input.readBytes();
+ break;
+ }
+ case 290: {
+ if (!((mutable_bitField1_ & 0x00000004) == 0x00000004)) {
encodedCQCounters_ = new java.util.ArrayList<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter>();
- mutable_bitField1_ |= 0x00000002;
+ mutable_bitField1_ |= 0x00000004;
}
encodedCQCounters_.add(input.readMessage(org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.PARSER, extensionRegistry));
break;
@@ -3755,7 +3770,7 @@ public final class PTableProtos {
if (((mutable_bitField0_ & 0x00020000) == 0x00020000)) {
physicalNames_ = java.util.Collections.unmodifiableList(physicalNames_);
}
- if (((mutable_bitField1_ & 0x00000002) == 0x00000002)) {
+ if (((mutable_bitField1_ & 0x00000004) == 0x00000004)) {
encodedCQCounters_ = java.util.Collections.unmodifiableList(encodedCQCounters_);
}
this.unknownFields = unknownFields.build();
@@ -4433,36 +4448,52 @@ public final class PTableProtos {
return storageScheme_;
}
- // repeated .EncodedCQCounter encodedCQCounters = 35;
- public static final int ENCODEDCQCOUNTERS_FIELD_NUMBER = 35;
+ // optional bytes encodingScheme = 35;
+ public static final int ENCODINGSCHEME_FIELD_NUMBER = 35;
+ private com.google.protobuf.ByteString encodingScheme_;
+ /**
+ * <code>optional bytes encodingScheme = 35;</code>
+ */
+ public boolean hasEncodingScheme() {
+ return ((bitField0_ & 0x40000000) == 0x40000000);
+ }
+ /**
+ * <code>optional bytes encodingScheme = 35;</code>
+ */
+ public com.google.protobuf.ByteString getEncodingScheme() {
+ return encodingScheme_;
+ }
+
+ // repeated .EncodedCQCounter encodedCQCounters = 36;
+ public static final int ENCODEDCQCOUNTERS_FIELD_NUMBER = 36;
private java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> encodedCQCounters_;
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> getEncodedCQCountersList() {
return encodedCQCounters_;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public java.util.List<? extends org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder>
getEncodedCQCountersOrBuilderList() {
return encodedCQCounters_;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public int getEncodedCQCountersCount() {
return encodedCQCounters_.size();
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter getEncodedCQCounters(int index) {
return encodedCQCounters_.get(index);
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder getEncodedCQCountersOrBuilder(
int index) {
@@ -4503,6 +4534,7 @@ public final class PTableProtos {
isAppendOnlySchema_ = false;
parentNameBytes_ = com.google.protobuf.ByteString.EMPTY;
storageScheme_ = com.google.protobuf.ByteString.EMPTY;
+ encodingScheme_ = com.google.protobuf.ByteString.EMPTY;
encodedCQCounters_ = java.util.Collections.emptyList();
}
private byte memoizedIsInitialized = -1;
@@ -4670,8 +4702,11 @@ public final class PTableProtos {
if (((bitField0_ & 0x20000000) == 0x20000000)) {
output.writeBytes(34, storageScheme_);
}
+ if (((bitField0_ & 0x40000000) == 0x40000000)) {
+ output.writeBytes(35, encodingScheme_);
+ }
for (int i = 0; i < encodedCQCounters_.size(); i++) {
- output.writeMessage(35, encodedCQCounters_.get(i));
+ output.writeMessage(36, encodedCQCounters_.get(i));
}
getUnknownFields().writeTo(output);
}
@@ -4819,9 +4854,13 @@ public final class PTableProtos {
size += com.google.protobuf.CodedOutputStream
.computeBytesSize(34, storageScheme_);
}
+ if (((bitField0_ & 0x40000000) == 0x40000000)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(35, encodingScheme_);
+ }
for (int i = 0; i < encodedCQCounters_.size(); i++) {
size += com.google.protobuf.CodedOutputStream
- .computeMessageSize(35, encodedCQCounters_.get(i));
+ .computeMessageSize(36, encodedCQCounters_.get(i));
}
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
@@ -5002,6 +5041,11 @@ public final class PTableProtos {
result = result && getStorageScheme()
.equals(other.getStorageScheme());
}
+ result = result && (hasEncodingScheme() == other.hasEncodingScheme());
+ if (hasEncodingScheme()) {
+ result = result && getEncodingScheme()
+ .equals(other.getEncodingScheme());
+ }
result = result && getEncodedCQCountersList()
.equals(other.getEncodedCQCountersList());
result = result &&
@@ -5149,6 +5193,10 @@ public final class PTableProtos {
hash = (37 * hash) + STORAGESCHEME_FIELD_NUMBER;
hash = (53 * hash) + getStorageScheme().hashCode();
}
+ if (hasEncodingScheme()) {
+ hash = (37 * hash) + ENCODINGSCHEME_FIELD_NUMBER;
+ hash = (53 * hash) + getEncodingScheme().hashCode();
+ }
if (getEncodedCQCountersCount() > 0) {
hash = (37 * hash) + ENCODEDCQCOUNTERS_FIELD_NUMBER;
hash = (53 * hash) + getEncodedCQCountersList().hashCode();
@@ -5339,9 +5387,11 @@ public final class PTableProtos {
bitField0_ = (bitField0_ & ~0x80000000);
storageScheme_ = com.google.protobuf.ByteString.EMPTY;
bitField1_ = (bitField1_ & ~0x00000001);
+ encodingScheme_ = com.google.protobuf.ByteString.EMPTY;
+ bitField1_ = (bitField1_ & ~0x00000002);
if (encodedCQCountersBuilder_ == null) {
encodedCQCounters_ = java.util.Collections.emptyList();
- bitField1_ = (bitField1_ & ~0x00000002);
+ bitField1_ = (bitField1_ & ~0x00000004);
} else {
encodedCQCountersBuilder_.clear();
}
@@ -5517,10 +5567,14 @@ public final class PTableProtos {
to_bitField0_ |= 0x20000000;
}
result.storageScheme_ = storageScheme_;
+ if (((from_bitField1_ & 0x00000002) == 0x00000002)) {
+ to_bitField0_ |= 0x40000000;
+ }
+ result.encodingScheme_ = encodingScheme_;
if (encodedCQCountersBuilder_ == null) {
- if (((bitField1_ & 0x00000002) == 0x00000002)) {
+ if (((bitField1_ & 0x00000004) == 0x00000004)) {
encodedCQCounters_ = java.util.Collections.unmodifiableList(encodedCQCounters_);
- bitField1_ = (bitField1_ & ~0x00000002);
+ bitField1_ = (bitField1_ & ~0x00000004);
}
result.encodedCQCounters_ = encodedCQCounters_;
} else {
@@ -5698,11 +5752,14 @@ public final class PTableProtos {
if (other.hasStorageScheme()) {
setStorageScheme(other.getStorageScheme());
}
+ if (other.hasEncodingScheme()) {
+ setEncodingScheme(other.getEncodingScheme());
+ }
if (encodedCQCountersBuilder_ == null) {
if (!other.encodedCQCounters_.isEmpty()) {
if (encodedCQCounters_.isEmpty()) {
encodedCQCounters_ = other.encodedCQCounters_;
- bitField1_ = (bitField1_ & ~0x00000002);
+ bitField1_ = (bitField1_ & ~0x00000004);
} else {
ensureEncodedCQCountersIsMutable();
encodedCQCounters_.addAll(other.encodedCQCounters_);
@@ -5715,7 +5772,7 @@ public final class PTableProtos {
encodedCQCountersBuilder_.dispose();
encodedCQCountersBuilder_ = null;
encodedCQCounters_ = other.encodedCQCounters_;
- bitField1_ = (bitField1_ & ~0x00000002);
+ bitField1_ = (bitField1_ & ~0x00000004);
encodedCQCountersBuilder_ =
com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
getEncodedCQCountersFieldBuilder() : null;
@@ -7494,13 +7551,49 @@ public final class PTableProtos {
return this;
}
- // repeated .EncodedCQCounter encodedCQCounters = 35;
+ // optional bytes encodingScheme = 35;
+ private com.google.protobuf.ByteString encodingScheme_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * <code>optional bytes encodingScheme = 35;</code>
+ */
+ public boolean hasEncodingScheme() {
+ return ((bitField1_ & 0x00000002) == 0x00000002);
+ }
+ /**
+ * <code>optional bytes encodingScheme = 35;</code>
+ */
+ public com.google.protobuf.ByteString getEncodingScheme() {
+ return encodingScheme_;
+ }
+ /**
+ * <code>optional bytes encodingScheme = 35;</code>
+ */
+ public Builder setEncodingScheme(com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField1_ |= 0x00000002;
+ encodingScheme_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional bytes encodingScheme = 35;</code>
+ */
+ public Builder clearEncodingScheme() {
+ bitField1_ = (bitField1_ & ~0x00000002);
+ encodingScheme_ = getDefaultInstance().getEncodingScheme();
+ onChanged();
+ return this;
+ }
+
+ // repeated .EncodedCQCounter encodedCQCounters = 36;
private java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> encodedCQCounters_ =
java.util.Collections.emptyList();
private void ensureEncodedCQCountersIsMutable() {
- if (!((bitField1_ & 0x00000002) == 0x00000002)) {
+ if (!((bitField1_ & 0x00000004) == 0x00000004)) {
encodedCQCounters_ = new java.util.ArrayList<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter>(encodedCQCounters_);
- bitField1_ |= 0x00000002;
+ bitField1_ |= 0x00000004;
}
}
@@ -7508,7 +7601,7 @@ public final class PTableProtos {
org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder> encodedCQCountersBuilder_;
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> getEncodedCQCountersList() {
if (encodedCQCountersBuilder_ == null) {
@@ -7518,7 +7611,7 @@ public final class PTableProtos {
}
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public int getEncodedCQCountersCount() {
if (encodedCQCountersBuilder_ == null) {
@@ -7528,7 +7621,7 @@ public final class PTableProtos {
}
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter getEncodedCQCounters(int index) {
if (encodedCQCountersBuilder_ == null) {
@@ -7538,7 +7631,7 @@ public final class PTableProtos {
}
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public Builder setEncodedCQCounters(
int index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter value) {
@@ -7555,7 +7648,7 @@ public final class PTableProtos {
return this;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public Builder setEncodedCQCounters(
int index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder builderForValue) {
@@ -7569,7 +7662,7 @@ public final class PTableProtos {
return this;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public Builder addEncodedCQCounters(org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter value) {
if (encodedCQCountersBuilder_ == null) {
@@ -7585,7 +7678,7 @@ public final class PTableProtos {
return this;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public Builder addEncodedCQCounters(
int index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter value) {
@@ -7602,7 +7695,7 @@ public final class PTableProtos {
return this;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public Builder addEncodedCQCounters(
org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder builderForValue) {
@@ -7616,7 +7709,7 @@ public final class PTableProtos {
return this;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public Builder addEncodedCQCounters(
int index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder builderForValue) {
@@ -7630,7 +7723,7 @@ public final class PTableProtos {
return this;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public Builder addAllEncodedCQCounters(
java.lang.Iterable<? extends org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> values) {
@@ -7644,12 +7737,12 @@ public final class PTableProtos {
return this;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public Builder clearEncodedCQCounters() {
if (encodedCQCountersBuilder_ == null) {
encodedCQCounters_ = java.util.Collections.emptyList();
- bitField1_ = (bitField1_ & ~0x00000002);
+ bitField1_ = (bitField1_ & ~0x00000004);
onChanged();
} else {
encodedCQCountersBuilder_.clear();
@@ -7657,7 +7750,7 @@ public final class PTableProtos {
return this;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public Builder removeEncodedCQCounters(int index) {
if (encodedCQCountersBuilder_ == null) {
@@ -7670,14 +7763,14 @@ public final class PTableProtos {
return this;
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder getEncodedCQCountersBuilder(
int index) {
return getEncodedCQCountersFieldBuilder().getBuilder(index);
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder getEncodedCQCountersOrBuilder(
int index) {
@@ -7687,7 +7780,7 @@ public final class PTableProtos {
}
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public java.util.List<? extends org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder>
getEncodedCQCountersOrBuilderList() {
@@ -7698,14 +7791,14 @@ public final class PTableProtos {
}
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder addEncodedCQCountersBuilder() {
return getEncodedCQCountersFieldBuilder().addBuilder(
org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.getDefaultInstance());
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder addEncodedCQCountersBuilder(
int index) {
@@ -7713,7 +7806,7 @@ public final class PTableProtos {
index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.getDefaultInstance());
}
/**
- * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 36;</code>
*/
public java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder>
getEncodedCQCountersBuilderList() {
@@ -7726,7 +7819,7 @@ public final class PTableProtos {
encodedCQCountersBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<
org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder>(
encodedCQCounters_,
- ((bitField1_ & 0x00000002) == 0x00000002),
+ ((bitField1_ & 0x00000004) == 0x00000004),
getParentForChildren(),
isClean());
encodedCQCounters_ = null;
@@ -8389,7 +8482,7 @@ public final class PTableProtos {
descriptor;
static {
java.lang.String[] descriptorData = {
- "\n\014PTable.proto\032\021PGuidePosts.proto\"\277\002\n\007PC" +
+ "\n\014PTable.proto\032\021PGuidePosts.proto\"\306\002\n\007PC" +
"olumn\022\027\n\017columnNameBytes\030\001 \002(\014\022\027\n\017family" +
"NameBytes\030\002 \001(\014\022\020\n\010dataType\030\003 \002(\t\022\021\n\tmax" +
"Length\030\004 \001(\005\022\r\n\005scale\030\005 \001(\005\022\020\n\010nullable\030" +
@@ -8397,37 +8490,38 @@ public final class PTableProtos {
"(\005\022\021\n\tarraySize\030\t \001(\005\022\024\n\014viewConstant\030\n " +
"\001(\014\022\026\n\016viewReferenced\030\013 \001(\010\022\022\n\nexpressio" +
"n\030\014 \001(\t\022\026\n\016isRowTimestamp\030\r \001(\010\022\021\n\tisDyn" +
- "amic\030\016 \001(\010\022\027\n\017columnQualifier\030\017 \001(\005\"\232\001\n\013" +
- "PTableStats\022\013\n\003key\030\001 \002(\014\022\016\n\006values\030\002 \003(\014",
- "\022\033\n\023guidePostsByteCount\030\003 \001(\003\022\025\n\rkeyByte" +
- "sCount\030\004 \001(\003\022\027\n\017guidePostsCount\030\005 \001(\005\022!\n" +
- "\013pGuidePosts\030\006 \001(\0132\014.PGuidePosts\"\324\006\n\006PTa" +
- "ble\022\027\n\017schemaNameBytes\030\001 \002(\014\022\026\n\016tableNam" +
- "eBytes\030\002 \002(\014\022\036\n\ttableType\030\003 \002(\0162\013.PTable" +
- "Type\022\022\n\nindexState\030\004 \001(\t\022\026\n\016sequenceNumb" +
- "er\030\005 \002(\003\022\021\n\ttimeStamp\030\006 \002(\003\022\023\n\013pkNameByt" +
- "es\030\007 \001(\014\022\021\n\tbucketNum\030\010 \002(\005\022\031\n\007columns\030\t" +
- " \003(\0132\010.PColumn\022\030\n\007indexes\030\n \003(\0132\007.PTable" +
- "\022\027\n\017isImmutableRows\030\013 \002(\010\022\032\n\022dataTableNa",
- "meBytes\030\r \001(\014\022\031\n\021defaultFamilyName\030\016 \001(\014" +
- "\022\022\n\ndisableWAL\030\017 \002(\010\022\023\n\013multiTenant\030\020 \002(" +
- "\010\022\020\n\010viewType\030\021 \001(\014\022\025\n\rviewStatement\030\022 \001" +
- "(\014\022\025\n\rphysicalNames\030\023 \003(\014\022\020\n\010tenantId\030\024 " +
- "\001(\014\022\023\n\013viewIndexId\030\025 \001(\005\022\021\n\tindexType\030\026 " +
- "\001(\014\022\026\n\016statsTimeStamp\030\027 \001(\003\022\022\n\nstoreNull" +
- "s\030\030 \001(\010\022\027\n\017baseColumnCount\030\031 \001(\005\022\036\n\026rowK" +
- "eyOrderOptimizable\030\032 \001(\010\022\025\n\rtransactiona" +
- "l\030\033 \001(\010\022\034\n\024updateCacheFrequency\030\034 \001(\003\022\035\n" +
- "\025indexDisableTimestamp\030\035 \001(\003\022\031\n\021isNamesp",
- "aceMapped\030\036 \001(\010\022\034\n\024autoParititonSeqName\030" +
- "\037 \001(\t\022\032\n\022isAppendOnlySchema\030 \001(\010\022\027\n\017par" +
- "entNameBytes\030! \001(\014\022\025\n\rstorageScheme\030\" \001(" +
- "\014\022,\n\021encodedCQCounters\030# \003(\0132\021.EncodedCQ" +
- "Counter\"6\n\020EncodedCQCounter\022\021\n\tcolFamily" +
- "\030\001 \002(\t\022\017\n\007counter\030\002 \002(\005*A\n\nPTableType\022\n\n" +
- "\006SYSTEM\020\000\022\010\n\004USER\020\001\022\010\n\004VIEW\020\002\022\t\n\005INDEX\020\003" +
- "\022\010\n\004JOIN\020\004B@\n(org.apache.phoenix.coproce" +
- "ssor.generatedB\014PTableProtosH\001\210\001\001\240\001\001"
+ "amic\030\016 \001(\010\022\036\n\026encodedColumnQualifier\030\017 \001" +
+ "(\005\"\232\001\n\013PTableStats\022\013\n\003key\030\001 \002(\014\022\016\n\006value",
+ "s\030\002 \003(\014\022\033\n\023guidePostsByteCount\030\003 \001(\003\022\025\n\r" +
+ "keyBytesCount\030\004 \001(\003\022\027\n\017guidePostsCount\030\005" +
+ " \001(\005\022!\n\013pGuidePosts\030\006 \001(\0132\014.PGuidePosts\"" +
+ "\354\006\n\006PTable\022\027\n\017schemaNameBytes\030\001 \002(\014\022\026\n\016t" +
+ "ableNameBytes\030\002 \002(\014\022\036\n\ttableType\030\003 \002(\0162\013" +
+ ".PTableType\022\022\n\nindexState\030\004 \001(\t\022\026\n\016seque" +
+ "nceNumber\030\005 \002(\003\022\021\n\ttimeStamp\030\006 \002(\003\022\023\n\013pk" +
+ "NameBytes\030\007 \001(\014\022\021\n\tbucketNum\030\010 \002(\005\022\031\n\007co" +
+ "lumns\030\t \003(\0132\010.PColumn\022\030\n\007indexes\030\n \003(\0132\007" +
+ ".PTable\022\027\n\017isImmutableRows\030\013 \002(\010\022\032\n\022data",
+ "TableNameBytes\030\r \001(\014\022\031\n\021defaultFamilyNam" +
+ "e\030\016 \001(\014\022\022\n\ndisableWAL\030\017 \002(\010\022\023\n\013multiTena" +
+ "nt\030\020 \002(\010\022\020\n\010viewType\030\021 \001(\014\022\025\n\rviewStatem" +
+ "ent\030\022 \001(\014\022\025\n\rphysicalNames\030\023 \003(\014\022\020\n\010tena" +
+ "ntId\030\024 \001(\014\022\023\n\013viewIndexId\030\025 \001(\005\022\021\n\tindex" +
+ "Type\030\026 \001(\014\022\026\n\016statsTimeStamp\030\027 \001(\003\022\022\n\nst" +
+ "oreNulls\030\030 \001(\010\022\027\n\017baseColumnCount\030\031 \001(\005\022" +
+ "\036\n\026rowKeyOrderOptimizable\030\032 \001(\010\022\025\n\rtrans" +
+ "actional\030\033 \001(\010\022\034\n\024updateCacheFrequency\030\034" +
+ " \001(\003\022\035\n\025indexDisableTimestamp\030\035 \001(\003\022\031\n\021i",
+ "sNamespaceMapped\030\036 \001(\010\022\034\n\024autoParititonS" +
+ "eqName\030\037 \001(\t\022\032\n\022isAppendOnlySchema\030 \001(\010" +
+ "\022\027\n\017parentNameBytes\030! \001(\014\022\025\n\rstorageSche" +
+ "me\030\" \001(\014\022\026\n\016encodingScheme\030# \001(\014\022,\n\021enco" +
+ "dedCQCounters\030$ \003(\0132\021.EncodedCQCounter\"6" +
+ "\n\020EncodedCQCounter\022\021\n\tcolFamily\030\001 \002(\t\022\017\n" +
+ "\007counter\030\002 \002(\005*A\n\nPTableType\022\n\n\006SYSTEM\020\000" +
+ "\022\010\n\004USER\020\001\022\010\n\004VIEW\020\002\022\t\n\005INDEX\020\003\022\010\n\004JOIN\020" +
+ "\004B@\n(org.apache.phoenix.coprocessor.gene" +
+ "ratedB\014PTableProtosH\001\210\001\001\240\001\001"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -8439,7 +8533,7 @@ public final class PTableProtos {
internal_static_PColumn_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_PColumn_descriptor,
- new java.lang.String[] { "ColumnNameBytes", "FamilyNameBytes", "DataType", "MaxLength", "Scale", "Nullable", "Position", "SortOrder", "ArraySize", "ViewConstant", "ViewReferenced", "Expression", "IsRowTimestamp", "IsDynamic", "ColumnQualifier", });
+ new java.lang.String[] { "ColumnNameBytes", "FamilyNameBytes", "DataType", "MaxLength", "Scale", "Nullable", "Position", "SortOrder", "ArraySize", "ViewConstant", "ViewReferenced", "Expression", "IsRowTimestamp", "IsDynamic", "EncodedColumnQualifier", });
internal_static_PTableStats_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_PTableStats_fieldAccessorTable = new
@@ -8451,7 +8545,7 @@ public final class PTableProtos {
internal_static_PTable_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_PTable_descriptor,
- new java.lang.String[] { "SchemaNameBytes", "TableNameBytes", "TableType", "IndexState", "SequenceNumber", "TimeStamp", "PkNameBytes", "BucketNum", "Columns", "Indexes", "IsImmutableRows", "DataTableNameBytes", "DefaultFamilyName", "DisableWAL", "MultiTenant", "ViewType", "ViewStatement", "PhysicalNames", "TenantId", "ViewIndexId", "IndexType", "StatsTimeStamp", "StoreNulls", "BaseColumnCount", "RowKeyOrderOptimizable", "Transactional", "UpdateCacheFrequency", "IndexDisableTimestamp", "IsNamespaceMapped", "AutoParititonSeqName", "IsAppendOnlySchema", "ParentNameBytes", "StorageScheme", "EncodedCQCounters", });
+ new java.lang.String[] { "SchemaNameBytes", "TableNameBytes", "TableType", "IndexState", "SequenceNumber", "TimeStamp", "PkNameBytes", "BucketNum", "Columns", "Indexes", "IsImmutableRows", "DataTableNameBytes", "DefaultFamilyName", "DisableWAL", "MultiTenant", "ViewType", "ViewStatement", "PhysicalNames", "TenantId", "ViewIndexId", "IndexType", "StatsTimeStamp", "StoreNulls", "BaseColumnCount", "RowKeyOrderOptimizable", "Transactional", "UpdateCacheFrequency", "IndexDisableTimestamp", "IsNamespaceMapped", "AutoParititonSeqName", "IsAppendOnlySchema", "ParentNameBytes", "StorageScheme", "EncodingScheme", "EncodedCQCounters", });
internal_static_EncodedCQCounter_descriptor =
getDescriptor().getMessageTypes().get(3);
internal_static_EncodedCQCounter_fieldAccessorTable = new
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/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 7c88a25..a876a0b 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
@@ -1716,7 +1716,7 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
return StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
}
if (usesEncodedColumnNames) {
- return StorageScheme.ENCODED_COLUMN_NAMES;
+ return StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS;
}
return StorageScheme.NON_ENCODED_COLUMN_NAMES;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
index cdd9cbc..fc6e3bf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
@@ -272,7 +272,7 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
throws SQLException {
PTable table = context.getCurrentTable().getTable();
StorageScheme storageScheme = table.getStorageScheme();
- checkArgument(storageScheme == StorageScheme.ENCODED_COLUMN_NAMES,
+ checkArgument(storageScheme == StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS,
"Method should only be used for tables using encoded column names");
Pair<Integer, Integer> minMaxQualifiers = new Pair<>();
for (Pair<byte[], byte[]> whereCol : context.getWhereConditionColumns()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/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 bc81447..40952cd 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
@@ -322,6 +322,8 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData {
public static final String STORAGE_SCHEME = "STORAGE_SCHEME";
public static final byte[] STORAGE_SCHEME_BYTES = Bytes.toBytes(STORAGE_SCHEME);
+ public static final String ENCODING_SCHEME = "ENCODING_SCHEME";
+ public static final byte[] ENCODING_SCHEME_BYTES = Bytes.toBytes(ENCODING_SCHEME);
public static final String ENCODED_COLUMN_QUALIFIER = "COLUMN_QUALIFIER";
public static final byte[] ENCODED_COLUMN_QUALIFIER_BYTES = Bytes.toBytes(ENCODED_COLUMN_QUALIFIER);
public static final String COLUMN_QUALIFIER_COUNTER = "QUALIFIER_COUNTER";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/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 e44d83e..954e78a 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
@@ -42,6 +42,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAM
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_VALUE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODING_SCHEME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FUNCTION_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH;
@@ -315,7 +316,8 @@ public interface QueryConstants {
APPEND_ONLY_SCHEMA + " BOOLEAN," +
GUIDE_POSTS_WIDTH + " BIGINT," +
ENCODED_COLUMN_QUALIFIER + " UNSIGNED_INT," +
- STORAGE_SCHEME + " TINYINT, " +
+ STORAGE_SCHEME + " TINYINT, " +
+ ENCODING_SCHEME + " TINYINT, " +
COLUMN_QUALIFIER_COUNTER + " INTEGER, " +
"CONSTRAINT " + SYSTEM_TABLE_PK_NAME + " PRIMARY KEY (" + TENANT_ID + ","
+ TABLE_SCHEM + "," + TABLE_NAME + "," + COLUMN_NAME + "," + COLUMN_FAMILY + "))\n" +
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
index b09fc5f..7168c5e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
@@ -305,4 +305,9 @@ public class DelegateTable implements PTable {
public EncodedCQCounter getEncodedCQCounter() {
return delegate.getEncodedCQCounter();
}
+
+ @Override
+ public QualifierEncodingScheme getEncodingScheme() {
+ return delegate.getEncodingScheme();
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/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 cb20db1..7725877 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
@@ -43,6 +43,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAM
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_VALUE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODING_SCHEME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FUNCTION_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IMMUTABLE_ROWS;
@@ -193,6 +194,7 @@ import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTable.LinkType;
+import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTable.ViewType;
import org.apache.phoenix.schema.stats.GuidePostsKey;
@@ -267,8 +269,9 @@ public class MetaDataClient {
AUTO_PARTITION_SEQ + "," +
APPEND_ONLY_SCHEMA + "," +
GUIDE_POSTS_WIDTH + "," +
- STORAGE_SCHEME +
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ STORAGE_SCHEME + "," +
+ ENCODING_SCHEME +
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String CREATE_SCHEMA = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE
+ "\"( " + TABLE_SCHEM + "," + TABLE_NAME + ") VALUES (?,?)";
@@ -2085,11 +2088,15 @@ public class MetaDataClient {
// since we are storing all columns of a column family in a single key value we can't use deletes to store nulls
storeNulls = true;
} else {
- storageScheme = StorageScheme.ENCODED_COLUMN_NAMES;
+ storageScheme = StorageScheme.COLUMNS_STORED_IN_INDIVIDUAL_CELLS;
}
cqCounter = storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES ? new EncodedCQCounter() : NULL_COUNTER;
}
+ //FIXME: samarth change this once we start having qualifier encoding scheme options
+ QualifierEncodingScheme encodingScheme =
+ storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES ? QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS
+ : QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
Map<String, Integer> changedCqCounters = new HashMap<>(colDefs.size());
for (ColumnDef colDef : colDefs) {
rowTimeStampColumnAlreadyFound = checkAndValidateRowTimestampCol(colDef, pkConstraint, rowTimeStampColumnAlreadyFound, tableType);
@@ -2252,7 +2259,7 @@ public class MetaDataClient {
Collections.<PTable>emptyList(), isImmutableRows,
Collections.<PName>emptyList(), defaultFamilyName == null ? null :
PNameFactory.newName(defaultFamilyName), null,
- Boolean.TRUE.equals(disableWAL), false, false, null, null, indexType, true, false, 0, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, StorageScheme.NON_ENCODED_COLUMN_NAMES, PTable.EncodedCQCounter.NULL_COUNTER);
+ Boolean.TRUE.equals(disableWAL), false, false, null, null, indexType, true, false, 0, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, StorageScheme.NON_ENCODED_COLUMN_NAMES, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER);
connection.addTable(table, MetaDataProtocol.MIN_TABLE_TIMESTAMP);
}
@@ -2406,7 +2413,8 @@ public class MetaDataClient {
} else {
tableUpsert.setLong(25, guidePostsWidth);
}
- tableUpsert.setByte(26, storageScheme.getSerializedValue()); //TODO: samarth should there be a null check here?
+ tableUpsert.setByte(26, storageScheme.getSerializedMetadataValue()); //TODO: samarth should there be a null check here?
+ tableUpsert.setByte(27, encodingScheme.getSerializedMetadataValue());
tableUpsert.execute();
if (asyncCreatedDate != null) {
@@ -2511,7 +2519,7 @@ public class MetaDataClient {
PTable.INITIAL_SEQ_NUM, pkName == null ? null : PNameFactory.newName(pkName), saltBucketNum, columns.values(),
parent == null ? null : parent.getSchemaName(), parent == null ? null : parent.getTableName(), Collections.<PTable>emptyList(), isImmutableRows,
physicalNames, defaultFamilyName == null ? null : PNameFactory.newName(defaultFamilyName), viewStatement, Boolean.TRUE.equals(disableWAL), multiTenant, storeNulls, viewType,
- result.getViewIndexId(), indexType, rowKeyOrderOptimizable, transactional, updateCacheFrequency, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, storageScheme, cqCounterToBe);
+ result.getViewIndexId(), indexType, rowKeyOrderOptimizable, transactional, updateCacheFrequency, 0L, isNamespaceMapped, autoPartitionSeq, isAppendOnlySchema, storageScheme, encodingScheme, cqCounterToBe);
result = new MetaDataMutationResult(code, result.getMutationTime(), table, true);
addTableToCache(result);
return table;
@@ -3603,7 +3611,7 @@ public class MetaDataClient {
sharedTableState.getSchemaName(), sharedTableState.getTableName(), ts,
table.getColumnFamilies(), sharedTableState.getColumns(),
sharedTableState.getPhysicalNames(), sharedTableState.getViewIndexId(),
- table.isMultiTenant(), table.isNamespaceMapped(), table.getStorageScheme(), table.getEncodedCQCounter());
+ table.isMultiTenant(), table.isNamespaceMapped(), table.getStorageScheme(), table.getEncodingScheme(), table.getEncodedCQCounter());
TableRef indexTableRef = new TableRef(viewIndexTable);
PName indexTableTenantId = sharedTableState.getTenantId();
if (indexTableTenantId==null) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/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 e6f8b71..dbb96d5 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
@@ -259,8 +259,8 @@ public class PColumnImpl implements PColumn {
isDynamic = column.getIsDynamic();
}
Integer columnQualifier = null;
- if (column.hasColumnQualifier()) {
- columnQualifier = column.getColumnQualifier();
+ if (column.hasEncodedColumnQualifier()) {
+ columnQualifier = column.getEncodedColumnQualifier();
}
return new PColumnImpl(columnName, familyName, dataType, maxLength, scale, nullable, position, sortOrder,
arraySize, viewConstant, isViewReferenced, expressionStr, isRowTimestamp, isDynamic, columnQualifier);
@@ -295,7 +295,7 @@ public class PColumnImpl implements PColumn {
}
builder.setIsRowTimestamp(column.isRowTimestamp());
if (column.getEncodedColumnQualifier() != null) {
- builder.setColumnQualifier(column.getEncodedColumnQualifier());
+ builder.setEncodedColumnQualifier(column.getEncodedColumnQualifier());
}
return builder.build();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a1de1cb/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
index d3b11b2..afe664b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.schema;
import static org.apache.phoenix.query.QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE;
+import java.nio.ByteOrder;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -163,12 +164,13 @@ public interface PTable extends PMetaDataEntity {
}
public enum StorageScheme {
- ENCODED_COLUMN_NAMES((byte)1),
- NON_ENCODED_COLUMN_NAMES((byte)2),
+ COLUMNS_STORED_IN_INDIVIDUAL_CELLS((byte)1),
+ NON_ENCODED_COLUMN_NAMES((byte)2),//TODO: samarth don't need this as storage scheme. Instead make it an encoding scheme
COLUMNS_STORED_IN_SINGLE_CELL((byte)3);
private final byte[] byteValue;
private final byte serializedValue;
+ private static final ByteOrder BYTE_ORDER = ByteOrder.nativeOrder();
StorageScheme(byte serializedValue) {
this.serializedValue = serializedValue;
@@ -179,7 +181,7 @@ public interface PTable extends PMetaDataEntity {
return byteValue;
}
- public byte getSerializedValue() {
+ public byte getSerializedMetadataValue() {
return this.serializedValue;
}
@@ -190,6 +192,171 @@ public interface PTable extends PMetaDataEntity {
return StorageScheme.values()[serializedValue-1];
}
}
+
+ public static class QualifierEncodingScheme<E> implements QualifierEncoderDecoder<E> {
+
+ public static final QualifierEncodingScheme NON_ENCODED_QUALIFIERS = new QualifierEncodingScheme<String>((byte)0, "NON_ENCODED_QUALIFIERS", null) {
+ @Override
+ public byte[] getEncodedBytes(String value) {
+ return Bytes.toBytes(value);
+ }
+
+ @Override
+ public String getDecodedValue(byte[] bytes) {
+ return Bytes.toString(bytes);
+ }
+
+ @Override
+ public String getDecodedValue(byte[] bytes, int offset, int length) {
+ return Bytes.toString(bytes, offset, length);
+ }
+
+ @Override
+ public boolean isEncodeable(String value) {
+ return true;
+ }
+ };
+ public static final QualifierEncodingScheme ONE_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)1, "ONE_BYTE_QUALIFIERS", 255l) {
+ @Override
+ public byte[] getEncodedBytes(Long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Long getDecodedValue(byte[] bytes) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Long getDecodedValue(byte[] bytes, int offset, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isEncodeable(Long value) {
+ return true;
+ }
+ };
+ public static final QualifierEncodingScheme TWO_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)2, "TWO_BYTE_QUALIFIERS", 65535l) {
+ @Override
+ public byte[] getEncodedBytes(Long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Long getDecodedValue(byte[] bytes) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Long getDecodedValue(byte[] bytes, int offset, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isEncodeable(Long value) {
+ return true;
+ }
+ };
+ public static final QualifierEncodingScheme THREE_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)3, "THREE_BYTE_QUALIFIERS", 16777215l) {
+ @Override
+ public byte[] getEncodedBytes(Long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Long getDecodedValue(byte[] bytes) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Long getDecodedValue(byte[] bytes, int offset, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isEncodeable(Long value) {
+ return true;
+ }
+ };
+ public static final QualifierEncodingScheme FOUR_BYTE_QUALIFIERS = new QualifierEncodingScheme<Long>((byte)4, "FOUR_BYTE_QUALIFIERS", 4294967295l) {
+ @Override
+ public byte[] getEncodedBytes(Long value) {
+ return Bytes.toBytes(value);
+ }
+
+ @Override
+ public Long getDecodedValue(byte[] bytes) {
+ return Bytes.toLong(bytes);
+ }
+
+ @Override
+ public Long getDecodedValue(byte[] bytes, int offset, int length) {
+ return Bytes.toLong(bytes, offset, length);
+ }
+
+ @Override
+ public boolean isEncodeable(Long value) {
+ return true;
+ }
+ };
+ public static final QualifierEncodingScheme[] schemes = {NON_ENCODED_QUALIFIERS, ONE_BYTE_QUALIFIERS, TWO_BYTE_QUALIFIERS, THREE_BYTE_QUALIFIERS, FOUR_BYTE_QUALIFIERS};
+ private final byte[] metadataBytes;
+ private final byte metadataValue;
+ private final Long maxQualifier;
+
+ private QualifierEncodingScheme(byte serializedMetadataValue, String name, Long maxQualifier) {
+ this.metadataValue = serializedMetadataValue;
+ this.metadataBytes = Bytes.toBytes(name);
+ this.maxQualifier = maxQualifier;
+ }
+
+ public byte[] getMetadataBytes() {
+ return metadataBytes;
+ }
+
+ public byte getSerializedMetadataValue() {
+ return this.metadataValue;
+ }
+
+ public static QualifierEncodingScheme fromSerializedValue(byte serializedValue) {
+ if (serializedValue < 0 || serializedValue > schemes.length - 1) {
+ return null;
+ }
+ return schemes[serializedValue];
+ }
+
+ public Long getMaxQualifier() {
+ return maxQualifier;
+ }
+
+ @Override
+ public byte[] getEncodedBytes(E value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public E getDecodedValue(byte[] bytes) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public E getDecodedValue(byte[] bytes, int offset, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isEncodeable(E value) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ interface QualifierEncoderDecoder<E> {
+ byte[] getEncodedBytes(E value);
+ E getDecodedValue(byte[] bytes);
+ E getDecodedValue(byte[] bytes, int offset, int length);
+ boolean isEncodeable(E value);
+ }
long getTimeStamp();
long getSequenceNumber();
@@ -405,6 +572,7 @@ public interface PTable extends PMetaDataEntity {
*/
boolean isAppendOnlySchema();
StorageScheme getStorageScheme();
+ QualifierEncodingScheme getEncodingScheme();
EncodedCQCounter getEncodedCQCounter();
/**
@@ -472,7 +640,7 @@ public interface PTable extends PMetaDataEntity {
/**
*
* @param columnFamily
- * @return true if the counter was incrememnted, false otherwise.
+ * @return true if the counter was incremented, false otherwise.
*/
public boolean increment(String columnFamily) {
if (columnFamily == null) {
[24/42] phoenix git commit: Fail-fast iterators for
EncodedColumnQualifierCellsList. Use list iterators instead of get(index) for
navigating lists. Use HBase bytes utility for encoded column names. Fix test
failures for immutable tables and indexes.
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
index 8e4d9aa..f5df980 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
@@ -71,6 +71,7 @@ import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
@@ -125,10 +126,12 @@ public class FromCompiler {
throw new ColumnNotFoundException(schemaName, tableName, null, colName);
}
+ @Override
public PFunction resolveFunction(String functionName) throws SQLException {
throw new FunctionNotFoundException(functionName);
}
+ @Override
public boolean hasUDFs() {
return false;
}
@@ -185,7 +188,7 @@ public class FromCompiler {
if (htable != null) Closeables.closeQuietly(htable);
}
tableNode = NamedTableNode.create(null, baseTable, statement.getColumnDefs());
- return new SingleTableColumnResolver(connection, tableNode, e.getTimeStamp(), new HashMap<String, UDFParseNode>(1), false);
+ return new SingleTableColumnResolver(connection, tableNode, e.getTimeStamp(), new HashMap<String, UDFParseNode>(1), false, false);
}
throw e;
}
@@ -257,7 +260,7 @@ public class FromCompiler {
Expression sourceExpression = projector.getColumnProjector(column.getPosition()).getExpression();
PColumnImpl projectedColumn = new PColumnImpl(column.getName(), column.getFamilyName(),
sourceExpression.getDataType(), sourceExpression.getMaxLength(), sourceExpression.getScale(), sourceExpression.isNullable(),
- column.getPosition(), sourceExpression.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(), column.isDynamic());
+ column.getPosition(), sourceExpression.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(), column.isDynamic(), column.getEncodedColumnQualifier());
projectedColumns.add(projectedColumn);
}
PTable t = PTableImpl.makePTable(table, projectedColumns);
@@ -332,26 +335,26 @@ public class FromCompiler {
private final String alias;
private final List<PSchema> schemas;
- public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode table, long timeStamp, Map<String, UDFParseNode> udfParseNodes, boolean isNamespaceMapped) throws SQLException {
- super(connection, 0, false, udfParseNodes);
- List<PColumnFamily> families = Lists.newArrayListWithExpectedSize(table.getDynamicColumns().size());
- for (ColumnDef def : table.getDynamicColumns()) {
- if (def.getColumnDefName().getFamilyName() != null) {
- families.add(new PColumnFamilyImpl(PNameFactory.newName(def.getColumnDefName().getFamilyName()),Collections.<PColumn>emptyList()));
- }
+ public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode table, long timeStamp, Map<String, UDFParseNode> udfParseNodes, boolean isNamespaceMapped, boolean useEncodedColumnNames) throws SQLException {
+ super(connection, 0, false, udfParseNodes);
+ List<PColumnFamily> families = Lists.newArrayListWithExpectedSize(table.getDynamicColumns().size());
+ for (ColumnDef def : table.getDynamicColumns()) {
+ if (def.getColumnDefName().getFamilyName() != null) {
+ families.add(new PColumnFamilyImpl(PNameFactory.newName(def.getColumnDefName().getFamilyName()),Collections.<PColumn>emptyList(), useEncodedColumnNames));
+ }
}
Long scn = connection.getSCN();
String schema = table.getName().getSchemaName();
if (connection.getSchema() != null) {
schema = schema != null ? schema : connection.getSchema();
}
- PTable theTable = new PTableImpl(connection.getTenantId(), schema, table.getName().getTableName(),
+ PTable theTable = new PTableImpl(connection.getTenantId(), schema, table.getName().getTableName(),
scn == null ? HConstants.LATEST_TIMESTAMP : scn, families, isNamespaceMapped);
- theTable = this.addDynamicColumns(table.getDynamicColumns(), theTable);
- alias = null;
- tableRefs = ImmutableList.of(new TableRef(alias, theTable, timeStamp, !table.getDynamicColumns().isEmpty()));
- schemas = ImmutableList.of(new PSchema(theTable.getSchemaName().toString(), timeStamp));
- }
+ theTable = this.addDynamicColumns(table.getDynamicColumns(), theTable);
+ alias = null;
+ tableRefs = ImmutableList.of(new TableRef(alias, theTable, timeStamp, !table.getDynamicColumns().isEmpty()));
+ schemas = ImmutableList.of(new PSchema(theTable.getSchemaName().toString(), timeStamp));
+ }
public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode tableNode, boolean updateCacheImmediately) throws SQLException {
this(connection, tableNode, updateCacheImmediately, 0, new HashMap<String,UDFParseNode>(1));
@@ -447,8 +450,8 @@ public class FromCompiler {
}
PColumn column = resolveCF
- ? tableRef.getTable().getColumnFamily(tableName).getColumn(colName)
- : tableRef.getTable().getColumn(colName);
+ ? tableRef.getTable().getColumnFamily(tableName).getPColumnForColumnName(colName)
+ : tableRef.getTable().getPColumnForColumnName(colName);
return new ColumnRef(tableRef, column.getPosition());
}
@@ -671,8 +674,9 @@ public class FromCompiler {
theTable.getColumnFamily(family); // Verifies that column family exists
familyName = PNameFactory.newName(family);
}
+ // Dynamic columns don't have an encoded column name
allcolumns.add(new PColumnImpl(name, familyName, dynColumn.getDataType(), dynColumn.getMaxLength(),
- dynColumn.getScale(), dynColumn.isNull(), position, dynColumn.getSortOrder(), dynColumn.getArraySize(), null, false, dynColumn.getExpression(), false, true));
+ dynColumn.getScale(), dynColumn.isNull(), position, dynColumn.getSortOrder(), dynColumn.getArraySize(), null, false, dynColumn.getExpression(), false, true, null));
position++;
}
theTable = PTableImpl.makePTable(theTable, allcolumns);
@@ -776,14 +780,14 @@ public class FromCompiler {
}
PColumnImpl column = new PColumnImpl(PNameFactory.newName(alias),
PNameFactory.newName(QueryConstants.DEFAULT_COLUMN_FAMILY),
- null, 0, 0, true, position++, SortOrder.ASC, null, null, false, null, false, false);
+ null, 0, 0, true, position++, SortOrder.ASC, null, null, false, null, false, false, null);
columns.add(column);
}
PTable t = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME, PTableType.SUBQUERY, null,
MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM, null, null, columns, null, null,
Collections.<PTable> emptyList(), false, Collections.<PName> emptyList(), null, null, false, false,
false, null, null, null, false, false, 0, 0L, SchemaUtil
- .isNamespaceMappingEnabled(PTableType.SUBQUERY, connection.getQueryServices().getProps()), null, false);
+ .isNamespaceMappingEnabled(PTableType.SUBQUERY, connection.getQueryServices().getProps()), null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, PTable.EncodedCQCounter.NULL_COUNTER);
String alias = subselectNode.getAlias();
TableRef tableRef = new TableRef(alias, t, MetaDataProtocol.MIN_TABLE_TIMESTAMP, false);
@@ -858,7 +862,7 @@ public class FromCompiler {
while (iterator.hasNext()) {
TableRef tableRef = iterator.next();
try {
- PColumn column = tableRef.getTable().getColumn(colName);
+ PColumn column = tableRef.getTable().getPColumnForColumnName(colName);
if (theTableRef != null) { throw new AmbiguousColumnException(colName); }
theTableRef = tableRef;
theColumnPosition = column.getPosition();
@@ -871,12 +875,12 @@ public class FromCompiler {
} else {
try {
TableRef tableRef = resolveTable(schemaName, tableName);
- PColumn column = tableRef.getTable().getColumn(colName);
+ PColumn column = tableRef.getTable().getPColumnForColumnName(colName);
return new ColumnRef(tableRef, column.getPosition());
} catch (TableNotFoundException e) {
// Try using the tableName as a columnFamily reference instead
ColumnFamilyRef cfRef = resolveColumnFamily(schemaName, tableName);
- PColumn column = cfRef.getFamily().getColumn(colName);
+ PColumn column = cfRef.getFamily().getPColumnForColumnName(colName);
return new ColumnRef(cfRef.getTableRef(), column.getPosition());
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index e8c05ca..489b993 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -76,6 +76,7 @@ import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.ProjectedColumn;
@@ -93,6 +94,7 @@ import org.apache.phoenix.schema.types.PTimestamp;
import org.apache.phoenix.schema.types.PTinyint;
import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -714,7 +716,7 @@ public class JoinCompiler {
if (columnRef.getTableRef().equals(tableRef)
&& !SchemaUtil.isPKColumn(columnRef.getColumn())
&& !(columnRef instanceof LocalIndexColumnRef)) {
- scan.addColumn(columnRef.getColumn().getFamilyName().getBytes(), columnRef.getColumn().getName().getBytes());
+ EncodedColumnsUtil.setColumns(columnRef.getColumn(), tableRef.getTable(), scan);
}
}
}
@@ -1301,7 +1303,7 @@ public class JoinCompiler {
if (left.getBucketNum() != null) {
merged.remove(0);
}
-
+ //TODO: samarth should projected join table should always have non-encoded column names? Is this where we also decide that once we start supporting joins then have the storage scheme right.
return PTableImpl.makePTable(left.getTenantId(), left.getSchemaName(),
PNameFactory.newName(SchemaUtil.getTableName(left.getName().getString(), right.getName().getString())),
left.getType(), left.getIndexState(), left.getTimeStamp(), left.getSequenceNumber(), left.getPKName(),
@@ -1310,7 +1312,7 @@ public class JoinCompiler {
left.isMultiTenant(), left.getStoreNulls(), left.getViewType(), left.getViewIndexId(),
left.getIndexType(), left.rowKeyOrderOptimizable(), left.isTransactional(),
left.getUpdateCacheFrequency(), left.getIndexDisableTimestamp(), left.isNamespaceMapped(),
- left.getAutoPartitionSeqName(), left.isAppendOnlySchema());
+ left.getAutoPartitionSeqName(), left.isAppendOnlySchema(), StorageScheme.NON_ENCODED_COLUMN_NAMES, PTable.EncodedCQCounter.NULL_COUNTER);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
index 2df0671..436e69b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
@@ -80,7 +80,7 @@ public class ListJarsQueryPlan implements QueryPlan {
PColumn column =
new PColumnImpl(PNameFactory.newName("jar_location"), null,
PVarchar.INSTANCE, null, null, false, 0, SortOrder.getDefault(), 0, null,
- false, null, false, false);
+ false, null, false, false, null);
List<PColumn> columns = new ArrayList<PColumn>();
columns.add(column);
Expression expression =
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
index 393499a..3820ee5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
@@ -50,6 +50,7 @@ import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.ScanUtil;
import org.apache.phoenix.util.TransactionUtil;
@@ -176,8 +177,8 @@ public class PostDDLCompiler {
@Override
public ColumnRef resolveColumn(String schemaName, String tableName, String colName) throws SQLException {
PColumn column = tableName != null
- ? tableRef.getTable().getColumnFamily(tableName).getColumn(colName)
- : tableRef.getTable().getColumn(colName);
+ ? tableRef.getTable().getColumnFamily(tableName).getPColumnForColumnName(colName)
+ : tableRef.getTable().getPColumnForColumnName(colName);
return new ColumnRef(tableRef, column.getPosition());
}
@@ -213,6 +214,7 @@ public class PostDDLCompiler {
ScanUtil.setTimeRange(scan, scan.getTimeRange().getMin(), ts);
if (emptyCF != null) {
scan.setAttribute(BaseScannerRegionObserver.EMPTY_CF, emptyCF);
+ scan.setAttribute(BaseScannerRegionObserver.EMPTY_COLUMN_QUALIFIER, EncodedColumnsUtil.getEmptyKeyValueInfo(tableRef.getTable()).getFirst());
}
ServerCache cache = null;
try {
@@ -236,11 +238,12 @@ public class PostDDLCompiler {
// data empty column family to stay the same, while the index empty column family
// changes.
PColumn column = deleteList.get(0);
+ byte[] cq = EncodedColumnsUtil.getColumnQualifier(column, tableRef.getTable());
if (emptyCF == null) {
- scan.addColumn(column.getFamilyName().getBytes(), column.getName().getBytes());
+ scan.addColumn(column.getFamilyName().getBytes(), cq);
}
scan.setAttribute(BaseScannerRegionObserver.DELETE_CF, column.getFamilyName().getBytes());
- scan.setAttribute(BaseScannerRegionObserver.DELETE_CQ, column.getName().getBytes());
+ scan.setAttribute(BaseScannerRegionObserver.DELETE_CQ, cq);
}
}
List<byte[]> columnFamilies = Lists.newArrayListWithExpectedSize(tableRef.getTable().getColumnFamilies().size());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
index 81dbe0d..d6fd6ff 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
@@ -31,6 +31,7 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.jdbc.PhoenixStatement.Operation;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.tuple.Tuple;
@@ -82,7 +83,11 @@ public class PostLocalIndexDDLCompiler {
// However, in this case, we need to project all of the data columns that contribute to the index.
IndexMaintainer indexMaintainer = index.getIndexMaintainer(dataTable, connection);
for (ColumnReference columnRef : indexMaintainer.getAllColumns()) {
- scan.addColumn(columnRef.getFamily(), columnRef.getQualifier());
+ if (index.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ scan.addFamily(columnRef.getFamily());
+ } else {
+ scan.addColumn(columnRef.getFamily(), columnRef.getQualifier());
+ }
}
// Go through MutationPlan abstraction so that we can create local indexes
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 99a9731..25aee35 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
@@ -88,6 +88,7 @@ import org.apache.phoenix.schema.ValueBitSet;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.SizedUtil;
@@ -217,7 +218,7 @@ public class ProjectionCompiler {
PColumn indexColumn = null;
ColumnRef ref = null;
try {
- indexColumn = index.getColumn(indexColName);
+ indexColumn = index.getPColumnForColumnName(indexColName);
ref = new ColumnRef(tableRef, indexColumn.getPosition());
} catch (ColumnNotFoundException e) {
if (index.getIndexType() == IndexType.LOCAL) {
@@ -289,7 +290,7 @@ public class ProjectionCompiler {
ColumnRef ref = null;
String indexColumnFamily = null;
try {
- indexColumn = index.getColumn(indexColName);
+ indexColumn = index.getPColumnForColumnName(indexColName);
ref = new ColumnRef(tableRef, indexColumn.getPosition());
indexColumnFamily = indexColumn.getFamilyName() == null ? null : indexColumn.getFamilyName().getString();
} catch (ColumnNotFoundException e) {
@@ -484,7 +485,7 @@ public class ProjectionCompiler {
}
} else {
for (byte[] cq : entry.getValue()) {
- PColumn column = family.getColumn(cq);
+ PColumn column = family.getPColumnForColumnQualifier(cq);
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;
@@ -663,7 +664,8 @@ public class ProjectionCompiler {
public Void visit(ProjectedColumnExpression expression) {
if (expression.getDataType().isArrayType()) {
indexProjectedColumns.add(expression);
- KeyValueColumnExpression keyValueColumnExpression = new KeyValueColumnExpression(expression.getColumn());
+ PColumn col = expression.getColumn();
+ KeyValueColumnExpression keyValueColumnExpression = new KeyValueColumnExpression(col, EncodedColumnsUtil.hasEncodedColumnName(col));
indexKVs.add(keyValueColumnExpression);
copyOfChildren.set(0, keyValueColumnExpression);
Integer count = arrayExpressionCounts.get(expression);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
index 2258f28..5126c8b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
@@ -94,7 +94,7 @@ public class QueryCompiler {
*/
private static final String LOAD_COLUMN_FAMILIES_ON_DEMAND_ATTR = "_ondemand_";
private final PhoenixStatement statement;
- private final Scan scan;
+ private final Scan scan;
private final Scan originalScan;
private final ColumnResolver resolver;
private final SelectStatement select;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
index ed5cda9..10260cb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
@@ -78,7 +78,7 @@ public class TraceQueryPlan implements QueryPlan {
PColumn column =
new PColumnImpl(PNameFactory.newName(MetricInfo.TRACE.columnName), null,
PLong.INSTANCE, null, null, false, 0, SortOrder.getDefault(), 0, null,
- false, null, false, false);
+ false, null, false, false, null);
List<PColumn> columns = new ArrayList<PColumn>();
columns.add(column);
Expression expression =
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
index 4d3c0cf..c472039 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
@@ -17,6 +17,8 @@
*/
package org.apache.phoenix.compile;
+import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_FAMILY;
+
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
@@ -24,7 +26,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.apache.phoenix.execute.TupleProjector;
import org.apache.phoenix.parse.AliasedNode;
import org.apache.phoenix.parse.ColumnParseNode;
import org.apache.phoenix.parse.FamilyWildcardParseNode;
@@ -43,11 +44,14 @@ import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.ProjectedColumn;
import org.apache.phoenix.schema.TableRef;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -136,7 +140,7 @@ public class TupleProjectionCompiler {
projectedColumns.add(column);
// Wildcard or FamilyWildcard will be handled by ProjectionCompiler.
if (!isWildcard && !families.contains(sourceColumn.getFamilyName())) {
- context.getScan().addColumn(sourceColumn.getFamilyName().getBytes(), sourceColumn.getName().getBytes());
+ EncodedColumnsUtil.setColumns(column, table, context.getScan());
}
}
// add LocalIndexDataColumnRef
@@ -154,9 +158,9 @@ public class TupleProjectionCompiler {
null, null, table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(),
table.getViewIndexId(),
table.getIndexType(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(),
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
-
+
public static PTable createProjectedTable(TableRef tableRef, List<ColumnRef> sourceColumnRefs, boolean retainPKColumns) throws SQLException {
PTable table = tableRef.getTable();
boolean hasSaltingColumn = retainPKColumns && table.getBucketNum() != null;
@@ -172,17 +176,22 @@ public class TupleProjectionCompiler {
PColumn column = new ProjectedColumn(PNameFactory.newName(aliasedName),
retainPKColumns && SchemaUtil.isPKColumn(sourceColumn) ?
- null : PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY),
+ null : PNameFactory.newName(VALUE_COLUMN_FAMILY),
position++, sourceColumn.isNullable(), sourceColumnRef);
projectedColumns.add(column);
}
+ StorageScheme storageScheme = table.getStorageScheme();
+ EncodedCQCounter cqCounter = EncodedCQCounter.NULL_COUNTER;
+ if (storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES) {
+ cqCounter = EncodedCQCounter.copy(table.getEncodedCQCounter());
+ }
return PTableImpl.makePTable(table.getTenantId(), PROJECTED_TABLE_SCHEMA, table.getName(), PTableType.PROJECTED,
null, table.getTimeStamp(), table.getSequenceNumber(), table.getPKName(),
retainPKColumns ? table.getBucketNum() : null, projectedColumns, null, null,
Collections.<PTable> emptyList(), table.isImmutableRows(), Collections.<PName> emptyList(), null, null,
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(),
table.getViewIndexId(), null, table.rowKeyOrderOptimizable(), table.isTransactional(),
- table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), storageScheme, cqCounter);
}
// For extracting column references from single select statement
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
index bc3466c..d779df1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UnionCompiler.java
@@ -39,6 +39,7 @@ import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableRef;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.util.SchemaUtil;
@@ -88,7 +89,7 @@ public class UnionCompiler {
UNION_FAMILY_NAME, targetTypes.get(i).getType(), targetTypes.get(i).getMaxLength(),
targetTypes.get(i).getScale(), colProj.getExpression().isNullable(), i,
targetTypes.get(i).getSortOrder(), 500, null, false,
- colProj.getExpression().toString(), false, false);
+ colProj.getExpression().toString(), false, false, null);
projectedColumns.add(projectedColumn);
}
Long scn = statement.getConnection().getSCN();
@@ -98,7 +99,7 @@ public class UnionCompiler {
null, null, projectedColumns, null, null, null, true, null, null, null, true,
true, true, null, null, null, false, false, 0, 0L,
SchemaUtil.isNamespaceMappingEnabled(PTableType.SUBQUERY,
- statement.getConnection().getQueryServices().getProps()), null, false);
+ statement.getConnection().getQueryServices().getProps()), null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, PTable.EncodedCQCounter.NULL_COUNTER);
TableRef tableRef = new TableRef(null, tempTable, 0, false);
return tableRef;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 8837445..fbe07df 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -903,10 +903,11 @@ public class UpsertCompiler {
UpdateColumnCompiler compiler = new UpdateColumnCompiler(context);
int nColumns = onDupKeyPairs.size();
List<Expression> updateExpressions = Lists.newArrayListWithExpectedSize(nColumns);
- LinkedHashSet<PColumn>updateColumns = Sets.newLinkedHashSetWithExpectedSize(nColumns + 1);
+ LinkedHashSet<PColumn> updateColumns = Sets.newLinkedHashSetWithExpectedSize(nColumns + 1);
+ //TODO: samarth verify if we should pass the column qualifier as null here.
updateColumns.add(new PColumnImpl(
table.getPKColumns().get(0).getName(), // Use first PK column name as we know it won't conflict with others
- null, PVarbinary.INSTANCE, null, null, false, 0, SortOrder.getDefault(), 0, null, false, null, false, false));
+ null, PVarbinary.INSTANCE, null, null, false, 0, SortOrder.getDefault(), 0, null, false, null, false, false, null));
for (Pair<ColumnName,ParseNode> columnPair : onDupKeyPairs) {
ColumnName colName = columnPair.getFirst();
PColumn updateColumn = resolver.resolveColumn(null, colName.getFamilyName(), colName.getColumnName()).getColumn();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 39451b8..e42ec26 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -51,12 +51,14 @@ import org.apache.phoenix.schema.ColumnNotFoundException;
import org.apache.phoenix.schema.ColumnRef;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.TypeMismatchException;
import org.apache.phoenix.schema.types.PBoolean;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.ExpressionUtil;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.ScanUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -169,12 +171,14 @@ public class WhereCompiler {
public Expression visit(ColumnParseNode node) throws SQLException {
ColumnRef ref = resolveColumn(node);
TableRef tableRef = ref.getTableRef();
+ Expression newColumnExpression = ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive());
if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(ref.getColumn())) {
+ byte[] cq = tableRef.getTable().getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL
+ ? ref.getColumn().getFamilyName().getBytes() : EncodedColumnsUtil.getColumnQualifier(ref.getColumn(), tableRef.getTable());
// track the where condition columns. Later we need to ensure the Scan in HRS scans these column CFs
- context.addWhereCoditionColumn(ref.getColumn().getFamilyName().getBytes(), ref.getColumn().getName()
- .getBytes());
+ context.addWhereCoditionColumn(ref.getColumn().getFamilyName().getBytes(), cq);
}
- return ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive());
+ return newColumnExpression;
}
@Override
@@ -195,7 +199,7 @@ public class WhereCompiler {
// just use that.
try {
if (!SchemaUtil.isPKColumn(ref.getColumn())) {
- table.getColumn(ref.getColumn().getName().getString());
+ table.getPColumnForColumnName(ref.getColumn().getName().getString());
}
} catch (AmbiguousColumnException e) {
disambiguateWithFamily = true;
@@ -223,6 +227,7 @@ public class WhereCompiler {
}
}
+
public Count getCount() {
return count;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
index ba9f7c8..9589c37 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
@@ -50,6 +50,8 @@ import org.apache.phoenix.schema.KeyValueSchema;
import org.apache.phoenix.schema.StaleRegionBoundaryCacheException;
import org.apache.phoenix.schema.ValueBitSet;
import org.apache.phoenix.schema.tuple.MultiKeyValueTuple;
+import org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple;
+import org.apache.phoenix.schema.tuple.PositionBasedResultTuple;
import org.apache.phoenix.schema.tuple.ResultTuple;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.IndexUtil;
@@ -77,12 +79,14 @@ abstract public class BaseScannerRegionObserver extends BaseRegionObserver {
public static final String DELETE_CQ = "_DeleteCQ";
public static final String DELETE_CF = "_DeleteCF";
public static final String EMPTY_CF = "_EmptyCF";
+ public static final String EMPTY_COLUMN_QUALIFIER = "_EmptyColumnQualifier";
public static final String SPECIFIC_ARRAY_INDEX = "_SpecificArrayIndex";
public static final String GROUP_BY_LIMIT = "_GroupByLimit";
public static final String LOCAL_INDEX = "_LocalIndex";
public static final String LOCAL_INDEX_BUILD = "_LocalIndexBuild";
public static final String LOCAL_INDEX_JOIN_SCHEMA = "_LocalIndexJoinSchema";
public static final String DATA_TABLE_COLUMNS_TO_JOIN = "_DataTableColumnsToJoin";
+ public static final String COLUMNS_STORED_IN_SINGLE_CELL = "_ColumnsStoredInSingleCell";
public static final String VIEW_CONSTANTS = "_ViewConstants";
public static final String EXPECTED_UPPER_REGION_KEY = "_ExpectedUpperRegionKey";
public static final String REVERSE_SCAN = "_ReverseScan";
@@ -101,6 +105,8 @@ abstract public class BaseScannerRegionObserver extends BaseRegionObserver {
public final static String SCAN_OFFSET = "_RowOffset";
public static final String SCAN_START_ROW_SUFFIX = "_ScanStartRowSuffix";
public static final String SCAN_STOP_ROW_SUFFIX = "_ScanStopRowSuffix";
+ public final static String MIN_QUALIFIER = "_MinQualifier";
+ public final static String MAX_QUALIFIER = "_MaxQualifier";
/**
* Attribute name used to pass custom annotations in Scans and Mutations (later). Custom annotations
@@ -307,14 +313,14 @@ abstract public class BaseScannerRegionObserver extends BaseRegionObserver {
* @param indexMaintainer
* @param viewConstants
*/
- protected RegionScanner getWrappedScanner(final ObserverContext<RegionCoprocessorEnvironment> c,
+ RegionScanner getWrappedScanner(final ObserverContext<RegionCoprocessorEnvironment> c,
final RegionScanner s, final int offset, final Scan scan,
final ColumnReference[] dataColumns, final TupleProjector tupleProjector,
final HRegion dataRegion, final IndexMaintainer indexMaintainer,
final byte[][] viewConstants, final TupleProjector projector,
- final ImmutableBytesWritable ptr) {
+ final ImmutableBytesWritable ptr, final boolean useQualiferAsListIndex) {
return getWrappedScanner(c, s, null, null, offset, scan, dataColumns, tupleProjector,
- dataRegion, indexMaintainer, null, viewConstants, null, null, projector, ptr);
+ dataRegion, indexMaintainer, null, viewConstants, null, null, projector, ptr, useQualiferAsListIndex);
}
/**
@@ -332,7 +338,7 @@ abstract public class BaseScannerRegionObserver extends BaseRegionObserver {
* @param tx current transaction
* @param viewConstants
*/
- protected RegionScanner getWrappedScanner(final ObserverContext<RegionCoprocessorEnvironment> c,
+ RegionScanner getWrappedScanner(final ObserverContext<RegionCoprocessorEnvironment> c,
final RegionScanner s, final Set<KeyValueColumnExpression> arrayKVRefs,
final Expression[] arrayFuncRefs, final int offset, final Scan scan,
final ColumnReference[] dataColumns, final TupleProjector tupleProjector,
@@ -340,7 +346,7 @@ abstract public class BaseScannerRegionObserver extends BaseRegionObserver {
Transaction tx,
final byte[][] viewConstants, final KeyValueSchema kvSchema,
final ValueBitSet kvSchemaBitSet, final TupleProjector projector,
- final ImmutableBytesWritable ptr) {
+ final ImmutableBytesWritable ptr, final boolean useQualifierAsListIndex) {
return new RegionScanner() {
private boolean hasReferences = checkForReferenceFiles();
@@ -437,11 +443,13 @@ abstract public class BaseScannerRegionObserver extends BaseRegionObserver {
tupleProjector, dataRegion, indexMaintainer, viewConstants, ptr);
}
if (projector != null) {
- Tuple tuple = projector.projectResults(new ResultTuple(Result.create(result)));
+ Tuple toProject = useQualifierAsListIndex ? new PositionBasedResultTuple(result) : new ResultTuple(Result.create(result));
+ Tuple tuple = projector.projectResults(toProject);
result.clear();
result.add(tuple.getValue(0));
- if(arrayElementCell != null)
+ if (arrayElementCell != null) {
result.add(arrayElementCell);
+ }
}
// There is a scanattribute set to retrieve the specific array element
return next;
@@ -475,7 +483,8 @@ abstract public class BaseScannerRegionObserver extends BaseRegionObserver {
tupleProjector, dataRegion, indexMaintainer, viewConstants, ptr);
}
if (projector != null) {
- Tuple tuple = projector.projectResults(new ResultTuple(Result.create(result)));
+ Tuple toProject = useQualifierAsListIndex ? new PositionBasedMultiKeyValueTuple(result) : new ResultTuple(Result.create(result));
+ Tuple tuple = projector.projectResults(toProject);
result.clear();
result.add(tuple.getValue(0));
if(arrayElementCell != null)
@@ -528,21 +537,6 @@ abstract public class BaseScannerRegionObserver extends BaseRegionObserver {
// Using KeyValueSchema to set and retrieve the value
// collect the first kv to get the row
Cell rowKv = result.get(0);
- for (KeyValueColumnExpression kvExp : arrayKVRefs) {
- if (kvExp.evaluate(tuple, ptr)) {
- for (int idx = tuple.size() - 1; idx >= 0; idx--) {
- Cell kv = tuple.getValue(idx);
- if (Bytes.equals(kvExp.getColumnFamily(), 0, kvExp.getColumnFamily().length,
- kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength())
- && Bytes.equals(kvExp.getColumnName(), 0, kvExp.getColumnName().length,
- kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength())) {
- // remove the kv that has the full array values.
- result.remove(idx);
- break;
- }
- }
- }
- }
byte[] value = kvSchema.toBytes(tuple, arrayFuncRefs,
kvSchemaBitSet, ptr);
// Add a dummy kv with the exact value of the array index
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionScanner.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionScanner.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionScanner.java
index 8cb6dac..0843ba2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionScanner.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/DelegateRegionScanner.java
@@ -56,22 +56,27 @@ public class DelegateRegionScanner implements RegionScanner {
delegate.close();
}
+ @Override
public long getMaxResultSize() {
return delegate.getMaxResultSize();
}
+ @Override
public boolean next(List<Cell> arg0, int arg1) throws IOException {
return delegate.next(arg0, arg1);
}
+ @Override
public boolean next(List<Cell> arg0) throws IOException {
return delegate.next(arg0);
}
+ @Override
public boolean nextRaw(List<Cell> arg0, int arg1) throws IOException {
return delegate.nextRaw(arg0, arg1);
}
+ @Override
public boolean nextRaw(List<Cell> arg0) throws IOException {
return delegate.nextRaw(arg0);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
index 49e3d71..66cd288 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
@@ -24,6 +24,7 @@ import static org.apache.phoenix.query.QueryServices.GROUPBY_ESTIMATED_DISTINCT_
import static org.apache.phoenix.query.QueryServices.GROUPBY_SPILLABLE_ATTRIB;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_GROUPBY_ESTIMATED_DISTINCT_VALUES;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_GROUPBY_SPILLABLE;
+import static org.apache.phoenix.util.ScanUtil.getMinMaxQualifiersFromScan;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -46,6 +47,7 @@ import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.RegionScanner;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.io.WritableUtils;
import org.apache.phoenix.cache.GlobalCache;
import org.apache.phoenix.cache.TenantCache;
@@ -62,7 +64,10 @@ import org.apache.phoenix.join.HashJoinInfo;
import org.apache.phoenix.memory.MemoryManager.MemoryChunk;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.tuple.EncodedColumnQualiferCellsList;
import org.apache.phoenix.schema.tuple.MultiKeyValueTuple;
+import org.apache.phoenix.schema.tuple.PositionBasedMultiKeyValueTuple;
+import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.util.Closeables;
import org.apache.phoenix.util.IndexUtil;
@@ -131,6 +136,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
final TupleProjector p = TupleProjector.deserializeProjectorFromScan(scan);
final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan);
+ boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(ScanUtil.getMinMaxQualifiersFromScan(scan));
if (ScanUtil.isLocalIndex(scan) || (j == null && p != null)) {
if (dataColumns != null) {
tupleProjector = IndexUtil.getTupleProjector(scan, dataColumns);
@@ -139,13 +145,13 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
ImmutableBytesPtr tempPtr = new ImmutableBytesPtr();
innerScanner =
getWrappedScanner(c, innerScanner, offset, scan, dataColumns, tupleProjector,
- c.getEnvironment().getRegion(), indexMaintainers == null ? null : indexMaintainers.get(0), viewConstants, p, tempPtr);
+ c.getEnvironment().getRegion(), indexMaintainers == null ? null : indexMaintainers.get(0), viewConstants, p, tempPtr, useQualifierAsIndex);
}
if (j != null) {
innerScanner =
new HashJoinRegionScanner(innerScanner, p, j, ScanUtil.getTenantId(scan),
- c.getEnvironment());
+ c.getEnvironment(), useQualifierAsIndex);
}
long limit = Long.MAX_VALUE;
@@ -377,7 +383,8 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
estDistVals = Math.max(MIN_DISTINCT_VALUES,
(int) (Bytes.toInt(estDistValsBytes) * 1.5f));
}
-
+ Pair<Integer, Integer> minMaxQualifiers = getMinMaxQualifiersFromScan(scan);
+ boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(ScanUtil.getMinMaxQualifiersFromScan(scan));
final boolean spillableEnabled =
conf.getBoolean(GROUPBY_SPILLABLE_ATTRIB, DEFAULT_GROUPBY_SPILLABLE);
@@ -388,12 +395,10 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
boolean success = false;
try {
boolean hasMore;
-
- MultiKeyValueTuple result = new MultiKeyValueTuple();
+ Tuple result = useQualifierAsIndex ? new PositionBasedMultiKeyValueTuple() : new MultiKeyValueTuple();
if (logger.isDebugEnabled()) {
logger.debug(LogUtil.addCustomAnnotations("Spillable groupby enabled: " + spillableEnabled, ScanUtil.getCustomAnnotations(scan)));
}
-
HRegion region = c.getEnvironment().getRegion();
boolean acquiredLock = false;
try {
@@ -401,7 +406,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
acquiredLock = true;
synchronized (scanner) {
do {
- List<Cell> results = new ArrayList<Cell>();
+ List<Cell> results = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond()) : new ArrayList<Cell>();
// Results are potentially returned even when the return
// value of s.next is false
// since this is an indication of whether or not there are
@@ -436,7 +441,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
}
}
}
-
+
/**
* Used for an aggregate query in which the key order match the group by key order. In this
* case, we can do the aggregation as we scan, by detecting when the group by key changes.
@@ -451,6 +456,8 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
logger.debug(LogUtil.addCustomAnnotations("Grouped aggregation over ordered rows with scan " + scan + ", group by "
+ expressions + ", aggregators " + aggregators, ScanUtil.getCustomAnnotations(scan)));
}
+ final Pair<Integer, Integer> minMaxQualifiers = getMinMaxQualifiersFromScan(scan);
+ final boolean useQualifierAsIndex = ScanUtil.useQualifierAsIndex(minMaxQualifiers);
return new BaseRegionScanner(scanner) {
private long rowCount = 0;
private ImmutableBytesPtr currentKey = null;
@@ -460,7 +467,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
boolean hasMore;
boolean atLimit;
boolean aggBoundary = false;
- MultiKeyValueTuple result = new MultiKeyValueTuple();
+ Tuple result = useQualifierAsIndex ? new PositionBasedMultiKeyValueTuple() : new MultiKeyValueTuple();
ImmutableBytesPtr key = null;
Aggregator[] rowAggregators = aggregators.getAggregators();
// If we're calculating no aggregate functions, we can exit at the
@@ -473,7 +480,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
acquiredLock = true;
synchronized (scanner) {
do {
- List<Cell> kvs = new ArrayList<Cell>();
+ List<Cell> kvs = useQualifierAsIndex ? new EncodedColumnQualiferCellsList(minMaxQualifiers.getFirst(), minMaxQualifiers.getSecond()) : new ArrayList<Cell>();
// Results are potentially returned even when the return
// value of s.next is false
// since this is an indication of whether or not there
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/HashJoinRegionScanner.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/HashJoinRegionScanner.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/HashJoinRegionScanner.java
index 480ee6d..1ea6b12 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/HashJoinRegionScanner.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/HashJoinRegionScanner.java
@@ -42,6 +42,7 @@ import org.apache.phoenix.parse.JoinTableNode.JoinType;
import org.apache.phoenix.schema.IllegalDataException;
import org.apache.phoenix.schema.KeyValueSchema;
import org.apache.phoenix.schema.ValueBitSet;
+import org.apache.phoenix.schema.tuple.PositionBasedResultTuple;
import org.apache.phoenix.schema.tuple.ResultTuple;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.ServerUtil;
@@ -61,9 +62,10 @@ public class HashJoinRegionScanner implements RegionScanner {
private List<Tuple>[] tempTuples;
private ValueBitSet tempDestBitSet;
private ValueBitSet[] tempSrcBitSet;
+ private final boolean useQualifierAsListIndex;
@SuppressWarnings("unchecked")
- public HashJoinRegionScanner(RegionScanner scanner, TupleProjector projector, HashJoinInfo joinInfo, ImmutableBytesPtr tenantId, RegionCoprocessorEnvironment env) throws IOException {
+ public HashJoinRegionScanner(RegionScanner scanner, TupleProjector projector, HashJoinInfo joinInfo, ImmutableBytesPtr tenantId, RegionCoprocessorEnvironment env, boolean useQualifierAsIndex) throws IOException {
this.env = env;
this.scanner = scanner;
this.projector = projector;
@@ -104,13 +106,13 @@ public class HashJoinRegionScanner implements RegionScanner {
this.tempDestBitSet = ValueBitSet.newInstance(joinInfo.getJoinedSchema());
this.projector.setValueBitSet(tempDestBitSet);
}
+ this.useQualifierAsListIndex = useQualifierAsIndex;
}
private void processResults(List<Cell> result, boolean hasBatchLimit) throws IOException {
if (result.isEmpty())
return;
-
- Tuple tuple = new ResultTuple(Result.create(result));
+ Tuple tuple = useQualifierAsListIndex ? new PositionBasedResultTuple(result) : new ResultTuple(Result.create(result));
// For backward compatibility. In new versions, HashJoinInfo.forceProjection()
// always returns true.
if (joinInfo.forceProjection()) {
@@ -314,7 +316,6 @@ public class HashJoinRegionScanner implements RegionScanner {
processResults(result, limit >= 0);
result.clear();
}
-
return nextInQueue(result);
} catch (Throwable t) {
ServerUtil.throwIOException(env.getRegion().getRegionNameAsString(), t);
[30/42] phoenix git commit: Make connection less tests use encoded
column names. Add test cases around dynamic columns and qualifier ranges
Posted by td...@apache.org.
Make connection less tests use encoded column names. Add test cases around dynamic columns and qualifier ranges
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/37836a01
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/37836a01
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/37836a01
Branch: refs/heads/encodecolumns2
Commit: 37836a01f612df885f8b5bfdf2ba7bbfa38d9150
Parents: 1bddaa0
Author: Samarth <sa...@salesforce.com>
Authored: Wed Nov 23 16:09:58 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../apache/phoenix/end2end/DynamicColumnIT.java | 63 ++++++++++++++++++++
.../apache/phoenix/schema/MetaDataClient.java | 5 +-
.../java/org/apache/phoenix/schema/PTable.java | 1 -
.../apache/phoenix/util/EncodedColumnsUtil.java | 3 +-
.../phoenix/compile/QueryOptimizerTest.java | 51 ++++++++++++++++
.../phoenix/compile/WhereCompilerTest.java | 4 +-
.../phoenix/execute/MutationStateTest.java | 4 +-
.../phoenix/query/ConnectionlessTest.java | 16 +++--
8 files changed, 130 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/37836a01/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
index 25e7230..3f02113 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
@@ -213,5 +213,68 @@ public class DynamicColumnIT extends ParallelStatsDisabledIT {
conn.close();
}
}
+
+ @Test
+ public void testDynamicColumnOnNewTable() throws Exception {
+ String tableName = generateUniqueName();
+ String ddl = "create table " + tableName +
+ " (entry varchar not null," +
+ " F varchar," +
+ " A.F1v1 varchar," +
+ " A.F1v2 varchar," +
+ " B.F2v1 varchar" +
+ " CONSTRAINT pk PRIMARY KEY (entry))";
+ String dml = "UPSERT INTO " + tableName + " values (?, ?, ?, ?, ?)";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(ddl);
+ try (PreparedStatement stmt = conn.prepareStatement(dml)) {
+ stmt.setString(1, "entry");
+ stmt.setString(2, "a");
+ stmt.setString(3, "b");
+ stmt.setString(4, "c");
+ stmt.setString(5, "d");
+ stmt.executeUpdate();
+ conn.commit();
+ }
+ dml = "UPSERT INTO " + tableName + "(entry, F, A.F1V1, A.F1v2, B.F2V1, DYNCOL1 VARCHAR, DYNCOL2 VARCHAR) VALUES (?, ?, ?, ?, ?, ?, ?)";
+ try (PreparedStatement stmt = conn.prepareStatement(dml)) {
+ stmt.setString(1, "dynentry");
+ stmt.setString(2, "a");
+ stmt.setString(3, "b");
+ stmt.setString(4, "c");
+ stmt.setString(5, "d");
+ stmt.setString(6, "e");
+ stmt.setString(7, "f");
+ stmt.executeUpdate();
+ conn.commit();
+ }
+
+ // test dynamic column in where clause
+ String query = "SELECT entry, F from " + tableName + " (DYNCOL1 VARCHAR, DYNCOL2 VARCHAR) " + " WHERE DYNCOL1 = ?";
+ try (PreparedStatement stmt = conn.prepareStatement(query)) {
+ stmt.setString(1, "e");
+ ResultSet rs = stmt.executeQuery();
+ assertTrue(rs.next());
+ assertEquals("dynentry", rs.getString(1));
+ assertEquals("a", rs.getString(2));
+ assertFalse(rs.next());
+ }
+
+ // test dynamic column with projection
+ query = "SELECT entry, dyncol1, dyncol2 from " + tableName + " (DYNCOL1 VARCHAR, DYNCOL2 VARCHAR) ";
+ try (PreparedStatement stmt = conn.prepareStatement(query)) {
+ ResultSet rs = stmt.executeQuery();
+ assertTrue(rs.next());
+ assertEquals("dynentry", rs.getString(1));
+ assertEquals("e", rs.getString(2));
+ assertEquals("f", rs.getString(3));
+ assertTrue(rs.next());
+ assertEquals("entry", rs.getString(1));
+ assertEquals(null, rs.getString(2));
+ assertEquals(null, rs.getString(2));
+ assertFalse(rs.next());
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/37836a01/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 53c1c86..a7144bb 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
@@ -2079,7 +2079,10 @@ public class MetaDataClient {
byte[] tableNameBytes = SchemaUtil.getTableNameAsBytes(schemaName, tableName);
boolean tableExists = true;
try {
- connection.getQueryServices().getTableDescriptor(tableNameBytes);
+ HTableDescriptor tableDescriptor = connection.getQueryServices().getTableDescriptor(tableNameBytes);
+ if (tableDescriptor == null) { // for connectionless
+ tableExists = false;
+ }
} catch (org.apache.phoenix.schema.TableNotFoundException e) {
tableExists = false;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/37836a01/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
index 1ee2320..184a588 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
@@ -19,7 +19,6 @@ package org.apache.phoenix.schema;
import static org.apache.phoenix.query.QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE;
-import java.nio.ByteOrder;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/37836a01/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
index c73e5b0..a9addf0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
@@ -77,8 +77,7 @@ public class EncodedColumnsUtil {
// (with the qualifier name being same as the family name), just project the column family here
// so that we can calculate estimatedByteSize correctly in ProjectionCompiler
scan.addFamily(column.getFamilyName().getBytes());
- //scan.addColumn(column.getFamilyName().getBytes(), column.getFamilyName().getBytes());
- }
+ }
else {
scan.addColumn(column.getFamilyName().getBytes(), EncodedColumnsUtil.getColumnQualifier(column, table));
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/37836a01/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
index 25280fa..67aae72 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
@@ -17,8 +17,13 @@
*/
package org.apache.phoenix.compile;
+import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.MAX_QUALIFIER;
+import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.MIN_QUALIFIER;
+import static org.apache.phoenix.query.QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE;
+import static org.apache.phoenix.query.QueryConstants.ENCODED_EMPTY_COLUMN_NAME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.sql.Array;
@@ -32,9 +37,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
import org.apache.phoenix.jdbc.PhoenixPreparedStatement;
+import org.apache.phoenix.jdbc.PhoenixResultSet;
import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.query.BaseConnectionlessQueryTest;
import org.apache.phoenix.query.QueryConstants;
@@ -750,4 +758,47 @@ public class QueryOptimizerTest extends BaseConnectionlessQueryTest {
return Joiner.on(",").join(pkColsDataTypes);
}
+ @Test
+ public void testMinMaxQualifierRangeWithOrderByOnKVColumn() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ String tableName = "testMintestMinMaxQualifierRange".toUpperCase();
+ conn.createStatement().execute("CREATE TABLE " + tableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER, v2 VARCHAR)");
+ PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
+ ResultSet rs = stmt.executeQuery("SELECT K from " + tableName + " ORDER BY (v1)");
+ assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE);
+ rs = stmt.executeQuery("SELECT K from " + tableName + " ORDER BY (v1, v2)");
+ assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
+ rs = stmt.executeQuery("SELECT V2 from " + tableName + " ORDER BY (v1)");
+ assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
+ rs = stmt.executeQuery("SELECT V1 from " + tableName + " ORDER BY (v1, v2)");
+ assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
+ }
+
+ @Test
+ public void testMinMaxQualifierRangeWithNoOrderBy() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ String tableName = "testMintestMinMaxQualifierRange".toUpperCase();
+ conn.createStatement().execute("CREATE TABLE " + tableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER, v2 VARCHAR)");
+ PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
+ ResultSet rs = stmt.executeQuery("SELECT K from " + tableName);
+ assertQualifierRanges(rs, ENCODED_CQ_COUNTER_INITIAL_VALUE, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
+ rs = stmt.executeQuery("SELECT V2 from " + tableName);
+ assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
+ rs = stmt.executeQuery("SELECT V1 from " + tableName);
+ assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE);
+ }
+
+ private static void assertQualifierRanges(ResultSet rs, int minQualifier, int maxQualifier) throws SQLException {
+ Scan scan = rs.unwrap(PhoenixResultSet.class).getStatement().getQueryPlan().getContext().getScan();
+ assertNotNull(scan.getAttribute(MIN_QUALIFIER));
+ assertNotNull(scan.getAttribute(MAX_QUALIFIER));
+ assertEquals(minQualifier, Bytes.toInt(scan.getAttribute(MIN_QUALIFIER)));
+ assertEquals(maxQualifier, Bytes.toInt(scan.getAttribute(MAX_QUALIFIER)));
+ }
+
+// private static void assertQualifierRangesNotPresent(ResultSet rs) throws SQLException {
+// Scan scan = rs.unwrap(PhoenixResultSet.class).getStatement().getQueryPlan().getContext().getScan();
+// assertNull(scan.getAttribute(MIN_QUALIFIER));
+// assertNull(scan.getAttribute(MAX_QUALIFIER));
+// }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/37836a01/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
index c65408e..06c20d3 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
@@ -121,7 +121,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
Filter filter = scan.getFilter();
Expression idExpression = new ColumnRef(plan.getTableRef(), plan.getTableRef().getTable().getPColumnForColumnName("ID").getPosition()).newColumnExpression();
Expression id = new RowKeyColumnExpression(idExpression,new RowKeyValueAccessor(plan.getTableRef().getTable().getPKColumns(),0));
- Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getPColumnForColumnName("COMPANY"), false);
+ Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getPColumnForColumnName("COMPANY"), true);
// FilterList has no equals implementation
assertTrue(filter instanceof FilterList);
FilterList filterList = (FilterList)filter;
@@ -153,7 +153,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
assertEquals(
singleKVFilter(constantComparison(
CompareOp.EQUAL,
- new KeyValueColumnExpression(column, false),
+ new KeyValueColumnExpression(column, true),
"c3")),
filter);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/37836a01/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
index 276d946..8553b73 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
@@ -127,11 +127,11 @@ public class MutationStateTest {
private void assertTable(String tableName1,List<KeyValue> keyValues1,String tableName2,List<KeyValue> keyValues2) {
assertTrue("MUTATION_TEST1".equals(tableName1));
assertTrue(Bytes.equals(PUnsignedInt.INSTANCE.toBytes(111),CellUtil.cloneRow(keyValues1.get(0))));
- assertTrue("app1".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues1.get(0)))));
+ assertTrue("app1".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues1.get(1)))));
assertTrue("MUTATION_TEST2".equals(tableName2));
assertTrue(Bytes.equals(PUnsignedInt.INSTANCE.toBytes(222),CellUtil.cloneRow(keyValues2.get(0))));
- assertTrue("app2".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues2.get(0)))));
+ assertTrue("app2".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues2.get(1)))));
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/37836a01/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
index 089c5f1..1d71ec0 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
@@ -141,31 +141,29 @@ public class ConnectionlessTest {
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey1, kv.getRow());
- assertEquals(name1, PVarchar.INSTANCE.toObject(kv.getValue()));
- assertTrue(iterator.hasNext());
+ assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
kv = iterator.next();
assertArrayEquals(expectedRowKey1, kv.getRow());
- assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
+ assertEquals(name1, PVarchar.INSTANCE.toObject(kv.getValue()));
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey1, kv.getRow());
- assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
+ assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
}
private static void assertRow2(Iterator<KeyValue> iterator, byte[] expectedRowKey2) {
KeyValue kv;
- assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey2, kv.getRow());
- assertEquals(name2, PVarchar.INSTANCE.toObject(kv.getValue()));
+ assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey2, kv.getRow());
- assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
+ assertEquals(name2, PVarchar.INSTANCE.toObject(kv.getValue()));
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey2, kv.getRow());
- assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
+ assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
}
@Test
@@ -204,4 +202,4 @@ public class ConnectionlessTest {
}
-}
+}
\ No newline at end of file
[05/42] phoenix git commit: TTL on UPGRADE_LOCK cell causes upgrade
to fail
Posted by td...@apache.org.
TTL on UPGRADE_LOCK cell causes upgrade to fail
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/8a231a94
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8a231a94
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8a231a94
Branch: refs/heads/encodecolumns2
Commit: 8a231a94ceb07f8b3967a15bde07b694a92ae58e
Parents: 96b6554
Author: Samarth <sa...@salesforce.com>
Authored: Mon Dec 12 12:01:38 2016 -0800
Committer: Samarth <sa...@salesforce.com>
Committed: Mon Dec 12 12:01:38 2016 -0800
----------------------------------------------------------------------
.../phoenix/query/ConnectionQueryServicesImpl.java | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8a231a94/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 9bc088d..c8d42d9 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
@@ -2997,8 +2997,20 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
Put put = new Put(rowToLock);
put.add(family, qualifier, newValue);
boolean acquired = sysMutexTable.checkAndPut(rowToLock, family, qualifier, oldValue, put);
- if (!acquired) { throw new UpgradeInProgressException(getVersion(currentServerSideTableTimestamp),
- getVersion(MIN_SYSTEM_TABLE_TIMESTAMP)); }
+ if (!acquired) {
+ /*
+ * Because of TTL on the SYSTEM_MUTEX_FAMILY, it is very much possible that the cell
+ * has gone away. So we need to retry with an old value of null. Note there is a small
+ * race condition here that between the two checkAndPut calls, it is possible that another
+ * request would have set the value back to UPGRADE_MUTEX_UNLOCKED. In that scenario this
+ * following checkAndPut would still return false even though the lock was available.
+ */
+ acquired = sysMutexTable.checkAndPut(rowToLock, family, qualifier, null, put);
+ if (!acquired) {
+ throw new UpgradeInProgressException(getVersion(currentServerSideTableTimestamp),
+ getVersion(MIN_SYSTEM_TABLE_TIMESTAMP));
+ }
+ }
return true;
}
}
[35/42] phoenix git commit: PHOENIX-3442 Support null when columns
have default values for immutable tables with encoding scheme
COLUMNS_STORED_IN_SINGLE_CELL
Posted by td...@apache.org.
PHOENIX-3442 Support null when columns have default values for immutable tables with encoding scheme COLUMNS_STORED_IN_SINGLE_CELL
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/01ef5d5b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/01ef5d5b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/01ef5d5b
Branch: refs/heads/encodecolumns2
Commit: 01ef5d5b4a298e203cbc43487cc421bd920fbbac
Parents: aa7450f
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Wed Nov 23 19:11:25 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../phoenix/end2end/DefaultColumnValueIT.java | 2 +-
.../expression/ArrayColumnExpression.java | 3 +-
.../expression/ArrayConstructorExpression.java | 67 ++---
.../expression/util/regex/JONIPattern.java | 2 +-
.../org/apache/phoenix/schema/ColumnRef.java | 8 +-
.../org/apache/phoenix/schema/PTableImpl.java | 29 ++-
.../phoenix/schema/types/PArrayDataType.java | 244 +++++++++++--------
.../ArrayConstructorExpressionTest.java | 106 +++++++-
8 files changed, 289 insertions(+), 172 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01ef5d5b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
index 8302604..7c04d01 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
@@ -258,7 +258,7 @@ public class DefaultColumnValueIT extends ParallelStatsDisabledIT {
assertFalse(rs.next());
}
- @Ignore //FIXME: PHOENIX-3442
+ @Test
public void testDefaultImmutableRows() throws Exception {
String table = generateUniqueName();
String ddl = "CREATE TABLE IF NOT EXISTS " + table + " (" +
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01ef5d5b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
index f09fb62..747d7e6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
@@ -74,8 +74,7 @@ public class ArrayColumnExpression extends KeyValueColumnExpression {
// 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, positionInArray, PVarbinary.INSTANCE, null);
- return true;
+ return PArrayDataType.positionAtArrayElement(ptr, positionInArray, PVarbinary.INSTANCE, null);
}
@Override
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01ef5d5b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
index 783e962..2a6b484 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
@@ -21,6 +21,7 @@ import org.apache.hadoop.io.WritableUtils;
import org.apache.phoenix.expression.visitor.ExpressionVisitor;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PArrayDataType.PArrayDataTypeBytesArrayBuilder;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.TrustedByteArrayOutputStream;
@@ -31,7 +32,6 @@ import org.apache.phoenix.util.TrustedByteArrayOutputStream;
public class ArrayConstructorExpression extends BaseCompoundExpression {
private PDataType baseType;
private int position = -1;
- private int nNulls = 0;
private Object[] elements;
private final ImmutableBytesWritable valuePtr = new ImmutableBytesWritable();
private int estimatedSize = 0;
@@ -39,20 +39,25 @@ public class ArrayConstructorExpression extends BaseCompoundExpression {
// and serialize into byte stream
private int[] offsetPos;
private boolean rowKeyOrderOptimizable;
+ private byte serializationVersion;
public ArrayConstructorExpression() {
}
public ArrayConstructorExpression(List<Expression> children, PDataType baseType, boolean rowKeyOrderOptimizable) {
+ this(children, baseType, rowKeyOrderOptimizable, PArrayDataType.SORTABLE_SERIALIZATION_VERSION);
+ }
+
+ public ArrayConstructorExpression(List<Expression> children, PDataType baseType, boolean rowKeyOrderOptimizable, byte serializationVersion) {
super(children);
- init(baseType, rowKeyOrderOptimizable);
+ init(baseType, rowKeyOrderOptimizable, serializationVersion);
}
public ArrayConstructorExpression clone(List<Expression> children) {
- return new ArrayConstructorExpression(children, this.baseType, this.rowKeyOrderOptimizable);
+ return new ArrayConstructorExpression(children, this.baseType, this.rowKeyOrderOptimizable, PArrayDataType.SORTABLE_SERIALIZATION_VERSION);
}
- private void init(PDataType baseType, boolean rowKeyOrderOptimizable) {
+ private void init(PDataType baseType, boolean rowKeyOrderOptimizable, byte serializationVersion) {
this.baseType = baseType;
this.rowKeyOrderOptimizable = rowKeyOrderOptimizable;
elements = new Object[getChildren().size()];
@@ -61,6 +66,7 @@ public class ArrayConstructorExpression extends BaseCompoundExpression {
if (!this.baseType.isFixedWidth()) {
offsetPos = new int[children.size()];
}
+ this.serializationVersion = serializationVersion;
}
@Override
@@ -72,7 +78,6 @@ public class ArrayConstructorExpression extends BaseCompoundExpression {
public void reset() {
super.reset();
position = 0;
- nNulls = 0;
Arrays.fill(elements, null);
valuePtr.set(ByteUtil.EMPTY_BYTE_ARRAY);
}
@@ -85,9 +90,9 @@ public class ArrayConstructorExpression extends BaseCompoundExpression {
}
TrustedByteArrayOutputStream byteStream = new TrustedByteArrayOutputStream(estimatedSize);
DataOutputStream oStream = new DataOutputStream(byteStream);
+ PArrayDataTypeBytesArrayBuilder builder =
+ new PArrayDataTypeBytesArrayBuilder(byteStream, oStream, children.size(), baseType, getSortOrder(), rowKeyOrderOptimizable, serializationVersion);
try {
- int noOfElements = children.size();
- nNulls = 0;
for (int i = position >= 0 ? position : 0; i < elements.length; i++) {
Expression child = children.get(i);
if (!child.evaluate(tuple, ptr)) {
@@ -95,48 +100,19 @@ public class ArrayConstructorExpression extends BaseCompoundExpression {
if (position >= 0) position = i;
return false;
}
- } else {
- // track the offset position here from the size of the byteStream
- if (!baseType.isFixedWidth()) {
- // Any variable length array would follow the below order
- // Every element would be seperated by a seperator byte '0'
- // Null elements are counted and once a first non null element appears we
- // write the count of the nulls prefixed with a seperator byte
- // Trailing nulls are not taken into account
- // The last non null element is followed by two seperator bytes
- // For eg
- // a, b, null, null, c, null would be
- // 65 0 66 0 0 2 67 0 0 0
- // a null null null b c null d would be
- // 65 0 0 3 66 0 67 0 0 1 68 0 0 0
- if (ptr.getLength() == 0) {
- offsetPos[i] = byteStream.size();
- nNulls++;
- } else {
- PArrayDataType.serializeNulls(oStream, nNulls);
- offsetPos[i] = byteStream.size();
- oStream.write(ptr.get(), ptr.getOffset(), ptr.getLength());
- oStream.write(PArrayDataType.getSeparatorByte(rowKeyOrderOptimizable, getSortOrder()));
- nNulls = 0;
- }
- } else { // No nulls for fixed length
- oStream.write(ptr.get(), ptr.getOffset(), ptr.getLength());
+ else {
+ // its possible for the expression to evaluate to null if the serialization format is immutable and the data type is variable length
+ builder.appendMissingElement();
}
+ } else {
+ builder.appendElem(ptr.get(), ptr.getOffset(), ptr.getLength());
}
}
if (position >= 0) position = elements.length;
- if (!baseType.isFixedWidth()) {
- // Double seperator byte to show end of the non null array
- PArrayDataType.writeEndSeperatorForVarLengthArray(oStream, getSortOrder(), rowKeyOrderOptimizable);
- noOfElements = PArrayDataType.serailizeOffsetArrayIntoStream(oStream, byteStream, noOfElements,
- offsetPos[offsetPos.length - 1], offsetPos);
- PArrayDataType.serializeHeaderInfoIntoStream(oStream, noOfElements);
- }
- ptr.set(byteStream.getBuffer(), 0, byteStream.size());
+ byte[] bytes = builder.getBytesAndClose();
+ ptr.set(bytes, 0, bytes.length);
valuePtr.set(ptr.get(), ptr.getOffset(), ptr.getLength());
return true;
- } catch (IOException e) {
- throw new RuntimeException("Exception while serializing the byte array");
} finally {
try {
byteStream.close();
@@ -157,7 +133,8 @@ public class ArrayConstructorExpression extends BaseCompoundExpression {
rowKeyOrderOptimizable = true;
baseTypeOrdinal = -(baseTypeOrdinal+1);
}
- init(PDataType.values()[baseTypeOrdinal], rowKeyOrderOptimizable);
+ byte serializationVersion = input.readByte();
+ init(PDataType.values()[baseTypeOrdinal], rowKeyOrderOptimizable, serializationVersion);
}
@Override
@@ -168,6 +145,7 @@ public class ArrayConstructorExpression extends BaseCompoundExpression {
} else {
WritableUtils.writeVInt(output, baseType.ordinal());
}
+ output.write(serializationVersion);
}
@Override
@@ -196,4 +174,5 @@ public class ArrayConstructorExpression extends BaseCompoundExpression {
buf.append(children.get(children.size()-1) + "]");
return buf.toString();
}
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01ef5d5b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java
index af5bc2b..522a4e7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java
@@ -192,7 +192,7 @@ public class JONIPattern extends AbstractBasePattern implements AbstractBaseSpli
break;
}
}
- byte[] bytes = builder.getBytesAndClose(SortOrder.ASC);
+ byte[] bytes = builder.getBytesAndClose();
if (bytes == null) return false;
outPtr.set(bytes);
return true;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01ef5d5b/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
index 256575c..d757322 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ColumnRef.java
@@ -128,7 +128,8 @@ public class ColumnRef {
return new ProjectedColumnExpression(column, table, displayName);
}
- Expression expression = new KeyValueColumnExpression(column, displayName, usesEncodedColumnNames(table));
+ Expression expression = table.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY ?
+ new ArrayColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table)) : new KeyValueColumnExpression(column, displayName, usesEncodedColumnNames(table));
if (column.getExpressionStr() != null) {
String url = PhoenixRuntime.JDBC_PROTOCOL
@@ -146,10 +147,7 @@ public class ColumnRef {
}
}
- if (table.getStorageScheme() == StorageScheme.ONE_CELL_PER_COLUMN_FAMILY) {
- return new ArrayColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table.getEncodingScheme()));
- }
- return new KeyValueColumnExpression(column, displayName, EncodedColumnsUtil.usesEncodedColumnNames(table.getEncodingScheme()));
+ return expression;
}
public ColumnRef cloneAtTimestamp(long timestamp) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01ef5d5b/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 8522c13..7e6f35b 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
@@ -26,6 +26,7 @@ import java.io.IOException;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -49,6 +50,7 @@ import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.coprocessor.generated.PTableProtos;
import org.apache.phoenix.exception.DataExceedsCapacityException;
import org.apache.phoenix.expression.ArrayConstructorExpression;
+import org.apache.phoenix.expression.DelegateExpression;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
@@ -61,7 +63,8 @@ import org.apache.phoenix.parse.SQLParser;
import org.apache.phoenix.protobuf.ProtobufUtil;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
-import org.apache.phoenix.schema.tuple.BaseTuple;
+import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PArrayDataType;
import org.apache.phoenix.schema.types.PBinary;
import org.apache.phoenix.schema.types.PChar;
import org.apache.phoenix.schema.types.PDataType;
@@ -897,21 +900,27 @@ public class PTableImpl implements PTable {
for (PColumn column : columns) {
maxEncodedColumnQualifier = Math.max(maxEncodedColumnQualifier, column.getEncodedColumnQualifier());
}
- byte[][] colValues = new byte[maxEncodedColumnQualifier+1][];
+ Expression[] colValues = new Expression[maxEncodedColumnQualifier+1];
+ Arrays.fill(colValues, new DelegateExpression(LiteralExpression.newConstant(null)) {
+ @Override
+ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+ return false;
+ }
+ });
+ // 0 is a reserved position, set it to a non-null value so that we can represent absence of a value using a negative offset
+ colValues[0]=LiteralExpression.newConstant(QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
for (PColumn column : columns) {
- colValues[column.getEncodedColumnQualifier()] = columnToValueMap.get(column);
+ if (columnToValueMap.containsKey(column)) {
+ colValues[column.getEncodedColumnQualifier()] = new LiteralExpression(columnToValueMap.get(column));
+ }
}
- List<Expression> children = Lists.newArrayListWithExpectedSize(columns.size());
- // create an expression list with all the columns
- for (int i=0; i<colValues.length; ++i) {
- children.add(new LiteralExpression(colValues[i]==null ? ByteUtil.EMPTY_BYTE_ARRAY : colValues[i] ));
- }
+ List<Expression> children = Arrays.asList(colValues);
// we use ArrayConstructorExpression to serialize multiple columns into a single byte[]
// construct the ArrayConstructorExpression with a variable length data type since columns can be of fixed or variable length
- ArrayConstructorExpression arrayExpression = new ArrayConstructorExpression(children, PVarbinary.INSTANCE, rowKeyOrderOptimizable);
+ ArrayConstructorExpression arrayExpression = new ArrayConstructorExpression(children, PVarbinary.INSTANCE, rowKeyOrderOptimizable, PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
- arrayExpression.evaluate(new BaseTuple() {}, ptr);
+ arrayExpression.evaluate(null, ptr);
ImmutableBytesPtr colFamilyPtr = new ImmutableBytesPtr(columnFamily);
addQuietly(put, kvBuilder, kvBuilder.buildPut(keyPtr,
colFamilyPtr, QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES_PTR, ts, ptr));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01ef5d5b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
index 1d2cfb2..fede7d8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.sql.Types;
import java.text.Format;
+import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
@@ -74,8 +75,11 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
this, actualModifer, desiredModifier, true);
}
- public static final byte ARRAY_SERIALIZATION_VERSION = 1;
-
+ // array serialization format where bytes can be used as part of the row key
+ public static final byte SORTABLE_SERIALIZATION_VERSION = 1;
+ // array serialization format where bytes are immutable (does not support prepend/append or sorting)
+ public static final byte IMMUTABLE_SERIALIZATION_VERSION = 2;
+
protected PArrayDataType(String sqlTypeName, int sqlType, Class clazz, PDataCodec codec, int ordinal) {
super(sqlTypeName, sqlType, clazz, codec, ordinal);
}
@@ -186,9 +190,17 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
oStream.write(sepByte);
}
- public static boolean useShortForOffsetArray(int maxOffset) {
- // If the max offset is less than Short.MAX_VALUE then offset array can use short
- if (maxOffset <= (2 * Short.MAX_VALUE)) { return true; }
+ // this method is only for append/prepend/concat operations which are only supported for the SORTABLE_SERIALIZATION_VERSION
+ public static boolean useShortForOffsetArray(int maxoffset) {
+ return useShortForOffsetArray(maxoffset, SORTABLE_SERIALIZATION_VERSION);
+ }
+
+ public static boolean useShortForOffsetArray(int maxoffset, byte serializationVersion) {
+ if (serializationVersion == IMMUTABLE_SERIALIZATION_VERSION) {
+ return (maxoffset <= Short.MAX_VALUE && maxoffset >= Short.MIN_VALUE );
+ }
+ // If the max offset is less than Short.MAX_VALUE then offset array can use short
+ else if (maxoffset <= (2 * Short.MAX_VALUE)) { return true; }
// else offset array can use Int
return false;
}
@@ -350,15 +362,15 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
// 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)
- positionAtArrayElement(ptr, index - 1, pDataType, maxLen);
- return true;
+ return positionAtArrayElement(ptr, index - 1, pDataType, maxLen);
}
- public static void positionAtArrayElement(ImmutableBytesWritable ptr, int arrayIndex, PDataType baseDataType,
+ public static boolean positionAtArrayElement(ImmutableBytesWritable ptr, int arrayIndex, PDataType baseDataType,
Integer byteSize) {
byte[] bytes = ptr.get();
int initPos = ptr.getOffset();
if (!baseDataType.isFixedWidth()) {
+ byte serializationVersion = bytes[ptr.getOffset() + ptr.getLength() - Bytes.SIZEOF_BYTE];
int noOfElements = Bytes.toInt(bytes,
(ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)), Bytes.SIZEOF_INT);
boolean useShort = true;
@@ -368,13 +380,14 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
}
if (arrayIndex >= noOfElements) {
ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
- return;
+ return false;
}
int indexOffset = Bytes.toInt(bytes,
(ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + 2 * Bytes.SIZEOF_INT))) + ptr.getOffset();
if (arrayIndex >= noOfElements) {
ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
+ return false;
} else {
// Skip those many offsets as given in the arrayIndex
// If suppose there are 5 elements in the array and the arrayIndex = 3
@@ -383,14 +396,20 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
// offset of 5th element.
// Subtracting the offset of 5th element and 4th element will give the length of 4th element
// So we could just skip reading the other elements.
- int currOffset = getOffset(bytes, arrayIndex, useShort, indexOffset);
+ int currOffset = getSerializedOffset(bytes, arrayIndex, useShort, indexOffset, serializationVersion);
+ if (currOffset<0) {
+ ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
+ return false;
+ }
int elementLength = 0;
if (arrayIndex == (noOfElements - 1)) {
+ int separatorBytes = serializationVersion == SORTABLE_SERIALIZATION_VERSION ? 3 : 0;
elementLength = (bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE || bytes[currOffset + initPos] == QueryConstants.DESC_SEPARATOR_BYTE) ? 0 : indexOffset
- - (currOffset + initPos) - 3;
+ - (currOffset + initPos) - separatorBytes;
} else {
+ int separatorByte = serializationVersion == SORTABLE_SERIALIZATION_VERSION ? 1 : 0;
elementLength = (bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE || bytes[currOffset + initPos] == QueryConstants.DESC_SEPARATOR_BYTE) ? 0 : getOffset(bytes,
- arrayIndex + 1, useShort, indexOffset) - currOffset - 1;
+ arrayIndex + 1, useShort, indexOffset, serializationVersion) - currOffset - separatorByte;
}
ptr.set(bytes, currOffset + initPos, elementLength);
}
@@ -403,12 +422,14 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
ptr.set(bytes, ptr.getOffset() + offset, elemByteSize);
}
}
+ return true;
}
public static void positionAtArrayElement(ImmutableBytesWritable ptr, int arrayIndex, PDataType baseDataType,
Integer byteSize, int offset, int length, int noOfElements, boolean first) {
byte[] bytes = ptr.get();
if (!baseDataType.isFixedWidth()) {
+ byte serializationVersion = bytes[ptr.getOffset() + ptr.getLength() - Bytes.SIZEOF_BYTE];
int indexOffset = Bytes.toInt(bytes, (offset + length - (Bytes.SIZEOF_BYTE + 2 * Bytes.SIZEOF_INT)))
+ offset;
boolean useShort = true;
@@ -430,14 +451,14 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
// offset of 5th element.
// Subtracting the offset of 5th element and 4th element will give the length of 4th element
// So we could just skip reading the other elements.
- int currOffset = getOffset(bytes, arrayIndex, useShort, indexOffset);
+ int currOffset = getOffset(bytes, arrayIndex, useShort, indexOffset, serializationVersion);
int elementLength = 0;
if (arrayIndex == (noOfElements - 1)) {
elementLength = (bytes[currOffset + offset] == QueryConstants.SEPARATOR_BYTE || bytes[currOffset + offset] == QueryConstants.DESC_SEPARATOR_BYTE) ? 0 : indexOffset
- (currOffset + offset) - 3;
} else {
elementLength = (bytes[currOffset + offset] == QueryConstants.SEPARATOR_BYTE || bytes[currOffset + offset] == QueryConstants.DESC_SEPARATOR_BYTE) ? 0 : getOffset(bytes,
- arrayIndex + 1, useShort, indexOffset) - currOffset - 1;
+ arrayIndex + 1, useShort, indexOffset, serializationVersion) - currOffset - 1;
}
ptr.set(bytes, currOffset + offset, elementLength);
}
@@ -452,16 +473,20 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
}
}
- private static int getOffset(byte[] bytes, int arrayIndex, boolean useShort, int indexOffset) {
- int offset;
+ private static int getOffset(byte[] bytes, int arrayIndex, boolean useShort, int indexOffset, byte serializationVersion) {
+ return Math.abs(getSerializedOffset(bytes, arrayIndex, useShort, indexOffset, serializationVersion));
+ }
+
+ private static int getSerializedOffset(byte[] bytes, int arrayIndex, boolean useShort, int indexOffset, byte serializationVersion) {
+ int offset;
if (useShort) {
offset = indexOffset + (Bytes.SIZEOF_SHORT * arrayIndex);
- return Bytes.toShort(bytes, offset, Bytes.SIZEOF_SHORT) + Short.MAX_VALUE;
+ return Bytes.toShort(bytes, offset, Bytes.SIZEOF_SHORT) + (serializationVersion == PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION ? 0 : Short.MAX_VALUE);
} else {
offset = indexOffset + (Bytes.SIZEOF_INT * arrayIndex);
return Bytes.toInt(bytes, offset, Bytes.SIZEOF_INT);
}
- }
+ }
private static int getOffset(ByteBuffer indexBuffer, int arrayIndex, boolean useShort, int indexOffset) {
int offset;
@@ -484,58 +509,18 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
}
/**
- * creates array bytes
+ * creates array bytes using the SORTABLE_SERIALIZATION_VERSION format
* @param rowKeyOrderOptimizable TODO
*/
private byte[] createArrayBytes(TrustedByteArrayOutputStream byteStream, DataOutputStream oStream,
PhoenixArray array, int noOfElements, PDataType baseType, SortOrder sortOrder, boolean rowKeyOrderOptimizable) {
- try {
- if (!baseType.isFixedWidth()) {
- int[] offsetPos = new int[noOfElements];
- int nulls = 0;
- for (int i = 0; i < noOfElements; i++) {
- byte[] bytes = array.toBytes(i);
- if (bytes.length == 0) {
- offsetPos[i] = byteStream.size();
- nulls++;
- } else {
- nulls = serializeNulls(oStream, nulls);
- offsetPos[i] = byteStream.size();
- if (sortOrder == SortOrder.DESC) {
- SortOrder.invert(bytes, 0, bytes, 0, bytes.length);
- }
- oStream.write(bytes, 0, bytes.length);
- oStream.write(getSeparatorByte(rowKeyOrderOptimizable, sortOrder));
- }
- }
- // Double seperator byte to show end of the non null array
- writeEndSeperatorForVarLengthArray(oStream, sortOrder, rowKeyOrderOptimizable);
- noOfElements = PArrayDataType.serailizeOffsetArrayIntoStream(oStream, byteStream, noOfElements,
- offsetPos[offsetPos.length - 1], offsetPos);
- serializeHeaderInfoIntoStream(oStream, noOfElements);
- } else {
- for (int i = 0; i < noOfElements; i++) {
- byte[] bytes = array.toBytes(i);
- int length = bytes.length;
- if (sortOrder == SortOrder.DESC) {
- SortOrder.invert(bytes, 0, bytes, 0, bytes.length);
- }
- oStream.write(bytes, 0, length);
- }
- }
- ImmutableBytesWritable ptr = new ImmutableBytesWritable();
- ptr.set(byteStream.getBuffer(), 0, byteStream.size());
- return ByteUtil.copyKeyBytesIfNecessary(ptr);
- } catch (IOException e) {
- try {
- byteStream.close();
- oStream.close();
- } catch (IOException ioe) {
-
- }
+ PArrayDataTypeBytesArrayBuilder builder =
+ new PArrayDataTypeBytesArrayBuilder(byteStream, oStream, noOfElements, baseType, sortOrder, rowKeyOrderOptimizable);
+ for (int i = 0; i < noOfElements; i++) {
+ byte[] bytes = array.toBytes(i);
+ builder.appendElem(bytes);
}
- // This should not happen
- return null;
+ return builder.getBytesAndClose();
}
public static boolean appendItemToArray(ImmutableBytesWritable ptr, int length, int offset, byte[] arrayBytes,
@@ -557,7 +542,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
byte[] newArray;
if (!baseType.isFixedWidth()) {
-
+ byte serializationVersion = arrayBytes[offset + length - Bytes.SIZEOF_BYTE];
int offsetArrayPosition = Bytes.toInt(arrayBytes, offset + length - Bytes.SIZEOF_INT - Bytes.SIZEOF_INT
- Bytes.SIZEOF_BYTE, Bytes.SIZEOF_INT);
int offsetArrayLength = length - offsetArrayPosition - Bytes.SIZEOF_INT - Bytes.SIZEOF_INT
@@ -612,7 +597,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
int off = newOffsetArrayPosition;
for (int arrayIndex = 0; arrayIndex < Math.abs(arrayLength) - 1; arrayIndex++) {
Bytes.putInt(newArray, off,
- getOffset(arrayBytes, arrayIndex, true, offsetArrayPosition + offset));
+ getOffset(arrayBytes, arrayIndex, true, offsetArrayPosition + offset, serializationVersion));
off += Bytes.SIZEOF_INT;
}
@@ -659,6 +644,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
byte[] newArray;
if (!baseType.isFixedWidth()) {
+ byte serializationVersion = arrayBytes[offset + length - Bytes.SIZEOF_BYTE];
int offsetArrayPosition = Bytes.toInt(arrayBytes, offset + length - Bytes.SIZEOF_INT - Bytes.SIZEOF_INT
- Bytes.SIZEOF_BYTE, Bytes.SIZEOF_INT);
int offsetArrayLength = length - offsetArrayPosition - Bytes.SIZEOF_INT - Bytes.SIZEOF_INT
@@ -668,7 +654,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
// checks whether offset array consists of shorts or integers
boolean useInt = offsetArrayLength / arrayLength == Bytes.SIZEOF_INT;
boolean convertToInt = false;
- int endElementPosition = getOffset(arrayBytes, arrayLength - 1, !useInt, offsetArrayPosition + offset)
+ int endElementPosition = getOffset(arrayBytes, arrayLength - 1, !useInt, offsetArrayPosition + offset, serializationVersion)
+ elementLength + Bytes.SIZEOF_BYTE;
int newOffsetArrayPosition;
int lengthIncrease;
@@ -679,7 +665,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
int nulls = 1;
// counts the number of nulls which are already at the beginning of the array
for (int index = 0; index < arrayLength; index++) {
- int currOffset = getOffset(arrayBytes, index, !useInt, offsetArrayPosition + offset);
+ int currOffset = getOffset(arrayBytes, index, !useInt, offsetArrayPosition + offset, serializationVersion);
if (arrayBytes[offset + currOffset] == QueryConstants.SEPARATOR_BYTE) {
nulls++;
} else {
@@ -709,7 +695,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
// ex: initial array - 0 45(inverted) 65 0 66 0 0 0 after prepending null - 0 46(inverted) 65 0 66 0 0 0
lengthIncrease = nRemainingNulls == 1 ? (nMultiplesOver255 == 0 ? 2 * Bytes.SIZEOF_BYTE
: Bytes.SIZEOF_BYTE) : 0;
- endElementPosition = getOffset(arrayBytes, arrayLength - 1, !useInt, offsetArrayPosition + offset)
+ endElementPosition = getOffset(arrayBytes, arrayLength - 1, !useInt, offsetArrayPosition + offset, serializationVersion)
+ lengthIncrease;
if (!useInt) {
if (PArrayDataType.useShortForOffsetArray(endElementPosition)) {
@@ -785,8 +771,9 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
currentPosition += offsetArrayElementSize;
boolean nullsAtBeginning = true;
+ byte serializationVersion = arrayBytes[offset + length - Bytes.SIZEOF_BYTE];
for (int arrayIndex = 0; arrayIndex < arrayLength - 1; arrayIndex++) {
- int oldOffset = getOffset(arrayBytes, arrayIndex, useShortPrevious, offsetArrayPosition + offset);
+ int oldOffset = getOffset(arrayBytes, arrayIndex, useShortPrevious, offsetArrayPosition + offset, serializationVersion);
if (arrayBytes[offset + oldOffset] == QueryConstants.SEPARATOR_BYTE && nullsAtBeginning) {
if (useShortNew) {
Bytes.putShort(newArray, currentPosition, (short)(oldOffset - Short.MAX_VALUE));
@@ -820,6 +807,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
byte[] newArray;
if (!baseType.isFixedWidth()) {
+ byte serializationVersion1 = array1Bytes[array1BytesOffset + array1BytesLength - Bytes.SIZEOF_BYTE];
int offsetArrayPositionArray1 = Bytes.toInt(array1Bytes, array1BytesOffset + array1BytesLength
- Bytes.SIZEOF_INT - Bytes.SIZEOF_INT - Bytes.SIZEOF_BYTE, Bytes.SIZEOF_INT);
int offsetArrayPositionArray2 = Bytes.toInt(array2Bytes, array2BytesOffset + array2BytesLength
@@ -837,7 +825,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
boolean useIntNewArray = false;
// count nulls at the end of array 1
for (int index = actualLengthOfArray1 - 1; index > -1; index--) {
- int offset = getOffset(array1Bytes, index, !useIntArray1, array1BytesOffset + offsetArrayPositionArray1);
+ int offset = getOffset(array1Bytes, index, !useIntArray1, array1BytesOffset + offsetArrayPositionArray1, serializationVersion1);
if (array1Bytes[array1BytesOffset + offset] == QueryConstants.SEPARATOR_BYTE || array1Bytes[array1BytesOffset + offset] == QueryConstants.DESC_SEPARATOR_BYTE) {
nullsAtTheEndOfArray1++;
} else {
@@ -847,8 +835,9 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
// count nulls at the beginning of the array 2
int array2FirstNonNullElementOffset = 0;
int array2FirstNonNullIndex = 0;
+ byte serializationVersion2 = array2Bytes[array2BytesOffset + array2BytesLength - Bytes.SIZEOF_BYTE];
for (int index = 0; index < actualLengthOfArray2; index++) {
- int offset = getOffset(array2Bytes, index, !useIntArray2, array2BytesOffset + offsetArrayPositionArray2);
+ int offset = getOffset(array2Bytes, index, !useIntArray2, array2BytesOffset + offsetArrayPositionArray2, serializationVersion2);
if (array2Bytes[array2BytesOffset + offset] == QueryConstants.SEPARATOR_BYTE) {
nullsAtTheBeginningOfArray2++;
} else {
@@ -870,7 +859,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
int newOffsetArrayPosition = offsetArrayPositionArray1 + offsetArrayPositionArray2 + lengthIncreaseForNulls
- 2 * Bytes.SIZEOF_BYTE;
int endElementPositionOfArray2 = getOffset(array2Bytes, actualLengthOfArray2 - 1, !useIntArray2,
- array2BytesOffset + offsetArrayPositionArray2);
+ array2BytesOffset + offsetArrayPositionArray2, serializationVersion2);
int newEndElementPosition = lengthIncreaseForNulls + endElementPositionOfArray2 + offsetArrayPositionArray1
- 2 * Bytes.SIZEOF_BYTE;
// Creates a byte array to store the concatenated array
@@ -902,14 +891,14 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
// offsets for the elements from array 1. Simply copied.
for (int index = 0; index < actualLengthOfArray1; index++) {
int offset = getOffset(array1Bytes, index, !useIntArray1, array1BytesOffset
- + offsetArrayPositionArray1);
+ + offsetArrayPositionArray1, serializationVersion1);
Bytes.putInt(newArray, currentPosition, offset);
currentPosition += Bytes.SIZEOF_INT;
}
// offsets for nulls in the middle
for (int index = 0; index < array2FirstNonNullIndex; index++) {
int offset = getOffset(array2Bytes, index, !useIntArray2, array2BytesOffset
- + offsetArrayPositionArray2);
+ + offsetArrayPositionArray2, serializationVersion2);
Bytes.putInt(newArray, currentPosition, offset + array2StartingPosition);
currentPosition += Bytes.SIZEOF_INT;
}
@@ -918,7 +907,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
+ (bytesForNullsAfter == 0 ? 0 : Bytes.SIZEOF_BYTE);
for (int index = array2FirstNonNullIndex; index < actualLengthOfArray2; index++) {
int offset = getOffset(array2Bytes, index, !useIntArray2, array2BytesOffset
- + offsetArrayPositionArray2);
+ + offsetArrayPositionArray2, serializationVersion2);
Bytes.putInt(newArray, currentPosition, offset - array2FirstNonNullElementOffset
+ part2NonNullStartingPosition);
currentPosition += Bytes.SIZEOF_INT;
@@ -927,14 +916,14 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
// offsets for the elements from array 1. Simply copied.
for (int index = 0; index < actualLengthOfArray1; index++) {
int offset = getOffset(array1Bytes, index, !useIntArray1, array1BytesOffset
- + offsetArrayPositionArray1);
+ + offsetArrayPositionArray1, serializationVersion1);
Bytes.putShort(newArray, currentPosition, (short)(offset - Short.MAX_VALUE));
currentPosition += Bytes.SIZEOF_SHORT;
}
// offsets for nulls in the middle
for (int index = 0; index < array2FirstNonNullIndex; index++) {
int offset = getOffset(array2Bytes, index, !useIntArray2, array2BytesOffset
- + offsetArrayPositionArray2);
+ + offsetArrayPositionArray2, serializationVersion2);
Bytes.putShort(newArray, currentPosition,
(short)(offset + array2StartingPosition - Short.MAX_VALUE));
currentPosition += Bytes.SIZEOF_SHORT;
@@ -944,7 +933,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
+ (bytesForNullsAfter == 0 ? 0 : Bytes.SIZEOF_BYTE);
for (int index = array2FirstNonNullIndex; index < actualLengthOfArray2; index++) {
int offset = getOffset(array2Bytes, index, !useIntArray2, array2BytesOffset
- + offsetArrayPositionArray2);
+ + offsetArrayPositionArray2, serializationVersion2);
Bytes.putShort(newArray, currentPosition, (short)(offset - array2FirstNonNullElementOffset
+ part2NonNullStartingPosition - Short.MAX_VALUE));
currentPosition += Bytes.SIZEOF_SHORT;
@@ -1013,13 +1002,13 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
ptr.set(PVarcharArray.INSTANCE.toBytes(phoenixArray, PVarchar.INSTANCE, sortOrder));
return true;
}
-
- public static int serailizeOffsetArrayIntoStream(DataOutputStream oStream, TrustedByteArrayOutputStream byteStream,
- int noOfElements, int maxOffset, int[] offsetPos) throws IOException {
+
+ public static int serializeOffsetArrayIntoStream(DataOutputStream oStream, TrustedByteArrayOutputStream byteStream,
+ int noOfElements, int maxOffset, int[] offsetPos, byte serializationVersion) throws IOException {
int offsetPosition = (byteStream.size());
byte[] offsetArr = null;
boolean useInt = true;
- if (PArrayDataType.useShortForOffsetArray(maxOffset)) {
+ if (PArrayDataType.useShortForOffsetArray(maxOffset, serializationVersion)) {
offsetArr = new byte[PArrayDataType.initOffsetArray(noOfElements, Bytes.SIZEOF_SHORT)];
useInt = false;
} else {
@@ -1034,7 +1023,8 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
}
} else {
for (int pos : offsetPos) {
- Bytes.putShort(offsetArr, off, (short)(pos - Short.MAX_VALUE));
+ short val = serializationVersion == PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION ? (short)pos : (short)(pos - Short.MAX_VALUE);
+ Bytes.putShort(offsetArr, off, val);
off += Bytes.SIZEOF_SHORT;
}
}
@@ -1043,18 +1033,11 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
return noOfElements;
}
- public static void serializeHeaderInfoIntoBuffer(ByteBuffer buffer, int noOfElements) {
- // No of elements
- buffer.putInt(noOfElements);
- // Version of the array
- buffer.put(ARRAY_SERIALIZATION_VERSION);
- }
-
- public static void serializeHeaderInfoIntoStream(DataOutputStream oStream, int noOfElements) throws IOException {
+ public static void serializeHeaderInfoIntoStream(DataOutputStream oStream, int noOfElements, byte serializationVersion) throws IOException {
// No of elements
oStream.writeInt(noOfElements);
// Version of the array
- oStream.write(ARRAY_SERIALIZATION_VERSION);
+ oStream.write(serializationVersion);
}
public static int initOffsetArray(int noOfElements, int baseSize) {
@@ -1229,8 +1212,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
return buf.toString();
}
- // FIXME: remove this duplicate code
- static public class PArrayDataTypeBytesArrayBuilder<T> {
+ static public class PArrayDataTypeBytesArrayBuilder {
static private final int BYTE_ARRAY_DEFAULT_SIZE = 128;
private PDataType baseType;
@@ -1239,14 +1221,38 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
private TrustedByteArrayOutputStream byteStream;
private DataOutputStream oStream;
private int nulls;
+ private byte serializationVersion;
+ private boolean rowKeyOrderOptimizable;
public PArrayDataTypeBytesArrayBuilder(PDataType baseType, SortOrder sortOrder) {
+ this(new TrustedByteArrayOutputStream(BYTE_ARRAY_DEFAULT_SIZE), new LinkedList<Integer>(), baseType, sortOrder, true);
+ }
+
+ public PArrayDataTypeBytesArrayBuilder(TrustedByteArrayOutputStream byteStream, DataOutputStream oStream,
+ int numElements, PDataType baseType, SortOrder sortOrder, boolean rowKeyOrderOptimizable, byte serializationVersion) {
+ this(byteStream, oStream, new ArrayList<Integer>(numElements), baseType, sortOrder, rowKeyOrderOptimizable, serializationVersion);
+ }
+
+ public PArrayDataTypeBytesArrayBuilder(TrustedByteArrayOutputStream byteStream, DataOutputStream oStream,
+ int numElements, PDataType baseType, SortOrder sortOrder, boolean rowKeyOrderOptimizable) {
+ this(byteStream, oStream, new ArrayList<Integer>(numElements), baseType, sortOrder, rowKeyOrderOptimizable, PArrayDataType.SORTABLE_SERIALIZATION_VERSION);
+ }
+
+ public PArrayDataTypeBytesArrayBuilder(TrustedByteArrayOutputStream byteStream,
+ List<Integer> offsetPos, PDataType baseType, SortOrder sortOrder, boolean rowKeyOrderOptimizable) {
+ this(byteStream, new DataOutputStream(byteStream), offsetPos, baseType, sortOrder, rowKeyOrderOptimizable, PArrayDataType.SORTABLE_SERIALIZATION_VERSION);
+ }
+
+ public PArrayDataTypeBytesArrayBuilder(TrustedByteArrayOutputStream byteStream, DataOutputStream oStream,
+ List<Integer> offsetPos, PDataType baseType, SortOrder sortOrder, boolean rowKeyOrderOptimizable, byte serializationVersion) {
this.baseType = baseType;
this.sortOrder = sortOrder;
- offsetPos = new LinkedList<Integer>();
- byteStream = new TrustedByteArrayOutputStream(BYTE_ARRAY_DEFAULT_SIZE);
- oStream = new DataOutputStream(byteStream);
- nulls = 0;
+ this.offsetPos = offsetPos;
+ this.byteStream = byteStream;
+ this.oStream = oStream;
+ this.nulls = 0;
+ this.serializationVersion = serializationVersion;
+ this.rowKeyOrderOptimizable = rowKeyOrderOptimizable;
}
private void close() {
@@ -1257,6 +1263,14 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
oStream = null;
} catch (IOException ioe) {}
}
+
+ // used to represent the absence of a value
+ public void appendMissingElement() {
+ if (serializationVersion == PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION && !baseType.isFixedWidth()) {
+ offsetPos.add(-byteStream.size());
+ nulls++;
+ }
+ }
public boolean appendElem(byte[] bytes) {
return appendElem(bytes, 0, bytes.length);
@@ -1265,7 +1279,19 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
public boolean appendElem(byte[] bytes, int offset, int len) {
if (oStream == null || byteStream == null) return false;
try {
+ // track the offset position here from the size of the byteStream
if (!baseType.isFixedWidth()) {
+ // Any variable length array would follow the below order
+ // Every element would be seperated by a seperator byte '0'
+ // Null elements are counted and once a first non null element appears we
+ // write the count of the nulls prefixed with a seperator byte
+ // Trailing nulls are not taken into account
+ // The last non null element is followed by two seperator bytes
+ // For eg
+ // a, b, null, null, c, null would be
+ // 65 0 66 0 0 2 67 0 0 0
+ // a null null null b c null d would be
+ // 65 0 0 3 66 0 67 0 0 1 68 0 0 0
if (len == 0) {
offsetPos.add(byteStream.size());
nulls++;
@@ -1277,9 +1303,12 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
offset = 0;
}
oStream.write(bytes, offset, len);
- oStream.write(getSeparatorByte(true, sortOrder));
+ if (serializationVersion == SORTABLE_SERIALIZATION_VERSION) {
+ oStream.write(getSeparatorByte(rowKeyOrderOptimizable, sortOrder));
+ }
}
} else {
+ // No nulls for fixed length
if (sortOrder == SortOrder.DESC) {
SortOrder.invert(bytes, offset, bytes, offset, len);
offset = 0;
@@ -1291,7 +1320,7 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
return false;
}
- public byte[] getBytesAndClose(SortOrder sortOrder) {
+ public byte[] getBytesAndClose() {
try {
if (!baseType.isFixedWidth()) {
int noOfElements = offsetPos.size();
@@ -1301,10 +1330,13 @@ public abstract class PArrayDataType<T> extends PDataType<T> {
offsetPosArray[index] = i;
++index;
}
- PArrayDataType.writeEndSeperatorForVarLengthArray(oStream, sortOrder);
- noOfElements = PArrayDataType.serailizeOffsetArrayIntoStream(oStream, byteStream, noOfElements,
- offsetPosArray[offsetPosArray.length - 1], offsetPosArray);
- serializeHeaderInfoIntoStream(oStream, noOfElements);
+ if (serializationVersion == SORTABLE_SERIALIZATION_VERSION) {
+ // Double seperator byte to show end of the non null array
+ writeEndSeperatorForVarLengthArray(oStream, sortOrder, rowKeyOrderOptimizable);
+ }
+ noOfElements = PArrayDataType.serializeOffsetArrayIntoStream(oStream, byteStream, noOfElements,
+ offsetPosArray[offsetPosArray.length - 1], offsetPosArray, serializationVersion);
+ serializeHeaderInfoIntoStream(oStream, noOfElements, serializationVersion);
}
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
ptr.set(byteStream.getBuffer(), 0, byteStream.size());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/01ef5d5b/phoenix-core/src/test/java/org/apache/phoenix/expression/ArrayConstructorExpressionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/ArrayConstructorExpressionTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/ArrayConstructorExpressionTest.java
index e99a71c..a78e87e 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/ArrayConstructorExpressionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/ArrayConstructorExpressionTest.java
@@ -18,11 +18,17 @@
package org.apache.phoenix.expression;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.List;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.phoenix.expression.function.ArrayElemRefExpression;
import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PArrayDataType;
import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.util.ByteUtil;
import org.junit.Test;
@@ -31,18 +37,34 @@ import com.google.common.collect.Lists;
public class ArrayConstructorExpressionTest {
+ private static final LiteralExpression CONSTANT_EXPRESSION = LiteralExpression.newConstant(QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
private static final byte[] BYTE_ARRAY1 = new byte[]{1,2,3,4,5};
private static final byte[] BYTE_ARRAY2 = new byte[]{6,7,8};
-
+ private Expression FALSE_EVAL_EXPRESSION = new DelegateExpression(LiteralExpression.newConstant(null)) {
+ @Override
+ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+ return false;
+ }
+ };
+
+ @Test
+ public void testLeadingNullsForSortableSerialization() throws Exception {
+ helpTestLeadingNulls(PArrayDataType.SORTABLE_SERIALIZATION_VERSION);
+ }
+
@Test
- public void testArraysWithLeadingNulls() throws Exception {
+ public void testLeadingNullsForImmutableSerialization() throws Exception {
+ helpTestLeadingNulls(PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION);
+ }
+
+ public void helpTestLeadingNulls(byte serializationVersion) throws Exception {
List<Expression> children = Lists.newArrayListWithExpectedSize(4);
LiteralExpression nullExpression = LiteralExpression.newConstant(null);
children.add(nullExpression);
children.add(nullExpression);
children.add(LiteralExpression.newConstant(BYTE_ARRAY1, PVarbinary.INSTANCE));
children.add(LiteralExpression.newConstant(BYTE_ARRAY2, PVarbinary.INSTANCE));
- ArrayConstructorExpression arrayConstructorExpression = new ArrayConstructorExpression(children, PVarbinary.INSTANCE, false);
+ ArrayConstructorExpression arrayConstructorExpression = new ArrayConstructorExpression(children, PVarbinary.INSTANCE, false, serializationVersion);
ImmutableBytesPtr ptr = new ImmutableBytesPtr();
ArrayElemRefExpression arrayElemRefExpression = new ArrayElemRefExpression(Lists.<Expression>newArrayList(arrayConstructorExpression));
@@ -60,4 +82,82 @@ public class ArrayConstructorExpressionTest {
arrayElemRefExpression.evaluate(null, ptr);
assertArrayEquals(BYTE_ARRAY2, ptr.copyBytesIfNecessary());
}
+
+ @Test
+ public void testWithExpressionsThatEvaluatetoFalse() throws Exception {
+ List<Expression> children = Lists.newArrayListWithExpectedSize(4);
+ children.add(CONSTANT_EXPRESSION);
+ children.add(FALSE_EVAL_EXPRESSION);
+ children.add(LiteralExpression.newConstant(BYTE_ARRAY1, PVarbinary.INSTANCE));
+ children.add(FALSE_EVAL_EXPRESSION);
+ children.add(LiteralExpression.newConstant(BYTE_ARRAY2, PVarbinary.INSTANCE));
+ ArrayConstructorExpression arrayConstructorExpression = new ArrayConstructorExpression(children, PVarbinary.INSTANCE, false, PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION);
+ ImmutableBytesPtr ptr = new ImmutableBytesPtr();
+
+ ArrayElemRefExpression arrayElemRefExpression = new ArrayElemRefExpression(Lists.<Expression>newArrayList(arrayConstructorExpression));
+ arrayElemRefExpression.setIndex(1);
+ assertTrue(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(QueryConstants.EMPTY_COLUMN_VALUE_BYTES, ptr.copyBytesIfNecessary());
+ arrayElemRefExpression.setIndex(2);
+ assertFalse(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptr.copyBytesIfNecessary());
+ arrayElemRefExpression.setIndex(3);
+ assertTrue(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(BYTE_ARRAY1, ptr.copyBytesIfNecessary());
+ arrayElemRefExpression.setIndex(4);
+ assertFalse(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptr.copyBytesIfNecessary());
+ arrayElemRefExpression.setIndex(5);
+ assertTrue(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(BYTE_ARRAY2, ptr.copyBytesIfNecessary());
+ }
+
+ @Test
+ public void testWithMaxOffsetLargerThanShortMax() throws Exception {
+ int numElements = Short.MAX_VALUE+2;
+ List<Expression> children = Lists.newArrayListWithExpectedSize(numElements);
+ for (int i=0; i<numElements; ++i) {
+ children.add(CONSTANT_EXPRESSION);
+ }
+ ArrayConstructorExpression arrayConstructorExpression = new ArrayConstructorExpression(children, PVarbinary.INSTANCE, false, PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION);
+ ArrayElemRefExpression arrayElemRefExpression = new ArrayElemRefExpression(Lists.<Expression>newArrayList(arrayConstructorExpression));
+ ImmutableBytesPtr ptr = new ImmutableBytesPtr();
+
+ arrayElemRefExpression.setIndex(1);
+ assertTrue(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(QueryConstants.EMPTY_COLUMN_VALUE_BYTES, ptr.copyBytesIfNecessary());
+
+ arrayElemRefExpression.setIndex(15000);
+ assertTrue(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(QueryConstants.EMPTY_COLUMN_VALUE_BYTES, ptr.copyBytesIfNecessary());
+
+ arrayElemRefExpression.setIndex(numElements);
+ assertTrue(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(QueryConstants.EMPTY_COLUMN_VALUE_BYTES, ptr.copyBytesIfNecessary());
+ }
+
+ @Test
+ public void testWithMaxOffsetSmallerThanShortMin() throws Exception {
+ int numElements = Short.MAX_VALUE+2;
+ List<Expression> children = Lists.newArrayListWithExpectedSize(numElements);
+ for (int i=1; i<numElements; i+=2) {
+ children.add(CONSTANT_EXPRESSION);
+ children.add(FALSE_EVAL_EXPRESSION);
+ }
+ ArrayConstructorExpression arrayConstructorExpression = new ArrayConstructorExpression(children, PVarbinary.INSTANCE, false, PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION);
+ ArrayElemRefExpression arrayElemRefExpression = new ArrayElemRefExpression(Lists.<Expression>newArrayList(arrayConstructorExpression));
+ ImmutableBytesPtr ptr = new ImmutableBytesPtr();
+
+ arrayElemRefExpression.setIndex(2);
+ assertFalse(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptr.copyBytesIfNecessary());
+
+ arrayElemRefExpression.setIndex(15000);
+ assertFalse(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptr.copyBytesIfNecessary());
+
+ arrayElemRefExpression.setIndex(numElements);
+ assertFalse(arrayElemRefExpression.evaluate(null, ptr));
+ assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptr.copyBytesIfNecessary());
+ }
}
[22/42] phoenix git commit: Fail-fast iterators for
EncodedColumnQualifierCellsList. Use list iterators instead of get(index) for
navigating lists. Use HBase bytes utility for encoded column names. Fix test
failures for immutable tables and indexes.
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
index b8b8b2f..2f0c00b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
@@ -269,6 +269,16 @@ public final class PTableProtos {
* <code>optional bool isDynamic = 14;</code>
*/
boolean getIsDynamic();
+
+ // optional int32 columnQualifier = 15;
+ /**
+ * <code>optional int32 columnQualifier = 15;</code>
+ */
+ boolean hasColumnQualifier();
+ /**
+ * <code>optional int32 columnQualifier = 15;</code>
+ */
+ int getColumnQualifier();
}
/**
* Protobuf type {@code PColumn}
@@ -391,6 +401,11 @@ public final class PTableProtos {
isDynamic_ = input.readBool();
break;
}
+ case 120: {
+ bitField0_ |= 0x00004000;
+ columnQualifier_ = input.readInt32();
+ break;
+ }
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -709,6 +724,22 @@ public final class PTableProtos {
return isDynamic_;
}
+ // optional int32 columnQualifier = 15;
+ public static final int COLUMNQUALIFIER_FIELD_NUMBER = 15;
+ private int columnQualifier_;
+ /**
+ * <code>optional int32 columnQualifier = 15;</code>
+ */
+ public boolean hasColumnQualifier() {
+ return ((bitField0_ & 0x00004000) == 0x00004000);
+ }
+ /**
+ * <code>optional int32 columnQualifier = 15;</code>
+ */
+ public int getColumnQualifier() {
+ return columnQualifier_;
+ }
+
private void initFields() {
columnNameBytes_ = com.google.protobuf.ByteString.EMPTY;
familyNameBytes_ = com.google.protobuf.ByteString.EMPTY;
@@ -724,6 +755,7 @@ public final class PTableProtos {
expression_ = "";
isRowTimestamp_ = false;
isDynamic_ = false;
+ columnQualifier_ = 0;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -799,6 +831,9 @@ public final class PTableProtos {
if (((bitField0_ & 0x00002000) == 0x00002000)) {
output.writeBool(14, isDynamic_);
}
+ if (((bitField0_ & 0x00004000) == 0x00004000)) {
+ output.writeInt32(15, columnQualifier_);
+ }
getUnknownFields().writeTo(output);
}
@@ -864,6 +899,10 @@ public final class PTableProtos {
size += com.google.protobuf.CodedOutputStream
.computeBoolSize(14, isDynamic_);
}
+ if (((bitField0_ & 0x00004000) == 0x00004000)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt32Size(15, columnQualifier_);
+ }
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
return size;
@@ -957,6 +996,11 @@ public final class PTableProtos {
result = result && (getIsDynamic()
== other.getIsDynamic());
}
+ result = result && (hasColumnQualifier() == other.hasColumnQualifier());
+ if (hasColumnQualifier()) {
+ result = result && (getColumnQualifier()
+ == other.getColumnQualifier());
+ }
result = result &&
getUnknownFields().equals(other.getUnknownFields());
return result;
@@ -1026,6 +1070,10 @@ public final class PTableProtos {
hash = (37 * hash) + ISDYNAMIC_FIELD_NUMBER;
hash = (53 * hash) + hashBoolean(getIsDynamic());
}
+ if (hasColumnQualifier()) {
+ hash = (37 * hash) + COLUMNQUALIFIER_FIELD_NUMBER;
+ hash = (53 * hash) + getColumnQualifier();
+ }
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
@@ -1163,6 +1211,8 @@ public final class PTableProtos {
bitField0_ = (bitField0_ & ~0x00001000);
isDynamic_ = false;
bitField0_ = (bitField0_ & ~0x00002000);
+ columnQualifier_ = 0;
+ bitField0_ = (bitField0_ & ~0x00004000);
return this;
}
@@ -1247,6 +1297,10 @@ public final class PTableProtos {
to_bitField0_ |= 0x00002000;
}
result.isDynamic_ = isDynamic_;
+ if (((from_bitField0_ & 0x00004000) == 0x00004000)) {
+ to_bitField0_ |= 0x00004000;
+ }
+ result.columnQualifier_ = columnQualifier_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -1309,6 +1363,9 @@ public final class PTableProtos {
if (other.hasIsDynamic()) {
setIsDynamic(other.getIsDynamic());
}
+ if (other.hasColumnQualifier()) {
+ setColumnQualifier(other.getColumnQualifier());
+ }
this.mergeUnknownFields(other.getUnknownFields());
return this;
}
@@ -1909,6 +1966,39 @@ public final class PTableProtos {
return this;
}
+ // optional int32 columnQualifier = 15;
+ private int columnQualifier_ ;
+ /**
+ * <code>optional int32 columnQualifier = 15;</code>
+ */
+ public boolean hasColumnQualifier() {
+ return ((bitField0_ & 0x00004000) == 0x00004000);
+ }
+ /**
+ * <code>optional int32 columnQualifier = 15;</code>
+ */
+ public int getColumnQualifier() {
+ return columnQualifier_;
+ }
+ /**
+ * <code>optional int32 columnQualifier = 15;</code>
+ */
+ public Builder setColumnQualifier(int value) {
+ bitField0_ |= 0x00004000;
+ columnQualifier_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional int32 columnQualifier = 15;</code>
+ */
+ public Builder clearColumnQualifier() {
+ bitField0_ = (bitField0_ & ~0x00004000);
+ columnQualifier_ = 0;
+ onChanged();
+ return this;
+ }
+
// @@protoc_insertion_point(builder_scope:PColumn)
}
@@ -3372,6 +3462,41 @@ public final class PTableProtos {
* <code>optional bytes parentNameBytes = 33;</code>
*/
com.google.protobuf.ByteString getParentNameBytes();
+
+ // optional bytes storageScheme = 34;
+ /**
+ * <code>optional bytes storageScheme = 34;</code>
+ */
+ boolean hasStorageScheme();
+ /**
+ * <code>optional bytes storageScheme = 34;</code>
+ */
+ com.google.protobuf.ByteString getStorageScheme();
+
+ // repeated .EncodedCQCounter encodedCQCounters = 35;
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter>
+ getEncodedCQCountersList();
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter getEncodedCQCounters(int index);
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ int getEncodedCQCountersCount();
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ java.util.List<? extends org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder>
+ getEncodedCQCountersOrBuilderList();
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder getEncodedCQCountersOrBuilder(
+ int index);
}
/**
* Protobuf type {@code PTable}
@@ -3407,6 +3532,7 @@ public final class PTableProtos {
throws com.google.protobuf.InvalidProtocolBufferException {
initFields();
int mutable_bitField0_ = 0;
+ int mutable_bitField1_ = 0;
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
@@ -3599,6 +3725,19 @@ public final class PTableProtos {
parentNameBytes_ = input.readBytes();
break;
}
+ case 274: {
+ bitField0_ |= 0x20000000;
+ storageScheme_ = input.readBytes();
+ break;
+ }
+ case 282: {
+ if (!((mutable_bitField1_ & 0x00000002) == 0x00000002)) {
+ encodedCQCounters_ = new java.util.ArrayList<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter>();
+ mutable_bitField1_ |= 0x00000002;
+ }
+ encodedCQCounters_.add(input.readMessage(org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.PARSER, extensionRegistry));
+ break;
+ }
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -3616,6 +3755,9 @@ public final class PTableProtos {
if (((mutable_bitField0_ & 0x00020000) == 0x00020000)) {
physicalNames_ = java.util.Collections.unmodifiableList(physicalNames_);
}
+ if (((mutable_bitField1_ & 0x00000002) == 0x00000002)) {
+ encodedCQCounters_ = java.util.Collections.unmodifiableList(encodedCQCounters_);
+ }
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
@@ -4275,6 +4417,58 @@ public final class PTableProtos {
return parentNameBytes_;
}
+ // optional bytes storageScheme = 34;
+ public static final int STORAGESCHEME_FIELD_NUMBER = 34;
+ private com.google.protobuf.ByteString storageScheme_;
+ /**
+ * <code>optional bytes storageScheme = 34;</code>
+ */
+ public boolean hasStorageScheme() {
+ return ((bitField0_ & 0x20000000) == 0x20000000);
+ }
+ /**
+ * <code>optional bytes storageScheme = 34;</code>
+ */
+ public com.google.protobuf.ByteString getStorageScheme() {
+ return storageScheme_;
+ }
+
+ // repeated .EncodedCQCounter encodedCQCounters = 35;
+ public static final int ENCODEDCQCOUNTERS_FIELD_NUMBER = 35;
+ private java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> encodedCQCounters_;
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> getEncodedCQCountersList() {
+ return encodedCQCounters_;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public java.util.List<? extends org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder>
+ getEncodedCQCountersOrBuilderList() {
+ return encodedCQCounters_;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public int getEncodedCQCountersCount() {
+ return encodedCQCounters_.size();
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter getEncodedCQCounters(int index) {
+ return encodedCQCounters_.get(index);
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder getEncodedCQCountersOrBuilder(
+ int index) {
+ return encodedCQCounters_.get(index);
+ }
+
private void initFields() {
schemaNameBytes_ = com.google.protobuf.ByteString.EMPTY;
tableNameBytes_ = com.google.protobuf.ByteString.EMPTY;
@@ -4308,6 +4502,8 @@ public final class PTableProtos {
autoParititonSeqName_ = "";
isAppendOnlySchema_ = false;
parentNameBytes_ = com.google.protobuf.ByteString.EMPTY;
+ storageScheme_ = com.google.protobuf.ByteString.EMPTY;
+ encodedCQCounters_ = java.util.Collections.emptyList();
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -4362,6 +4558,12 @@ public final class PTableProtos {
return false;
}
}
+ for (int i = 0; i < getEncodedCQCountersCount(); i++) {
+ if (!getEncodedCQCounters(i).isInitialized()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ }
memoizedIsInitialized = 1;
return true;
}
@@ -4465,6 +4667,12 @@ public final class PTableProtos {
if (((bitField0_ & 0x10000000) == 0x10000000)) {
output.writeBytes(33, parentNameBytes_);
}
+ if (((bitField0_ & 0x20000000) == 0x20000000)) {
+ output.writeBytes(34, storageScheme_);
+ }
+ for (int i = 0; i < encodedCQCounters_.size(); i++) {
+ output.writeMessage(35, encodedCQCounters_.get(i));
+ }
getUnknownFields().writeTo(output);
}
@@ -4607,6 +4815,14 @@ public final class PTableProtos {
size += com.google.protobuf.CodedOutputStream
.computeBytesSize(33, parentNameBytes_);
}
+ if (((bitField0_ & 0x20000000) == 0x20000000)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(34, storageScheme_);
+ }
+ for (int i = 0; i < encodedCQCounters_.size(); i++) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(35, encodedCQCounters_.get(i));
+ }
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
return size;
@@ -4781,6 +4997,13 @@ public final class PTableProtos {
result = result && getParentNameBytes()
.equals(other.getParentNameBytes());
}
+ result = result && (hasStorageScheme() == other.hasStorageScheme());
+ if (hasStorageScheme()) {
+ result = result && getStorageScheme()
+ .equals(other.getStorageScheme());
+ }
+ result = result && getEncodedCQCountersList()
+ .equals(other.getEncodedCQCountersList());
result = result &&
getUnknownFields().equals(other.getUnknownFields());
return result;
@@ -4922,6 +5145,14 @@ public final class PTableProtos {
hash = (37 * hash) + PARENTNAMEBYTES_FIELD_NUMBER;
hash = (53 * hash) + getParentNameBytes().hashCode();
}
+ if (hasStorageScheme()) {
+ hash = (37 * hash) + STORAGESCHEME_FIELD_NUMBER;
+ hash = (53 * hash) + getStorageScheme().hashCode();
+ }
+ if (getEncodedCQCountersCount() > 0) {
+ hash = (37 * hash) + ENCODEDCQCOUNTERS_FIELD_NUMBER;
+ hash = (53 * hash) + getEncodedCQCountersList().hashCode();
+ }
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
@@ -5025,6 +5256,7 @@ public final class PTableProtos {
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
getColumnsFieldBuilder();
getIndexesFieldBuilder();
+ getEncodedCQCountersFieldBuilder();
}
}
private static Builder create() {
@@ -5105,6 +5337,14 @@ public final class PTableProtos {
bitField0_ = (bitField0_ & ~0x40000000);
parentNameBytes_ = com.google.protobuf.ByteString.EMPTY;
bitField0_ = (bitField0_ & ~0x80000000);
+ storageScheme_ = com.google.protobuf.ByteString.EMPTY;
+ bitField1_ = (bitField1_ & ~0x00000001);
+ if (encodedCQCountersBuilder_ == null) {
+ encodedCQCounters_ = java.util.Collections.emptyList();
+ bitField1_ = (bitField1_ & ~0x00000002);
+ } else {
+ encodedCQCountersBuilder_.clear();
+ }
return this;
}
@@ -5132,6 +5372,7 @@ public final class PTableProtos {
public org.apache.phoenix.coprocessor.generated.PTableProtos.PTable buildPartial() {
org.apache.phoenix.coprocessor.generated.PTableProtos.PTable result = new org.apache.phoenix.coprocessor.generated.PTableProtos.PTable(this);
int from_bitField0_ = bitField0_;
+ int from_bitField1_ = bitField1_;
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
to_bitField0_ |= 0x00000001;
@@ -5272,6 +5513,19 @@ public final class PTableProtos {
to_bitField0_ |= 0x10000000;
}
result.parentNameBytes_ = parentNameBytes_;
+ if (((from_bitField1_ & 0x00000001) == 0x00000001)) {
+ to_bitField0_ |= 0x20000000;
+ }
+ result.storageScheme_ = storageScheme_;
+ if (encodedCQCountersBuilder_ == null) {
+ if (((bitField1_ & 0x00000002) == 0x00000002)) {
+ encodedCQCounters_ = java.util.Collections.unmodifiableList(encodedCQCounters_);
+ bitField1_ = (bitField1_ & ~0x00000002);
+ }
+ result.encodedCQCounters_ = encodedCQCounters_;
+ } else {
+ result.encodedCQCounters_ = encodedCQCountersBuilder_.build();
+ }
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -5441,6 +5695,35 @@ public final class PTableProtos {
if (other.hasParentNameBytes()) {
setParentNameBytes(other.getParentNameBytes());
}
+ if (other.hasStorageScheme()) {
+ setStorageScheme(other.getStorageScheme());
+ }
+ if (encodedCQCountersBuilder_ == null) {
+ if (!other.encodedCQCounters_.isEmpty()) {
+ if (encodedCQCounters_.isEmpty()) {
+ encodedCQCounters_ = other.encodedCQCounters_;
+ bitField1_ = (bitField1_ & ~0x00000002);
+ } else {
+ ensureEncodedCQCountersIsMutable();
+ encodedCQCounters_.addAll(other.encodedCQCounters_);
+ }
+ onChanged();
+ }
+ } else {
+ if (!other.encodedCQCounters_.isEmpty()) {
+ if (encodedCQCountersBuilder_.isEmpty()) {
+ encodedCQCountersBuilder_.dispose();
+ encodedCQCountersBuilder_ = null;
+ encodedCQCounters_ = other.encodedCQCounters_;
+ bitField1_ = (bitField1_ & ~0x00000002);
+ encodedCQCountersBuilder_ =
+ com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
+ getEncodedCQCountersFieldBuilder() : null;
+ } else {
+ encodedCQCountersBuilder_.addAllMessages(other.encodedCQCounters_);
+ }
+ }
+ }
this.mergeUnknownFields(other.getUnknownFields());
return this;
}
@@ -5494,6 +5777,12 @@ public final class PTableProtos {
return false;
}
}
+ for (int i = 0; i < getEncodedCQCountersCount(); i++) {
+ if (!getEncodedCQCounters(i).isInitialized()) {
+
+ return false;
+ }
+ }
return true;
}
@@ -5515,6 +5804,7 @@ public final class PTableProtos {
return this;
}
private int bitField0_;
+ private int bitField1_;
// required bytes schemaNameBytes = 1;
private com.google.protobuf.ByteString schemaNameBytes_ = com.google.protobuf.ByteString.EMPTY;
@@ -7168,101 +7458,1006 @@ public final class PTableProtos {
return this;
}
- // @@protoc_insertion_point(builder_scope:PTable)
- }
-
- static {
- defaultInstance = new PTable(true);
- defaultInstance.initFields();
- }
-
- // @@protoc_insertion_point(class_scope:PTable)
+ // optional bytes storageScheme = 34;
+ private com.google.protobuf.ByteString storageScheme_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * <code>optional bytes storageScheme = 34;</code>
+ */
+ public boolean hasStorageScheme() {
+ return ((bitField1_ & 0x00000001) == 0x00000001);
+ }
+ /**
+ * <code>optional bytes storageScheme = 34;</code>
+ */
+ public com.google.protobuf.ByteString getStorageScheme() {
+ return storageScheme_;
+ }
+ /**
+ * <code>optional bytes storageScheme = 34;</code>
+ */
+ public Builder setStorageScheme(com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
}
+ bitField1_ |= 0x00000001;
+ storageScheme_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional bytes storageScheme = 34;</code>
+ */
+ public Builder clearStorageScheme() {
+ bitField1_ = (bitField1_ & ~0x00000001);
+ storageScheme_ = getDefaultInstance().getStorageScheme();
+ onChanged();
+ return this;
+ }
- private static com.google.protobuf.Descriptors.Descriptor
- internal_static_PColumn_descriptor;
- private static
- com.google.protobuf.GeneratedMessage.FieldAccessorTable
- internal_static_PColumn_fieldAccessorTable;
- private static com.google.protobuf.Descriptors.Descriptor
- internal_static_PTableStats_descriptor;
- private static
- com.google.protobuf.GeneratedMessage.FieldAccessorTable
- internal_static_PTableStats_fieldAccessorTable;
- private static com.google.protobuf.Descriptors.Descriptor
- internal_static_PTable_descriptor;
- private static
- com.google.protobuf.GeneratedMessage.FieldAccessorTable
- internal_static_PTable_fieldAccessorTable;
+ // repeated .EncodedCQCounter encodedCQCounters = 35;
+ private java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> encodedCQCounters_ =
+ java.util.Collections.emptyList();
+ private void ensureEncodedCQCountersIsMutable() {
+ if (!((bitField1_ & 0x00000002) == 0x00000002)) {
+ encodedCQCounters_ = new java.util.ArrayList<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter>(encodedCQCounters_);
+ bitField1_ |= 0x00000002;
+ }
+ }
- public static com.google.protobuf.Descriptors.FileDescriptor
- getDescriptor() {
- return descriptor;
- }
- private static com.google.protobuf.Descriptors.FileDescriptor
- descriptor;
- static {
- java.lang.String[] descriptorData = {
- "\n\014PTable.proto\032\021PGuidePosts.proto\"\246\002\n\007PC" +
- "olumn\022\027\n\017columnNameBytes\030\001 \002(\014\022\027\n\017family" +
- "NameBytes\030\002 \001(\014\022\020\n\010dataType\030\003 \002(\t\022\021\n\tmax" +
- "Length\030\004 \001(\005\022\r\n\005scale\030\005 \001(\005\022\020\n\010nullable\030" +
- "\006 \002(\010\022\020\n\010position\030\007 \002(\005\022\021\n\tsortOrder\030\010 \002" +
- "(\005\022\021\n\tarraySize\030\t \001(\005\022\024\n\014viewConstant\030\n " +
- "\001(\014\022\026\n\016viewReferenced\030\013 \001(\010\022\022\n\nexpressio" +
- "n\030\014 \001(\t\022\026\n\016isRowTimestamp\030\r \001(\010\022\021\n\tisDyn" +
- "amic\030\016 \001(\010\"\232\001\n\013PTableStats\022\013\n\003key\030\001 \002(\014\022" +
- "\016\n\006values\030\002 \003(\014\022\033\n\023guidePostsByteCount\030\003",
- " \001(\003\022\025\n\rkeyBytesCount\030\004 \001(\003\022\027\n\017guidePost" +
- "sCount\030\005 \001(\005\022!\n\013pGuidePosts\030\006 \001(\0132\014.PGui" +
- "dePosts\"\217\006\n\006PTable\022\027\n\017schemaNameBytes\030\001 " +
- "\002(\014\022\026\n\016tableNameBytes\030\002 \002(\014\022\036\n\ttableType" +
- "\030\003 \002(\0162\013.PTableType\022\022\n\nindexState\030\004 \001(\t\022" +
- "\026\n\016sequenceNumber\030\005 \002(\003\022\021\n\ttimeStamp\030\006 \002" +
- "(\003\022\023\n\013pkNameBytes\030\007 \001(\014\022\021\n\tbucketNum\030\010 \002" +
- "(\005\022\031\n\007columns\030\t \003(\0132\010.PColumn\022\030\n\007indexes" +
- "\030\n \003(\0132\007.PTable\022\027\n\017isImmutableRows\030\013 \002(\010" +
- "\022\032\n\022dataTableNameBytes\030\r \001(\014\022\031\n\021defaultF",
- "amilyName\030\016 \001(\014\022\022\n\ndisableWAL\030\017 \002(\010\022\023\n\013m" +
- "ultiTenant\030\020 \002(\010\022\020\n\010viewType\030\021 \001(\014\022\025\n\rvi" +
- "ewStatement\030\022 \001(\014\022\025\n\rphysicalNames\030\023 \003(\014" +
- "\022\020\n\010tenantId\030\024 \001(\014\022\023\n\013viewIndexId\030\025 \001(\005\022" +
- "\021\n\tindexType\030\026 \001(\014\022\026\n\016statsTimeStamp\030\027 \001" +
- "(\003\022\022\n\nstoreNulls\030\030 \001(\010\022\027\n\017baseColumnCoun" +
- "t\030\031 \001(\005\022\036\n\026rowKeyOrderOptimizable\030\032 \001(\010\022" +
- "\025\n\rtransactional\030\033 \001(\010\022\034\n\024updateCacheFre" +
- "quency\030\034 \001(\003\022\035\n\025indexDisableTimestamp\030\035 " +
- "\001(\003\022\031\n\021isNamespaceMapped\030\036 \001(\010\022\034\n\024autoPa",
- "rititonSeqName\030\037 \001(\t\022\032\n\022isAppendOnlySche" +
- "ma\030 \001(\010\022\027\n\017parentNameBytes\030! \001(\014*A\n\nPTa" +
- "bleType\022\n\n\006SYSTEM\020\000\022\010\n\004USER\020\001\022\010\n\004VIEW\020\002\022" +
- "\t\n\005INDEX\020\003\022\010\n\004JOIN\020\004B@\n(org.apache.phoen" +
- "ix.coprocessor.generatedB\014PTableProtosH\001" +
- "\210\001\001\240\001\001"
- };
- com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
- new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
- public com.google.protobuf.ExtensionRegistry assignDescriptors(
- com.google.protobuf.Descriptors.FileDescriptor root) {
- descriptor = root;
- internal_static_PColumn_descriptor =
- getDescriptor().getMessageTypes().get(0);
- internal_static_PColumn_fieldAccessorTable = new
- com.google.protobuf.GeneratedMessage.FieldAccessorTable(
- internal_static_PColumn_descriptor,
- new java.lang.String[] { "ColumnNameBytes", "FamilyNameBytes", "DataType", "MaxLength", "Scale", "Nullable", "Position", "SortOrder", "ArraySize", "ViewConstant", "ViewReferenced", "Expression", "IsRowTimestamp", "IsDynamic", });
- internal_static_PTableStats_descriptor =
- getDescriptor().getMessageTypes().get(1);
- internal_static_PTableStats_fieldAccessorTable = new
- com.google.protobuf.GeneratedMessage.FieldAccessorTable(
- internal_static_PTableStats_descriptor,
- new java.lang.String[] { "Key", "Values", "GuidePostsByteCount", "KeyBytesCount", "GuidePostsCount", "PGuidePosts", });
- internal_static_PTable_descriptor =
- getDescriptor().getMessageTypes().get(2);
- internal_static_PTable_fieldAccessorTable = new
- com.google.protobuf.GeneratedMessage.FieldAccessorTable(
- internal_static_PTable_descriptor,
- new java.lang.String[] { "SchemaNameBytes", "TableNameBytes", "TableType", "IndexState", "SequenceNumber", "TimeStamp", "PkNameBytes", "BucketNum", "Columns", "Indexes", "IsImmutableRows", "DataTableNameBytes", "DefaultFamilyName", "DisableWAL", "MultiTenant", "ViewType", "ViewStatement", "PhysicalNames", "TenantId", "ViewIndexId", "IndexType", "StatsTimeStamp", "StoreNulls", "BaseColumnCount", "RowKeyOrderOptimizable", "Transactional", "UpdateCacheFrequency", "IndexDisableTimestamp", "IsNamespaceMapped", "AutoParititonSeqName", "IsAppendOnlySchema", "ParentNameBytes", });
+ private com.google.protobuf.RepeatedFieldBuilder<
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder> encodedCQCountersBuilder_;
+
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> getEncodedCQCountersList() {
+ if (encodedCQCountersBuilder_ == null) {
+ return java.util.Collections.unmodifiableList(encodedCQCounters_);
+ } else {
+ return encodedCQCountersBuilder_.getMessageList();
+ }
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public int getEncodedCQCountersCount() {
+ if (encodedCQCountersBuilder_ == null) {
+ return encodedCQCounters_.size();
+ } else {
+ return encodedCQCountersBuilder_.getCount();
+ }
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter getEncodedCQCounters(int index) {
+ if (encodedCQCountersBuilder_ == null) {
+ return encodedCQCounters_.get(index);
+ } else {
+ return encodedCQCountersBuilder_.getMessage(index);
+ }
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public Builder setEncodedCQCounters(
+ int index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter value) {
+ if (encodedCQCountersBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensureEncodedCQCountersIsMutable();
+ encodedCQCounters_.set(index, value);
+ onChanged();
+ } else {
+ encodedCQCountersBuilder_.setMessage(index, value);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public Builder setEncodedCQCounters(
+ int index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder builderForValue) {
+ if (encodedCQCountersBuilder_ == null) {
+ ensureEncodedCQCountersIsMutable();
+ encodedCQCounters_.set(index, builderForValue.build());
+ onChanged();
+ } else {
+ encodedCQCountersBuilder_.setMessage(index, builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public Builder addEncodedCQCounters(org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter value) {
+ if (encodedCQCountersBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensureEncodedCQCountersIsMutable();
+ encodedCQCounters_.add(value);
+ onChanged();
+ } else {
+ encodedCQCountersBuilder_.addMessage(value);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public Builder addEncodedCQCounters(
+ int index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter value) {
+ if (encodedCQCountersBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensureEncodedCQCountersIsMutable();
+ encodedCQCounters_.add(index, value);
+ onChanged();
+ } else {
+ encodedCQCountersBuilder_.addMessage(index, value);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public Builder addEncodedCQCounters(
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder builderForValue) {
+ if (encodedCQCountersBuilder_ == null) {
+ ensureEncodedCQCountersIsMutable();
+ encodedCQCounters_.add(builderForValue.build());
+ onChanged();
+ } else {
+ encodedCQCountersBuilder_.addMessage(builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public Builder addEncodedCQCounters(
+ int index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder builderForValue) {
+ if (encodedCQCountersBuilder_ == null) {
+ ensureEncodedCQCountersIsMutable();
+ encodedCQCounters_.add(index, builderForValue.build());
+ onChanged();
+ } else {
+ encodedCQCountersBuilder_.addMessage(index, builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public Builder addAllEncodedCQCounters(
+ java.lang.Iterable<? extends org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter> values) {
+ if (encodedCQCountersBuilder_ == null) {
+ ensureEncodedCQCountersIsMutable();
+ super.addAll(values, encodedCQCounters_);
+ onChanged();
+ } else {
+ encodedCQCountersBuilder_.addAllMessages(values);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public Builder clearEncodedCQCounters() {
+ if (encodedCQCountersBuilder_ == null) {
+ encodedCQCounters_ = java.util.Collections.emptyList();
+ bitField1_ = (bitField1_ & ~0x00000002);
+ onChanged();
+ } else {
+ encodedCQCountersBuilder_.clear();
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public Builder removeEncodedCQCounters(int index) {
+ if (encodedCQCountersBuilder_ == null) {
+ ensureEncodedCQCountersIsMutable();
+ encodedCQCounters_.remove(index);
+ onChanged();
+ } else {
+ encodedCQCountersBuilder_.remove(index);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder getEncodedCQCountersBuilder(
+ int index) {
+ return getEncodedCQCountersFieldBuilder().getBuilder(index);
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder getEncodedCQCountersOrBuilder(
+ int index) {
+ if (encodedCQCountersBuilder_ == null) {
+ return encodedCQCounters_.get(index); } else {
+ return encodedCQCountersBuilder_.getMessageOrBuilder(index);
+ }
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public java.util.List<? extends org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder>
+ getEncodedCQCountersOrBuilderList() {
+ if (encodedCQCountersBuilder_ != null) {
+ return encodedCQCountersBuilder_.getMessageOrBuilderList();
+ } else {
+ return java.util.Collections.unmodifiableList(encodedCQCounters_);
+ }
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder addEncodedCQCountersBuilder() {
+ return getEncodedCQCountersFieldBuilder().addBuilder(
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.getDefaultInstance());
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder addEncodedCQCountersBuilder(
+ int index) {
+ return getEncodedCQCountersFieldBuilder().addBuilder(
+ index, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.getDefaultInstance());
+ }
+ /**
+ * <code>repeated .EncodedCQCounter encodedCQCounters = 35;</code>
+ */
+ public java.util.List<org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder>
+ getEncodedCQCountersBuilderList() {
+ return getEncodedCQCountersFieldBuilder().getBuilderList();
+ }
+ private com.google.protobuf.RepeatedFieldBuilder<
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder>
+ getEncodedCQCountersFieldBuilder() {
+ if (encodedCQCountersBuilder_ == null) {
+ encodedCQCountersBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder>(
+ encodedCQCounters_,
+ ((bitField1_ & 0x00000002) == 0x00000002),
+ getParentForChildren(),
+ isClean());
+ encodedCQCounters_ = null;
+ }
+ return encodedCQCountersBuilder_;
+ }
+
+ // @@protoc_insertion_point(builder_scope:PTable)
+ }
+
+ static {
+ defaultInstance = new PTable(true);
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:PTable)
+ }
+
+ public interface EncodedCQCounterOrBuilder
+ extends com.google.protobuf.MessageOrBuilder {
+
+ // required string colFamily = 1;
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ boolean hasColFamily();
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ java.lang.String getColFamily();
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ com.google.protobuf.ByteString
+ getColFamilyBytes();
+
+ // required int32 counter = 2;
+ /**
+ * <code>required int32 counter = 2;</code>
+ */
+ boolean hasCounter();
+ /**
+ * <code>required int32 counter = 2;</code>
+ */
+ int getCounter();
+ }
+ /**
+ * Protobuf type {@code EncodedCQCounter}
+ */
+ public static final class EncodedCQCounter extends
+ com.google.protobuf.GeneratedMessage
+ implements EncodedCQCounterOrBuilder {
+ // Use EncodedCQCounter.newBuilder() to construct.
+ private EncodedCQCounter(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+ super(builder);
+ this.unknownFields = builder.getUnknownFields();
+ }
+ private EncodedCQCounter(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+
+ private static final EncodedCQCounter defaultInstance;
+ public static EncodedCQCounter getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public EncodedCQCounter getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ private final com.google.protobuf.UnknownFieldSet unknownFields;
+ @java.lang.Override
+ public final com.google.protobuf.UnknownFieldSet
+ getUnknownFields() {
+ return this.unknownFields;
+ }
+ private EncodedCQCounter(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ initFields();
+ int mutable_bitField0_ = 0;
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder();
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ done = true;
+ }
+ break;
+ }
+ case 10: {
+ bitField0_ |= 0x00000001;
+ colFamily_ = input.readBytes();
+ break;
+ }
+ case 16: {
+ bitField0_ |= 0x00000002;
+ counter_ = input.readInt32();
+ break;
+ }
+ }
+ }
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(this);
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(
+ e.getMessage()).setUnfinishedMessage(this);
+ } finally {
+ this.unknownFields = unknownFields.build();
+ makeExtensionsImmutable();
+ }
+ }
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return org.apache.phoenix.coprocessor.generated.PTableProtos.internal_static_EncodedCQCounter_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return org.apache.phoenix.coprocessor.generated.PTableProtos.internal_static_EncodedCQCounter_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.class, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder.class);
+ }
+
+ public static com.google.protobuf.Parser<EncodedCQCounter> PARSER =
+ new com.google.protobuf.AbstractParser<EncodedCQCounter>() {
+ public EncodedCQCounter parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return new EncodedCQCounter(input, extensionRegistry);
+ }
+ };
+
+ @java.lang.Override
+ public com.google.protobuf.Parser<EncodedCQCounter> getParserForType() {
+ return PARSER;
+ }
+
+ private int bitField0_;
+ // required string colFamily = 1;
+ public static final int COLFAMILY_FIELD_NUMBER = 1;
+ private java.lang.Object colFamily_;
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ public boolean hasColFamily() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ public java.lang.String getColFamily() {
+ java.lang.Object ref = colFamily_;
+ if (ref instanceof java.lang.String) {
+ return (java.lang.String) ref;
+ } else {
+ com.google.protobuf.ByteString bs =
+ (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ if (bs.isValidUtf8()) {
+ colFamily_ = s;
+ }
+ return s;
+ }
+ }
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ public com.google.protobuf.ByteString
+ getColFamilyBytes() {
+ java.lang.Object ref = colFamily_;
+ if (ref instanceof java.lang.String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ colFamily_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+
+ // required int32 counter = 2;
+ public static final int COUNTER_FIELD_NUMBER = 2;
+ private int counter_;
+ /**
+ * <code>required int32 counter = 2;</code>
+ */
+ public boolean hasCounter() {
+ return ((bitField0_ & 0x00000002) == 0x00000002);
+ }
+ /**
+ * <code>required int32 counter = 2;</code>
+ */
+ public int getCounter() {
+ return counter_;
+ }
+
+ private void initFields() {
+ colFamily_ = "";
+ counter_ = 0;
+ }
+ private byte memoizedIsInitialized = -1;
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized != -1) return isInitialized == 1;
+
+ if (!hasColFamily()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ if (!hasCounter()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ output.writeBytes(1, getColFamilyBytes());
+ }
+ if (((bitField0_ & 0x00000002) == 0x00000002)) {
+ output.writeInt32(2, counter_);
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(1, getColFamilyBytes());
+ }
+ if (((bitField0_ & 0x00000002) == 0x00000002)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt32Size(2, counter_);
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ private static final long serialVersionUID = 0L;
+ @java.lang.Override
+ protected java.lang.Object writeReplace()
+ throws java.io.ObjectStreamException {
+ return super.writeReplace();
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter)) {
+ return super.equals(obj);
+ }
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter other = (org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter) obj;
+
+ boolean result = true;
+ result = result && (hasColFamily() == other.hasColFamily());
+ if (hasColFamily()) {
+ result = result && getColFamily()
+ .equals(other.getColFamily());
+ }
+ result = result && (hasCounter() == other.hasCounter());
+ if (hasCounter()) {
+ result = result && (getCounter()
+ == other.getCounter());
+ }
+ result = result &&
+ getUnknownFields().equals(other.getUnknownFields());
+ return result;
+ }
+
+ private int memoizedHashCode = 0;
+ @java.lang.Override
+ public int hashCode() {
+ if (memoizedHashCode != 0) {
+ return memoizedHashCode;
+ }
+ int hash = 41;
+ hash = (19 * hash) + getDescriptorForType().hashCode();
+ if (hasColFamily()) {
+ hash = (37 * hash) + COLFAMILY_FIELD_NUMBER;
+ hash = (53 * hash) + getColFamily().hashCode();
+ }
+ if (hasCounter()) {
+ hash = (37 * hash) + COUNTER_FIELD_NUMBER;
+ hash = (53 * hash) + getCounter();
+ }
+ hash = (29 * hash) + getUnknownFields().hashCode();
+ memoizedHashCode = hash;
+ return hash;
+ }
+
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input);
+ }
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input, extensionRegistry);
+ }
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code EncodedCQCounter}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder>
+ implements org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounterOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return org.apache.phoenix.coprocessor.generated.PTableProtos.internal_static_EncodedCQCounter_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return org.apache.phoenix.coprocessor.generated.PTableProtos.internal_static_EncodedCQCounter_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.class, org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder.class);
+ }
+
+ // Construct using org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+ }
+ }
+ private static Builder create() {
+ return new Builder();
+ }
+
+ public Builder clear() {
+ super.clear();
+ colFamily_ = "";
+ bitField0_ = (bitField0_ & ~0x00000001);
+ counter_ = 0;
+ bitField0_ = (bitField0_ & ~0x00000002);
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(buildPartial());
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return org.apache.phoenix.coprocessor.generated.PTableProtos.internal_static_EncodedCQCounter_descriptor;
+ }
+
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter getDefaultInstanceForType() {
+ return org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.getDefaultInstance();
+ }
+
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter build() {
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ public org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter buildPartial() {
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter result = new org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter(this);
+ int from_bitField0_ = bitField0_;
+ int to_bitField0_ = 0;
+ if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
+ to_bitField0_ |= 0x00000001;
+ }
+ result.colFamily_ = colFamily_;
+ if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
+ to_bitField0_ |= 0x00000002;
+ }
+ result.counter_ = counter_;
+ result.bitField0_ = to_bitField0_;
+ onBuilt();
+ return result;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter) {
+ return mergeFrom((org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter other) {
+ if (other == org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.getDefaultInstance()) return this;
+ if (other.hasColFamily()) {
+ bitField0_ |= 0x00000001;
+ colFamily_ = other.colFamily_;
+ onChanged();
+ }
+ if (other.hasCounter()) {
+ setCounter(other.getCounter());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public final boolean isInitialized() {
+ if (!hasColFamily()) {
+
+ return false;
+ }
+ if (!hasCounter()) {
+
+ return false;
+ }
+ return true;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter parsedMessage = null;
+ try {
+ parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ parsedMessage = (org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter) e.getUnfinishedMessage();
+ throw e;
+ } finally {
+ if (parsedMessage != null) {
+ mergeFrom(parsedMessage);
+ }
+ }
+ return this;
+ }
+ private int bitField0_;
+
+ // required string colFamily = 1;
+ private java.lang.Object colFamily_ = "";
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ public boolean hasColFamily() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ public java.lang.String getColFamily() {
+ java.lang.Object ref = colFamily_;
+ if (!(ref instanceof java.lang.String)) {
+ java.lang.String s = ((com.google.protobuf.ByteString) ref)
+ .toStringUtf8();
+ colFamily_ = s;
+ return s;
+ } else {
+ return (java.lang.String) ref;
+ }
+ }
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ public com.google.protobuf.ByteString
+ getColFamilyBytes() {
+ java.lang.Object ref = colFamily_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ colFamily_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ public Builder setColFamily(
+ java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000001;
+ colFamily_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ public Builder clearColFamily() {
+ bitField0_ = (bitField0_ & ~0x00000001);
+ colFamily_ = getDefaultInstance().getColFamily();
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required string colFamily = 1;</code>
+ */
+ public Builder setColFamilyBytes(
+ com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000001;
+ colFamily_ = value;
+ onChanged();
+ return this;
+ }
+
+ // required int32 counter = 2;
+ private int counter_ ;
+ /**
+ * <code>required int32 counter = 2;</code>
+ */
+ public boolean hasCounter() {
+ return ((bitField0_ & 0x00000002) == 0x00000002);
+ }
+ /**
+ * <code>required int32 counter = 2;</code>
+ */
+ public int getCounter() {
+ return counter_;
+ }
+ /**
+ * <code>required int32 counter = 2;</code>
+ */
+ public Builder setCounter(int value) {
+ bitField0_ |= 0x00000002;
+ counter_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required int32 counter = 2;</code>
+ */
+ public Builder clearCounter() {
+ bitField0_ = (bitField0_ & ~0x00000002);
+ counter_ = 0;
+ onChanged();
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:EncodedCQCounter)
+ }
+
+ static {
+ defaultInstance = new EncodedCQCounter(true);
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:EncodedCQCounter)
+ }
+
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_PColumn_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_PColumn_fieldAccessorTable;
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_PTableStats_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_PTableStats_fieldAccessorTable;
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_PTable_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_PTable_fieldAccessorTable;
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_EncodedCQCounter_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_EncodedCQCounter_fieldAccessorTable;
+
+ public static com.google.protobuf.Descriptors.FileDescriptor
+ getDescriptor() {
+ return descriptor;
+ }
+ private static com.google.protobuf.Descriptors.FileDescriptor
+ descriptor;
+ static {
+ java.lang.String[] descriptorData = {
+ "\n\014PTable.proto\032\021PGuidePosts.proto\"\277\002\n\007PC" +
+ "olumn\022\027\n\017columnNameBytes\030\001 \002(\014\022\027\n\017family" +
+ "NameBytes\030\002 \001(\014\022\020\n\010dataType\030\003 \002(\t\022\021\n\tmax" +
+ "Length\030\004 \001(\005\022\r\n\005scale\030\005 \001(\005\022\020\n\010nullable\030" +
+ "\006 \002(\010\022\020\n\010position\030\007 \002(\005\022\021\n\tsortOrder\030\010 \002" +
+ "(\005\022\021\n\tarraySize\030\t \001(\005\022\024\n\014viewConstant\030\n " +
+ "\001(\014\022\026\n\016viewReferenced\030\013 \001(\010\022\022\n\nexpressio" +
+ "n\030\014 \001(\t\022\026\n\016isRowTimestamp\030\r \001(\010\022\021\n\tisDyn" +
+ "amic\030\016 \001(\010\022\027\n\017columnQualifier\030\017 \001(\005\"\232\001\n\013" +
+ "PTableStats\022\013\n\003key\030\001 \002(\014\022\016\n\006values\030\002 \003(\014",
+ "\022\033\n\023guidePostsByteCount\030\003 \001(\003\022\025\n\rkeyByte" +
+ "sCount\030\004 \001(\003\022\027\n\017guidePostsCount\030\005 \001(\005\022!\n" +
+ "\013pGuidePosts\030\006 \001(\0132\014.PGuidePosts\"\324\006\n\006PTa" +
+ "ble\022\027\n\017schemaNameBytes\030\001 \002(\014\022\026\n\016tableNam" +
+ "eBytes\030\002 \002(\014\022\036\n\ttableType\030\003 \002(\0162\013.PTable" +
+ "Type\022\022\n\nindexState\030\004 \001(\t\022\026\n\016sequenceNumb" +
+ "er\030\005 \002(\003\022\021\n\ttimeStamp\030\006 \002(\003\022\023\n\013pkNameByt" +
+ "es\030\007 \001(\014\022\021\n\tbucketNum\030\010 \002(\005\022\031\n\007columns\030\t" +
+ " \003(\0132\010.PColumn\022\030\n\007indexes\030\n \003(\0132\007.PTable" +
+ "\022\027\n\017isImmutableRows\030\013 \002(\010\022\032\n\022dataTableNa",
+ "meBytes\030\r \001(\014\022\031\n\021defaultFamilyName\030\016 \001(\014" +
+ "\022\022\n\ndisableWAL\030\017 \002(\010\022\023\n\013multiTenant\030\020 \002(" +
+ "\010\022\020\n\010viewType\030\021 \001(\014\022\025\n\rviewStatement\030\022 \001" +
+ "(\014\022\025\n\rphysicalNames\030\023 \003(\014\022\020\n\010tenantId\030\024 " +
+ "\001(\014\022\023\n\013viewIndexId\030\025 \001(\005\022\021\n\tindexType\030\026 " +
+ "\001(\014\022\026\n\016statsTimeStamp\030\027 \001(\003\022\022\n\nstoreNull" +
+ "s\030\030 \001(\010\022\027\n\017baseColumnCount\030\031 \001(\005\022\036\n\026rowK" +
+ "eyOrderOptimizable\030\032 \001(\010\022\025\n\rtransactiona" +
+ "l\030\033 \001(\010\022\034\n\024updateCacheFrequency\030\034 \001(\003\022\035\n" +
+ "\025indexDisableTimestamp\030\035 \001(\003\022\031\n\021isNamesp",
+ "aceMapped\030\036 \001(\010\022\034\n\024autoParititonSeqName\030" +
+ "\037 \001(\t\022\032\n\022isAppendOnlySchema\030 \001(\010\022\027\n\017par" +
+ "entNameBytes\030! \001(\014\022\025\n\rstorageScheme\030\" \001(" +
+ "\014\022,\n\021encodedCQCounters\030# \003(\0132\021.EncodedCQ" +
+ "Counter\"6\n\020EncodedCQCounter\022\021\n\tcolFamily" +
+ "\030\001 \002(\t\022\017\n\007counter\030\002 \002(\005*A\n\nPTableType\022\n\n" +
+ "\006SYSTEM\020\000\022\010\n\004USER\020\001\022\010\n\004VIEW\020\002\022\t\n\005INDEX\020\003" +
+ "\022\010\n\004JOIN\020\004B@\n(org.apache.phoenix.coproce" +
+ "ssor.generatedB\014PTableProtosH\001\210\001\001\240\001\001"
+ };
+ com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
+ new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
+ public com.google.protobuf.ExtensionRegistry assignDescriptors(
+ com.google.protobuf.Descriptors.FileDescriptor root) {
+ descriptor = root;
+ internal_static_PColumn_descriptor =
+ getDescriptor().getMessageTypes().get(0);
+ internal_static_PColumn_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_PColumn_descriptor,
+ new java.lang.String[] { "ColumnNameBytes", "FamilyNameBytes", "DataType", "MaxLength", "Scale", "Nullable", "Position", "SortOrder", "ArraySize", "ViewConstant", "ViewReferenced", "Expression", "IsRowTimestamp", "IsDynamic", "ColumnQualifier", });
+ internal_static_PTableStats_descriptor =
+ getDescriptor().getMessageTypes().get(1);
+ internal_static_PTableStats_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_PTableStats_descriptor,
+ new java.lang.String[] { "Key", "Values", "GuidePostsByteCount", "KeyBytesCount", "GuidePostsCount", "PGuidePosts", });
+ internal_static_PTable_descriptor =
+ getDescriptor().getMessageTypes().get(2);
+ internal_static_PTable_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_PTable_descriptor,
+ new java.lang.String[] { "SchemaNameBytes", "TableNameBytes", "TableType", "IndexState", "SequenceNumber", "TimeStamp", "PkNameBytes", "BucketNum", "Columns", "Indexes", "IsImmutableRows", "DataTableNameBytes", "DefaultFamilyName", "DisableWAL", "MultiTenant", "ViewType", "ViewStatement", "PhysicalNames", "TenantId", "ViewIndexId", "IndexType", "StatsTimeStamp", "StoreNulls", "BaseColumnCount", "RowKeyOrderOptimizable", "Transactional", "UpdateCacheFrequency", "IndexDisableTimestamp", "IsNamespaceMapped", "AutoParititonSeqName", "IsAppendOnlySchema", "ParentNameBytes", "StorageScheme", "EncodedCQCounters", });
+ internal_static_EncodedCQCounter_descriptor =
+ getDescriptor().getMessageTypes().get(3);
+ internal_static_EncodedCQCounter_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_EncodedCQCounter_descriptor,
+ new java.lang.String[] { "ColFamily", "Counter", });
return null;
}
};
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index 352b533..fb5af32 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -64,11 +64,13 @@ import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.trace.TracingIterator;
import org.apache.phoenix.trace.util.Tracing;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.LogUtil;
import org.apache.phoenix.util.SQLCloseable;
@@ -307,10 +309,6 @@ public abstract class BaseQueryPlan implements QueryPlan {
// project is not present in the index then we need to skip this plan.
if (!dataColumns.isEmpty()) {
// Set data columns to be join back from data table.
- serializeDataTableColumnsToJoin(scan, dataColumns);
- KeyValueSchema schema = ProjectedColumnExpression.buildSchema(dataColumns);
- // Set key value schema of the data columns.
- serializeSchemaIntoScan(scan, schema);
PTable parentTable = context.getCurrentTable().getTable();
String parentSchemaName = parentTable.getParentSchemaName().getString();
String parentTableName = parentTable.getParentTableName().getString();
@@ -321,6 +319,12 @@ public abstract class BaseQueryPlan implements QueryPlan {
FACTORY.namedTable(null, TableName.create(parentSchemaName, parentTableName)),
context.getConnection()).resolveTable(parentSchemaName, parentTableName);
PTable dataTable = dataTableRef.getTable();
+ // Set data columns to be join back from data table.
+ serializeDataTableColumnsToJoin(scan, dataColumns, dataTable);
+ KeyValueSchema schema = ProjectedColumnExpression.buildSchema(dataColumns);
+ // Set key value schema of the data columns.
+ serializeSchemaIntoScan(scan, schema);
+
// Set index maintainer of the local index.
serializeIndexMaintainerIntoScan(scan, dataTable);
// Set view constants if exists.
@@ -423,14 +427,21 @@ public abstract class BaseQueryPlan implements QueryPlan {
}
}
- private void serializeDataTableColumnsToJoin(Scan scan, Set<PColumn> dataColumns) {
+ private void serializeDataTableColumnsToJoin(Scan scan, Set<PColumn> dataColumns, PTable dataTable) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
DataOutputStream output = new DataOutputStream(stream);
+ boolean storeColsInSingleCell = dataTable.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
+ if (storeColsInSingleCell) {
+ // if storeColsInSingleCell is true all columns of a given column family are stored in a single cell
+ scan.setAttribute(BaseScannerRegionObserver.COLUMNS_STORED_IN_SINGLE_CELL, QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
+ }
WritableUtils.writeVInt(output, dataColumns.size());
for (PColumn column : dataColumns) {
- Bytes.writeByteArray(output, column.getFamilyName().getBytes());
- Bytes.writeByteArray(output, column.getName().getBytes());
+ byte[] cf = column.getFamilyName().getBytes();
+ byte[] cq = EncodedColumnsUtil.getColumnQualifier(column, dataTable);
+ Bytes.writeByteArray(output, cf);
+ Bytes.writeByteArray(output, cq);
}
scan.setAttribute(BaseScannerRegionObserver.DATA_TABLE_COLUMNS_TO_JOIN, stream.toByteArray());
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
index cb66968..a030150 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
@@ -585,7 +585,7 @@ public class MutationState implements SQLCloseable {
List<Mutation> indexMutations;
try {
indexMutations =
- IndexUtil.generateIndexData(table, index, mutationsPertainingToIndex,
+ IndexUtil.generateIndexData(table, index, values, mutationsPertainingToIndex,
connection.getKeyValueBuilder(), connection);
// we may also have to include delete mutations for immutable tables if we are not processing all the tables in the mutations map
if (!sendAll) {
@@ -619,6 +619,7 @@ public class MutationState implements SQLCloseable {
Iterator<Map.Entry<ImmutableBytesPtr, RowMutationState>> iterator =
values.entrySet().iterator();
long timestampToUse = timestamp;
+ Map<ImmutableBytesPtr, RowMutationState> modifiedValues = Maps.newHashMap();
while (iterator.hasNext()) {
Map.Entry<ImmutableBytesPtr, RowMutationState> rowEntry = iterator.next();
byte[] onDupKeyBytes = rowEntry.getValue().getOnDupKeyBytes();
@@ -628,6 +629,10 @@ public class MutationState implements SQLCloseable {
if (tableWithRowTimestampCol) {
RowTimestampColInfo rowTsColInfo = state.getRowTimestampColInfo();
if (rowTsColInfo.useServerTimestamp()) {
+ // since we are about to modify the byte[] stored in key (which changes its hashcode)
+ // we need to remove the entry from the values map and add a new entry with the modified byte[]
+ modifiedValues.put(key, state);
+ iterator.remove();
// regenerate the key with this timestamp.
key = getNewRowKeyWithRowTimestamp(key, timestampToUse, table);
} else {
@@ -668,6 +673,7 @@ public class MutationState implements SQLCloseable {
if (mutationsPertainingToIndex != null) mutationsPertainingToIndex
.addAll(rowMutationsPertainingToIndex);
}
+ values.putAll(modifiedValues);
}
/**
@@ -806,7 +812,7 @@ public class MutationState implements SQLCloseable {
}
for (PColumn column : columns) {
if (column != null) {
- resolvedTable.getColumnFamily(column.getFamilyName().getString()).getColumn(column.getName().getString());
+ resolvedTable.getColumnFamily(column.getFamilyName().getString()).getPColumnForColumnName(column.getName().getString());
}
}
}
@@ -1480,8 +1486,8 @@ public class MutationState implements SQLCloseable {
byte[] getOnDupKeyBytes() {
return onDupKeyBytes;
}
-
- Map<PColumn, byte[]> getColumnValues() {
+
+ public Map<PColumn, byte[]> getColumnValues() {
return columnValues;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java
index 592b68e..127af96 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java
@@ -17,6 +17,9 @@
*/
package org.apache.phoenix.execute;
+import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_FAMILY;
+import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_QUALIFIER;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
@@ -51,9 +54,6 @@ import org.apache.phoenix.util.SchemaUtil;
import com.google.common.base.Preconditions;
public class TupleProjector {
- public static final byte[] VALUE_COLUMN_FAMILY = Bytes.toBytes("_v");
- public static final byte[] VALUE_COLUMN_QUALIFIER = new byte[0];
-
private static final String SCAN_PROJECTOR = "scanProjector";
private final KeyValueSchema schema;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
new file mode 100644
index 0000000..f4616da
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayColumnExpression.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.expression;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.io.WritableUtils;
+import org.apache.phoenix.compile.CreateTableCompiler.ViewWhereExpressionVisitor;
+import org.apache.phoenix.expression.visitor.ExpressionVisitor;
+import org.apache.phoenix.schema.PColumn;
+import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.util.EncodedColumnsUtil;
+import org.apache.phoenix.util.SchemaUtil;
+
+/**
+ *
+ * Class to access a column that is stored in a KeyValue that contains all
+ * columns for a given column family (stored in an array).
+ *
+ */
+public class ArrayColumnExpression extends KeyValueColumnExpression {
+
+ private int encodedCQ;
+ private String displayName;
+
+ public ArrayColumnExpression() {
+ }
+
+ public ArrayColumnExpression(PDatum column, byte[] cf, int encodedCQ) {
+ super(column, cf, cf);
+ this.encodedCQ = encodedCQ;
+ }
+
+ public ArrayColumnExpression(PColumn column, String displayName, boolean encodedColumnName) {
+ super(column, column.getFamilyName().getBytes(), column.getFamilyName().getBytes());
+ this.displayName = SchemaUtil.getColumnDisplayName(column.getFamilyName().getString(), column.getName().getString());
+ this.encodedCQ = column.getEncodedColumnQualifier();
+ }
+
+ @Override
+ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+ if (!super.evaluate(tuple, ptr)) {
+ return false;
+ } else if (ptr.getLength() == 0) {
+ return true;
+ }
+
+ // 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, encodedCQ, PVarbinary.INSTANCE, null);
+ return true;
+ }
+
+ @Override
+ public void readFields(DataInput input) throws IOException {
+ super.readFields(input);
+ encodedCQ = WritableUtils.readVInt(input);
+ }
+
+ @Override
+ public void write(DataOutput output) throws IOException {
+ super.write(output);
+ WritableUtils.writeVInt(output, encodedCQ);
+ }
+
+ public KeyValueColumnExpression getKeyValueExpression() {
+ final boolean isNullable = isNullable();
+ final SortOrder sortOrder = getSortOrder();
+ final Integer scale = getScale();
+ final Integer maxLength = getMaxLength();
+ final PDataType datatype = getDataType();
+ return new KeyValueColumnExpression(new PDatum() {
+
+ @Override
+ public boolean isNullable() {
+ return isNullable;
+ }
+
+ @Override
+ public SortOrder getSortOrder() {
+ return sortOrder;
+ }
+
+ @Override
+ public Integer getScale() {
+ return scale;
+ }
+
+ @Override
+ public Integer getMaxLength() {
+ return maxLength;
+ }
+
+ @Override
+ public PDataType getDataType() {
+ return datatype;
+ }
+ }, getColumnFamily(), getEncodedColumnQualifier());
+ }
+
+ @Override
+ public String toString() {
+ return displayName;
+ }
+
+ public byte[] getEncodedColumnQualifier() {
+ return EncodedColumnsUtil.getEncodedColumnQualifier(encodedCQ);
+ }
+
+ @Override
+ public <T> T accept(ExpressionVisitor<T> visitor) {
+ //FIXME: this is ugly but can't think of a good solution.
+ if (visitor instanceof ViewWhereExpressionVisitor) {
+ return visitor.visit(this);
+ } else {
+ return super.accept(visitor);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
index c2f4dd2..783e962 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
@@ -117,7 +117,7 @@ public class ArrayConstructorExpression extends BaseCompoundExpression {
offsetPos[i] = byteStream.size();
oStream.write(ptr.get(), ptr.getOffset(), ptr.getLength());
oStream.write(PArrayDataType.getSeparatorByte(rowKeyOrderOptimizable, getSortOrder()));
- nNulls=0;
+ nNulls = 0;
}
} else { // No nulls for fixed length
oStream.write(ptr.get(), ptr.getOffset(), ptr.getLength());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java
index 658605e..006777b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ExpressionType.java
@@ -178,9 +178,8 @@ public enum ExpressionType {
CeilYearExpression(CeilYearExpression.class),
DayOfWeekFunction(DayOfWeekFunction.class),
DayOfYearFunction(DayOfYearFunction.class),
- DefaultValueExpression(DefaultValueExpression.class);
-
-
+ DefaultValueExpression(DefaultValueExpression.class),
+ ArrayColumnExpression(ArrayColumnExpression.class);
ExpressionType(Class<? extends Expression> clazz) {
this.clazz = clazz;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
index 4b5fdbb..6170418 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/KeyValueColumnExpression.java
@@ -28,6 +28,7 @@ import org.apache.phoenix.expression.visitor.ExpressionVisitor;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PDatum;
import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -41,13 +42,13 @@ import org.apache.phoenix.util.SchemaUtil;
public class KeyValueColumnExpression extends ColumnExpression {
private byte[] cf;
private byte[] cq;
- private String displayName; // client-side only
+ private String displayName; // client-side only. TODO: samarth see what can you do for encoded column names.
public KeyValueColumnExpression() {
}
- public KeyValueColumnExpression(PColumn column) {
- this(column, null);
+ public KeyValueColumnExpression(PColumn column, boolean encodedColumnName) {
+ this(column, null, encodedColumnName);
}
public KeyValueColumnExpression(PDatum column, byte[] cf, byte[] cq) {
@@ -56,18 +57,18 @@ public class KeyValueColumnExpression extends ColumnExpression {
this.cq = cq;
}
- public KeyValueColumnExpression(PColumn column, String displayName) {
+ public KeyValueColumnExpression(PColumn column, String displayName, boolean encodedColumnName) {
super(column);
this.cf = column.getFamilyName().getBytes();
- this.cq = column.getName().getBytes();
+ this.cq = EncodedColumnsUtil.getColumnQualifier(column, encodedColumnName);
this.displayName = displayName;
}
public byte[] getColumnFamily() {
return cf;
}
-
- public byte[] getColumnName() {
+
+ public byte[] getColumnQualifier() {
return cq;
}
@@ -120,7 +121,7 @@ public class KeyValueColumnExpression extends ColumnExpression {
}
@Override
- public final <T> T accept(ExpressionVisitor<T> visitor) {
+ public <T> T accept(ExpressionVisitor<T> visitor) {
return visitor.visit(this);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 90882a2..f20d7e2 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
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.sql.SQLException;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.WritableUtils;
import org.apache.phoenix.expression.visitor.ExpressionVisitor;
import org.apache.phoenix.schema.IllegalDataException;
@@ -214,6 +215,11 @@ public class LiteralExpression extends BaseTerminalExpression {
public LiteralExpression() {
}
+
+ public LiteralExpression(byte[] byteValue) {
+ this.byteValue = byteValue!=null ? byteValue : ByteUtil.EMPTY_BYTE_ARRAY;
+ this.determinism = Determinism.ALWAYS;
+ }
private LiteralExpression(PDataType type, Determinism determinism) {
this(null, type, ByteUtil.EMPTY_BYTE_ARRAY, determinism);
@@ -242,7 +248,10 @@ public class LiteralExpression extends BaseTerminalExpression {
@Override
public String toString() {
- if (value == null) {
+ if (value == null && byteValue!=null) {
+ return Bytes.toStringBinary(byteValue);
+ }
+ else if (value == null) {
return "null";
}
// TODO: move into PDataType?
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java
index 3a38dee..2744f35 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java
@@ -154,6 +154,7 @@ public class ProjectedColumnExpression extends ColumnExpression {
return Determinism.PER_INVOCATION;
}
+ @Override
public ProjectedColumnExpression clone() {
return new ProjectedColumnExpression(this.column, this.columns, this.position, this.displayName);
}
[10/42] phoenix git commit: PHOENIX-3532 Pass tenantId parameter to
PhoenixRDD when reading (Nico Pappagianis)
Posted by td...@apache.org.
PHOENIX-3532 Pass tenantId parameter to PhoenixRDD when reading (Nico Pappagianis)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e2020209
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e2020209
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e2020209
Branch: refs/heads/encodecolumns2
Commit: e2020209316572b1575abda5057196e4678439ee
Parents: 42a84b3
Author: Josh Mahonin <jm...@gmail.com>
Authored: Mon Dec 19 11:15:15 2016 -0500
Committer: Josh Mahonin <jm...@gmail.com>
Committed: Mon Dec 19 11:16:15 2016 -0500
----------------------------------------------------------------------
phoenix-spark/src/it/resources/tenantSetup.sql | 1 +
.../phoenix/spark/AbstractPhoenixSparkIT.scala | 5 -
.../spark/PhoenixSparkITTenantSpecific.scala | 99 +++++++++++++-------
.../org/apache/phoenix/spark/PhoenixRDD.scala | 16 +++-
.../phoenix/spark/SparkContextFunctions.scala | 4 +-
.../spark/SparkSqlContextFunctions.scala | 6 +-
6 files changed, 85 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e2020209/phoenix-spark/src/it/resources/tenantSetup.sql
----------------------------------------------------------------------
diff --git a/phoenix-spark/src/it/resources/tenantSetup.sql b/phoenix-spark/src/it/resources/tenantSetup.sql
index 4a866dc..f62d843 100644
--- a/phoenix-spark/src/it/resources/tenantSetup.sql
+++ b/phoenix-spark/src/it/resources/tenantSetup.sql
@@ -15,3 +15,4 @@
-- limitations under the License.
CREATE VIEW IF NOT EXISTS TENANT_VIEW(TENANT_ONLY_COL VARCHAR) AS SELECT * FROM MULTITENANT_TEST_TABLE
+UPSERT INTO TENANT_VIEW (ORGANIZATION_ID, TENANT_ONLY_COL) VALUES ('defaultOrg', 'defaultData')
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e2020209/phoenix-spark/src/it/scala/org/apache/phoenix/spark/AbstractPhoenixSparkIT.scala
----------------------------------------------------------------------
diff --git a/phoenix-spark/src/it/scala/org/apache/phoenix/spark/AbstractPhoenixSparkIT.scala b/phoenix-spark/src/it/scala/org/apache/phoenix/spark/AbstractPhoenixSparkIT.scala
index f81438f..ecaedc7 100644
--- a/phoenix-spark/src/it/scala/org/apache/phoenix/spark/AbstractPhoenixSparkIT.scala
+++ b/phoenix-spark/src/it/scala/org/apache/phoenix/spark/AbstractPhoenixSparkIT.scala
@@ -46,11 +46,6 @@ class AbstractPhoenixSparkIT extends FunSuite with Matchers with BeforeAndAfterA
// A global tenantId we can use across tests
final val TenantId = "theTenant"
- // TENANT_VIEW schema
- val OrgId = "ORGANIZATION_ID"
- val TenantCol = "TENANT_ONLY_COL"
- val ViewName = "TENANT_VIEW"
-
var conn: Connection = _
var sc: SparkContext = _
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e2020209/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkITTenantSpecific.scala
----------------------------------------------------------------------
diff --git a/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkITTenantSpecific.scala b/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkITTenantSpecific.scala
index a1c1e22..77b41af 100644
--- a/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkITTenantSpecific.scala
+++ b/phoenix-spark/src/it/scala/org/apache/phoenix/spark/PhoenixSparkITTenantSpecific.scala
@@ -19,7 +19,10 @@ import org.apache.spark.sql.SQLContext
import scala.collection.mutable.ListBuffer
/**
- * Sub-class of PhoenixSparkIT used for tenant-specific test
+ * Sub-class of PhoenixSparkIT used for tenant-specific tests
+ *
+ * Note: All schema related variables (table name, column names, default data, etc) are coupled with
+ * phoenix-spark/src/it/resources/tenantSetup.sql
*
* Note: If running directly from an IDE, these are the recommended VM parameters:
* -Xmx1536m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=512m
@@ -27,10 +30,24 @@ import scala.collection.mutable.ListBuffer
*/
class PhoenixSparkITTenantSpecific extends AbstractPhoenixSparkIT {
- val SelectStatement = "SELECT " + OrgId + "," + TenantCol + " FROM " + ViewName
- val DataSet = List(("testOrg1", "data1"), ("testOrg2", "data2"), ("testOrg3", "data3"))
+ // Tenant-specific schema info
+ val OrgIdCol = "ORGANIZATION_ID"
+ val TenantOnlyCol = "TENANT_ONLY_COL"
+ val TenantTable = "TENANT_VIEW"
+
+ // Data set for tests that write to Phoenix
+ val TestDataSet = List(("testOrg1", "data1"), ("testOrg2", "data2"), ("testOrg3", "data3"))
+ /**
+ * Helper method used by write tests to verify content written.
+ * Assumes the caller has written the TestDataSet (defined above) to Phoenix
+ * and that 1 row of default data exists (upserted after table creation in tenantSetup.sql)
+ */
def verifyResults(): Unit = {
+ // Contains the default data upserted into the tenant-specific table in tenantSetup.sql and the data upserted by tests
+ val VerificationDataSet = List(("defaultOrg", "defaultData")) ::: TestDataSet
+
+ val SelectStatement = "SELECT " + OrgIdCol + "," + TenantOnlyCol + " FROM " + TenantTable
val stmt = conn.createStatement()
val rs = stmt.executeQuery(SelectStatement)
@@ -39,62 +56,78 @@ class PhoenixSparkITTenantSpecific extends AbstractPhoenixSparkIT {
results.append((rs.getString(1), rs.getString(2)))
}
stmt.close()
-
- results.toList shouldEqual DataSet
+ results.toList shouldEqual VerificationDataSet
}
- test("Can persist a dataframe using 'DataFrame.saveToPhoenix' on tenant-specific view") {
+ /*****************/
+ /** Read tests **/
+ /*****************/
+
+ test("Can read from tenant-specific table as DataFrame") {
val sqlContext = new SQLContext(sc)
- import sqlContext.implicits._
+ val df = sqlContext.phoenixTableAsDataFrame(
+ TenantTable,
+ Seq(OrgIdCol, TenantOnlyCol),
+ zkUrl = Some(quorumAddress),
+ tenantId = Some(TenantId),
+ conf = hbaseConfiguration)
+
+ // There should only be 1 row upserted in tenantSetup.sql
+ val count = df.count()
+ count shouldEqual 1L
+ }
- val dataSet = List(("testOrg1", "data1"), ("testOrg2", "data2"), ("testOrg3", "data3"))
+ test("Can read from tenant-specific table as RDD") {
+ val rdd = sc.phoenixTableAsRDD(
+ TenantTable,
+ Seq(OrgIdCol, TenantOnlyCol),
+ zkUrl = Some(quorumAddress),
+ tenantId = Some(TenantId),
+ conf = hbaseConfiguration)
+
+ // There should only be 1 row upserted in tenantSetup.sql
+ val count = rdd.count()
+ count shouldEqual 1L
+ }
- val df = sc.parallelize(dataSet).toDF(OrgId, TenantCol)
+ /*****************/
+ /** Write tests **/
+ /*****************/
- // Save to tenant-specific view
- df.saveToPhoenix("TENANT_VIEW", zkUrl = Some(quorumAddress), tenantId = Some(TenantId))
+ test("Can write a DataFrame using 'DataFrame.saveToPhoenix' to tenant-specific view") {
+ val sqlContext = new SQLContext(sc)
+ import sqlContext.implicits._
+
+ val df = sc.parallelize(TestDataSet).toDF(OrgIdCol, TenantOnlyCol)
+ df.saveToPhoenix(TenantTable, zkUrl = Some(quorumAddress), tenantId = Some(TenantId))
verifyResults
}
- test("Can persist a dataframe using 'DataFrame.write' on tenant-specific view") {
-
+ test("Can write a DataFrame using 'DataFrame.write' to tenant-specific view") {
val sqlContext = new SQLContext(sc)
import sqlContext.implicits._
- val dataSet = List(("testOrg1", "data1"), ("testOrg2", "data2"), ("testOrg3", "data3"))
-
- val df = sc.parallelize(dataSet).toDF(OrgId, TenantCol)
+ val df = sc.parallelize(TestDataSet).toDF(OrgIdCol, TenantOnlyCol)
df.write
.format("org.apache.phoenix.spark")
.mode("overwrite")
- .option("table", "TENANT_VIEW")
- .option(PhoenixRuntime.TENANT_ID_ATTRIB, "theTenant")
+ .option("table", TenantTable)
+ .option(PhoenixRuntime.TENANT_ID_ATTRIB, TenantId)
.option("zkUrl", PhoenixSparkITHelper.getUrl)
.save()
verifyResults
}
- test("Can save to Phoenix tenant-specific view") {
+ test("Can write an RDD to Phoenix tenant-specific view") {
val sqlContext = new SQLContext(sc)
-
- // This view name must match the view we create in phoenix-spark/src/it/resources/tenantSetup.sql
- val ViewName = "TENANT_VIEW"
-
- // Columns from the TENANT_VIEW schema
- val OrgId = "ORGANIZATION_ID"
- val TenantCol = "TENANT_ONLY_COL"
-
- // Data matching the schema for TENANT_VIEW created in tenantSetup.sql
- val dataSet = List(("testOrg1", "data1"), ("testOrg2", "data2"), ("testOrg3", "data3"))
-
sc
- .parallelize(dataSet)
+ .parallelize(TestDataSet)
.saveToPhoenix(
- ViewName,
- Seq(OrgId, TenantCol),
+ TenantTable,
+ Seq(OrgIdCol, TenantOnlyCol),
hbaseConfiguration,
tenantId = Some(TenantId)
)
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e2020209/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala
----------------------------------------------------------------------
diff --git a/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala b/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala
index cfaefa1..505de1b 100644
--- a/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala
+++ b/phoenix-spark/src/main/scala/org/apache/phoenix/spark/PhoenixRDD.scala
@@ -18,7 +18,7 @@ import java.sql.DriverManager
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.{HBaseConfiguration, HConstants}
import org.apache.hadoop.io.NullWritable
-import org.apache.phoenix.jdbc.{PhoenixDriver, PhoenixEmbeddedDriver}
+import org.apache.phoenix.jdbc.PhoenixDriver
import org.apache.phoenix.mapreduce.PhoenixInputFormat
import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil
import org.apache.phoenix.schema.types._
@@ -26,14 +26,17 @@ import org.apache.phoenix.util.ColumnInfo
import org.apache.spark._
import org.apache.spark.annotation.DeveloperApi
import org.apache.spark.rdd.RDD
-import org.apache.spark.sql.{DataFrame, Row, SQLContext}
import org.apache.spark.sql.types._
+import org.apache.spark.sql.{DataFrame, Row, SQLContext}
import scala.collection.JavaConverters._
class PhoenixRDD(sc: SparkContext, table: String, columns: Seq[String],
- predicate: Option[String] = None, zkUrl: Option[String] = None,
- @transient conf: Configuration, dateAsTimestamp: Boolean = false)
+ predicate: Option[String] = None,
+ zkUrl: Option[String] = None,
+ @transient conf: Configuration, dateAsTimestamp: Boolean = false,
+ tenantId: Option[String] = None
+ )
extends RDD[PhoenixRecordWritable](sc, Nil) with Logging {
// Make sure to register the Phoenix driver
@@ -97,6 +100,11 @@ class PhoenixRDD(sc: SparkContext, table: String, columns: Seq[String],
}
}
+ tenantId match {
+ case Some(tid) => ConfigurationUtil.setTenantId(config, tid)
+ case _ =>
+ }
+
config
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e2020209/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkContextFunctions.scala
----------------------------------------------------------------------
diff --git a/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkContextFunctions.scala b/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkContextFunctions.scala
index a3cd8f0..476ce8a 100644
--- a/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkContextFunctions.scala
+++ b/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkContextFunctions.scala
@@ -32,10 +32,10 @@ class SparkContextFunctions(@transient val sc: SparkContext) extends Serializabl
*/
def phoenixTableAsRDD(table: String, columns: Seq[String], predicate: Option[String] = None,
- zkUrl: Option[String] = None, conf: Configuration = new Configuration())
+ zkUrl: Option[String] = None, tenantId: Option[String] = None, conf: Configuration = new Configuration())
: RDD[Map[String, AnyRef]] = {
// Create a PhoenixRDD, but only return the serializable 'result' map
- new PhoenixRDD(sc, table, columns, predicate, zkUrl, conf).map(_.result)
+ new PhoenixRDD(sc, table, columns, predicate, zkUrl, conf, tenantId = tenantId).map(_.result)
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e2020209/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkSqlContextFunctions.scala
----------------------------------------------------------------------
diff --git a/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkSqlContextFunctions.scala b/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkSqlContextFunctions.scala
index cc3f378..a0842c9 100644
--- a/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkSqlContextFunctions.scala
+++ b/phoenix-spark/src/main/scala/org/apache/phoenix/spark/SparkSqlContextFunctions.scala
@@ -29,11 +29,13 @@ class SparkSqlContextFunctions(@transient val sqlContext: SQLContext) extends Se
property will be used
*/
def phoenixTableAsDataFrame(table: String, columns: Seq[String],
- predicate: Option[String] = None, zkUrl: Option[String] = None,
+ predicate: Option[String] = None,
+ zkUrl: Option[String] = None,
+ tenantId: Option[String] = None,
conf: Configuration = new Configuration): DataFrame = {
// Create the PhoenixRDD and convert it to a DataFrame
- new PhoenixRDD(sqlContext.sparkContext, table, columns, predicate, zkUrl, conf)
+ new PhoenixRDD(sqlContext.sparkContext, table, columns, predicate, zkUrl, conf, tenantId = tenantId)
.toDataFrame(sqlContext)
}
}
\ No newline at end of file
[18/42] phoenix git commit: Fail-fast iterators for
EncodedColumnQualifierCellsList. Use list iterators instead of get(index) for
navigating lists. Use HBase bytes utility for encoded column names. Fix test
failures for immutable tables and indexes.
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/ResultTuple.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/ResultTuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/ResultTuple.java
index c28a2bf..3774837 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/ResultTuple.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/ResultTuple.java
@@ -17,6 +17,8 @@
*/
package org.apache.phoenix.schema.tuple;
+import java.util.Collections;
+
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Result;
@@ -25,25 +27,23 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder;
import org.apache.phoenix.util.KeyValueUtil;
-
+/**
+ *
+ * Wrapper around {@link Result} that implements Phoenix's {@link Tuple} interface.
+ *
+ */
public class ResultTuple extends BaseTuple {
- private Result result;
+ private final Result result;
+ public static final ResultTuple EMPTY_TUPLE = new ResultTuple(Result.create(Collections.<Cell>emptyList()));
public ResultTuple(Result result) {
this.result = result;
}
- public ResultTuple() {
- }
-
public Result getResult() {
return this.result;
}
- public void setResult(Result result) {
- this.result = result;
- }
-
@Override
public void getKey(ImmutableBytesWritable ptr) {
ptr.set(result.getRow());
@@ -104,4 +104,4 @@ public class ResultTuple extends BaseTuple {
ptr.set(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
return true;
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/Tuple.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/Tuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/Tuple.java
index 61b2a4f..e4a887b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/Tuple.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/Tuple.java
@@ -17,6 +17,8 @@
*/
package org.apache.phoenix.schema.tuple;
+import java.util.List;
+
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
@@ -87,4 +89,6 @@ public interface Tuple {
* @return the current or next sequence value
*/
public long getSequenceValue(int index);
+
+ public void setKeyValues(List<Cell> values);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
new file mode 100644
index 0000000..aeb4e46
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.util;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.PColumn;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.StorageScheme;
+import org.apache.phoenix.schema.types.PInteger;
+
+public class EncodedColumnsUtil {
+
+ public static boolean usesEncodedColumnNames(PTable table) {
+ return usesEncodedColumnNames(table.getStorageScheme());
+ }
+
+ public static boolean usesEncodedColumnNames(StorageScheme storageScheme) {
+ return storageScheme != null && storageScheme != StorageScheme.NON_ENCODED_COLUMN_NAMES;
+ }
+
+ public static byte[] getEncodedColumnQualifier(PColumn column) {
+ checkArgument(!SchemaUtil.isPKColumn(column), "No column qualifiers for PK columns");
+ checkArgument(!column.isDynamic(), "No encoded column qualifiers for dynamic columns");
+ return Bytes.toBytes(column.getEncodedColumnQualifier());
+ }
+
+ public static int getEncodedColumnQualifier(byte[] bytes, int offset, int length) {
+ return Bytes.toInt(bytes, offset, length);
+ }
+
+ public static byte[] getEncodedColumnQualifier(int value) {
+ return Bytes.toBytes(value);
+ }
+
+ public static int getEncodedColumnQualifier(byte[] bytes) {
+ return Bytes.toInt(bytes);
+ }
+
+ public static byte[] getColumnQualifier(PColumn column, PTable table) {
+ return EncodedColumnsUtil.getColumnQualifier(column, usesEncodedColumnNames(table));
+ }
+
+ public static void setColumns(PColumn column, PTable table, Scan scan) {
+ if (table.getStorageScheme() == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ // if a table storage scheme is COLUMNS_STORED_IN_SINGLE_CELL set then all columns of a column family are stored in a single cell
+ // (with the qualifier name being same as the family name), just project the column family here
+ // so that we can calculate estimatedByteSize correctly in ProjectionCompiler
+ scan.addFamily(column.getFamilyName().getBytes());
+ //scan.addColumn(column.getFamilyName().getBytes(), column.getFamilyName().getBytes());
+ }
+ else {
+ scan.addColumn(column.getFamilyName().getBytes(), EncodedColumnsUtil.getColumnQualifier(column, table));
+ }
+ }
+
+ public static byte[] getColumnQualifier(PColumn column, boolean encodedColumnName) {
+ checkArgument(!SchemaUtil.isPKColumn(column), "No column qualifiers for PK columns");
+ if (column.isDynamic()) { // Dynamic column names don't have encoded column names
+ return column.getName().getBytes();
+ }
+ return encodedColumnName ? getEncodedColumnQualifier(column) : column.getName().getBytes();
+ }
+
+ /**
+ * @return pair of byte arrays. The first part of the pair is the empty key value's column qualifier, and the second
+ * part is the value to use for it.
+ */
+ public static Pair<byte[], byte[]> getEmptyKeyValueInfo(PTable table) {
+ return usesEncodedColumnNames(table) ? new Pair<>(QueryConstants.ENCODED_EMPTY_COLUMN_BYTES,
+ QueryConstants.ENCODED_EMPTY_COLUMN_VALUE_BYTES) : new Pair<>(QueryConstants.EMPTY_COLUMN_BYTES,
+ QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
+ }
+
+ /**
+ * @return pair of byte arrays. The first part of the pair is the empty key value's column qualifier, and the second
+ * part is the value to use for it.
+ */
+ public static Pair<byte[], byte[]> getEmptyKeyValueInfo(boolean usesEncodedColumnNames) {
+ return usesEncodedColumnNames ? new Pair<>(QueryConstants.ENCODED_EMPTY_COLUMN_BYTES,
+ QueryConstants.ENCODED_EMPTY_COLUMN_VALUE_BYTES) : new Pair<>(QueryConstants.EMPTY_COLUMN_BYTES,
+ QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
+ }
+
+ public static boolean hasEncodedColumnName(PColumn column){
+ return !SchemaUtil.isPKColumn(column) && !column.isDynamic() && column.getEncodedColumnQualifier() != null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
index 9eb3fae..c088b25 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
@@ -18,6 +18,10 @@
package org.apache.phoenix.util;
import static org.apache.phoenix.query.QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX;
+import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_FAMILY;
+import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_QUALIFIER;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
+
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
@@ -25,6 +29,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import org.apache.hadoop.hbase.Cell;
@@ -54,7 +59,9 @@ import org.apache.phoenix.compile.WhereCompiler;
import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.execute.MutationState.RowMutationState;
import org.apache.phoenix.execute.TupleProjector;
+import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.KeyValueColumnExpression;
import org.apache.phoenix.expression.RowKeyColumnExpression;
@@ -77,21 +84,24 @@ import org.apache.phoenix.schema.KeyValueSchema;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnFamily;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.schema.TableRef;
+import org.apache.phoenix.schema.ValueSchema.Field;
import org.apache.phoenix.schema.tuple.ResultTuple;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PBinary;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.tephra.TxConstants;
import com.google.common.collect.Lists;
-import org.apache.tephra.TxConstants;
-
public class IndexUtil {
public static final String INDEX_COLUMN_NAME_SEP = ":";
public static final byte[] INDEX_COLUMN_NAME_SEP_BYTES = Bytes.toBytes(INDEX_COLUMN_NAME_SEP);
@@ -192,7 +202,7 @@ public class IndexUtil {
throw new IllegalArgumentException("Could not find column family \"" + indexColumnName.substring(0, pos) + "\" in index column name of \"" + indexColumnName + "\"", e);
}
try {
- return family.getColumn(indexColumnName.substring(pos+1));
+ return family.getPColumnForColumnName(indexColumnName.substring(pos+1));
} catch (ColumnNotFoundException e) {
throw new IllegalArgumentException("Could not find column \"" + indexColumnName.substring(pos+1) + "\" in index column name of \"" + indexColumnName + "\"", e);
}
@@ -219,10 +229,11 @@ public class IndexUtil {
private static boolean isEmptyKeyValue(PTable table, ColumnReference ref) {
byte[] emptyKeyValueCF = SchemaUtil.getEmptyColumnFamily(table);
+ byte[] emptyKeyValueQualifier = EncodedColumnsUtil.getEmptyKeyValueInfo(table).getFirst();
return (Bytes.compareTo(emptyKeyValueCF, 0, emptyKeyValueCF.length, ref.getFamilyWritable()
.get(), ref.getFamilyWritable().getOffset(), ref.getFamilyWritable().getLength()) == 0 && Bytes
- .compareTo(QueryConstants.EMPTY_COLUMN_BYTES, 0,
- QueryConstants.EMPTY_COLUMN_BYTES.length, ref.getQualifierWritable().get(), ref
+ .compareTo(emptyKeyValueQualifier, 0,
+ emptyKeyValueQualifier.length, ref.getQualifierWritable().get(), ref
.getQualifierWritable().getOffset(), ref.getQualifierWritable()
.getLength()) == 0);
}
@@ -254,10 +265,10 @@ public class IndexUtil {
}
public static List<Mutation> generateIndexData(final PTable table, PTable index,
- List<Mutation> dataMutations, final KeyValueBuilder kvBuilder, PhoenixConnection connection)
+ final Map<ImmutableBytesPtr, RowMutationState> valuesMap, List<Mutation> dataMutations, final KeyValueBuilder kvBuilder, PhoenixConnection connection)
throws SQLException {
try {
- final ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+ final ImmutableBytesPtr ptr = new ImmutableBytesPtr();
IndexMaintainer maintainer = index.getIndexMaintainer(table, connection);
List<Mutation> indexMutations = Lists.newArrayListWithExpectedSize(dataMutations.size());
for (final Mutation dataMutation : dataMutations) {
@@ -270,8 +281,6 @@ public class IndexUtil {
* updating an existing row.
*/
if (dataMutation instanceof Put) {
- // TODO: is this more efficient than looking in our mutation map
- // using the key plus finding the PColumn?
ValueGetter valueGetter = new ValueGetter() {
@Override
@@ -286,13 +295,13 @@ public class IndexUtil {
if (isEmptyKeyValue(table, ref)) {
return null;
}
- Map<byte [], List<Cell>> familyMap = dataMutation.getFamilyCellMap();
byte[] family = ref.getFamily();
+ byte[] qualifier = ref.getQualifier();
+ Map<byte [], List<Cell>> familyMap = dataMutation.getFamilyCellMap();
List<Cell> kvs = familyMap.get(family);
if (kvs == null) {
return null;
}
- byte[] qualifier = ref.getQualifier();
for (Cell kv : kvs) {
if (Bytes.compareTo(kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength(), family, 0, family.length) == 0 &&
Bytes.compareTo(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength(), qualifier, 0, qualifier.length) == 0) {
@@ -426,13 +435,18 @@ public class IndexUtil {
public static TupleProjector getTupleProjector(Scan scan, ColumnReference[] dataColumns) {
if (dataColumns != null && dataColumns.length != 0) {
KeyValueSchema keyValueSchema = deserializeLocalIndexJoinSchemaFromScan(scan);
- KeyValueColumnExpression[] keyValueColumns = new KeyValueColumnExpression[dataColumns.length];
+ boolean storeColsInSingleCell = scan.getAttribute(BaseScannerRegionObserver.COLUMNS_STORED_IN_SINGLE_CELL)!=null;
+ Expression[] colExpressions = storeColsInSingleCell ? new ArrayColumnExpression[dataColumns.length] : new KeyValueColumnExpression[dataColumns.length];
for (int i = 0; i < dataColumns.length; i++) {
- ColumnReference dataColumn = dataColumns[i];
- KeyValueColumnExpression dataColumnExpr = new KeyValueColumnExpression(keyValueSchema.getField(i), dataColumn.getFamily(), dataColumn.getQualifier());
- keyValueColumns[i] = dataColumnExpr;
+ byte[] family = dataColumns[i].getFamily();
+ byte[] qualifier = dataColumns[i].getQualifier();
+ Field field = keyValueSchema.getField(i);
+ Expression dataColumnExpr =
+ storeColsInSingleCell ? new ArrayColumnExpression(field, family, getEncodedColumnQualifier(qualifier))
+ : new KeyValueColumnExpression(field, family, qualifier);
+ colExpressions[i] = dataColumnExpr;
}
- return new TupleProjector(keyValueSchema, keyValueColumns);
+ return new TupleProjector(keyValueSchema, colExpressions);
}
return null;
}
@@ -481,8 +495,14 @@ public class IndexUtil {
ptr.set(indexRowKey, firstCell.getRowOffset() + offset, firstCell.getRowLength() - offset);
byte[] dataRowKey = indexMaintainer.buildDataRowKey(ptr, viewConstants);
Get get = new Get(dataRowKey);
+ StorageScheme storageScheme = indexMaintainer.getIndexStorageScheme();
+ boolean colsStoredInSingleCell = storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL;
for (int i = 0; i < dataColumns.length; i++) {
- get.addColumn(dataColumns[i].getFamily(), dataColumns[i].getQualifier());
+ if (colsStoredInSingleCell) {
+ get.addFamily(dataColumns[i].getFamily());
+ } else {
+ get.addColumn(dataColumns[i].getFamily(), dataColumns[i].getQualifier());
+ }
}
Result joinResult = null;
if (dataRegion != null) {
@@ -499,7 +519,8 @@ public class IndexUtil {
if (table != null) table.close();
}
}
-
+ // at this point join result has data from the data table. We now need to take this result and
+ // add it to the cells that we are returning.
// TODO: handle null case (but shouldn't happen)
Tuple joinTuple = new ResultTuple(joinResult);
// This will create a byte[] that captures all of the values from the data table
@@ -507,12 +528,14 @@ public class IndexUtil {
tupleProjector.getSchema().toBytes(joinTuple, tupleProjector.getExpressions(),
tupleProjector.getValueBitSet(), ptr);
KeyValue keyValue =
- KeyValueUtil.newKeyValue(firstCell.getRowArray(),firstCell.getRowOffset(),firstCell.getRowLength(), TupleProjector.VALUE_COLUMN_FAMILY,
- TupleProjector.VALUE_COLUMN_QUALIFIER, firstCell.getTimestamp(), value, 0, value.length);
+ KeyValueUtil.newKeyValue(firstCell.getRowArray(),firstCell.getRowOffset(),firstCell.getRowLength(), VALUE_COLUMN_FAMILY,
+ VALUE_COLUMN_QUALIFIER, firstCell.getTimestamp(), value, 0, value.length);
result.add(keyValue);
}
- for (int i = 0; i < result.size(); i++) {
- final Cell cell = result.get(i);
+
+ ListIterator<Cell> itr = result.listIterator();
+ while (itr.hasNext()) {
+ final Cell cell = itr.next();
// TODO: Create DelegateCell class instead
Cell newCell = new Cell() {
@@ -528,7 +551,7 @@ public class IndexUtil {
@Override
public short getRowLength() {
- return (short)(cell.getRowLength() - offset);
+ return (short) (cell.getRowLength() - offset);
}
@Override
@@ -632,8 +655,7 @@ public class IndexUtil {
return cell.getTagsLengthUnsigned();
}
};
- // Wrap cell in cell that offsets row key
- result.set(i, newCell);
+ itr.set(newCell);
}
}
@@ -686,4 +708,9 @@ public class IndexUtil {
}
return true;
}
+
+ public static boolean isLocalIndexFamily(String family) {
+ return family.indexOf(LOCAL_INDEX_COLUMN_FAMILY_PREFIX) != -1;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/util/KeyValueUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/KeyValueUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/KeyValueUtil.java
index b8850d2..071de66 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/KeyValueUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/KeyValueUtil.java
@@ -25,10 +25,8 @@ import java.util.List;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValue.KVComparator;
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
/**
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
index 01e1575..e7e91cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
@@ -643,4 +643,10 @@ public class MetaDataUtil {
public static boolean isLocalIndexFamily(byte[] cf) {
return Bytes.startsWith(cf, QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX_BYTES);
}
+
+ public static final byte[] getPhysicalTableRowForView(PTable view) {
+ byte[] physicalTableSchemaName = Bytes.toBytes(SchemaUtil.getSchemaNameFromFullName(view.getPhysicalName().getString()));
+ byte[] physicalTableName = Bytes.toBytes(SchemaUtil.getTableNameFromFullName(view.getPhysicalName().getString()));
+ return SchemaUtil.getTableKey(ByteUtil.EMPTY_BYTE_ARRAY, physicalTableSchemaName, physicalTableName);
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index 0c74b84..a946575 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -495,9 +495,9 @@ public class PhoenixRuntime {
String familyName = tokens[0];
String familyColumn = tokens[1];
PColumnFamily family = table.getColumnFamily(familyName);
- pColumn = family.getColumn(familyColumn);
+ pColumn = family.getPColumnForColumnName(familyColumn);
} else {
- pColumn = table.getColumn(columnName);
+ pColumn = table.getPColumnForColumnName(columnName);
}
return getColumnInfo(pColumn);
}
@@ -1188,9 +1188,9 @@ public class PhoenixRuntime {
PColumn pColumn = null;
if (familyName != null) {
PColumnFamily family = table.getColumnFamily(familyName);
- pColumn = family.getColumn(columnName);
+ pColumn = family.getPColumnForColumnName(columnName);
} else {
- pColumn = table.getColumn(columnName);
+ pColumn = table.getPColumnForColumnName(columnName);
}
return pColumn;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/util/ResultUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ResultUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ResultUtil.java
index dba6550..f97230b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ResultUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ResultUtil.java
@@ -18,7 +18,6 @@
package org.apache.phoenix.util;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@@ -129,63 +128,4 @@ public class ResultUtil {
return Bytes.compareTo(getRawBytes(r1), getKeyOffset(r1), getKeyLength(r1), getRawBytes(r2), getKeyOffset(r2), getKeyLength(r2));
}
- /**
- * Binary search for latest column value without allocating memory in the process
- */
- public static KeyValue getColumnLatest(Result r, byte[] family, byte[] qualifier) {
- byte[] rbytes = getRawBytes(r);
- int roffset = getKeyOffset(r);
- int rlength = getKeyLength(r);
- return getColumnLatest(r, rbytes, roffset, rlength, family, 0, family.length, qualifier, 0, qualifier.length);
- }
-
- public static KeyValue getSearchTerm(Result r, byte[] family, byte[] qualifier) {
- byte[] rbytes = getRawBytes(r);
- int roffset = getKeyOffset(r);
- int rlength = getKeyLength(r);
- return KeyValue.createFirstOnRow(rbytes, roffset, rlength, family, 0, family.length, qualifier, 0, qualifier.length);
- }
- /**
- * Binary search for latest column value without allocating memory in the process
- */
- public static KeyValue getColumnLatest(Result r, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) {
- KeyValue searchTerm = KeyValue.createFirstOnRow(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, qlength);
- return getColumnLatest(r,searchTerm);
-
- }
-
- /**
- * Binary search for latest column value without allocating memory in the process
- * @param r
- * @param searchTerm
- */
- @SuppressWarnings("deprecation")
- public static KeyValue getColumnLatest(Result r, KeyValue searchTerm) {
- KeyValue [] kvs = r.raw(); // side effect possibly.
- if (kvs == null || kvs.length == 0) {
- return null;
- }
-
- // pos === ( -(insertion point) - 1)
- int pos = Arrays.binarySearch(kvs, searchTerm, KeyValue.COMPARATOR);
- // never will exact match
- if (pos < 0) {
- pos = (pos+1) * -1;
- // pos is now insertion point
- }
- if (pos == kvs.length) {
- return null; // doesn't exist
- }
-
- KeyValue kv = kvs[pos];
- if (Bytes.compareTo(kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength(),
- searchTerm.getBuffer(), searchTerm.getFamilyOffset(), searchTerm.getFamilyLength()) != 0) {
- return null;
- }
- if (Bytes.compareTo(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength(),
- searchTerm.getBuffer(), searchTerm.getQualifierOffset(), searchTerm.getQualifierLength()) != 0) {
- return null;
- }
- return kv;
- }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
index acaeb31..8c2f58d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
@@ -23,6 +23,7 @@ import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.CUSTOM_AN
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_ACTUAL_START_ROW;
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_START_ROW_SUFFIX;
import static org.apache.phoenix.coprocessor.BaseScannerRegionObserver.SCAN_STOP_ROW_SUFFIX;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import java.io.IOException;
import java.sql.SQLException;
@@ -43,6 +44,7 @@ import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.io.TimeRange;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.io.WritableComparator;
import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
import org.apache.phoenix.compile.ScanRanges;
@@ -63,13 +65,16 @@ import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.schema.IllegalDataException;
+import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.RowKeySchema;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.ValueSchema.Field;
import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PVarbinary;
import com.google.common.collect.Iterators;
@@ -894,6 +899,40 @@ public class ScanUtil {
}
return true;
}
+
+ public static Pair<Integer, Integer> getMinMaxQualifiersFromScan(Scan scan) {
+ Integer minQ = null, maxQ = null;
+ byte[] minQualifier = scan.getAttribute(BaseScannerRegionObserver.MIN_QUALIFIER);
+ if (minQualifier != null) {
+ minQ = getEncodedColumnQualifier(minQualifier);
+ }
+ byte[] maxQualifier = scan.getAttribute(BaseScannerRegionObserver.MAX_QUALIFIER);
+ if (maxQualifier != null) {
+ maxQ = getEncodedColumnQualifier(maxQualifier);
+ }
+ if (minQualifier == null) {
+ return null;
+ }
+ return new Pair<>(minQ, maxQ);
+ }
+
+ public static boolean useQualifierAsIndex(Pair<Integer, Integer> minMaxQualifiers) {
+ return minMaxQualifiers != null;
+ }
+
+ public static boolean setQualifierRanges(PTable table) {
+ return table.getStorageScheme() != null && table.getStorageScheme() == StorageScheme.ENCODED_COLUMN_NAMES
+ && !table.isTransactional() && !hasDynamicColumns(table);
+ }
+
+ public static boolean hasDynamicColumns(PTable table) {
+ for (PColumn col : table.getColumns()) {
+ if (col.isDynamic()) {
+ return true;
+ }
+ }
+ return false;
+ }
public static boolean isIndexRebuild(Scan scan) {
return scan.getAttribute((BaseScannerRegionObserver.REBUILD_INDEXES)) != null;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 9f22239..1a4502e 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
@@ -47,6 +47,8 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.exception.DataExceedsCapacityException;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.expression.Expression;
@@ -69,6 +71,7 @@ import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.RowKeySchema;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
import org.apache.phoenix.schema.SaltingUtil;
import org.apache.phoenix.schema.SortOrder;
@@ -155,8 +158,9 @@ public class SchemaUtil {
rowSize += KeyValue.getKeyValueDataStructureSize(keyLength, column.getFamilyName().getBytes().length, column.getName().getBytes().length, valueLength);
}
}
+ byte[] emptyKeyValueKV = EncodedColumnsUtil.getEmptyKeyValueInfo(table).getFirst();
// Empty key value
- rowSize += KeyValue.getKeyValueDataStructureSize(keyLength, getEmptyColumnFamily(table).length, QueryConstants.EMPTY_COLUMN_BYTES.length, 0);
+ rowSize += KeyValue.getKeyValueDataStructureSize(keyLength, getEmptyColumnFamily(table).length, emptyKeyValueKV.length, 0);
return rowSize;
}
@@ -410,7 +414,7 @@ public class SchemaUtil {
}
} else {
try {
- return table.getColumnFamily(familyName.getString()).getColumn(column.getName().getString()).getName().getString();
+ return table.getColumnFamily(familyName.getString()).getPColumnForColumnName(column.getName().getString()).getName().getString();
} catch (ColumnFamilyNotFoundException e) {
continue; // Shouldn't happen
} catch (ColumnNotFoundException e) {
@@ -615,7 +619,7 @@ public class SchemaUtil {
public static boolean columnExists(PTable table, String columnName) {
try {
- table.getColumn(columnName);
+ table.getPColumnForColumnName(columnName);
return true;
} catch (ColumnNotFoundException e) {
return false;
@@ -1052,7 +1056,7 @@ public class SchemaUtil {
}
return getStrippedName(physicalTableName, indexPrefix);
}
-
+
private static String getStrippedName(String physicalTableName, String indexPrefix) {
return physicalTableName.indexOf(indexPrefix) == 0 ? physicalTableName.substring(indexPrefix.length())
: physicalTableName;
@@ -1073,4 +1077,46 @@ public class SchemaUtil {
return normalizeIdentifier(tableName);
}
}
+
+ /**
+ * Pads the data in ptr by the required amount for fixed width data types
+ */
+ public static void padData(String tableName, PColumn column, ImmutableBytesWritable ptr) {
+ PDataType type = column.getDataType();
+ byte[] byteValue = ptr.get();
+ boolean isNull = type.isNull(byteValue);
+ Integer maxLength = column.getMaxLength();
+ if (!isNull && type.isFixedWidth() && maxLength != null) {
+ if (ptr.getLength() < maxLength) {
+ type.pad(ptr, maxLength, column.getSortOrder());
+ } else if (ptr.getLength() > maxLength) {
+ throw new DataExceedsCapacityException(tableName + "." + column.getName().getString() + " may not exceed " + maxLength + " bytes (" + type.toObject(byteValue) + ")");
+ }
+ }
+ }
+
+ public static Map<String, Pair<Integer, Integer>> getQualifierRanges(PTable table) {
+ Preconditions.checkArgument(table.getStorageScheme() == StorageScheme.ENCODED_COLUMN_NAMES,
+ "Use this method only for tables with storage scheme "
+ + StorageScheme.ENCODED_COLUMN_NAMES.name());
+ Map<String, Pair<Integer, Integer>> toReturn = Maps.newHashMapWithExpectedSize(table.getColumns().size());
+ for (PColumn column : table.getColumns()) {
+ if (!isPKColumn(column)) {
+ String colFamily = column.getFamilyName().getString();
+ Pair<Integer, Integer> minMaxQualifiers = toReturn.get(colFamily);
+ Integer encodedColumnQualifier = column.getEncodedColumnQualifier();
+ if (minMaxQualifiers == null) {
+ minMaxQualifiers = new Pair<>(encodedColumnQualifier, encodedColumnQualifier);
+ toReturn.put(colFamily, minMaxQualifiers);
+ } else {
+ if (encodedColumnQualifier < minMaxQualifiers.getFirst()) {
+ minMaxQualifiers.setFirst(encodedColumnQualifier);
+ } else if (encodedColumnQualifier > minMaxQualifiers.getSecond()) {
+ minMaxQualifiers.setSecond(encodedColumnQualifier);
+ }
+ }
+ }
+ }
+ return toReturn;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/compile/HavingCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/HavingCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/HavingCompilerTest.java
index 1c7477d..ae2bd14 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/HavingCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/HavingCompilerTest.java
@@ -156,7 +156,7 @@ public class HavingCompilerTest extends BaseConnectionlessQueryTest {
String query = "select count(1) from atable group by a_string having count(1) >= 1 or a_string = 'foo'";
List<Object> binds = Collections.emptyList();
Expressions expressions = compileStatement(query,binds);
- PColumn aCol = ATABLE.getColumn("A_STRING");
+ PColumn aCol = ATABLE.getPColumnForColumnName("A_STRING");
Expression h = or(
constantComparison(CompareOp.GREATER_OR_EQUAL, new CountAggregateFunction(),1L),
constantComparison(CompareOp.EQUAL,
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index 8daefc0..bc35e22 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -170,7 +170,7 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest {
String query = "CREATE TABLE t1 (k integer not null primary key, a.k decimal, b.k decimal)";
conn.createStatement().execute(query);
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
- PColumn c = pconn.getTable(new PTableKey(pconn.getTenantId(), "T1")).getColumn("K");
+ PColumn c = pconn.getTable(new PTableKey(pconn.getTenantId(), "T1")).getPColumnForColumnName("K");
assertTrue(SchemaUtil.isPKColumn(c));
} finally {
conn.close();
@@ -2623,7 +2623,7 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest {
conn.createStatement().execute(ddl);
PTable table = conn.unwrap(PhoenixConnection.class).getMetaDataCache()
.getTableRef(new PTableKey(null,"TABLE_WITH_DEFAULT")).getTable();
- assertNull(table.getColumn("V").getExpressionStr());
+ assertNull(table.getPColumnForColumnName("V").getExpressionStr());
}
@Test
@@ -2638,7 +2638,7 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest {
conn.createStatement().execute(ddl2);
PTable table = conn.unwrap(PhoenixConnection.class).getMetaDataCache()
.getTableRef(new PTableKey(null,"TABLE_WITH_DEFAULT")).getTable();
- assertNull(table.getColumn("V").getExpressionStr());
+ assertNull(table.getPColumnForColumnName("V").getExpressionStr());
}
@Test
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
index c0bff8a..c65408e 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
@@ -52,7 +52,6 @@ import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.expression.ColumnExpression;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.KeyValueColumnExpression;
import org.apache.phoenix.expression.LiteralExpression;
@@ -67,8 +66,10 @@ import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.ColumnRef;
import org.apache.phoenix.schema.PColumn;
+import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.RowKeyValueAccessor;
import org.apache.phoenix.schema.SaltingUtil;
+import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.types.PChar;
import org.apache.phoenix.schema.types.PLong;
import org.apache.phoenix.schema.types.PVarchar;
@@ -118,9 +119,9 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
Filter filter = scan.getFilter();
- Expression idExpression = new ColumnRef(plan.getTableRef(), plan.getTableRef().getTable().getColumn("ID").getPosition()).newColumnExpression();
+ Expression idExpression = new ColumnRef(plan.getTableRef(), plan.getTableRef().getTable().getPColumnForColumnName("ID").getPosition()).newColumnExpression();
Expression id = new RowKeyColumnExpression(idExpression,new RowKeyValueAccessor(plan.getTableRef().getTable().getPKColumns(),0));
- Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getColumn("COMPANY"));
+ Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getPColumnForColumnName("COMPANY"), false);
// FilterList has no equals implementation
assertTrue(filter instanceof FilterList);
FilterList filterList = (FilterList)filter;
@@ -148,11 +149,11 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
Filter filter = scan.getFilter();
- PColumn column = plan.getTableRef().getTable().getColumn("COMPANY");
+ PColumn column = plan.getTableRef().getTable().getPColumnForColumnName("COMPANY");
assertEquals(
singleKVFilter(constantComparison(
CompareOp.EQUAL,
- new KeyValueColumnExpression(column),
+ new KeyValueColumnExpression(column, false),
"c3")),
filter);
}
@@ -939,16 +940,18 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
Filter filter = scan.getFilter();
-
+ PTable table = plan.getTableRef().getTable();
+ Expression aInteger = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("A_INTEGER").getPosition()).newColumnExpression();
+ Expression aString = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("A_STRING").getPosition()).newColumnExpression();
assertEquals(
multiKVFilter(and(
constantComparison(
CompareOp.EQUAL,
- A_INTEGER,
+ aInteger,
0),
constantComparison(
CompareOp.EQUAL,
- A_STRING,
+ aString,
"foo"))),
filter);
@@ -971,16 +974,18 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
Filter filter = scan.getFilter();
-
+ PTable table = plan.getTableRef().getTable();
+ Expression aInteger = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("A_INTEGER").getPosition()).newColumnExpression();
+ Expression aString = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("A_STRING").getPosition()).newColumnExpression();
assertEquals(
multiKVFilter(and(
constantComparison(
CompareOp.EQUAL,
- A_INTEGER,
+ aInteger,
0),
constantComparison(
CompareOp.EQUAL,
- A_STRING,
+ aString,
"foo"))),
filter);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
index 62aafa5..ca6a471 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/CorrelatePlanTest.java
@@ -17,6 +17,7 @@
*/
package org.apache.phoenix.execute;
+import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_FAMILY;
import static org.apache.phoenix.util.PhoenixRuntime.CONNECTIONLESS;
import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL;
import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
@@ -55,12 +56,15 @@ import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.JoinTableNode.JoinType;
import org.apache.phoenix.parse.ParseNodeFactory;
import org.apache.phoenix.parse.SelectStatement;
+import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.ColumnRef;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnImpl;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.EncodedCQCounter;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.TableRef;
@@ -247,16 +251,16 @@ public class CorrelatePlanTest {
for (int i = 0; i < row.length; i++) {
String name = ParseNodeFactory.createTempAlias();
Expression expr = LiteralExpression.newConstant(row[i]);
- columns.add(new PColumnImpl(PNameFactory.newName(name), PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY),
+ columns.add(new PColumnImpl(PNameFactory.newName(name), PNameFactory.newName(VALUE_COLUMN_FAMILY),
expr.getDataType(), expr.getMaxLength(), expr.getScale(), expr.isNullable(),
- i, expr.getSortOrder(), null, null, false, name, false, false));
+ i, expr.getSortOrder(), null, null, false, name, false, false, null));
}
try {
PTable pTable = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME,
PTableType.SUBQUERY, null, MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM,
null, null, columns, null, null, Collections.<PTable>emptyList(),
false, Collections.<PName>emptyList(), null, null, false, false, false, null,
- null, null, true, false, 0, 0L, Boolean.FALSE, null, false);
+ null, null, true, false, 0, 0L, Boolean.FALSE, null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, EncodedCQCounter.NULL_COUNTER);
TableRef sourceTable = new TableRef(pTable);
List<ColumnRef> sourceColumnRefs = Lists.<ColumnRef> newArrayList();
for (PColumn column : sourceTable.getTable().getColumns()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
index 1b16d40..7fff2c4 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
@@ -17,6 +17,7 @@
*/
package org.apache.phoenix.execute;
+import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_FAMILY;
import static org.apache.phoenix.util.PhoenixRuntime.CONNECTIONLESS;
import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL;
import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
@@ -49,15 +50,18 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.ParseNodeFactory;
import org.apache.phoenix.parse.SelectStatement;
+import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.ColumnRef;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnImpl;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.TableRef;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.tuple.SingleKeyValueTuple;
import org.apache.phoenix.schema.tuple.Tuple;
import org.junit.Test;
@@ -170,14 +174,14 @@ public class LiteralResultIteratorPlanTest {
String name = ParseNodeFactory.createTempAlias();
Expression expr = LiteralExpression.newConstant(row[i]);
columns.add(new PColumnImpl(PNameFactory.newName(name),
- PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY), expr.getDataType(), expr.getMaxLength(),
- expr.getScale(), expr.isNullable(), i, expr.getSortOrder(), null, null, false, name, false, false));
+ PNameFactory.newName(VALUE_COLUMN_FAMILY), expr.getDataType(), expr.getMaxLength(),
+ expr.getScale(), expr.isNullable(), i, expr.getSortOrder(), null, null, false, name, false, false, null));
}
try {
PTable pTable = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME, PTableType.SUBQUERY, null,
MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM, null, null, columns, null, null,
Collections.<PTable> emptyList(), false, Collections.<PName> emptyList(), null, null, false, false,
- false, null, null, null, true, false, 0, 0L, false, null, false);
+ false, null, null, null, true, false, 0, 0L, false, null, false, StorageScheme.NON_ENCODED_COLUMN_NAMES, EncodedCQCounter.NULL_COUNTER);
TableRef sourceTable = new TableRef(pTable);
List<ColumnRef> sourceColumnRefs = Lists.<ColumnRef> newArrayList();
for (PColumn column : sourceTable.getTable().getColumns()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java
index 50e2721..ff62f63 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java
@@ -17,6 +17,7 @@
*/
package org.apache.phoenix.execute;
+import static org.apache.phoenix.query.QueryConstants.VALUE_COLUMN_FAMILY;
import static org.apache.phoenix.util.PhoenixRuntime.CONNECTIONLESS;
import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL;
import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
@@ -117,8 +118,8 @@ public class UnnestArrayPlanTest {
LiteralExpression dummy = LiteralExpression.newConstant(null, arrayType);
RowKeyValueAccessor accessor = new RowKeyValueAccessor(Arrays.asList(dummy), 0);
UnnestArrayPlan plan = new UnnestArrayPlan(subPlan, new RowKeyColumnExpression(dummy, accessor), withOrdinality);
- PColumn elemColumn = new PColumnImpl(PNameFactory.newName("ELEM"), PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY), baseType, null, null, true, 0, SortOrder.getDefault(), null, null, false, "", false, false);
- PColumn indexColumn = withOrdinality ? new PColumnImpl(PNameFactory.newName("IDX"), PNameFactory.newName(TupleProjector.VALUE_COLUMN_FAMILY), PInteger.INSTANCE, null, null, true, 0, SortOrder.getDefault(), null, null, false, "", false, false) : null;
+ PColumn elemColumn = new PColumnImpl(PNameFactory.newName("ELEM"), PNameFactory.newName(VALUE_COLUMN_FAMILY), baseType, null, null, true, 0, SortOrder.getDefault(), null, null, false, "", false, false, null);
+ PColumn indexColumn = withOrdinality ? new PColumnImpl(PNameFactory.newName("IDX"), PNameFactory.newName(VALUE_COLUMN_FAMILY), PInteger.INSTANCE, null, null, true, 0, SortOrder.getDefault(), null, null, false, "", false, false, null) : null;
List<PColumn> columns = withOrdinality ? Arrays.asList(elemColumn, indexColumn) : Arrays.asList(elemColumn);
ProjectedColumnExpression elemExpr = new ProjectedColumnExpression(elemColumn, columns, 0, elemColumn.getName().getString());
ProjectedColumnExpression indexExpr = withOrdinality ? new ProjectedColumnExpression(indexColumn, columns, 1, indexColumn.getName().getString()) : null;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
index 7ee579c..98c2495 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
@@ -41,8 +41,8 @@ public class ColumnExpressionTest {
int maxLen = 30;
int scale = 5;
PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDecimal.INSTANCE, maxLen, scale,
- true, 20, SortOrder.getDefault(), 0, null, false, null, false, false);
- ColumnExpression colExp = new KeyValueColumnExpression(column);
+ true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, 0);
+ ColumnExpression colExp = new KeyValueColumnExpression(column, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
@@ -61,8 +61,8 @@ public class ColumnExpressionTest {
public void testSerializationWithNullScale() throws Exception {
int maxLen = 30;
PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PBinary.INSTANCE, maxLen, null,
- true, 20, SortOrder.getDefault(), 0, null, false, null, false, false);
- ColumnExpression colExp = new KeyValueColumnExpression(column);
+ true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, 0);
+ ColumnExpression colExp = new KeyValueColumnExpression(column, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
@@ -81,8 +81,8 @@ public class ColumnExpressionTest {
public void testSerializationWithNullMaxLength() throws Exception {
int scale = 5;
PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PVarchar.INSTANCE, null, scale,
- true, 20, SortOrder.getDefault(), 0, null, false, null, false, false);
- ColumnExpression colExp = new KeyValueColumnExpression(column);
+ true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, 0);
+ ColumnExpression colExp = new KeyValueColumnExpression(column, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
@@ -100,8 +100,8 @@ public class ColumnExpressionTest {
@Test
public void testSerializationWithNullScaleAndMaxLength() throws Exception {
PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDecimal.INSTANCE, null, null, true,
- 20, SortOrder.getDefault(), 0, null, false, null, false, false);
- ColumnExpression colExp = new KeyValueColumnExpression(column);
+ 20, SortOrder.getDefault(), 0, null, false, null, false, false, 0);
+ ColumnExpression colExp = new KeyValueColumnExpression(column, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/index/IndexMaintainerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/index/IndexMaintainerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/index/IndexMaintainerTest.java
index 112109e..5887e5b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/index/IndexMaintainerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/index/IndexMaintainerTest.java
@@ -135,8 +135,7 @@ public class IndexMaintainerTest extends BaseConnectionlessQueryTest {
}
ValueGetter valueGetter = newValueGetter(row, valueMap);
- List<Mutation> indexMutations =
- IndexTestUtil.generateIndexData(index, table, dataMutation, ptr, builder);
+ List<Mutation> indexMutations = IndexTestUtil.generateIndexData(index, table, dataMutation, ptr, builder);
assertEquals(1,indexMutations.size());
assertTrue(indexMutations.get(0) instanceof Put);
Mutation indexMutation = indexMutations.get(0);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java
index 791eb23..ddd8241 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java
@@ -74,4 +74,4 @@ public class AggregateResultScannerTest extends BaseConnectionlessQueryTest {
ResultIterator scanner = new GroupedAggregatingResultIterator(new MergeSortRowKeyResultIterator(iterators), aggregators);
AssertResults.assertResults(scanner, expectedResults);
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java
index b74cefb..750e46f 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java
@@ -119,15 +119,15 @@ public class BaseConnectionlessQueryTest extends BaseTest {
try {
PTable table = conn.getTable(new PTableKey(null, ATABLE_NAME));
ATABLE = table;
- ORGANIZATION_ID = new ColumnRef(new TableRef(table), table.getColumn("ORGANIZATION_ID").getPosition()).newColumnExpression();
- ENTITY_ID = new ColumnRef(new TableRef(table), table.getColumn("ENTITY_ID").getPosition()).newColumnExpression();
- A_INTEGER = new ColumnRef(new TableRef(table), table.getColumn("A_INTEGER").getPosition()).newColumnExpression();
- A_STRING = new ColumnRef(new TableRef(table), table.getColumn("A_STRING").getPosition()).newColumnExpression();
- B_STRING = new ColumnRef(new TableRef(table), table.getColumn("B_STRING").getPosition()).newColumnExpression();
- A_DATE = new ColumnRef(new TableRef(table), table.getColumn("A_DATE").getPosition()).newColumnExpression();
- A_TIME = new ColumnRef(new TableRef(table), table.getColumn("A_TIME").getPosition()).newColumnExpression();
- A_TIMESTAMP = new ColumnRef(new TableRef(table), table.getColumn("A_TIMESTAMP").getPosition()).newColumnExpression();
- X_DECIMAL = new ColumnRef(new TableRef(table), table.getColumn("X_DECIMAL").getPosition()).newColumnExpression();
+ ORGANIZATION_ID = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("ORGANIZATION_ID").getPosition()).newColumnExpression();
+ ENTITY_ID = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("ENTITY_ID").getPosition()).newColumnExpression();
+ A_INTEGER = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("A_INTEGER").getPosition()).newColumnExpression();
+ A_STRING = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("A_STRING").getPosition()).newColumnExpression();
+ B_STRING = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("B_STRING").getPosition()).newColumnExpression();
+ A_DATE = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("A_DATE").getPosition()).newColumnExpression();
+ A_TIME = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("A_TIME").getPosition()).newColumnExpression();
+ A_TIMESTAMP = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("A_TIMESTAMP").getPosition()).newColumnExpression();
+ X_DECIMAL = new ColumnRef(new TableRef(table), table.getPColumnForColumnName("X_DECIMAL").getPosition()).newColumnExpression();
} finally {
conn.close();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
index 3396cf8..089c5f1 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
@@ -136,7 +136,6 @@ public class ConnectionlessTest {
conn.rollback(); // to clear the list of mutations for the next
}
- @SuppressWarnings("deprecation")
private static void assertRow1(Iterator<KeyValue> iterator, byte[] expectedRowKey1) {
KeyValue kv;
assertTrue(iterator.hasNext());
@@ -153,7 +152,6 @@ public class ConnectionlessTest {
assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
}
- @SuppressWarnings("deprecation")
private static void assertRow2(Iterator<KeyValue> iterator, byte[] expectedRowKey2) {
KeyValue kv;
assertTrue(iterator.hasNext());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/test/java/org/apache/phoenix/query/EncodedColumnQualifierCellsListTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/EncodedColumnQualifierCellsListTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/EncodedColumnQualifierCellsListTest.java
new file mode 100644
index 0000000..564e75e
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/EncodedColumnQualifierCellsListTest.java
@@ -0,0 +1,608 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.query;
+
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.tuple.EncodedColumnQualiferCellsList;
+import org.junit.Test;
+
+public class EncodedColumnQualifierCellsListTest {
+
+ private static final byte[] row = Bytes.toBytes("row");
+ private static final byte[] cf = Bytes.toBytes("cf");
+
+
+ @Test
+ public void testIterator() {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] cells = new Cell[7];
+ int i = 0;
+ populateListAndArray(list, cells);
+ Iterator itr = list.iterator();
+ assertTrue(itr.hasNext());
+
+ // test itr.next()
+ i = 0;
+ while (itr.hasNext()) {
+ assertEquals(cells[i++], itr.next());
+ }
+
+ assertEquals(7, list.size());
+
+ // test itr.remove()
+ itr = list.iterator();
+ i = 0;
+ int numRemoved = 0;
+ try {
+ itr.remove();
+ fail("Remove not allowed till next() is called");
+ } catch (IllegalStateException expected) {}
+
+ while (itr.hasNext()) {
+ assertEquals(cells[i++], itr.next());
+ itr.remove();
+ numRemoved++;
+ }
+ assertEquals("Number of elements removed should have been the size of the list", 7, numRemoved);
+ }
+
+ @Test
+ public void testSize() {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ assertEquals(0, list.size());
+
+ populateList(list);
+
+ assertEquals(7, list.size());
+ int originalSize = list.size();
+
+ Iterator itr = list.iterator();
+ while (itr.hasNext()) {
+ itr.next();
+ itr.remove();
+ assertEquals(--originalSize, list.size());
+ }
+ }
+
+ @Test
+ public void testIsEmpty() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ assertTrue(list.isEmpty());
+ populateList(list);
+ assertFalse(list.isEmpty());
+ Iterator itr = list.iterator();
+ while (itr.hasNext()) {
+ itr.next();
+ itr.remove();
+ if (itr.hasNext()) {
+ assertFalse(list.isEmpty());
+ }
+ }
+ assertTrue(list.isEmpty());
+ }
+
+ @Test
+ public void testContains() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] cells = new Cell[7];
+ populateListAndArray(list, cells);
+
+ for (Cell c : cells) {
+ assertTrue(list.contains(c));
+ }
+ assertFalse(list.contains(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(13))));
+ }
+
+ @Test
+ public void testToArrayWithParam() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] cells = new Cell[7];
+ populateListAndArray(list, cells);
+ Cell[] array = list.toArray(new Cell[0]);
+ assertTrue(Arrays.equals(cells, array));
+ }
+
+ @Test
+ public void testToArrayWithoutParam() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] cells = new Cell[7];
+ populateListAndArray(list, cells);
+ Object[] array = list.toArray();
+ assertTrue(Arrays.equals(cells, array));
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] cells = new Cell[7];
+ populateListAndArray(list, cells);
+ assertTrue(list.remove(cells[0]));
+ assertEquals(6, list.size());
+ assertTrue(list.remove(cells[6]));
+ assertEquals(5, list.size());
+ assertTrue(list.remove(cells[3]));
+ assertEquals(4, list.size());
+ assertFalse(list.remove(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(13))));
+ assertEquals(4, list.size());
+ }
+
+ @Test
+ public void testContainsAll() throws Exception {
+ EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list1);
+ EncodedColumnQualiferCellsList list2 = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list2);
+ assertTrue(list1.containsAll(list2));
+ list2.remove(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(11)));
+ assertTrue(list1.containsAll(list2));
+ assertFalse(list2.containsAll(list1));
+ list2.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(13)));
+ assertFalse(list1.containsAll(list2));
+ assertFalse(list2.containsAll(list1));
+ List<Cell> arrayList = new ArrayList<>();
+ populateList(arrayList);
+ assertTrue(list1.containsAll(arrayList));
+ }
+
+ @Test
+ public void testAddAll() throws Exception {
+ EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list1);
+ EncodedColumnQualiferCellsList list2 = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list2);
+ /*
+ * Note that we don't care about equality of the element being added with the element already
+ * present at the index.
+ */
+ assertTrue(list1.addAll(list2));
+ }
+
+ @Test
+ public void testAddAllAtIndexFails() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list);
+ try {
+ list.addAll(0, new ArrayList<Cell>());
+ } catch (UnsupportedOperationException expected) {
+ }
+ }
+
+ @Test
+ public void testRemoveAll() throws Exception {
+ EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list1);
+ ArrayList<Cell> list2 = new ArrayList<>();
+ populateList(list2);
+ assertTrue(list1.removeAll(list2));
+ assertTrue(list1.isEmpty());
+ assertFalse(list2.isEmpty());
+ }
+
+ @Test
+ public void testRetainAll() throws Exception {
+ EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list1);
+ EncodedColumnQualiferCellsList list2 = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list2);
+ // retainAll won't be modifying the list1 since they both have the same elements equality wise
+ assertFalse(list1.retainAll(list2));
+ list2.remove(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(12)));
+ assertTrue(list1.retainAll(list2));
+ assertEquals(list1.size(), list2.size());
+ for (Cell c : list1) {
+ assertTrue(list2.contains(c));
+ }
+ }
+
+ @Test
+ public void testClear() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list);
+ list.clear();
+ assertTrue(list.isEmpty());
+ assertEquals(0, list.size());
+ }
+
+ @Test
+ public void testGetIndex() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] cells = new Cell[7];
+ populateListAndArray(list, cells);
+ for (int i = 0; i < cells.length; i++) {
+ assertEquals(cells[i], list.get(i));
+ }
+ }
+
+ @Test
+ public void testIndexOf() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] cells = new Cell[7];
+ populateListAndArray(list, cells);
+ for (int i = 0; i < cells.length; i++) {
+ assertEquals(i, list.indexOf(cells[i]));
+ }
+ }
+
+ @Test
+ public void testLastIndexOf() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] cells = new Cell[7];
+ populateListAndArray(list, cells);
+ for (int i = 0; i < cells.length; i++) {
+ assertEquals(i, list.lastIndexOf(cells[i]));
+ }
+ }
+
+ @Test
+ public void testListIterator() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] cells = new Cell[7];
+ int i = 0;
+ populateListAndArray(list, cells);
+ ListIterator<Cell> itr = list.listIterator();
+ assertTrue(itr.hasNext());
+
+ // test itr.next()
+ i = 0;
+ while (itr.hasNext()) {
+ assertEquals(cells[i++], itr.next());
+ }
+
+ assertEquals(7, list.size());
+
+ // test itr.remove()
+ itr = list.listIterator();
+ i = 0;
+ int numRemoved = 0;
+ try {
+ itr.remove();
+ fail("Remove not allowed till next() is called");
+ } catch (IllegalStateException expected) {}
+
+ while (itr.hasNext()) {
+ assertEquals(cells[i++], itr.next());
+ itr.remove();
+ numRemoved++;
+ }
+ assertEquals("Number of elements removed should have been the size of the list", 7, numRemoved);
+ assertTrue(list.isEmpty());
+ }
+
+ @Test
+ public void testListIteratorSet() {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] array = new Cell[7];
+ populateListAndArray(list, array);
+ ListIterator<Cell> itr = list.listIterator();
+ // This cell is KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(12))
+ final Cell validCell = array[4];
+ // This cell is KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(14))
+ final Cell invalidCell = array[5];
+ String validCellName = "Valid Cell";
+ String invalidCellName = "Invalid Cell";
+ Cell validReplacementCell = new DelegateCell(validCell, validCellName);
+ Cell invalidReplacementCell = new DelegateCell(invalidCell, invalidCellName);
+ int i = 0;
+ while (itr.hasNext()) {
+ Cell c = itr.next();
+ if (i == 4) {
+ itr.set(validReplacementCell);
+ }
+ if (i == 6) {
+ try {
+ itr.set(invalidReplacementCell);
+ fail("This should have failed since " + invalidReplacementCell + " cannot be added where " + c + " is.");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+ i++;
+ }
+ itr = list.listIterator();
+ i = 0;
+ // Assert that the valid cell was added and invalid cell wasn't.
+ while (itr.hasNext()) {
+ Cell c = itr.next();
+ if (i == 4) {
+ assertEquals(validCellName, c.toString());
+ }
+ if (i == 6) {
+ assertNotEquals(invalidCellName, c.toString());
+ }
+ i++;
+ }
+ }
+
+ @Test
+ public void testListIteratorNextAndPrevious() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ Cell[] array = new Cell[7];
+ populateListAndArray(list, array);
+ ListIterator<Cell> itr = list.listIterator();
+ try {
+ itr.previous();
+ fail("Call to itr.previous() should have failed since the iterator hasn't been moved forward yet");
+ } catch (NoSuchElementException expected) {
+
+ }
+ Cell c = itr.next();
+ Cell d = itr.previous();
+ Cell e = itr.next();
+ Cell f = itr.previous();
+ assertTrue(c.equals(d) && c.equals(f) && c.equals(e));
+ itr = list.listIterator();
+ int i = 0;
+ assertEquals(array[i++], itr.next());
+ assertEquals(array[i++], itr.next());
+ assertEquals(array[i++], itr.next());
+ assertEquals(array[--i], itr.previous());
+ assertEquals(array[--i], itr.previous());
+ assertEquals(array[i++], itr.next());
+
+ // move itr forward till next() is exhausted
+ while (itr.hasNext()) {
+ itr.next();
+ }
+ i = 6;
+ while (itr.hasPrevious()) {
+ assertEquals(array[i--], itr.previous());
+ }
+ assertEquals("Not all elements navigated using previous()", -1, i);
+ // now that previous is exhausted, move itr() forward till next() is exhausted
+ i = 0;
+ while (itr.hasNext()) {
+ assertEquals(array[i++], itr.next());
+ }
+ assertEquals("Not all elements navigated using next()", 7, i);
+ }
+
+ @Test
+ public void testSetNull() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ try {
+ list.add(null);
+ fail("Adding null elements to the list is not allowed");
+ } catch (NullPointerException expected) {
+
+ }
+ }
+
+ @Test
+ public void testFailFastIterator() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list);
+ int i = 0;
+ Iterator<Cell> itr = list.iterator();
+ while (itr.hasNext()) {
+ i++;
+ try {
+ itr.next();
+ list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
+ if (i == 2) {
+ fail("ConcurrentModificationException should have been thrown as the list is being modified while being iterated through");
+ }
+ } catch (ConcurrentModificationException expected) {
+ assertEquals("Exception should have been thrown when getting the second element",
+ 2, i);
+ break;
+ }
+ }
+ }
+
+ @Test
+ public void testFailFastListIterator() throws Exception {
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list);
+ ListIterator<Cell> itr = list.listIterator();
+ itr.next();
+ list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
+ try {
+ itr.next();
+ fail("ConcurrentModificationException should have been thrown as the list was modified without using iterator");
+ } catch (ConcurrentModificationException expected) {
+
+ }
+ list = new EncodedColumnQualiferCellsList(11, 16);
+ populateList(list);
+ itr = list.listIterator();
+ itr.next();
+ itr.next();
+ itr.remove();
+ itr.next();
+ list.remove(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
+ try {
+ itr.next();
+ fail("ConcurrentModificationException should have been thrown as the list was modified without using iterator");
+ } catch (ConcurrentModificationException expected) {
+
+ }
+ }
+
+ private void populateListAndArray(List<Cell> list, Cell[] cells) {
+ // add elements in reserved range
+ list.add(cells[0] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
+ list.add(cells[1] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(5)));
+ list.add(cells[2] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(10)));
+
+ // add elements in qualifier range
+ list.add(cells[6] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(16)));
+ list.add(cells[4] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(12)));
+ list.add(cells[5] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(14)));
+ list.add(cells[3] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(11)));
+ }
+
+ private void populateList(List<Cell> list) {
+ // add elements in reserved range
+ list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
+ list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(5)));
+ list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(10)));
+
+ // add elements in qualifier range
+ list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(16)));
+ list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(12)));
+ list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(14)));
+ list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(11)));
+ }
+
+ private class DelegateCell implements Cell {
+ private final Cell delegate;
+ private final String name;
+ public DelegateCell(Cell delegate, String name) {
+ this.delegate = delegate;
+ this.name = name;
+ }
+
+ @Override
+ public int getValueOffset() {
+ return delegate.getValueOffset();
+ }
+
+ @Override
+ public int getValueLength() {
+ return delegate.getValueLength();
+ }
+
+ @Override
+ public byte[] getValueArray() {
+ return delegate.getValueArray();
+ }
+
+ @Override
+ public byte[] getValue() {
+ return delegate.getValue();
+ }
+
+ @Override
+ public byte getTypeByte() {
+ return delegate.getTypeByte();
+ }
+
+ @Override
+ public long getTimestamp() {
+ return delegate.getTimestamp();
+ }
+
+ @Override
+ public int getTagsOffset() {
+ return delegate.getTagsOffset();
+ }
+
+ @Override
+ public int getTagsLengthUnsigned() {
+ return delegate.getTagsLengthUnsigned();
+ }
+
+ @Override
+ public short getTagsLength() {
+ return delegate.getTagsLength();
+ }
+
+ @Override
+ public byte[] getTagsArray() {
+ return delegate.getTagsArray();
+ }
+
+ @Override
+ public int getRowOffset() {
+ return delegate.getRowOffset();
+ }
+
+ @Override
+ public short getRowLength() {
+ return delegate.getRowLength();
+ }
+
+ @Override
+ public byte[] getRowArray() {
+ return delegate.getRowArray();
+ }
+
+ @Override
+ public byte[] getRow() {
+ return delegate.getRow();
+ }
+
+ @Override
+ public int getQualifierOffset() {
+ return delegate.getQualifierOffset();
+ }
+
+ @Override
+ public int getQualifierLength() {
+ return delegate.getQualifierLength();
+ }
+
+ @Override
+ public byte[] getQualifierArray() {
+ return delegate.getQualifierArray();
+ }
+
+ @Override
+ public byte[] getQualifier() {
+ return delegate.getQualifier();
+ }
+
+ @Override
+ public long getMvccVersion() {
+ return delegate.getMvccVersion();
+ }
+
+ @Override
+ public int getFamilyOffset() {
+ return delegate.getFamilyOffset();
+ }
+
+ @Override
+ public byte getFamilyLength() {
+ return delegate.getFamilyLength();
+ }
+
+ @Override
+ public byte[] getFamilyArray() {
+ return delegate.getFamilyArray();
+ }
+
+ @Override
+ public byte[] getFamily() {
+ return delegate.getFamily();
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ }
+
+}
[29/42] phoenix git commit: Ignore
DefaultColumnValueIT#testDefaultImmutableRows till PHOENIX-3442 is fixed
Posted by td...@apache.org.
Ignore DefaultColumnValueIT#testDefaultImmutableRows till PHOENIX-3442 is fixed
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/2b3265e0
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/2b3265e0
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/2b3265e0
Branch: refs/heads/encodecolumns2
Commit: 2b3265e058a1d3b9176795e62285c8e96ef2ccfe
Parents: 9eb690f
Author: Samarth <sa...@salesforce.com>
Authored: Mon Nov 21 19:14:34 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/2b3265e0/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
index 62d79bc..8302604 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DefaultColumnValueIT.java
@@ -37,6 +37,7 @@ import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.DateUtil;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
@@ -257,7 +258,7 @@ public class DefaultColumnValueIT extends ParallelStatsDisabledIT {
assertFalse(rs.next());
}
- @Test
+ @Ignore //FIXME: PHOENIX-3442
public void testDefaultImmutableRows() throws Exception {
String table = generateUniqueName();
String ddl = "CREATE TABLE IF NOT EXISTS " + table + " (" +
[06/42] phoenix git commit: PHOENIX-2084 Support loading JSON data
using phoenix-flume (Kalyan Hadoop)
Posted by td...@apache.org.
PHOENIX-2084 Support loading JSON data using phoenix-flume (Kalyan Hadoop)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/9b06c60e
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/9b06c60e
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/9b06c60e
Branch: refs/heads/encodecolumns2
Commit: 9b06c60e6f1a5010bbe8d123accf75f890283e6b
Parents: 8a231a9
Author: Josh Mahonin <jm...@gmail.com>
Authored: Thu Dec 15 14:38:15 2016 -0500
Committer: Josh Mahonin <jm...@gmail.com>
Committed: Thu Dec 15 14:39:58 2016 -0500
----------------------------------------------------------------------
phoenix-flume/pom.xml | 12 +
.../phoenix/flume/JsonEventSerializerIT.java | 541 +++++++++++++++++++
.../apache/phoenix/flume/FlumeConstants.java | 7 +-
.../flume/serializer/BaseEventSerializer.java | 4 +-
.../flume/serializer/EventSerializers.java | 2 +-
.../flume/serializer/JsonEventSerializer.java | 226 ++++++++
6 files changed, 789 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b06c60e/phoenix-flume/pom.xml
----------------------------------------------------------------------
diff --git a/phoenix-flume/pom.xml b/phoenix-flume/pom.xml
index 0b21357..8046ff2 100644
--- a/phoenix-flume/pom.xml
+++ b/phoenix-flume/pom.xml
@@ -176,6 +176,18 @@
<scope>test</scope>
</dependency>
+ <!-- to work with json data using flume -->
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20160212</version>
+ </dependency>
+ <dependency>
+ <groupId>com.jayway.jsonpath</groupId>
+ <artifactId>json-path</artifactId>
+ <version>2.2.0</version>
+ </dependency>
+
<!-- Main dependency on flume. The last to avoid using old commons-io in IT -->
<dependency>
<groupId>org.apache.flume</groupId>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b06c60e/phoenix-flume/src/it/java/org/apache/phoenix/flume/JsonEventSerializerIT.java
----------------------------------------------------------------------
diff --git a/phoenix-flume/src/it/java/org/apache/phoenix/flume/JsonEventSerializerIT.java b/phoenix-flume/src/it/java/org/apache/phoenix/flume/JsonEventSerializerIT.java
new file mode 100644
index 0000000..0210bad
--- /dev/null
+++ b/phoenix-flume/src/it/java/org/apache/phoenix/flume/JsonEventSerializerIT.java
@@ -0,0 +1,541 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.flume;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.flume.Channel;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.flume.EventDeliveryException;
+import org.apache.flume.Transaction;
+import org.apache.flume.channel.MemoryChannel;
+import org.apache.flume.conf.Configurables;
+import org.apache.flume.event.EventBuilder;
+import org.apache.flume.lifecycle.LifecycleState;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.end2end.BaseHBaseManagedTimeIT;
+import org.apache.phoenix.flume.serializer.EventSerializers;
+import org.apache.phoenix.flume.sink.PhoenixSink;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.junit.Test;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class JsonEventSerializerIT extends BaseHBaseManagedTimeIT {
+
+ private Context sinkContext;
+ private PhoenixSink sink;
+
+ @Test
+ public void testWithOutColumnsMapping() throws EventDeliveryException, SQLException {
+
+ final String fullTableName = "FLUME_JSON_TEST";
+
+ String ddl = "CREATE TABLE IF NOT EXISTS " + fullTableName
+ + " (flume_time timestamp not null, col1 varchar , col2 double, col3 varchar[], col4 integer[]"
+ + " CONSTRAINT pk PRIMARY KEY (flume_time))\n";
+ String columns = "col1,col2,col3,col4";
+ String rowkeyType = DefaultKeyGenerator.TIMESTAMP.name();
+ initSinkContext(fullTableName, ddl, columns, null, rowkeyType, null);
+
+ sink = new PhoenixSink();
+ Configurables.configure(sink, sinkContext);
+
+ assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
+
+ final Channel channel = this.initChannel();
+ sink.setChannel(channel);
+
+ sink.start();
+ final String eventBody = "{\"col1\" : \"kalyan\", \"col2\" : 10.5, \"col3\" : [\"abc\",\"pqr\",\"xyz\"], \"col4\" : [1,2,3,4]}";
+ final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
+ // put event in channel
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ channel.put(event);
+ transaction.commit();
+ transaction.close();
+
+ sink.process();
+
+ int rowsInDb = countRows(fullTableName);
+ assertEquals(1, rowsInDb);
+
+ sink.stop();
+ assertEquals(LifecycleState.STOP, sink.getLifecycleState());
+
+ dropTable(fullTableName);
+ }
+
+ @Test
+ public void testDifferentColumnNames() throws EventDeliveryException, SQLException {
+
+ final String fullTableName = "FLUME_JSON_TEST";
+
+ String ddl = "CREATE TABLE IF NOT EXISTS " + fullTableName
+ + " (flume_time timestamp not null, col1 varchar , col2 double, col3 varchar[], col4 integer[]"
+ + " CONSTRAINT pk PRIMARY KEY (flume_time))\n";
+ String columns = "col1,col2,col3,col4";
+ String rowkeyType = DefaultKeyGenerator.TIMESTAMP.name();
+ String columnsMapping = "{\"col1\":\"col1\",\"col2\":\"f2\",\"col3\":\"f3\",\"col4\":\"col4\"}";
+
+ initSinkContext(fullTableName, ddl, columns, columnsMapping, rowkeyType, null);
+
+ sink = new PhoenixSink();
+ Configurables.configure(sink, sinkContext);
+
+ assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
+
+ final Channel channel = this.initChannel();
+ sink.setChannel(channel);
+
+ sink.start();
+ final String eventBody = "{\"col1\" : \"kalyan\", \"f2\" : 10.5, \"f3\" : [\"abc\",\"pqr\",\"xyz\"], \"col4\" : [1,2,3,4]}";
+ final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
+ // put event in channel
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ channel.put(event);
+ transaction.commit();
+ transaction.close();
+
+ sink.process();
+
+ int rowsInDb = countRows(fullTableName);
+ assertEquals(1, rowsInDb);
+
+ sink.stop();
+ assertEquals(LifecycleState.STOP, sink.getLifecycleState());
+
+ dropTable(fullTableName);
+ }
+
+ @Test
+ public void testInnerColumns() throws EventDeliveryException, SQLException {
+
+ final String fullTableName = "FLUME_JSON_TEST";
+
+ String ddl = "CREATE TABLE IF NOT EXISTS " + fullTableName
+ + " (flume_time timestamp not null, col1 varchar , col2 double, col3 varchar[], col4 integer[]"
+ + " CONSTRAINT pk PRIMARY KEY (flume_time))\n";
+ String columns = "col1,col2,col3,col4";
+ String rowkeyType = DefaultKeyGenerator.TIMESTAMP.name();
+ String columnsMapping = "{\"col1\":\"col1\",\"col2\":\"x.y\",\"col3\":\"a.b1.c\",\"col4\":\"col4\"}";
+
+ initSinkContext(fullTableName, ddl, columns, columnsMapping, rowkeyType, null);
+
+ sink = new PhoenixSink();
+ Configurables.configure(sink, sinkContext);
+
+ assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
+
+ final Channel channel = this.initChannel();
+ sink.setChannel(channel);
+
+ sink.start();
+ final String eventBody = "{\"col1\" : \"kalyan\", \"x\" : {\"y\" : 10.5}, \"a\" : {\"b1\" : {\"c\" : [\"abc\",\"pqr\",\"xyz\"] }, \"b2\" : 111}, \"col4\" : [1,2,3,4]}";
+ final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
+ // put event in channel
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ channel.put(event);
+ transaction.commit();
+ transaction.close();
+
+ sink.process();
+
+ int rowsInDb = countRows(fullTableName);
+ assertEquals(1, rowsInDb);
+
+ sink.stop();
+ assertEquals(LifecycleState.STOP, sink.getLifecycleState());
+
+ dropTable(fullTableName);
+ }
+
+ @Test
+ public void testInnerColumnsWithArrayMapping() throws EventDeliveryException, SQLException {
+
+ final String fullTableName = "FLUME_JSON_TEST";
+
+ String ddl = "CREATE TABLE IF NOT EXISTS " + fullTableName
+ + " (flume_time timestamp not null, col1 varchar , col2 double, col3 varchar[], col4 integer[]"
+ + " CONSTRAINT pk PRIMARY KEY (flume_time))\n";
+ String columns = "col1,col2,col3,col4";
+ String rowkeyType = DefaultKeyGenerator.TIMESTAMP.name();
+ String columnsMapping = "{\"col1\":\"col1\",\"col2\":\"x.y\",\"col3\":\"a.b[*].c\",\"col4\":\"col4\"}";
+
+ initSinkContext(fullTableName, ddl, columns, columnsMapping, rowkeyType, null);
+
+ sink = new PhoenixSink();
+ Configurables.configure(sink, sinkContext);
+
+ assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
+
+ final Channel channel = this.initChannel();
+ sink.setChannel(channel);
+
+ sink.start();
+ final String eventBody = "{\"col1\" : \"kalyan\", \"x\" : {\"y\" : 10.5}, \"a\" : {\"b\" : [{\"c\" : \"abc\"}, {\"c\" : \"pqr\"}, {\"c\" : \"xyz\"}] , \"b2\" : 111}, \"col4\" : [1,2,3,4]}";
+ final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
+ // put event in channel
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ channel.put(event);
+ transaction.commit();
+ transaction.close();
+
+ sink.process();
+
+ int rowsInDb = countRows(fullTableName);
+ assertEquals(1, rowsInDb);
+
+ sink.stop();
+ assertEquals(LifecycleState.STOP, sink.getLifecycleState());
+
+ dropTable(fullTableName);
+ }
+
+ @Test
+ public void testKeyGenerator() throws EventDeliveryException, SQLException {
+
+ final String fullTableName = "FLUME_JSON_TEST";
+ initSinkContextWithDefaults(fullTableName);
+
+ sink = new PhoenixSink();
+ Configurables.configure(sink, sinkContext);
+
+ assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
+
+ final Channel channel = this.initChannel();
+ sink.setChannel(channel);
+
+ sink.start();
+ final String eventBody = "{\"col1\" : \"kalyan\", \"col2\" : 10.5, \"col3\" : [\"abc\",\"pqr\",\"xyz\"], \"col4\" : [1,2,3,4]}";
+ final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
+ // put event in channel
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ channel.put(event);
+ transaction.commit();
+ transaction.close();
+
+ sink.process();
+
+ int rowsInDb = countRows(fullTableName);
+ assertEquals(1, rowsInDb);
+
+ sink.stop();
+ assertEquals(LifecycleState.STOP, sink.getLifecycleState());
+
+ dropTable(fullTableName);
+ }
+
+ @Test
+ public void testMismatchKeyGenerator() throws EventDeliveryException, SQLException {
+
+ final String fullTableName = "FLUME_JSON_TEST";
+ initSinkContextWithDefaults(fullTableName);
+ setConfig(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_ROWKEY_TYPE_GENERATOR,
+ DefaultKeyGenerator.UUID.name());
+
+ sink = new PhoenixSink();
+ Configurables.configure(sink, sinkContext);
+ assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
+
+ final Channel channel = this.initChannel();
+ sink.setChannel(channel);
+
+ sink.start();
+ final String eventBody = "{\"col1\" : \"kalyan\", \"col2\" : 10.5, \"col3\" : [\"abc\",\"pqr\",\"xyz\"], \"col4\" : [1,2,3,4]}";
+ final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
+ // put event in channel
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ channel.put(event);
+ transaction.commit();
+ transaction.close();
+
+ try {
+ sink.process();
+ fail();
+ } catch (Exception ex) {
+ assertTrue(ex.getCause().getMessage().contains("java.lang.IllegalArgumentException: Invalid format:"));
+ }
+
+ dropTable(fullTableName);
+ }
+
+ @Test
+ public void testMissingColumnsInEvent() throws EventDeliveryException, SQLException {
+
+ final String fullTableName = "FLUME_JSON_TEST";
+ initSinkContextWithDefaults(fullTableName);
+
+ sink = new PhoenixSink();
+ Configurables.configure(sink, sinkContext);
+ assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
+
+ final Channel channel = this.initChannel();
+ sink.setChannel(channel);
+
+ sink.start();
+ final String eventBody = "{\"col1\" : \"kalyan\", \"col3\" : [\"abc\",\"pqr\",\"xyz\"], \"col4\" : [1,2,3,4]}";
+ final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
+ // put event in channel
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ channel.put(event);
+ transaction.commit();
+ transaction.close();
+
+ sink.process();
+
+ int rowsInDb = countRows(fullTableName);
+ assertEquals(0, rowsInDb);
+
+ sink.stop();
+ assertEquals(LifecycleState.STOP, sink.getLifecycleState());
+
+ dropTable(fullTableName);
+ }
+
+ @Test
+ public void testBatchEvents() throws EventDeliveryException, SQLException {
+
+ final String fullTableName = "FLUME_JSON_TEST";
+ initSinkContextWithDefaults(fullTableName);
+
+ sink = new PhoenixSink();
+ Configurables.configure(sink, sinkContext);
+ assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
+
+ final Channel channel = this.initChannel();
+ sink.setChannel(channel);
+
+ sink.start();
+ int numEvents = 150;
+ String col1 = "val1";
+ String a1 = "[aaa,bbb,ccc]";
+ String a2 = "[1,2,3,4]";
+ String eventBody = null;
+ List<Event> eventList = Lists.newArrayListWithCapacity(numEvents);
+ for (int i = 0; i < eventList.size(); i++) {
+ eventBody = "{\"col1\" : \"" + (col1 + i) + "\", \"col2\" : " + i * 10.5 + " , \"col3\" : " + a1
+ + " , \"col4\" : " + a2 + "}";
+ Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
+ eventList.add(event);
+ }
+
+ // put event in channel
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ for (Event event : eventList) {
+ channel.put(event);
+ }
+ transaction.commit();
+ transaction.close();
+
+ sink.process();
+
+ int rowsInDb = countRows(fullTableName);
+ assertEquals(eventList.size(), rowsInDb);
+
+ sink.stop();
+ assertEquals(LifecycleState.STOP, sink.getLifecycleState());
+
+ dropTable(fullTableName);
+ }
+
+ @Test
+ public void testEventsWithHeaders() throws Exception {
+
+ sinkContext = new Context();
+ final String fullTableName = "FLUME_JSON_TEST";
+ final String ddl = "CREATE TABLE IF NOT EXISTS "
+ + fullTableName
+ + " (rowkey VARCHAR not null, col1 varchar , col2 double, col3 varchar[], col4 integer[], host varchar , source varchar \n"
+ + " CONSTRAINT pk PRIMARY KEY (rowkey))\n";
+ String columns = "col1,col2,col3,col4";
+ String columnsMapping = "{\"col1\":\"col1\",\"col2\":\"col2\",\"col3\":\"col3\",\"col4\":\"col4\"}";
+ String rowkeyType = DefaultKeyGenerator.UUID.name();
+ String headers = "host,source";
+ initSinkContext(fullTableName, ddl, columns, columnsMapping, rowkeyType, headers);
+
+ sink = new PhoenixSink();
+ Configurables.configure(sink, sinkContext);
+ assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
+
+ final Channel channel = this.initChannel();
+ sink.setChannel(channel);
+
+ sink.start();
+
+ int numEvents = 10;
+ String col1 = "val1";
+ String a1 = "[aaa,bbb,ccc]";
+ String a2 = "[1,2,3,4]";
+ String hostHeader = "host1";
+ String sourceHeader = "source1";
+ String eventBody = null;
+ List<Event> eventList = Lists.newArrayListWithCapacity(numEvents);
+ for (int i = 0; i < numEvents; i++) {
+ eventBody = "{\"col1\" : \"" + (col1 + i) + "\", \"col2\" : " + i * 10.5 + " , \"col3\" : " + a1
+ + " , \"col4\" : " + a2 + "}";
+ Map<String, String> headerMap = Maps.newHashMapWithExpectedSize(2);
+ headerMap.put("host", hostHeader);
+ headerMap.put("source", sourceHeader);
+ Event event = EventBuilder.withBody(Bytes.toBytes(eventBody), headerMap);
+ eventList.add(event);
+ }
+
+ // put event in channel
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ for (Event event : eventList) {
+ channel.put(event);
+ }
+ transaction.commit();
+ transaction.close();
+
+ sink.process();
+
+ final String query = " SELECT * FROM \n " + fullTableName;
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ final ResultSet rs;
+ final Connection conn = DriverManager.getConnection(getUrl(), props);
+ try {
+ rs = conn.createStatement().executeQuery(query);
+ assertTrue(rs.next());
+ assertEquals("host1", rs.getString("host"));
+ assertEquals("source1", rs.getString("source"));
+
+ assertTrue(rs.next());
+ assertEquals("host1", rs.getString("host"));
+ assertEquals("source1", rs.getString("source"));
+ } finally {
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ sink.stop();
+ assertEquals(LifecycleState.STOP, sink.getLifecycleState());
+
+ dropTable(fullTableName);
+ }
+
+ private Channel initChannel() {
+ // Channel configuration
+ Context channelContext = new Context();
+ channelContext.put("capacity", "10000");
+ channelContext.put("transactionCapacity", "200");
+
+ Channel channel = new MemoryChannel();
+ channel.setName("memorychannel");
+ Configurables.configure(channel, channelContext);
+ return channel;
+ }
+
+ private void initSinkContext(final String fullTableName, final String ddl, final String columns,
+ final String columnsMapping, final String rowkeyType, final String headers) {
+ Preconditions.checkNotNull(fullTableName);
+ sinkContext = new Context();
+ sinkContext.put(FlumeConstants.CONFIG_TABLE, fullTableName);
+ sinkContext.put(FlumeConstants.CONFIG_JDBC_URL, getUrl());
+ sinkContext.put(FlumeConstants.CONFIG_SERIALIZER, EventSerializers.JSON.name());
+ sinkContext.put(FlumeConstants.CONFIG_TABLE_DDL, ddl);
+ sinkContext.put(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_COLUMN_NAMES, columns);
+ if (null != columnsMapping)
+ sinkContext.put(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_COLUMNS_MAPPING,
+ columnsMapping);
+ if (null != rowkeyType)
+ sinkContext.put(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_ROWKEY_TYPE_GENERATOR,
+ rowkeyType);
+ if (null != headers)
+ sinkContext.put(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_HEADER_NAMES, headers);
+ }
+
+ private void initSinkContextWithDefaults(final String fullTableName) {
+ String ddl = "CREATE TABLE IF NOT EXISTS " + fullTableName
+ + " (flume_time timestamp not null, col1 varchar , col2 double, col3 varchar[], col4 integer[]"
+ + " CONSTRAINT pk PRIMARY KEY (flume_time))\n";
+ String columns = "col1,col2,col3,col4";
+ String columnsMapping = "{\"col1\":\"col1\",\"col2\":\"col2\",\"col3\":\"col3\",\"col4\":\"col4\"}";
+ String rowkeyType = DefaultKeyGenerator.TIMESTAMP.name();
+ initSinkContext(fullTableName, ddl, columns, columnsMapping, rowkeyType, null);
+ }
+
+ private void setConfig(final String configName, final String configValue) {
+ Preconditions.checkNotNull(sinkContext);
+ Preconditions.checkNotNull(configName);
+ Preconditions.checkNotNull(configValue);
+ sinkContext.put(configName, configValue);
+ }
+
+ private int countRows(final String fullTableName) throws SQLException {
+ Preconditions.checkNotNull(fullTableName);
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ final Connection conn = DriverManager.getConnection(getUrl(), props);
+ ResultSet rs = null;
+ try {
+ rs = conn.createStatement().executeQuery("select count(*) from " + fullTableName);
+ int rowsCount = 0;
+ while (rs.next()) {
+ rowsCount = rs.getInt(1);
+ }
+ return rowsCount;
+
+ } finally {
+ if (rs != null) {
+ rs.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+
+ }
+
+ private void dropTable(final String fullTableName) throws SQLException {
+ Preconditions.checkNotNull(fullTableName);
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ final Connection conn = DriverManager.getConnection(getUrl(), props);
+ try {
+ conn.createStatement().execute("drop table if exists " + fullTableName);
+ } finally {
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b06c60e/phoenix-flume/src/main/java/org/apache/phoenix/flume/FlumeConstants.java
----------------------------------------------------------------------
diff --git a/phoenix-flume/src/main/java/org/apache/phoenix/flume/FlumeConstants.java b/phoenix-flume/src/main/java/org/apache/phoenix/flume/FlumeConstants.java
index cf43a3b..f60d7dc 100644
--- a/phoenix-flume/src/main/java/org/apache/phoenix/flume/FlumeConstants.java
+++ b/phoenix-flume/src/main/java/org/apache/phoenix/flume/FlumeConstants.java
@@ -62,7 +62,12 @@ public final class FlumeConstants {
/** Whether to ignore case when performing regex matches. */
public static final String IGNORE_CASE_CONFIG = "regexIgnoreCase";
public static final boolean IGNORE_CASE_DEFAULT = false;
-
+
+ /** JSON expression used to parse groups from event data. */
+ public static final String CONFIG_COLUMNS_MAPPING = "columnsMapping";
+ public static final String CONFIG_PARTIAL_SCHEMA = "partialSchema";
+ public static final String JSON_DEFAULT = "{}";
+
/** Comma separated list of column names . */
public static final String CONFIG_COLUMN_NAMES = "columns";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b06c60e/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/BaseEventSerializer.java
----------------------------------------------------------------------
diff --git a/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/BaseEventSerializer.java b/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/BaseEventSerializer.java
index fddcba5..24527e3 100644
--- a/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/BaseEventSerializer.java
+++ b/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/BaseEventSerializer.java
@@ -157,7 +157,9 @@ public abstract class BaseEventSerializer implements EventSerializer {
while (rs.next()) {
cf = rs.getString(QueryUtil.COLUMN_FAMILY_POSITION);
cq = rs.getString(QueryUtil.COLUMN_NAME_POSITION);
- dt = rs.getInt(QueryUtil.DATA_TYPE_POSITION);
+ // TODO: Fix this .. change `DATA_TYPE_POSITION` value 5 to 26
+ // dt = rs.getInt(QueryUtil.DATA_TYPE_POSITION);
+ dt = rs.getInt(26);
if(Strings.isNullOrEmpty(cf)) {
rowkey = cq; // this is required only when row key is auto generated
} else {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b06c60e/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/EventSerializers.java
----------------------------------------------------------------------
diff --git a/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/EventSerializers.java b/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/EventSerializers.java
index eb0078d..68a609b 100644
--- a/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/EventSerializers.java
+++ b/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/EventSerializers.java
@@ -19,7 +19,7 @@ package org.apache.phoenix.flume.serializer;
public enum EventSerializers {
- REGEX(RegexEventSerializer.class.getName());
+ REGEX(RegexEventSerializer.class.getName()), JSON(JsonEventSerializer.class.getName());
private final String className;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b06c60e/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/JsonEventSerializer.java
----------------------------------------------------------------------
diff --git a/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/JsonEventSerializer.java b/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/JsonEventSerializer.java
new file mode 100644
index 0000000..9226017
--- /dev/null
+++ b/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/JsonEventSerializer.java
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.flume.serializer;
+
+import static org.apache.phoenix.flume.FlumeConstants.JSON_DEFAULT;
+import static org.apache.phoenix.flume.FlumeConstants.CONFIG_COLUMNS_MAPPING;
+import static org.apache.phoenix.flume.FlumeConstants.CONFIG_PARTIAL_SCHEMA;
+
+import java.sql.Array;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.phoenix.schema.types.PDataType;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.jayway.jsonpath.Configuration;
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
+import com.jayway.jsonpath.spi.mapper.JsonOrgMappingProvider;
+
+public class JsonEventSerializer extends BaseEventSerializer {
+
+ private static final Logger logger = LoggerFactory.getLogger(JsonEventSerializer.class);
+
+ private JSONObject jsonSchema;
+ private boolean isProperMapping;
+ private boolean partialSchema;
+
+ /**
+ *
+ */
+ @Override
+ public void doConfigure(Context context) {
+ final String jsonData = context.getString(CONFIG_COLUMNS_MAPPING, JSON_DEFAULT);
+ try {
+ jsonSchema = new JSONObject(jsonData);
+ if (jsonSchema.length() == 0) {
+ for (String colName : colNames) {
+ jsonSchema.put(colName, colName);
+ }
+ isProperMapping = true;
+ } else {
+ Iterator<String> keys = jsonSchema.keys();
+ List<String> keylist = new ArrayList<String>();
+ while (keys.hasNext()) {
+ keylist.add(keys.next());
+ }
+ isProperMapping = CollectionUtils.isEqualCollection(keylist, colNames);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ logger.debug("json mapping not proper, verify the data {} ", jsonData);
+ }
+ partialSchema = context.getBoolean(CONFIG_PARTIAL_SCHEMA, false);
+ }
+
+ /**
+ *
+ */
+ @Override
+ public void doInitialize() throws SQLException {
+ // NO-OP
+ }
+
+ @Override
+ public void upsertEvents(List<Event> events) throws SQLException {
+ Preconditions.checkNotNull(events);
+ Preconditions.checkNotNull(connection);
+ Preconditions.checkNotNull(this.upsertStatement);
+ Preconditions.checkArgument(isProperMapping, "Please verify fields mapping is not properly done..");
+
+ boolean wasAutoCommit = connection.getAutoCommit();
+ connection.setAutoCommit(false);
+ try (PreparedStatement colUpsert = connection.prepareStatement(upsertStatement)) {
+ String value = null;
+ Integer sqlType = null;
+ JSONObject inputJson = new JSONObject();
+ for (Event event : events) {
+ byte[] payloadBytes = event.getBody();
+ if (payloadBytes == null || payloadBytes.length == 0) {
+ continue;
+ }
+ String payload = new String(payloadBytes);
+
+ try {
+ inputJson = new JSONObject(payload);
+ } catch (Exception e) {
+ logger.debug("payload is not proper json");
+ continue;
+ }
+
+ Map<String, String> data = new HashMap<String, String>();
+ for (String colName : colNames) {
+ String pattern = colName;
+ if (jsonSchema.has(colName)) {
+ Object obj = jsonSchema.opt(colName);
+ if (null != obj) {
+ pattern = obj.toString();
+ }
+ }
+ pattern = "$." + pattern;
+ value = getPatternData(inputJson, pattern);
+
+ // if field mapping data is null then look for column data
+ if (null == value && partialSchema) {
+ pattern = "$." + colName;
+ value = getPatternData(inputJson, pattern);
+ }
+
+ data.put(colName, value);
+ }
+
+ Collection<String> values = data.values();
+ if (values.contains(null)) {
+ logger.debug("payload data {} doesn't match the fields mapping {} ", inputJson, jsonSchema);
+ continue;
+ }
+
+ int index = 1;
+ int offset = 0;
+ for (int i = 0; i < colNames.size(); i++, offset++) {
+ if (columnMetadata[offset] == null) {
+ continue;
+ }
+ String colName = colNames.get(i);
+ value = data.get(colName);
+ sqlType = columnMetadata[offset].getSqlType();
+ PDataType pDataType = PDataType.fromTypeId(sqlType);
+ Object upsertValue;
+ if (pDataType.isArrayType()) {
+ JSONArray jsonArray = new JSONArray(new JSONTokener(value));
+ Object[] vals = new Object[jsonArray.length()];
+ for (int x = 0; x < jsonArray.length(); x++) {
+ vals[x] = jsonArray.get(x);
+ }
+ String baseTypeSqlName = PDataType.arrayBaseType(pDataType).getSqlTypeName();
+ Array array = connection.createArrayOf(baseTypeSqlName, vals);
+ upsertValue = pDataType.toObject(array, pDataType);
+ } else {
+ upsertValue = pDataType.toObject(value);
+ }
+ if (upsertValue != null) {
+ colUpsert.setObject(index++, upsertValue, sqlType);
+ } else {
+ colUpsert.setNull(index++, sqlType);
+ }
+ }
+
+ // add headers if necessary
+ Map<String, String> headerValues = event.getHeaders();
+ for (int i = 0; i < headers.size(); i++, offset++) {
+ String headerName = headers.get(i);
+ String headerValue = headerValues.get(headerName);
+ sqlType = columnMetadata[offset].getSqlType();
+ Object upsertValue = PDataType.fromTypeId(sqlType).toObject(headerValue);
+ if (upsertValue != null) {
+ colUpsert.setObject(index++, upsertValue, sqlType);
+ } else {
+ colUpsert.setNull(index++, sqlType);
+ }
+ }
+
+ if (autoGenerateKey) {
+ sqlType = columnMetadata[offset].getSqlType();
+ String generatedRowValue = this.keyGenerator.generate();
+ Object rowkeyValue = PDataType.fromTypeId(sqlType).toObject(generatedRowValue);
+ colUpsert.setObject(index++, rowkeyValue, sqlType);
+ }
+ colUpsert.execute();
+ }
+ connection.commit();
+ } catch (Exception ex) {
+ logger.error("An error {} occurred during persisting the event ", ex.getMessage());
+ throw new SQLException(ex.getMessage());
+ } finally {
+ if (wasAutoCommit) {
+ connection.setAutoCommit(true);
+ }
+ }
+
+ }
+
+ private String getPatternData(JSONObject json, String pattern) {
+ Configuration JSON_ORG_CONFIGURATION = Configuration.builder().mappingProvider(new JsonOrgMappingProvider())
+ .jsonProvider(new JsonOrgJsonProvider()).build();
+ String value;
+ try {
+ Object object = JsonPath.using(JSON_ORG_CONFIGURATION).parse(json).read(pattern);
+ value = object.toString();
+ } catch (Exception e) {
+ value = null;
+ }
+ return value;
+ }
+
+}
\ No newline at end of file
[16/42] phoenix git commit: PHOENIX-3516 Performance Issues with
queries that have compound filters and specify
phoenix.query.force.rowkeyorder=true
Posted by td...@apache.org.
PHOENIX-3516 Performance Issues with queries that have compound filters and specify phoenix.query.force.rowkeyorder=true
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/54b7c218
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/54b7c218
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/54b7c218
Branch: refs/heads/encodecolumns2
Commit: 54b7c218d01ee26e5cbf16230ea2fc85d6ffa57f
Parents: 5706f51
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Tue Dec 20 17:56:37 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 10:50:43 2016 -0800
----------------------------------------------------------------------
.../end2end/TenantSpecificViewIndexIT.java | 47 ++++++++++++++++++++
.../apache/phoenix/compile/WhereCompiler.java | 3 +-
.../org/apache/phoenix/util/ExpressionUtil.java | 10 +++++
.../phoenix/query/KeyRangeIntersectTest.java | 9 +++-
4 files changed, 67 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/54b7c218/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java
index 3519cf7..cc2e46a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.end2end;
import static org.apache.phoenix.util.MetaDataUtil.getViewIndexSequenceName;
import static org.apache.phoenix.util.MetaDataUtil.getViewIndexSequenceSchemaName;
+import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -28,6 +29,7 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Properties;
import org.apache.hadoop.hbase.util.Bytes;
@@ -284,4 +286,49 @@ public class TenantSpecificViewIndexIT extends BaseTenantSpecificViewIndexIT {
assertEquals("value1", rs.getString(1));
assertFalse("No other rows should have been returned for the tenant", rs.next()); // should have just returned one record since for org1 we have only one row.
}
+
+ @Test
+ public void testOverlappingDatesFilter() throws SQLException {
+ String tenantUrl = getUrl() + ';' + TENANT_ID_ATTRIB + "=tenant1" + ";" + QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB + "=true";
+ String tableName = generateUniqueName();
+ String viewName = generateUniqueName();
+ String ddl = "CREATE TABLE " + tableName
+ + "(ORGANIZATION_ID CHAR(15) NOT NULL, "
+ + "PARENT_TYPE CHAR(3) NOT NULL, "
+ + "PARENT_ID CHAR(15) NOT NULL,"
+ + "CREATED_DATE DATE NOT NULL "
+ + "CONSTRAINT PK PRIMARY KEY (ORGANIZATION_ID, PARENT_TYPE, PARENT_ID, CREATED_DATE DESC)"
+ + ") VERSIONS=1,MULTI_TENANT=true,REPLICATION_SCOPE=1";
+
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ Connection viewConn = DriverManager.getConnection(tenantUrl) ) {
+ // create table
+ conn.createStatement().execute(ddl);
+ // create index
+ conn.createStatement().execute("CREATE INDEX IF NOT EXISTS IDX ON " + tableName + "(PARENT_TYPE, CREATED_DATE, PARENT_ID)");
+ // create view
+ viewConn.createStatement().execute("CREATE VIEW IF NOT EXISTS " + viewName + " AS SELECT * FROM "+ tableName );
+
+ String query ="EXPLAIN SELECT PARENT_ID FROM " + viewName
+ + " WHERE PARENT_TYPE='001' "
+ + "AND (CREATED_DATE > to_date('2011-01-01') AND CREATED_DATE < to_date('2016-10-31'))"
+ + "ORDER BY PARENT_TYPE,CREATED_DATE LIMIT 501";
+
+ ResultSet rs = viewConn.createStatement().executeQuery(query);
+ String expectedPlanFormat = "CLIENT SERIAL 1-WAY RANGE SCAN OVER IDX ['tenant1 ','001','%s 00:00:00.001'] - ['tenant1 ','001','%s 00:00:00.000']" + "\n" +
+ " SERVER FILTER BY FIRST KEY ONLY" + "\n" +
+ " SERVER 501 ROW LIMIT" + "\n" +
+ "CLIENT 501 ROW LIMIT";
+ assertEquals(String.format(expectedPlanFormat, "2011-01-01", "2016-10-31"), QueryUtil.getExplainPlan(rs));
+
+ query ="EXPLAIN SELECT PARENT_ID FROM " + viewName
+ + " WHERE PARENT_TYPE='001' "
+ + " AND (CREATED_DATE >= to_date('2011-01-01') AND CREATED_DATE <= to_date('2016-01-01'))"
+ + " AND (CREATED_DATE > to_date('2012-10-21') AND CREATED_DATE < to_date('2016-10-31')) "
+ + "ORDER BY PARENT_TYPE,CREATED_DATE LIMIT 501";
+
+ rs = viewConn.createStatement().executeQuery(query);
+ assertEquals(String.format(expectedPlanFormat, "2012-10-21", "2016-01-01"), QueryUtil.getExplainPlan(rs));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/54b7c218/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 13963d7..39451b8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -56,6 +56,7 @@ import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.TypeMismatchException;
import org.apache.phoenix.schema.types.PBoolean;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.ExpressionUtil;
import org.apache.phoenix.util.ScanUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -237,7 +238,7 @@ public class WhereCompiler {
if (LiteralExpression.isBooleanFalseOrNull(whereClause)) {
context.setScanRanges(ScanRanges.NOTHING);
- } else if (whereClause != null && !LiteralExpression.isTrue(whereClause) && !hashJoinOptimization) {
+ } else if (whereClause != null && !ExpressionUtil.evaluatesToTrue(whereClause) && !hashJoinOptimization) {
Filter filter = null;
final Counter counter = new Counter();
whereClause.accept(new KeyValueExpressionVisitor() {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/54b7c218/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
index 65cf075..1fbb534 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
@@ -15,6 +15,7 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.phoenix.expression.Determinism;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.LiteralExpression;
+import org.apache.phoenix.schema.types.PBoolean;
import org.apache.phoenix.schema.types.PDataType;
public class ExpressionUtil {
@@ -43,5 +44,14 @@ public class ExpressionUtil {
public static LiteralExpression getNullExpression(Expression expression) throws SQLException {
return LiteralExpression.newConstant(null, expression.getDataType(), expression.getDeterminism());
}
+
+ public static boolean evaluatesToTrue(Expression expression) {
+ if (isConstant(expression)) {
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+ expression.evaluate(null, ptr);
+ return Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(ptr));
+ }
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/54b7c218/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java
index 98c10a8..9e21b69 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java
@@ -18,9 +18,9 @@
package org.apache.phoenix.query;
+import static org.apache.hadoop.hbase.util.Bytes.toBytes;
import static org.apache.phoenix.query.KeyRange.EMPTY_RANGE;
import static org.apache.phoenix.query.KeyRange.EVERYTHING_RANGE;
-import static org.apache.hadoop.hbase.util.Bytes.toBytes;
import java.util.Arrays;
import java.util.Collection;
@@ -28,6 +28,8 @@ import java.util.Collection;
import junit.framework.TestCase;
import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.util.DateUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -86,6 +88,11 @@ public class KeyRangeIntersectTest extends TestCase {
PChar.INSTANCE.getKeyRange(toBytes("E"), false, toBytes("F"), true),
EMPTY_RANGE
},
+ {
+ PDate.INSTANCE.getKeyRange(PDate.INSTANCE.toBytes(DateUtil.parseDate("2011-01-01")), true, PDate.INSTANCE.toBytes(DateUtil.parseDate("2016-01-01")), true),
+ PDate.INSTANCE.getKeyRange(PDate.INSTANCE.toBytes(DateUtil.parseDate("2012-10-21")), false, PDate.INSTANCE.toBytes(DateUtil.parseDate("2016-10-31")), false),
+ PDate.INSTANCE.getKeyRange(PDate.INSTANCE.toBytes(DateUtil.parseDate("2012-10-21")), false, PDate.INSTANCE.toBytes(DateUtil.parseDate("2016-01-01")), true)
+ }
});
}
@Test
[39/42] phoenix git commit: Refactor code to store and use column
qualifiers in SYSTEM.CATALOG
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
index 0cd22ef..e8e42a6 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/LiteralResultIteratorPlanTest.java
@@ -174,9 +174,10 @@ public class LiteralResultIteratorPlanTest {
for (int i = 0; i < row.length; i++) {
String name = ParseNodeFactory.createTempAlias();
Expression expr = LiteralExpression.newConstant(row[i]);
+ PName colName = PNameFactory.newName(name);
columns.add(new PColumnImpl(PNameFactory.newName(name),
PNameFactory.newName(VALUE_COLUMN_FAMILY), expr.getDataType(), expr.getMaxLength(),
- expr.getScale(), expr.isNullable(), i, expr.getSortOrder(), null, null, false, name, false, false, null));
+ expr.getScale(), expr.isNullable(), i, expr.getSortOrder(), null, null, false, name, false, false, colName.getBytes()));
}
try {
PTable pTable = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME, PTableType.SUBQUERY, null,
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java
index ff62f63..195c2f0 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/UnnestArrayPlanTest.java
@@ -48,6 +48,7 @@ import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.SelectStatement;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnImpl;
+import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.RowKeyValueAccessor;
import org.apache.phoenix.schema.SortOrder;
@@ -118,8 +119,10 @@ public class UnnestArrayPlanTest {
LiteralExpression dummy = LiteralExpression.newConstant(null, arrayType);
RowKeyValueAccessor accessor = new RowKeyValueAccessor(Arrays.asList(dummy), 0);
UnnestArrayPlan plan = new UnnestArrayPlan(subPlan, new RowKeyColumnExpression(dummy, accessor), withOrdinality);
- PColumn elemColumn = new PColumnImpl(PNameFactory.newName("ELEM"), PNameFactory.newName(VALUE_COLUMN_FAMILY), baseType, null, null, true, 0, SortOrder.getDefault(), null, null, false, "", false, false, null);
- PColumn indexColumn = withOrdinality ? new PColumnImpl(PNameFactory.newName("IDX"), PNameFactory.newName(VALUE_COLUMN_FAMILY), PInteger.INSTANCE, null, null, true, 0, SortOrder.getDefault(), null, null, false, "", false, false, null) : null;
+ PName colName = PNameFactory.newName("ELEM");
+ PColumn elemColumn = new PColumnImpl(PNameFactory.newName("ELEM"), PNameFactory.newName(VALUE_COLUMN_FAMILY), baseType, null, null, true, 0, SortOrder.getDefault(), null, null, false, "", false, false, colName.getBytes());
+ colName = PNameFactory.newName("IDX");
+ PColumn indexColumn = withOrdinality ? new PColumnImpl(colName, PNameFactory.newName(VALUE_COLUMN_FAMILY), PInteger.INSTANCE, null, null, true, 0, SortOrder.getDefault(), null, null, false, "", false, false, colName.getBytes()) : null;
List<PColumn> columns = withOrdinality ? Arrays.asList(elemColumn, indexColumn) : Arrays.asList(elemColumn);
ProjectedColumnExpression elemExpr = new ProjectedColumnExpression(elemColumn, columns, 0, elemColumn.getName().getString());
ProjectedColumnExpression indexExpr = withOrdinality ? new ProjectedColumnExpression(indexColumn, columns, 1, indexColumn.getName().getString()) : null;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
index 98c2495..2788235 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
@@ -25,13 +25,14 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import org.apache.phoenix.schema.types.PBinary;
-import org.apache.phoenix.schema.types.PDecimal;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnImpl;
+import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
-import org.apache.phoenix.schema.types.PVarchar;
import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.types.PBinary;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PVarchar;
import org.junit.Test;
public class ColumnExpressionTest {
@@ -40,9 +41,10 @@ public class ColumnExpressionTest {
public void testSerialization() throws Exception {
int maxLen = 30;
int scale = 5;
- PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDecimal.INSTANCE, maxLen, scale,
- true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, 0);
- ColumnExpression colExp = new KeyValueColumnExpression(column, true);
+ PName colName = PNameFactory.newName("c1");
+ PColumn column = new PColumnImpl(colName, PNameFactory.newName("f1"), PDecimal.INSTANCE, maxLen, scale,
+ true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, colName.getBytes());
+ ColumnExpression colExp = new KeyValueColumnExpression(column);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
@@ -60,9 +62,10 @@ public class ColumnExpressionTest {
@Test
public void testSerializationWithNullScale() throws Exception {
int maxLen = 30;
- PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PBinary.INSTANCE, maxLen, null,
- true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, 0);
- ColumnExpression colExp = new KeyValueColumnExpression(column, true);
+ PName colName = PNameFactory.newName("c1");
+ PColumn column = new PColumnImpl(colName, PNameFactory.newName("f1"), PBinary.INSTANCE, maxLen, null,
+ true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, colName.getBytes());
+ ColumnExpression colExp = new KeyValueColumnExpression(column);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
@@ -80,9 +83,10 @@ public class ColumnExpressionTest {
@Test
public void testSerializationWithNullMaxLength() throws Exception {
int scale = 5;
- PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PVarchar.INSTANCE, null, scale,
- true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, 0);
- ColumnExpression colExp = new KeyValueColumnExpression(column, true);
+ PName colName = PNameFactory.newName("c1");
+ PColumn column = new PColumnImpl(colName, PNameFactory.newName("f1"), PVarchar.INSTANCE, null, scale,
+ true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, colName.getBytes());
+ ColumnExpression colExp = new KeyValueColumnExpression(column);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
@@ -99,9 +103,10 @@ public class ColumnExpressionTest {
@Test
public void testSerializationWithNullScaleAndMaxLength() throws Exception {
- PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDecimal.INSTANCE, null, null, true,
- 20, SortOrder.getDefault(), 0, null, false, null, false, false, 0);
- ColumnExpression colExp = new KeyValueColumnExpression(column, true);
+ PName colName = PNameFactory.newName("c1");
+ PColumn column = new PColumnImpl(colName, PNameFactory.newName("f1"), PDecimal.INSTANCE, null, null, true,
+ 20, SortOrder.getDefault(), 0, null, false, null, false, false, colName.getBytes());
+ ColumnExpression colExp = new KeyValueColumnExpression(column);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/test/java/org/apache/phoenix/query/EncodedColumnQualifierCellsListTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/EncodedColumnQualifierCellsListTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/EncodedColumnQualifierCellsListTest.java
index 564e75e..a25af78 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/EncodedColumnQualifierCellsListTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/EncodedColumnQualifierCellsListTest.java
@@ -17,7 +17,7 @@
*/
package org.apache.phoenix.query;
-import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
+import static org.apache.phoenix.schema.PTable.QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -46,7 +46,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testIterator() {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] cells = new Cell[7];
int i = 0;
populateListAndArray(list, cells);
@@ -80,7 +80,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testSize() {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
assertEquals(0, list.size());
populateList(list);
@@ -98,7 +98,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testIsEmpty() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
assertTrue(list.isEmpty());
populateList(list);
assertFalse(list.isEmpty());
@@ -115,19 +115,19 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testContains() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] cells = new Cell[7];
populateListAndArray(list, cells);
for (Cell c : cells) {
assertTrue(list.contains(c));
}
- assertFalse(list.contains(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(13))));
+ assertFalse(list.contains(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(13))));
}
@Test
public void testToArrayWithParam() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] cells = new Cell[7];
populateListAndArray(list, cells);
Cell[] array = list.toArray(new Cell[0]);
@@ -136,7 +136,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testToArrayWithoutParam() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] cells = new Cell[7];
populateListAndArray(list, cells);
Object[] array = list.toArray();
@@ -145,7 +145,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testRemove() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] cells = new Cell[7];
populateListAndArray(list, cells);
assertTrue(list.remove(cells[0]));
@@ -154,21 +154,21 @@ public class EncodedColumnQualifierCellsListTest {
assertEquals(5, list.size());
assertTrue(list.remove(cells[3]));
assertEquals(4, list.size());
- assertFalse(list.remove(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(13))));
+ assertFalse(list.remove(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(13))));
assertEquals(4, list.size());
}
@Test
public void testContainsAll() throws Exception {
- EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list1);
- EncodedColumnQualiferCellsList list2 = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list2 = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list2);
assertTrue(list1.containsAll(list2));
- list2.remove(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(11)));
+ list2.remove(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(11)));
assertTrue(list1.containsAll(list2));
assertFalse(list2.containsAll(list1));
- list2.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(13)));
+ list2.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(13)));
assertFalse(list1.containsAll(list2));
assertFalse(list2.containsAll(list1));
List<Cell> arrayList = new ArrayList<>();
@@ -178,9 +178,9 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testAddAll() throws Exception {
- EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list1);
- EncodedColumnQualiferCellsList list2 = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list2 = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list2);
/*
* Note that we don't care about equality of the element being added with the element already
@@ -191,7 +191,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testAddAllAtIndexFails() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list);
try {
list.addAll(0, new ArrayList<Cell>());
@@ -201,7 +201,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testRemoveAll() throws Exception {
- EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list1);
ArrayList<Cell> list2 = new ArrayList<>();
populateList(list2);
@@ -212,13 +212,13 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testRetainAll() throws Exception {
- EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list1 = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list1);
- EncodedColumnQualiferCellsList list2 = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list2 = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list2);
// retainAll won't be modifying the list1 since they both have the same elements equality wise
assertFalse(list1.retainAll(list2));
- list2.remove(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(12)));
+ list2.remove(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(12)));
assertTrue(list1.retainAll(list2));
assertEquals(list1.size(), list2.size());
for (Cell c : list1) {
@@ -228,7 +228,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testClear() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list);
list.clear();
assertTrue(list.isEmpty());
@@ -237,7 +237,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testGetIndex() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] cells = new Cell[7];
populateListAndArray(list, cells);
for (int i = 0; i < cells.length; i++) {
@@ -247,7 +247,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testIndexOf() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] cells = new Cell[7];
populateListAndArray(list, cells);
for (int i = 0; i < cells.length; i++) {
@@ -257,7 +257,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testLastIndexOf() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] cells = new Cell[7];
populateListAndArray(list, cells);
for (int i = 0; i < cells.length; i++) {
@@ -267,7 +267,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testListIterator() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] cells = new Cell[7];
int i = 0;
populateListAndArray(list, cells);
@@ -302,7 +302,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testListIteratorSet() {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] array = new Cell[7];
populateListAndArray(list, array);
ListIterator<Cell> itr = list.listIterator();
@@ -346,7 +346,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testListIteratorNextAndPrevious() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
Cell[] array = new Cell[7];
populateListAndArray(list, array);
ListIterator<Cell> itr = list.listIterator();
@@ -389,7 +389,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testSetNull() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
try {
list.add(null);
fail("Adding null elements to the list is not allowed");
@@ -400,7 +400,7 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testFailFastIterator() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list);
int i = 0;
Iterator<Cell> itr = list.iterator();
@@ -408,7 +408,7 @@ public class EncodedColumnQualifierCellsListTest {
i++;
try {
itr.next();
- list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
+ list.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(0)));
if (i == 2) {
fail("ConcurrentModificationException should have been thrown as the list is being modified while being iterated through");
}
@@ -422,25 +422,25 @@ public class EncodedColumnQualifierCellsListTest {
@Test
public void testFailFastListIterator() throws Exception {
- EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16);
+ EncodedColumnQualiferCellsList list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list);
ListIterator<Cell> itr = list.listIterator();
itr.next();
- list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
+ list.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(0)));
try {
itr.next();
fail("ConcurrentModificationException should have been thrown as the list was modified without using iterator");
} catch (ConcurrentModificationException expected) {
}
- list = new EncodedColumnQualiferCellsList(11, 16);
+ list = new EncodedColumnQualiferCellsList(11, 16, FOUR_BYTE_QUALIFIERS);
populateList(list);
itr = list.listIterator();
itr.next();
itr.next();
itr.remove();
itr.next();
- list.remove(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
+ list.remove(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(0)));
try {
itr.next();
fail("ConcurrentModificationException should have been thrown as the list was modified without using iterator");
@@ -451,28 +451,28 @@ public class EncodedColumnQualifierCellsListTest {
private void populateListAndArray(List<Cell> list, Cell[] cells) {
// add elements in reserved range
- list.add(cells[0] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
- list.add(cells[1] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(5)));
- list.add(cells[2] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(10)));
+ list.add(cells[0] = KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(0)));
+ list.add(cells[1] = KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(5)));
+ list.add(cells[2] = KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(10)));
// add elements in qualifier range
- list.add(cells[6] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(16)));
- list.add(cells[4] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(12)));
- list.add(cells[5] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(14)));
- list.add(cells[3] = KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(11)));
+ list.add(cells[6] = KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(16)));
+ list.add(cells[4] = KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(12)));
+ list.add(cells[5] = KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(14)));
+ list.add(cells[3] = KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(11)));
}
private void populateList(List<Cell> list) {
// add elements in reserved range
- list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(0)));
- list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(5)));
- list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(10)));
+ list.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(0)));
+ list.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(5)));
+ list.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(10)));
// add elements in qualifier range
- list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(16)));
- list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(12)));
- list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(14)));
- list.add(KeyValue.createFirstOnRow(row, cf, getEncodedColumnQualifier(11)));
+ list.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(16)));
+ list.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(12)));
+ list.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(14)));
+ list.add(KeyValue.createFirstOnRow(row, cf, FOUR_BYTE_QUALIFIERS.getEncodedBytes(11)));
}
private class DelegateCell implements Cell {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index 5409554..3c9a1bc 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -304,11 +304,11 @@ public class TestUtil {
}
public static Expression constantComparison(CompareOp op, PColumn c, Object o) {
- return new ComparisonExpression(Arrays.<Expression>asList(new KeyValueColumnExpression(c, true), LiteralExpression.newConstant(o)), op);
+ return new ComparisonExpression(Arrays.<Expression>asList(new KeyValueColumnExpression(c), LiteralExpression.newConstant(o)), op);
}
public static Expression kvColumn(PColumn c) {
- return new KeyValueColumnExpression(c, true);
+ return new KeyValueColumnExpression(c);
}
public static Expression pkColumn(PColumn c, List<PColumn> columns) {
@@ -725,10 +725,10 @@ public class TestUtil {
return false;
}
@Override
- public Integer getEncodedColumnQualifier() {
- return null;
+ public byte[] getColumnQualifierBytes() {
+ return SINGLE_COLUMN_NAME.getBytes();
}
- }, false)), null);
+ })), null);
aggregationManager.setAggregators(new ClientAggregators(Collections.<SingleAggregateFunction>singletonList(func), 1));
ClientAggregators aggregators = aggregationManager.getAggregators();
return aggregators;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a41074a9/phoenix-protocol/src/main/PTable.proto
----------------------------------------------------------------------
diff --git a/phoenix-protocol/src/main/PTable.proto b/phoenix-protocol/src/main/PTable.proto
index 3eac63b..f2eb46c 100644
--- a/phoenix-protocol/src/main/PTable.proto
+++ b/phoenix-protocol/src/main/PTable.proto
@@ -47,7 +47,7 @@ message PColumn {
optional string expression = 12;
optional bool isRowTimestamp = 13;
optional bool isDynamic = 14;
- optional int32 encodedColumnQualifier = 15;
+ optional bytes columnQualifierBytes = 15;
}
message PTableStats {
[25/42] phoenix git commit: Fail-fast iterators for
EncodedColumnQualifierCellsList. Use list iterators instead of get(index) for
navigating lists. Use HBase bytes utility for encoded column names. Fix test
failures for immutable tables and indexes.
Posted by td...@apache.org.
Fail-fast iterators for EncodedColumnQualifierCellsList.
Use list iterators instead of get(index) for navigating lists.
Use HBase bytes utility for encoded column names.
Fix test failures for immutable tables and indexes.
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/670b53a9
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/670b53a9
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/670b53a9
Branch: refs/heads/encodecolumns2
Commit: 670b53a96623562975541ccd06573c449724e19b
Parents: 54b7c21
Author: Samarth <sa...@salesforce.com>
Authored: Wed Oct 5 00:11:07 2016 -0700
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../AlterMultiTenantTableWithViewsIT.java | 25 +-
.../apache/phoenix/end2end/AlterTableIT.java | 286 +++-
.../phoenix/end2end/AlterTableWithViewsIT.java | 141 +-
.../apache/phoenix/end2end/CreateTableIT.java | 5 +
.../org/apache/phoenix/end2end/OrderByIT.java | 2 -
.../phoenix/end2end/PhoenixRuntimeIT.java | 4 +-
.../phoenix/end2end/RowValueConstructorIT.java | 2 +-
.../phoenix/end2end/StatsCollectorIT.java | 16 +-
.../apache/phoenix/end2end/StoreNullsIT.java | 41 +-
.../apache/phoenix/end2end/UpsertValuesIT.java | 45 +-
.../phoenix/end2end/index/DropMetadataIT.java | 13 +-
.../end2end/index/IndexExpressionIT.java | 28 +-
.../apache/phoenix/end2end/index/IndexIT.java | 26 +-
.../phoenix/end2end/index/IndexTestUtil.java | 11 +-
.../end2end/index/MutableIndexFailureIT.java | 2 +
.../phoenix/compile/CreateTableCompiler.java | 15 +-
.../phoenix/compile/ExpressionCompiler.java | 18 +-
.../apache/phoenix/compile/FromCompiler.java | 50 +-
.../apache/phoenix/compile/JoinCompiler.java | 8 +-
.../phoenix/compile/ListJarsQueryPlan.java | 2 +-
.../apache/phoenix/compile/PostDDLCompiler.java | 11 +-
.../compile/PostLocalIndexDDLCompiler.java | 7 +-
.../phoenix/compile/ProjectionCompiler.java | 10 +-
.../apache/phoenix/compile/QueryCompiler.java | 2 +-
.../apache/phoenix/compile/TraceQueryPlan.java | 2 +-
.../compile/TupleProjectionCompiler.java | 21 +-
.../apache/phoenix/compile/UnionCompiler.java | 5 +-
.../apache/phoenix/compile/UpsertCompiler.java | 5 +-
.../apache/phoenix/compile/WhereCompiler.java | 13 +-
.../coprocessor/BaseScannerRegionObserver.java | 40 +-
.../coprocessor/DelegateRegionScanner.java | 5 +
.../GroupedAggregateRegionObserver.java | 27 +-
.../coprocessor/HashJoinRegionScanner.java | 9 +-
.../coprocessor/MetaDataEndpointImpl.java | 228 ++-
.../phoenix/coprocessor/ScanRegionObserver.java | 15 +-
.../UngroupedAggregateRegionObserver.java | 16 +-
.../coprocessor/generated/PTableProtos.java | 1379 ++++++++++++++++--
.../apache/phoenix/execute/BaseQueryPlan.java | 25 +-
.../apache/phoenix/execute/MutationState.java | 14 +-
.../apache/phoenix/execute/TupleProjector.java | 6 +-
.../expression/ArrayColumnExpression.java | 142 ++
.../expression/ArrayConstructorExpression.java | 2 +-
.../phoenix/expression/ExpressionType.java | 5 +-
.../expression/KeyValueColumnExpression.java | 17 +-
.../phoenix/expression/LiteralExpression.java | 11 +-
.../expression/ProjectedColumnExpression.java | 1 +
.../visitor/CloneExpressionVisitor.java | 6 +
.../expression/visitor/ExpressionVisitor.java | 2 +
.../StatelessTraverseAllExpressionVisitor.java | 7 +-
.../StatelessTraverseNoExpressionVisitor.java | 7 +-
.../phoenix/filter/ColumnProjectionFilter.java | 24 +-
.../filter/MultiKeyValueComparisonFilter.java | 5 +-
.../SingleCQKeyValueComparisonFilter.java | 3 +-
.../filter/SingleKeyValueComparisonFilter.java | 4 +-
.../apache/phoenix/hbase/index/ValueGetter.java | 1 +
.../example/CoveredColumnIndexCodec.java | 1 -
.../hbase/index/util/KeyValueBuilder.java | 1 +
.../apache/phoenix/index/IndexMaintainer.java | 327 ++++-
.../phoenix/index/PhoenixIndexBuilder.java | 2 +-
.../index/PhoenixIndexFailurePolicy.java | 5 +-
.../index/PhoenixTransactionalIndexer.java | 16 +-
.../phoenix/iterate/BaseResultIterators.java | 95 +-
.../iterate/LookAheadResultIterator.java | 2 +-
.../phoenix/iterate/MappedByteBufferQueue.java | 1 +
.../phoenix/iterate/OrderedResultIterator.java | 3 +-
.../iterate/RegionScannerResultIterator.java | 14 +-
.../phoenix/jdbc/PhoenixDatabaseMetaData.java | 12 +-
.../apache/phoenix/jdbc/PhoenixResultSet.java | 2 +-
.../apache/phoenix/join/HashCacheFactory.java | 1 +
.../mapreduce/FormatToBytesWritableMapper.java | 22 +-
.../mapreduce/FormatToKeyValueReducer.java | 30 +-
.../query/ConnectionQueryServicesImpl.java | 4 +-
.../query/ConnectionlessQueryServicesImpl.java | 1 -
.../apache/phoenix/query/QueryConstants.java | 56 +-
.../phoenix/query/QueryServicesOptions.java | 1 -
.../org/apache/phoenix/schema/ColumnRef.java | 22 +-
.../apache/phoenix/schema/DelegateColumn.java | 4 +
.../apache/phoenix/schema/DelegateTable.java | 19 +-
.../apache/phoenix/schema/MetaDataClient.java | 343 ++++-
.../java/org/apache/phoenix/schema/PColumn.java | 4 +-
.../apache/phoenix/schema/PColumnFamily.java | 14 +-
.../phoenix/schema/PColumnFamilyImpl.java | 50 +-
.../org/apache/phoenix/schema/PColumnImpl.java | 24 +-
.../apache/phoenix/schema/PMetaDataImpl.java | 4 +-
.../java/org/apache/phoenix/schema/PName.java | 26 +
.../java/org/apache/phoenix/schema/PTable.java | 139 +-
.../org/apache/phoenix/schema/PTableImpl.java | 418 ++++--
.../org/apache/phoenix/schema/PTableKey.java | 6 +-
.../apache/phoenix/schema/ProjectedColumn.java | 1 +
.../org/apache/phoenix/schema/SaltingUtil.java | 2 +-
.../apache/phoenix/schema/tuple/BaseTuple.java | 39 +
.../phoenix/schema/tuple/DelegateTuple.java | 7 +
.../tuple/EncodedColumnQualiferCellsList.java | 569 ++++++++
.../schema/tuple/MultiKeyValueTuple.java | 1 +
.../tuple/PositionBasedMultiKeyValueTuple.java | 87 ++
.../schema/tuple/PositionBasedResultTuple.java | 126 ++
.../phoenix/schema/tuple/ResultTuple.java | 20 +-
.../org/apache/phoenix/schema/tuple/Tuple.java | 4 +
.../apache/phoenix/util/EncodedColumnsUtil.java | 108 ++
.../java/org/apache/phoenix/util/IndexUtil.java | 77 +-
.../org/apache/phoenix/util/KeyValueUtil.java | 2 -
.../org/apache/phoenix/util/MetaDataUtil.java | 6 +
.../org/apache/phoenix/util/PhoenixRuntime.java | 8 +-
.../org/apache/phoenix/util/ResultUtil.java | 60 -
.../java/org/apache/phoenix/util/ScanUtil.java | 39 +
.../org/apache/phoenix/util/SchemaUtil.java | 54 +-
.../phoenix/compile/HavingCompilerTest.java | 2 +-
.../phoenix/compile/QueryCompilerTest.java | 6 +-
.../phoenix/compile/WhereCompilerTest.java | 27 +-
.../phoenix/execute/CorrelatePlanTest.java | 10 +-
.../execute/LiteralResultIteratorPlanTest.java | 10 +-
.../phoenix/execute/UnnestArrayPlanTest.java | 5 +-
.../expression/ColumnExpressionTest.java | 16 +-
.../phoenix/index/IndexMaintainerTest.java | 3 +-
.../iterate/AggregateResultScannerTest.java | 2 +-
.../query/BaseConnectionlessQueryTest.java | 18 +-
.../phoenix/query/ConnectionlessTest.java | 2 -
.../EncodedColumnQualifierCellsListTest.java | 608 ++++++++
.../java/org/apache/phoenix/util/TestUtil.java | 43 +-
phoenix-protocol/src/main/PTable.proto | 8 +
120 files changed, 5461 insertions(+), 995 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
index adadca7..8275f3f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
@@ -17,6 +17,7 @@
*/
package org.apache.phoenix.end2end;
+import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE;
import static org.apache.phoenix.query.QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT;
import static org.apache.phoenix.query.QueryConstants.DIVERGED_VIEW_BASE_COLUMN_COUNT;
import static org.junit.Assert.assertEquals;
@@ -476,14 +477,14 @@ public class AlterMultiTenantTableWithViewsIT extends ParallelStatsDisabledIT {
// For a diverged view, only base table's pk column will be added and that too at the end.
assertTableDefinition(conn, divergedView, PTableType.VIEW, baseTable, 2, 7, DIVERGED_VIEW_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V3", "VIEW_COL1", "VIEW_COL2", "PK2");
- // Add existing column VIEW_COL2 to the base table
+ // Adding existing column VIEW_COL2 to the base table isn't allowed.
alterBaseTable = "ALTER TABLE " + baseTable + " ADD VIEW_COL2 CHAR(256)";
- conn.createStatement().execute(alterBaseTable);
-
- // For the non-diverged view, adding the column VIEW_COL2 will end up changing its ordinal position in the view.
- assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 2, 9, 8, "TENANT_ID", "PK1", "V1", "V2", "V3", "KV", "PK2", "VIEW_COL2", "VIEW_COL1");
- // For the diverged view, adding the column VIEW_COL2 will not change its ordinal position in the view. It also won't change the base column count or the sequence number
- assertTableDefinition(conn, divergedView, PTableType.VIEW, baseTable, 2, 7, DIVERGED_VIEW_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V3", "VIEW_COL1", "VIEW_COL2", "PK2");
+ try {
+ conn.createStatement().execute(alterBaseTable);
+ fail();
+ } catch (SQLException e) {
+ assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+ }
}
}
@@ -500,13 +501,13 @@ public class AlterMultiTenantTableWithViewsIT extends ParallelStatsDisabledIT {
tenant1Conn.createStatement().execute(view1DDL);
}
- assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 0, 5, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3");
+ assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 1, 5, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3");
assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 0, 7, 5, "TENANT_ID", "PK1", "V1", "V2", "V3", "VIEW_COL1", "VIEW_COL2");
String alterBaseTable = "ALTER TABLE " + baseTable + " ADD KV VARCHAR, PK2 VARCHAR PRIMARY KEY";
conn.createStatement().execute(alterBaseTable);
- assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 1, 7, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3", "KV", "PK2");
+ assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 2, 7, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3", "KV", "PK2");
assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 1, 9, 7, "TENANT_ID", "PK1", "V1", "V2", "V3", "KV", "PK2", "VIEW_COL1", "VIEW_COL2");
// verify that the both columns were added to view1
@@ -530,13 +531,13 @@ public class AlterMultiTenantTableWithViewsIT extends ParallelStatsDisabledIT {
tenant1Conn.createStatement().execute(view1DDL);
}
- assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 0, 5, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3");
+ assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 1, 5, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V2", "V3");
assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 0, 7, 5, "TENANT_ID", "PK1", "V1", "V2", "V3", "VIEW_COL1", "VIEW_COL2");
String alterBaseTable = "ALTER TABLE " + baseTable + " DROP COLUMN V2";
conn.createStatement().execute(alterBaseTable);
- assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 1, 4, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V3");
+ assertTableDefinition(conn, baseTable, PTableType.TABLE, null, 2, 4, BASE_TABLE_BASE_COLUMN_COUNT, "TENANT_ID", "PK1", "V1", "V3");
assertTableDefinition(conn, view1, PTableType.VIEW, baseTable, 1, 6, 4, "TENANT_ID", "PK1", "V1", "V3", "VIEW_COL1", "VIEW_COL2");
// verify that the dropped columns aren't visible
@@ -569,7 +570,7 @@ public class AlterMultiTenantTableWithViewsIT extends ParallelStatsDisabledIT {
String view1DDL = "CREATE VIEW " + view1 + " ( VIEW_COL1 DECIMAL(10,2), VIEW_COL2 CHAR(256)) AS SELECT * FROM " + baseTable;
tenant1Conn.createStatement().execute(view1DDL);
// This should not modify the base table
- String alterView = "ALTER VIEW " + view1 + " ADD NEWCOL1 VARCHAR";
+ String alterView = "ALTER VIEW " + view1 + " ADD NEWCOL1 VARCHAR, NEWCOL5 VARCHAR";
tenant1Conn.createStatement().execute(alterView);
HTableDescriptor tableDesc2 = tenant1Conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin().getTableDescriptor(Bytes.toBytes(baseTable));
assertEquals(tableDesc1, tableDesc2);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index 155b6c2..173a3be 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -18,6 +18,15 @@
package org.apache.phoenix.end2end;
import static org.apache.hadoop.hbase.HColumnDescriptor.DEFAULT_REPLICATION_SCOPE;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_FAMILY;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_QUALIFIER_COUNTER;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ENCODED_COLUMN_QUALIFIER;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SEQ_NUM;
+import static org.apache.phoenix.query.QueryConstants.DEFAULT_COLUMN_FAMILY;
+import static org.apache.phoenix.query.QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.apache.phoenix.util.TestUtil.closeConnection;
import static org.apache.phoenix.util.TestUtil.closeStatement;
@@ -55,6 +64,7 @@ import org.apache.phoenix.query.BaseTest;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.util.IndexUtil;
@@ -233,8 +243,18 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
assertEquals(exists, rs.next());
}
+
+ @Test
+ public void testDropIndexedColumnImmutableIndex() throws Exception {
+ helpTestDropIndexedColumn(true);
+ }
+
@Test
- public void testDropIndexedColumn() throws Exception {
+ public void testDropIndexedColumnMutableIndex() throws Exception {
+ helpTestDropIndexedColumn(false);
+ }
+
+ private void helpTestDropIndexedColumn(boolean immutable) throws Exception {
String query;
ResultSet rs;
PreparedStatement stmt;
@@ -246,7 +266,7 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
// make sure that the tables are empty, but reachable
conn.createStatement().execute(
"CREATE TABLE " + dataTableFullName
- + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
+ + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) " + (immutable ? "IMMUTABLE_ROWS = true" : ""));
query = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
@@ -2124,8 +2144,8 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
PTable table = phxConn.getTable(new PTableKey(phxConn.getTenantId(), dataTableFullName));
// Assert that the column shows up as row time stamp in the cache.
- assertTrue(table.getColumn("PK1").isRowTimestamp());
- assertFalse(table.getColumn("PK2").isRowTimestamp());
+ assertTrue(table.getPColumnForColumnName("PK1").isRowTimestamp());
+ assertFalse(table.getPColumnForColumnName("PK2").isRowTimestamp());
assertIsRowTimestampSet(schemaName, dataTableName, "PK1");
String dataTableName2 = BaseTest.generateUniqueName();
@@ -2133,18 +2153,17 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
conn.createStatement().execute("CREATE TABLE " + dataTableFullName2 + " (PK1 VARCHAR, PK2 DATE PRIMARY KEY ROW_TIMESTAMP, KV1 VARCHAR, KV2 INTEGER)");
table = phxConn.getTable(new PTableKey(phxConn.getTenantId(), dataTableFullName2));
// Assert that the column shows up as row time stamp in the cache.
- assertFalse(table.getColumn("PK1").isRowTimestamp());
- assertTrue(table.getColumn("PK2").isRowTimestamp());
+ assertFalse(table.getPColumnForColumnName("PK1").isRowTimestamp());
+ assertTrue(table.getPColumnForColumnName("PK2").isRowTimestamp());
assertIsRowTimestampSet(schemaName, dataTableName2, "PK2");
// Create an index on a table has a row time stamp pk column. The column should show up as a row time stamp column for the index too.
conn.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName2 + " (KV1) include (KV2)");
PTable indexTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), indexTableFullName));
- String indexColName = IndexUtil.getIndexColumnName(table.getColumn("PK2"));
+ String indexColName = IndexUtil.getIndexColumnName(table.getPColumnForColumnName("PK2"));
// Assert that the column shows up as row time stamp in the cache.
- assertTrue(indexTable.getColumn(indexColName).isRowTimestamp());
+ assertTrue(indexTable.getPColumnForColumnName(indexColName).isRowTimestamp());
assertIsRowTimestampSet(schemaName, indexTableName, indexColName);
-
String viewTableName2 = dataTableName2 + "_VIEW";
String viewTableFullName2 = SchemaUtil.getTableName(schemaName, viewTableName2);
// Creating a view with a row_timestamp column in its pk constraint is not allowed
@@ -2235,5 +2254,254 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testMetadataForImmutableTableWithEncodedColumns() throws Exception {
+ String schemaName = "XYZ";
+ String baseTableName = generateUniqueName();
+ String viewName = generateUniqueName();
+ String fullTableName = schemaName + "." + baseTableName;
+ String fullViewName = schemaName + "." + viewName;
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
+ conn.createStatement().execute("CREATE TABLE IF NOT EXISTS " + fullTableName + " ("
+ + " ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " KV1 VARCHAR"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (ID, COL1, COL2)"
+ + " ) IMMUTABLE_ROWS = true");
+ PTable baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
+ long initBaseTableSeqNumber = baseTable.getSequenceNumber();
+
+ // assert that the client side cache is updated.
+ EncodedCQCounter cqCounter = baseTable.getEncodedCQCounter();
+ assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 1), cqCounter.getNextQualifier(QueryConstants.DEFAULT_COLUMN_FAMILY));
+
+
+ // assert that the server side metadata is updated correctly.
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1, true);
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "KV1", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE);
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber);
+
+ // now create a view and validate client and server side metadata
+ String viewDDL = "CREATE VIEW " + fullViewName + " ( VIEW_COL1 INTEGER, A.VIEW_COL2 VARCHAR ) AS SELECT * FROM " + fullTableName;
+ conn.createStatement().execute(viewDDL);
+ baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
+ PTable view = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullViewName));
+
+ // verify that the client side cache is updated. Base table's cq counters should be updated.
+ assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 2), baseTable.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
+ assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 1), baseTable.getEncodedCQCounter().getNextQualifier("A"));
+ assertNull("A view should always have the null cq counter", view.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
+
+ // assert that the server side metadata for the base table and the view is also updated correctly.
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 2, true);
+ assertEncodedCQCounter("A", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1, true);
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL1", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
+ assertEncodedCQValue("A", "VIEW_COL2", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE);
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 1);
+ assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM);
+ }
+ }
+
+ @Test
+ public void testMetadataForMutableTableWithEncodedColumns() throws Exception {
+ String schemaName = "XYZ";
+ String baseTableName = generateUniqueName();
+ String viewName = generateUniqueName();
+ String fullTableName = schemaName + "." + baseTableName;
+ String fullViewName = schemaName + "." + viewName;
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
+ conn.createStatement().execute("CREATE TABLE IF NOT EXISTS " + fullTableName + " ("
+ + " ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " KV1 VARCHAR"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (ID, COL1, COL2)"
+ + " )");
+ PTable baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
+ long initBaseTableSeqNumber = baseTable.getSequenceNumber();
+
+ // assert that the client side cache is updated.
+ EncodedCQCounter cqCounter = baseTable.getEncodedCQCounter();
+ assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 1), cqCounter.getNextQualifier(QueryConstants.DEFAULT_COLUMN_FAMILY));
+
+
+ // assert that the server side metadata is updated correctly.
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1, true);
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "KV1", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE);
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber);
+
+ // now create a view and validate client and server side metadata
+ String viewDDL = "CREATE VIEW " + fullViewName + " ( VIEW_COL1 INTEGER, A.VIEW_COL2 VARCHAR ) AS SELECT * FROM " + fullTableName;
+ conn.createStatement().execute(viewDDL);
+ baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
+ PTable view = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullViewName));
+
+ // verify that the client side cache is updated. Base table's cq counters should be updated.
+ assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 3), baseTable.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
+ assertNull("A view should always have the null cq counter", view.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
+
+ // assert that the server side metadata for the base table and the view is also updated correctly.
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3, true);
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL1", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
+ assertEncodedCQValue("A", "VIEW_COL2", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 2);
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 1);
+ assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM);
+ }
+ }
+
+ @Test
+ public void testAddingColumnsToTablesAndViewsWithEncodedColumns() throws Exception {
+ String schemaName = "XYZ";
+ String baseTableName = generateUniqueName();
+ String viewName = generateUniqueName();
+ String fullTableName = schemaName + "." + baseTableName;
+ String fullViewName = schemaName + "." + viewName;
+ Properties props = new Properties();
+ props.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute("CREATE SCHEMA " + schemaName);
+ PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
+ conn.createStatement().execute("CREATE TABLE " + fullTableName + " ("
+ + " ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (ID, COL1, COL2)"
+ + " )");
+ PTable baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
+ long initBaseTableSeqNumber = baseTable.getSequenceNumber();
+
+ // Add a column to the base table and see if the client and server metadata is updated correctly
+ String alterDDL = "ALTER TABLE " + fullTableName + " ADD COL3 VARCHAR PRIMARY KEY, COL4 INTEGER, COL5 VARCHAR, B.COL6 DECIMAL (10, 2)";
+ conn.createStatement().execute(alterDDL);
+
+ // assert that the client side cache is updated.
+ baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
+ EncodedCQCounter encodedCqCounter = baseTable.getEncodedCQCounter();
+ assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 3), encodedCqCounter.getNextQualifier(DEFAULT_COLUMN_FAMILY));
+
+ // assert that the server side metadata is updated correctly.
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3, true);
+
+ // assert that the server side metadata for columns is updated correctly.
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "COL4", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE);
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "COL5", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
+ assertEncodedCQValue("B", "COL6", schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 2);
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 1);
+
+ // Create a view
+ String viewDDL = "CREATE VIEW " + fullViewName + " ( VIEW_COL1 INTEGER, A.VIEW_COL2 VARCHAR ) AS SELECT * FROM " + fullTableName;
+ conn.createStatement().execute(viewDDL);
+
+ // assert that the server side metadata is updated correctly.
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 5, true);
+
+ // assert that the server side metadata for columns is updated correctly.
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL1", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3);
+ assertEncodedCQValue("A", "VIEW_COL2", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 4);
+ // Creating a view that adds its own columns should increment the base table's sequence number too.
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 2);
+
+
+ // Add column to the view
+ viewDDL = "ALTER VIEW " + fullViewName + " ADD VIEW_COL3 DECIMAL(10, 2), A.VIEW_COL4 VARCHAR, B.VIEW_COL5 INTEGER";
+ conn.createStatement().execute(viewDDL);
+
+ // assert that the client cache for the base table is updated
+ baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
+ encodedCqCounter = baseTable.getEncodedCQCounter();
+ assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 8), encodedCqCounter.getNextQualifier(DEFAULT_COLUMN_FAMILY));
+
+ // assert client cache for view
+ PTable view = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullViewName));
+ encodedCqCounter = view.getEncodedCQCounter();
+ assertNull("A view should always have the column qualifier counter as null", view.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
+
+ // assert that the server side metadata for the base table and the view is also updated correctly.
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 8, true);
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL1", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 3);
+ assertEncodedCQValue("A", "VIEW_COL2", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 4);
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "VIEW_COL3", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 5);
+ assertEncodedCQValue("A", "VIEW_COL4", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 6);
+ assertEncodedCQValue("B", "VIEW_COL5", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 7);
+ // Adding a column to the should increment the base table's sequence number too since we update the cq counters for column families.
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 3);
+ assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM + 1);
+
+ // Add column to the base table which doesn't already exist in the view.
+ alterDDL = "ALTER TABLE " + fullTableName + " ADD COL10 VARCHAR, A.COL11 INTEGER";
+ conn.createStatement().execute(alterDDL);
+ baseTable = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullTableName));
+
+ // assert that the client cache for the base table is updated
+ encodedCqCounter = baseTable.getEncodedCQCounter();
+ assertEquals((Integer)(ENCODED_CQ_COUNTER_INITIAL_VALUE + 10), encodedCqCounter.getNextQualifier(DEFAULT_COLUMN_FAMILY));
+
+ // assert client cache for view
+ view = phxConn.getTable(new PTableKey(phxConn.getTenantId(), fullViewName));
+ encodedCqCounter = view.getEncodedCQCounter();
+ assertNull("A view should always have the column qualifier counter as null", view.getEncodedCQCounter().getNextQualifier(DEFAULT_COLUMN_FAMILY));
+
+ // assert that the server side metadata for the base table and the view is also updated correctly.
+ assertEncodedCQCounter(DEFAULT_COLUMN_FAMILY, schemaName, baseTableName, (ENCODED_CQ_COUNTER_INITIAL_VALUE + 10), true);
+ assertEncodedCQValue(DEFAULT_COLUMN_FAMILY, "COL10", schemaName, viewName, (ENCODED_CQ_COUNTER_INITIAL_VALUE + 8));
+ assertEncodedCQValue("A", "COL11", schemaName, viewName, ENCODED_CQ_COUNTER_INITIAL_VALUE + 9);
+ assertSequenceNumber(schemaName, baseTableName, initBaseTableSeqNumber + 4);
+ assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM + 2);
+ }
+ }
+
+ private void assertEncodedCQValue(String columnFamily, String columnName, String schemaName, String tableName, int expectedValue) throws Exception {
+ String query = "SELECT " + ENCODED_COLUMN_QUALIFIER + " FROM SYSTEM.CATALOG WHERE " + TABLE_SCHEM + " = ? AND " + TABLE_NAME
+ + " = ? " + " AND " + COLUMN_FAMILY + " = ?" + " AND " + COLUMN_NAME + " = ?";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ PreparedStatement stmt = conn.prepareStatement(query);
+ stmt.setString(1, schemaName);
+ stmt.setString(2, tableName);
+ stmt.setString(3, columnFamily);
+ stmt.setString(4, columnName);
+ ResultSet rs = stmt.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(expectedValue, rs.getInt(1));
+ assertFalse(rs.next());
+ }
+ }
+
+ private void assertEncodedCQCounter(String columnFamily, String schemaName, String tableName, int expectedValue, boolean rowExists) throws Exception {
+ String query = "SELECT " + COLUMN_QUALIFIER_COUNTER + " FROM SYSTEM.CATALOG WHERE " + TABLE_SCHEM + " = ? AND " + TABLE_NAME
+ + " = ? " + " AND " + COLUMN_FAMILY + " = ? AND " + COLUMN_QUALIFIER_COUNTER + " IS NOT NULL";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ PreparedStatement stmt = conn.prepareStatement(query);
+ stmt.setString(1, schemaName);
+ stmt.setString(2, tableName);
+ stmt.setString(3, columnFamily);
+ ResultSet rs = stmt.executeQuery();
+ if (rowExists) {
+ assertTrue(rs.next());
+ assertEquals(expectedValue, rs.getInt(1));
+ assertFalse(rs.next());
+ } else {
+ assertFalse(rs.next());
+ }
+ }
+ }
+
+ private void assertSequenceNumber(String schemaName, String tableName, long expectedSequenceNumber) throws Exception {
+ String query = "SELECT " + TABLE_SEQ_NUM + " FROM SYSTEM.CATALOG WHERE " + TABLE_SCHEM + " = ? AND " + TABLE_NAME
+ + " = ? AND " + TABLE_SEQ_NUM + " IS NOT NULL AND " + COLUMN_NAME + " IS NULL AND "
+ + COLUMN_FAMILY + " IS NULL ";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ PreparedStatement stmt = conn.prepareStatement(query);
+ stmt.setString(1, schemaName);
+ stmt.setString(2, tableName);
+ ResultSet rs = stmt.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(expectedSequenceNumber, rs.getInt(1));
+ assertFalse(rs.next());
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
index 52dae00..e0bbb10 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
@@ -66,7 +66,7 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
public static Collection<Boolean> data() {
return Arrays.asList(false, true);
}
-
+
private String generateDDL(String format) {
return String.format(format, isMultiTenant ? "TENANT_ID VARCHAR NOT NULL, " : "",
isMultiTenant ? "TENANT_ID, " : "", isMultiTenant ? "MULTI_TENANT=true" : "");
@@ -92,7 +92,7 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
// adding a new pk column and a new regular column
conn.createStatement().execute("ALTER TABLE " + tableName + " ADD COL3 varchar(10) PRIMARY KEY, COL4 integer");
- assertTableDefinition(conn, tableName, PTableType.TABLE, null, 1, 5, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "COL3", "COL4");
+ assertTableDefinition(conn, tableName, PTableType.TABLE, null, 2, 5, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "COL3", "COL4");
assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 1, 7, 5, "ID", "COL1", "COL2", "COL3", "COL4", "VIEW_COL1", "VIEW_COL2");
}
}
@@ -174,7 +174,7 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
// drop two columns from the base table
conn.createStatement().execute("ALTER TABLE " + tableName + " DROP COLUMN COL3, COL5");
- assertTableDefinition(conn, tableName, PTableType.TABLE, null, 1, 4,
+ assertTableDefinition(conn, tableName, PTableType.TABLE, null, 2, 4,
QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "COL4");
assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 1, 6, 4,
"ID", "COL1", "COL2", "COL4", "VIEW_COL1", "VIEW_COL2");
@@ -218,73 +218,80 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
viewConn.commit();
try {
- // should fail because there is already a view column with same name of different type
- conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 char(10)");
- fail();
- }
- catch (SQLException e) {
- assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
- }
-
- try {
- // should fail because there is already a view column with same name with different scale
- conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 DECIMAL(10,1)");
- fail();
- }
- catch (SQLException e) {
- assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
- }
-
- try {
- // should fail because there is already a view column with same name with different length
- conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 DECIMAL(9,2)");
+ // adding a key value column to the base table that already exists in the view is not allowed
+ conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL4 DECIMAL, VIEW_COL2 VARCHAR(256)");
fail();
- }
- catch (SQLException e) {
- assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
- }
-
- try {
- // should fail because there is already a view column with different length
- conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL2 VARCHAR");
- fail();
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
}
-
- // validate that there were no columns added to the table or view
- assertTableDefinition(conn, tableName, PTableType.TABLE, null, 0, 3, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2");
- assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 0, 9, 3, "ID", "COL1", "COL2", "VIEW_COL1", "VIEW_COL2", "VIEW_COL3", "VIEW_COL4", "VIEW_COL5", "VIEW_COL6");
-
- // should succeed
- conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL4 DECIMAL, VIEW_COL2 VARCHAR(256)");
- assertTableDefinition(conn, tableName, PTableType.TABLE, null, 1, 5, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "VIEW_COL4", "VIEW_COL2");
- assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 1, 9, 5, "ID", "COL1", "COL2", "VIEW_COL4", "VIEW_COL2", "VIEW_COL1", "VIEW_COL3", "VIEW_COL5", "VIEW_COL6");
-
- // query table
- ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName);
- assertTrue(rs.next());
- assertEquals("view1", rs.getString("ID"));
- assertEquals(12, rs.getInt("COL1"));
- assertEquals(13, rs.getInt("COL2"));
- assertEquals("view5", rs.getString("VIEW_COL2"));
- assertEquals(17, rs.getInt("VIEW_COL4"));
- assertFalse(rs.next());
-
- // query view
- rs = stmt.executeQuery("SELECT * FROM " + viewOfTable);
- assertTrue(rs.next());
- assertEquals("view1", rs.getString("ID"));
- assertEquals(12, rs.getInt("COL1"));
- assertEquals(13, rs.getInt("COL2"));
- assertEquals(14, rs.getInt("VIEW_COL1"));
- assertEquals("view5", rs.getString("VIEW_COL2"));
- assertEquals("view6", rs.getString("VIEW_COL3"));
- assertEquals(17, rs.getInt("VIEW_COL4"));
- assertEquals(18, rs.getInt("VIEW_COL5"));
- assertEquals("view9", rs.getString("VIEW_COL6"));
- assertFalse(rs.next());
+// try {
+// // should fail because there is already a view column with same name of different type
+// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 char(10)");
+// fail();
+// }
+// catch (SQLException e) {
+// assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+// }
+//
+// try {
+// // should fail because there is already a view column with same name with different scale
+// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 DECIMAL(10,1)");
+// fail();
+// }
+// catch (SQLException e) {
+// assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+// }
+//
+// try {
+// // should fail because there is already a view column with same name with different length
+// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL1 DECIMAL(9,2)");
+// fail();
+// }
+// catch (SQLException e) {
+// assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+// }
+//
+// try {
+// // should fail because there is already a view column with different length
+// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL2 VARCHAR");
+// fail();
+// }
+// catch (SQLException e) {
+// assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
+// }
+//
+// // validate that there were no columns added to the table or view
+// assertTableDefinition(conn, tableName, PTableType.TABLE, null, 1, 3, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2");
+// assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 0, 9, 3, "ID", "COL1", "COL2", "VIEW_COL1", "VIEW_COL2", "VIEW_COL3", "VIEW_COL4", "VIEW_COL5", "VIEW_COL6");
+//
+// // should succeed
+// conn.createStatement().execute("ALTER TABLE " + tableName + " ADD VIEW_COL4 DECIMAL, VIEW_COL2 VARCHAR(256)");
+// assertTableDefinition(conn, tableName, PTableType.TABLE, null, 2, 5, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, "ID", "COL1", "COL2", "VIEW_COL4", "VIEW_COL2");
+// assertTableDefinition(conn, viewOfTable, PTableType.VIEW, tableName, 1, 9, 5, "ID", "COL1", "COL2", "VIEW_COL4", "VIEW_COL2", "VIEW_COL1", "VIEW_COL3", "VIEW_COL5", "VIEW_COL6");
+//
+// // query table
+// ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName);
+// assertTrue(rs.next());
+// assertEquals("view1", rs.getString("ID"));
+// assertEquals(12, rs.getInt("COL1"));
+// assertEquals(13, rs.getInt("COL2"));
+// assertEquals("view5", rs.getString("VIEW_COL2"));
+// assertEquals(17, rs.getInt("VIEW_COL4"));
+// assertFalse(rs.next());
+//
+// // query view
+// rs = stmt.executeQuery("SELECT * FROM " + viewOfTable);
+// assertTrue(rs.next());
+// assertEquals("view1", rs.getString("ID"));
+// assertEquals(12, rs.getInt("COL1"));
+// assertEquals(13, rs.getInt("COL2"));
+// assertEquals(14, rs.getInt("VIEW_COL1"));
+// assertEquals("view5", rs.getString("VIEW_COL2"));
+// assertEquals("view6", rs.getString("VIEW_COL3"));
+// assertEquals(17, rs.getInt("VIEW_COL4"));
+// assertEquals(18, rs.getInt("VIEW_COL5"));
+// assertEquals("view9", rs.getString("VIEW_COL6"));
+// assertFalse(rs.next());
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
index 30bdb41..382fb06 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
@@ -502,4 +502,9 @@ public class CreateTableIT extends BaseClientManagedTimeIT {
fail();
}
}
+
+ @Test
+ public void testCreateTableIfNotExistsForEncodedColumnNames() throws Exception {
+
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
index cbdd6e1..ebbeeb4 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
@@ -288,7 +288,6 @@ public class OrderByIT extends ParallelStatsDisabledIT {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
-
try {
String tableName1 = generateUniqueName();
String ddl = "CREATE TABLE " + tableName1 +
@@ -376,7 +375,6 @@ public class OrderByIT extends ParallelStatsDisabledIT {
assertEquals("a",rs.getString(1));
assertEquals(40,rs.getInt(2));
assertFalse(rs.next());
- } catch (SQLException e) {
} finally {
conn.close();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
index cddca04..91e9370 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
@@ -61,11 +61,11 @@ public class PhoenixRuntimeIT extends ParallelStatsDisabledIT {
scan.setFilter(filter);
ResultScanner scanner = htable.getScanner(scan);
Result result = null;
- ResultTuple tuple = new ResultTuple();
+ ResultTuple tuple;
Set<String> actualTenantIds = Sets.newHashSetWithExpectedSize(tenantIds.length);
Set<String> expectedTenantIds = new HashSet<>(Arrays.asList(tenantIds));
while ((result = scanner.next()) != null) {
- tuple.setResult(result);
+ tuple = new ResultTuple(result);
e.evaluate(tuple, ptr);
String tenantId = (String)PVarchar.INSTANCE.toObject(ptr);
actualTenantIds.add(tenantId == null ? "" : tenantId);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
index f35484d..861455e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
@@ -107,7 +107,7 @@ public class RowValueConstructorIT extends BaseClientManagedTimeIT {
count++;
}
// we have 6 values for a_integer present in the atable where a >= 4. x_integer is null for a_integer = 4. So the query should have returned 5 rows.
- assertTrue(count == 5);
+ assertEquals(5, count);
} finally {
conn.close();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
index 85fc9d7..9a5e412 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
@@ -159,13 +159,13 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
rs = conn.createStatement().executeQuery("EXPLAIN SELECT * FROM " + fullTableName);
explainPlan = QueryUtil.getExplainPlan(rs);
assertEquals(
- "CLIENT 4-CHUNK 1 ROWS 34 BYTES PARALLEL 3-WAY FULL SCAN OVER " + physicalTableName + "\n" +
+ "CLIENT 4-CHUNK 1 ROWS 28 BYTES PARALLEL 3-WAY FULL SCAN OVER " + physicalTableName + "\n" +
"CLIENT MERGE SORT",
explainPlan);
rs = conn.createStatement().executeQuery("EXPLAIN SELECT * FROM " + fullTableName + " WHERE k = 'a'");
explainPlan = QueryUtil.getExplainPlan(rs);
assertEquals(
- "CLIENT 1-CHUNK 1 ROWS 202 BYTES PARALLEL 1-WAY POINT LOOKUP ON 1 KEY OVER " + physicalTableName + "\n" +
+ "CLIENT 1-CHUNK 1 ROWS 204 BYTES PARALLEL 1-WAY POINT LOOKUP ON 1 KEY OVER " + physicalTableName + "\n" +
"CLIENT MERGE SORT",
explainPlan);
@@ -473,7 +473,7 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
List<KeyRange> keyRanges = getAllSplits(conn, fullTableName);
assertEquals(26, keyRanges.size());
rs = conn.createStatement().executeQuery("EXPLAIN SELECT * FROM " + fullTableName);
- assertEquals("CLIENT 26-CHUNK 25 ROWS 12420 BYTES PARALLEL 1-WAY FULL SCAN OVER " + physicalTableName,
+ assertEquals("CLIENT 26-CHUNK 25 ROWS 12530 BYTES PARALLEL 1-WAY FULL SCAN OVER " + physicalTableName,
QueryUtil.getExplainPlan(rs));
ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
@@ -496,25 +496,25 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
assertTrue(rs.next());
assertEquals("A", rs.getString(1));
assertEquals(24, rs.getInt(2));
- assertEquals(12144, rs.getInt(3));
+ assertEquals(12252, rs.getInt(3));
assertEquals(11, rs.getInt(4));
assertTrue(rs.next());
assertEquals("B", rs.getString(1));
assertEquals(20, rs.getInt(2));
- assertEquals(5540, rs.getInt(3));
+ assertEquals(5600, rs.getInt(3));
assertEquals(5, rs.getInt(4));
assertTrue(rs.next());
assertEquals("C", rs.getString(1));
assertEquals(24, rs.getInt(2));
- assertEquals(6652, rs.getInt(3));
+ assertEquals(6724, rs.getInt(3));
assertEquals(6, rs.getInt(4));
assertTrue(rs.next());
assertEquals("D", rs.getString(1));
assertEquals(24, rs.getInt(2));
- assertEquals(6652, rs.getInt(3));
+ assertEquals(6724, rs.getInt(3));
assertEquals(6, rs.getInt(4));
assertFalse(rs.next());
@@ -559,7 +559,7 @@ public class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
int startIndex = r.nextInt(strings.length);
int endIndex = r.nextInt(strings.length - startIndex) + startIndex;
long rows = endIndex - startIndex;
- long c2Bytes = rows * 35;
+ long c2Bytes = rows * 37;
String physicalTableName = SchemaUtil.getPhysicalHBaseTableName(fullTableName, userTableNamespaceMapped, PTableType.TABLE).getString();
rs = conn.createStatement().executeQuery(
"SELECT COLUMN_FAMILY,SUM(GUIDE_POSTS_ROW_COUNT),SUM(GUIDE_POSTS_WIDTH) from SYSTEM.STATS where PHYSICAL_NAME = '"
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
index bb13f1b..07fc4e9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StoreNullsIT.java
@@ -17,6 +17,8 @@
*/
package org.apache.phoenix.end2end;
+import static org.apache.phoenix.query.QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES;
+import static org.apache.phoenix.query.QueryConstants.ENCODED_EMPTY_COLUMN_BYTES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -32,13 +34,22 @@ import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.expression.ArrayColumnExpression;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.PColumn;
+import org.apache.phoenix.schema.PTableKey;
+import org.apache.phoenix.schema.tuple.ResultTuple;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
@@ -52,6 +63,8 @@ import org.junit.Test;
* functionality allows having row-level versioning (similar to how KEEP_DELETED_CELLS works), but
* also allows permanently deleting a row.
*/
+
+//TODO: samarth parameterize this test once the storage scheme is optional
public class StoreNullsIT extends ParallelStatsDisabledIT {
private static final Log LOG = LogFactory.getLog(StoreNullsIT.class);
@@ -95,31 +108,37 @@ public class StoreNullsIT extends ParallelStatsDisabledIT {
}
@Test
- public void testStoringNulls() throws SQLException, InterruptedException, IOException {
+ public void testStoringNullsForImmutableTables() throws Exception {
stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITH_NULLS + " VALUES (1, 'v1')");
stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITHOUT_NULLS + " VALUES (1, 'v1')");
stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITH_NULLS + " VALUES (2, null)");
stmt.executeUpdate("UPSERT INTO " + IMMUTABLE_WITHOUT_NULLS + " VALUES (2, null)");
- ensureNullsNotStored(IMMUTABLE_WITH_NULLS);
- ensureNullsNotStored(IMMUTABLE_WITHOUT_NULLS);
+ ensureNullsStoredAsEmptyByteArrays(IMMUTABLE_WITH_NULLS);
+ ensureNullsStoredAsEmptyByteArrays(IMMUTABLE_WITHOUT_NULLS);
}
- private void ensureNullsNotStored(String tableName) throws IOException {
- tableName = SchemaUtil.normalizeIdentifier(tableName);
+ private void ensureNullsStoredAsEmptyByteArrays(String tableName) throws Exception {
HTable htable = new HTable(getUtility().getConfiguration(), tableName);
Scan s = new Scan();
s.setRaw(true);
ResultScanner scanner = htable.getScanner(s);
// first row has a value for name
Result rs = scanner.next();
- assertTrue(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, Bytes.toBytes("NAME")));
- assertTrue(rs.size() == 2);
- // 2nd row has not
+ assertTrue(rs.size() == 2); // 2 because it also includes the empty key value column
+ PColumn nameColumn = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, tableName)).getPColumnForColumnName("NAME");
+ ArrayColumnExpression colExpression = new ArrayColumnExpression(nameColumn, "NAME", true);
+ ImmutableBytesPtr ptr = new ImmutableBytesPtr();
+ colExpression.evaluate(new ResultTuple(rs), ptr);
+ assertEquals(new ImmutableBytesPtr(PVarchar.INSTANCE.toBytes("v1")), ptr);
+
rs = scanner.next();
- assertFalse(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, Bytes.toBytes("NAME")));
- // and no delete marker either
- assertTrue(rs.size() == 1);
+ assertTrue(rs.size() == 2); // 2 because it also includes the empty key value column
+
+ // assert null stored as empty
+ ptr = new ImmutableBytesPtr();
+ colExpression.evaluate(new ResultTuple(rs), ptr);
+ assertEquals(new ImmutableBytesPtr(ByteUtil.EMPTY_BYTE_ARRAY), ptr);
assertNull(scanner.next());
scanner.close();
htable.close();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
index eb81ae3..3e0e3af 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
@@ -35,15 +35,26 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
import java.util.Properties;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.compile.QueryPlan;
import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.util.DateUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.Test;
@@ -853,7 +864,7 @@ public class UpsertValuesIT extends BaseClientManagedTimeIT {
assertEquals("KV2", rs.getString(2));
assertFalse(rs.next());
- // Verify now that the data was correctly added to the mutable index too.
+ // Verify now that the data was correctly added to the immutable index too.
stmt = conn.prepareStatement("SELECT KV2 FROM " + tableName + " WHERE PK2 = ? AND KV1 = ?");
stmt.setDate(1, upsertedDate);
stmt.setString(2, "KV1");
@@ -966,6 +977,38 @@ public class UpsertValuesIT extends BaseClientManagedTimeIT {
}
}
+ public void testColumnQualifierForUpsertedValues() throws Exception {
+ String schemaName = "A";
+ String tableName = "TEST";
+ String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
+ String ddl = "create table " + fullTableName
+ + " ("
+ + " K varchar primary key,"
+ + " CF1.V1 varchar, CF2.V2 VARCHAR, CF2.V3 VARCHAR)";
+ try (Connection conn = getConnection(nextTimestamp())) {
+ conn.createStatement().execute(ddl);
+ }
+ String dml = "UPSERT INTO " + fullTableName + " VALUES (?, ?, ?, ?)";
+ try (Connection conn = getConnection(nextTimestamp())) {
+ PreparedStatement stmt = conn.prepareStatement(dml);
+ stmt.setString(1, "KEY1");
+ stmt.setString(2, "VALUE1");
+ stmt.setString(3, "VALUE2");
+ stmt.setString(4, "VALUE3");
+ stmt.executeUpdate();
+ conn.commit();
+ }
+ // Issue a raw hbase scan and assert that key values have the expected column qualifiers.
+ try (Connection conn = getConnection(nextTimestamp())) {
+ HTableInterface table = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(fullTableName));
+ ResultScanner scanner = table.getScanner(new Scan());
+ Result next = scanner.next();
+ assertTrue(next.containsColumn(Bytes.toBytes("CF1"), PInteger.INSTANCE.toBytes(1)));
+ assertTrue(next.containsColumn(Bytes.toBytes("CF2"), PInteger.INSTANCE.toBytes(2)));
+ assertTrue(next.containsColumn(Bytes.toBytes("CF2"), PInteger.INSTANCE.toBytes(3)));
+ }
+ }
+
private static Connection getConnection(long ts) throws SQLException {
Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
index 4e7d06a..b892c4d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropMetadataIT.java
@@ -43,11 +43,13 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.TableNotFoundException;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.QueryUtil;
@@ -175,6 +177,7 @@ public class DropMetadataIT extends ParallelStatsDisabledIT {
// verify that the local index physical table was *not* dropped
conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(localIndexTablePhysicalName.getBytes());
+ PTable localIndex2 = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, localIndexTableName2));
// there should be a single row belonging to localIndexTableName2
Scan scan = new Scan();
@@ -184,7 +187,7 @@ public class DropMetadataIT extends ParallelStatsDisabledIT {
Result result = results.next();
assertNotNull(result);
assertNotNull("localIndexTableName2 row is missing", result.getValue(QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES,
- IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, "V1").getBytes()));
+ EncodedColumnsUtil.getColumnQualifier(localIndex2.getPColumnForColumnName(IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, "V1")), localIndex2)));
assertNull(results.next());
}
}
@@ -295,9 +298,11 @@ public class DropMetadataIT extends ParallelStatsDisabledIT {
ResultScanner results = table.getScanner(scan);
Result result = results.next();
assertNotNull(result);
- // there should be a single row belonging to " + viewIndex2 + "
- assertNotNull( viewIndex2 + " row is missing", result.getValue(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES,
- IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, "V4").getBytes()));
+ PTable viewIndexPTable = pconn.getTable(new PTableKey(pconn.getTenantId(), viewIndex2));
+ PColumn column = viewIndexPTable.getPColumnForColumnName(IndexUtil.getIndexColumnName(QueryConstants.DEFAULT_COLUMN_FAMILY, "V4"));
+ byte[] cq = EncodedColumnsUtil.getColumnQualifier(column, viewIndexPTable);
+ // there should be a single row belonging to VIEWINDEX2
+ assertNotNull(viewIndex2 + " row is missing", result.getValue(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, cq));
assertNull(results.next());
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
index 50548bd..ee8afa8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
@@ -413,7 +413,12 @@ public class IndexExpressionIT extends ParallelStatsDisabledIT {
rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullIndexTableName);
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
-
+
+ String sql = "SELECT LONG_COL1 from " + fullDataTableName + " WHERE LONG_COL2 = 2";
+ rs = conn.createStatement().executeQuery(sql);
+ assertTrue(rs.next());
+ assertFalse(rs.next());
+
String dml = "DELETE from " + fullDataTableName + " WHERE long_col2 = 2";
assertEquals(1, conn.createStatement().executeUpdate(dml));
conn.commit();
@@ -870,8 +875,10 @@ public class IndexExpressionIT extends ParallelStatsDisabledIT {
conn.setAutoCommit(false);
// make sure that the tables are empty, but reachable
- conn.createStatement().execute(
- "CREATE TABLE " + dataTableName + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
+ conn.createStatement().execute(
+ "CREATE TABLE " + dataTableName
+ + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)"
+ + (!mutable ? " IMMUTABLE_ROWS=true" : ""));
query = "SELECT * FROM " + dataTableName ;
rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
@@ -1244,7 +1251,16 @@ public class IndexExpressionIT extends ParallelStatsDisabledIT {
}
@Test
- public void testViewUsesTableIndex() throws Exception {
+ public void testViewUsesMutableTableIndex() throws Exception {
+ helpTestViewUsesTableIndex(false);
+ }
+
+ @Test
+ public void testViewUsesImmutableTableIndex() throws Exception {
+ helpTestViewUsesTableIndex(true);
+ }
+
+ private void helpTestViewUsesTableIndex(boolean immutable) throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
try
{
@@ -1253,7 +1269,7 @@ public class IndexExpressionIT extends ParallelStatsDisabledIT {
String viewName = generateUniqueName();
String indexName2 = generateUniqueName();
ResultSet rs;
- String ddl = "CREATE TABLE " + dataTableName + " (k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, s1 VARCHAR, s2 VARCHAR, s3 VARCHAR, s4 VARCHAR CONSTRAINT pk PRIMARY KEY (k1, k2))";
+ String ddl = "CREATE TABLE " + dataTableName + " (k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, s1 VARCHAR, s2 VARCHAR, s3 VARCHAR, s4 VARCHAR CONSTRAINT pk PRIMARY KEY (k1, k2)) " + (immutable ? "IMMUTABLE_ROWS = true" : "");
conn.createStatement().execute(ddl);
conn.createStatement().execute("CREATE INDEX " + indexName1 + " ON " + dataTableName + "(k2, s2, s3, s1)");
conn.createStatement().execute("CREATE INDEX " + indexName2 + " ON " + dataTableName + "(k2, s2||'_'||s3, s1, s4)");
@@ -1350,7 +1366,7 @@ public class IndexExpressionIT extends ParallelStatsDisabledIT {
try {
conn.createStatement().execute(
"CREATE TABLE " + dataTableName + " (k VARCHAR NOT NULL PRIMARY KEY, v VARCHAR) "
- + (mutable ? "IMMUTABLE_ROWS=true" : ""));
+ + (!mutable ? "IMMUTABLE_ROWS=true" : ""));
String query = "SELECT * FROM " + dataTableName;
ResultSet rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
index 48fe3e6..c8318ec 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
@@ -810,23 +810,23 @@ public class IndexIT extends ParallelStatsDisabledIT {
stmt.execute();
conn.commit();
- // make sure the index is working as expected
- query = "SELECT * FROM " + fullIndexName;
+ query = "SELECT /*+ NO_INDEX */ * FROM " + testTable;
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
- assertEquals("x", rs.getString(1));
- assertEquals("1", rs.getString(2));
- assertEquals("a", rs.getString(3));
+ assertEquals("a", rs.getString(1));
+ assertEquals("x", rs.getString(2));
+ assertEquals("1", rs.getString(3));
assertTrue(rs.next());
- assertEquals("y", rs.getString(1));
- assertEquals("2", rs.getString(2));
- assertEquals("b", rs.getString(3));
+ assertEquals("b", rs.getString(1));
+ assertEquals("y", rs.getString(2));
+ assertEquals("2", rs.getString(3));
assertTrue(rs.next());
- assertEquals("z", rs.getString(1));
- assertEquals("3", rs.getString(2));
- assertEquals("c", rs.getString(3));
+ assertEquals("c", rs.getString(1));
+ assertEquals("z", rs.getString(2));
+ assertEquals("3", rs.getString(3));
assertFalse(rs.next());
-
+
+ // make sure the index is working as expected
query = "SELECT * FROM " + testTable;
rs = conn.createStatement().executeQuery("EXPLAIN " + query);
if (localIndex) {
@@ -899,7 +899,7 @@ public class IndexIT extends ParallelStatsDisabledIT {
} else {
assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullIndexName + " ['1']", QueryUtil.getExplainPlan(rs));
}
-
+
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
index e854f23..79cd1ce 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
@@ -39,7 +39,6 @@ import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
-import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.ColumnNotFoundException;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnFamily;
@@ -48,6 +47,7 @@ import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.RowKeySchema;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.MetaDataUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -115,7 +115,7 @@ public class IndexTestUtil {
while ((hasValue = dataRowKeySchema.next(ptr, i, maxOffset)) != null) {
if (hasValue) {
PColumn dataColumn = dataPKColumns.get(i);
- PColumn indexColumn = indexTable.getColumn(IndexUtil.getIndexColumnName(dataColumn));
+ PColumn indexColumn = indexTable.getPColumnForColumnName(IndexUtil.getIndexColumnName(dataColumn));
coerceDataValueToIndexValue(dataColumn, indexColumn, ptr);
indexValues[indexColumn.getPosition()-indexOffset] = ptr.copyBytes();
}
@@ -135,10 +135,11 @@ public class IndexTestUtil {
for (Cell kv : entry.getValue()) {
@SuppressWarnings("deprecation")
byte[] cq = kv.getQualifier();
- if (Bytes.compareTo(QueryConstants.EMPTY_COLUMN_BYTES, cq) != 0) {
+ byte[] emptyKVQualifier = EncodedColumnsUtil.getEmptyKeyValueInfo(dataTable).getFirst();
+ if (Bytes.compareTo(emptyKVQualifier, cq) != 0) {
try {
- PColumn dataColumn = family.getColumn(cq);
- PColumn indexColumn = indexTable.getColumn(IndexUtil.getIndexColumnName(family.getName().getString(), dataColumn.getName().getString()));
+ PColumn dataColumn = family.getPColumnForColumnQualifier(cq);
+ PColumn indexColumn = indexTable.getPColumnForColumnName(IndexUtil.getIndexColumnName(family.getName().getString(), dataColumn.getName().getString()));
ptr.set(kv.getValueArray(),kv.getValueOffset(),kv.getValueLength());
coerceDataValueToIndexValue(dataColumn, indexColumn, ptr);
indexValues[indexPKColumns.indexOf(indexColumn)-indexOffset] = ptr.copyBytes();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
index 9817f95..f74e505 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
@@ -284,6 +284,8 @@ public class MutableIndexFailureIT extends BaseTest {
// verify index table has correct data
validateDataWithIndex(conn, fullTableName, fullIndexName);
validateDataWithIndex(conn, secondTableName, secondFullIndexName);
+ } finally {
+ FAIL_WRITE = false;
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
index 07df105..c986c28 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
@@ -31,6 +31,7 @@ import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.execute.MutationState;
import org.apache.phoenix.expression.AndExpression;
+import org.apache.phoenix.expression.ArrayColumnExpression;
import org.apache.phoenix.expression.ComparisonExpression;
import org.apache.phoenix.expression.Determinism;
import org.apache.phoenix.expression.Expression;
@@ -239,7 +240,7 @@ public class CreateTableCompiler {
}
}
- private static class ViewWhereExpressionVisitor extends StatelessTraverseNoExpressionVisitor<Boolean> {
+ public static class ViewWhereExpressionVisitor extends StatelessTraverseNoExpressionVisitor<Boolean> {
private boolean isUpdatable = true;
private final PTable table;
private int position;
@@ -318,13 +319,23 @@ public class CreateTableCompiler {
@Override
public Boolean visit(KeyValueColumnExpression node) {
try {
- this.position = table.getColumnFamily(node.getColumnFamily()).getColumn(node.getColumnName()).getPosition();
+ this.position = table.getColumnFamily(node.getColumnFamily()).getPColumnForColumnQualifier(node.getColumnQualifier()).getPosition();
} catch (SQLException e) {
throw new RuntimeException(e); // Impossible
}
return Boolean.TRUE;
}
+ @Override
+ public Boolean visit(ArrayColumnExpression node) {
+ try {
+ this.position = table.getColumnFamily(node.getColumnFamily()).getPColumnForColumnQualifier(node.getEncodedColumnQualifier()).getPosition();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ return Boolean.TRUE;
+ }
+
}
private static class VarbinaryDatum implements PDatum {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 c05918b..846e966 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
@@ -117,12 +117,26 @@ import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PDatum;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTable.StorageScheme;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.RowKeyValueAccessor;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.TypeMismatchException;
-import org.apache.phoenix.schema.types.*;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PhoenixArray;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.ExpressionUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -386,7 +400,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
}
protected void addColumn(PColumn column) {
- context.getScan().addColumn(column.getFamilyName().getBytes(), column.getName().getBytes());
+ EncodedColumnsUtil.setColumns(column, context.getCurrentTable().getTable(), context.getScan());
}
@Override
[14/42] phoenix git commit: PHOENIX-3535 Addendum to fix test failures
Posted by td...@apache.org.
PHOENIX-3535 Addendum to fix test failures
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/f11d501b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f11d501b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f11d501b
Branch: refs/heads/encodecolumns2
Commit: f11d501b29483a3e543768f3f5e267bf2dd413b5
Parents: 90d27be
Author: Samarth <sa...@salesforce.com>
Authored: Wed Dec 21 17:44:49 2016 -0800
Committer: Samarth <sa...@salesforce.com>
Committed: Wed Dec 21 17:44:49 2016 -0800
----------------------------------------------------------------------
.../java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/f11d501b/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 9d7a3d2..f1de0bd 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
@@ -2352,7 +2352,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
hConnectionEstablished = true;
boolean isDoNotUpgradePropSet = UpgradeUtil.isNoUpgradeSet(props);
try (HBaseAdmin admin = getAdmin()) {
- createSysMutexTable(admin);
boolean mappedSystemCatalogExists = admin
.tableExists(SchemaUtil.getPhysicalTableName(SYSTEM_CATALOG_NAME_BYTES, true));
if (SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM,
@@ -2370,6 +2369,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
+ " is found but client does not have "
+ IS_NAMESPACE_MAPPING_ENABLED + " enabled")
.build().buildException(); }
+ createSysMutexTable(admin);
}
Properties scnProps = PropertiesUtil.deepCopy(props);
scnProps.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
[27/42] phoenix git commit: Fix compilation failure
Posted by td...@apache.org.
Fix compilation failure
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/28810916
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/28810916
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/28810916
Branch: refs/heads/encodecolumns2
Commit: 288109165a7bd03f1e949dbed0da0bdd33cbed4f
Parents: 670b53a
Author: Samarth <sa...@salesforce.com>
Authored: Mon Nov 7 13:27:06 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../src/main/java/org/apache/phoenix/util/PhoenixRuntime.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/28810916/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index a946575..563ccab 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -1148,9 +1148,9 @@ public class PhoenixRuntime {
PColumn pColumn = null;
if (familyName != null) {
PColumnFamily family = table.getColumnFamily(familyName);
- pColumn = family.getColumn(columnName);
+ pColumn = family.getPColumnForColumnName(columnName);
} else {
- pColumn = table.getColumn(columnName);
+ pColumn = table.getPColumnForColumnName(columnName);
}
return pColumn;
}
[37/42] phoenix git commit: Fix test failures
Posted by td...@apache.org.
Fix test failures
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/4128b563
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/4128b563
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/4128b563
Branch: refs/heads/encodecolumns2
Commit: 4128b5632a6fa5524155362964edf5246b8741da
Parents: 3426262
Author: Samarth <sa...@salesforce.com>
Authored: Tue Nov 22 22:32:42 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Thu Dec 22 13:00:44 2016 -0800
----------------------------------------------------------------------
.../org/apache/phoenix/compile/WhereCompilerTest.java | 4 ++--
.../org/apache/phoenix/execute/MutationStateTest.java | 4 ++--
.../org/apache/phoenix/query/ConnectionlessTest.java | 14 ++++++--------
3 files changed, 10 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/4128b563/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
index c65408e..06c20d3 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
@@ -121,7 +121,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
Filter filter = scan.getFilter();
Expression idExpression = new ColumnRef(plan.getTableRef(), plan.getTableRef().getTable().getPColumnForColumnName("ID").getPosition()).newColumnExpression();
Expression id = new RowKeyColumnExpression(idExpression,new RowKeyValueAccessor(plan.getTableRef().getTable().getPKColumns(),0));
- Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getPColumnForColumnName("COMPANY"), false);
+ Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getPColumnForColumnName("COMPANY"), true);
// FilterList has no equals implementation
assertTrue(filter instanceof FilterList);
FilterList filterList = (FilterList)filter;
@@ -153,7 +153,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
assertEquals(
singleKVFilter(constantComparison(
CompareOp.EQUAL,
- new KeyValueColumnExpression(column, false),
+ new KeyValueColumnExpression(column, true),
"c3")),
filter);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/4128b563/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java b/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
index 276d946..8553b73 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/execute/MutationStateTest.java
@@ -127,11 +127,11 @@ public class MutationStateTest {
private void assertTable(String tableName1,List<KeyValue> keyValues1,String tableName2,List<KeyValue> keyValues2) {
assertTrue("MUTATION_TEST1".equals(tableName1));
assertTrue(Bytes.equals(PUnsignedInt.INSTANCE.toBytes(111),CellUtil.cloneRow(keyValues1.get(0))));
- assertTrue("app1".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues1.get(0)))));
+ assertTrue("app1".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues1.get(1)))));
assertTrue("MUTATION_TEST2".equals(tableName2));
assertTrue(Bytes.equals(PUnsignedInt.INSTANCE.toBytes(222),CellUtil.cloneRow(keyValues2.get(0))));
- assertTrue("app2".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues2.get(0)))));
+ assertTrue("app2".equals(PVarchar.INSTANCE.toObject(CellUtil.cloneValue(keyValues2.get(1)))));
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/4128b563/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
index 089c5f1..84cc65c 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
@@ -141,31 +141,29 @@ public class ConnectionlessTest {
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey1, kv.getRow());
- assertEquals(name1, PVarchar.INSTANCE.toObject(kv.getValue()));
- assertTrue(iterator.hasNext());
+ assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
kv = iterator.next();
assertArrayEquals(expectedRowKey1, kv.getRow());
- assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
+ assertEquals(name1, PVarchar.INSTANCE.toObject(kv.getValue()));
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey1, kv.getRow());
- assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
+ assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
}
private static void assertRow2(Iterator<KeyValue> iterator, byte[] expectedRowKey2) {
KeyValue kv;
- assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey2, kv.getRow());
- assertEquals(name2, PVarchar.INSTANCE.toObject(kv.getValue()));
+ assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey2, kv.getRow());
- assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
+ assertEquals(name2, PVarchar.INSTANCE.toObject(kv.getValue()));
assertTrue(iterator.hasNext());
kv = iterator.next();
assertArrayEquals(expectedRowKey2, kv.getRow());
- assertEquals(QueryConstants.EMPTY_COLUMN_VALUE, PVarchar.INSTANCE.toObject(kv.getValue()));
+ assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
}
@Test
[03/42] phoenix git commit: PHOENIX-3522 Altering the mutability of a
parent table does not propagate to the child views
Posted by td...@apache.org.
PHOENIX-3522 Altering the mutability of a parent table does not propagate to the child views
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1704545b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1704545b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1704545b
Branch: refs/heads/encodecolumns2
Commit: 1704545b438bed47fa626c355a19f69d180883c6
Parents: af202f2
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Wed Dec 7 23:59:11 2016 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Wed Dec 7 23:59:11 2016 -0800
----------------------------------------------------------------------
.../phoenix/end2end/AlterTableWithViewsIT.java | 40 +++++++++++++++++
.../coprocessor/MetaDataEndpointImpl.java | 47 +++++++++++++++++---
.../apache/phoenix/schema/TableProperty.java | 12 +++++
3 files changed, 94 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/1704545b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
index e6bf2d2..6e4f5c0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
@@ -42,6 +42,7 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
+import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
import org.junit.Test;
@@ -97,6 +98,45 @@ public class AlterTableWithViewsIT extends ParallelStatsDisabledIT {
}
@Test
+ public void testAlterPropertiesOfParentTable() throws Exception {
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn ) {
+ String tableName = generateUniqueName();
+ String viewOfTable = tableName + "_VIEW";
+ String ddlFormat = "CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
+ + " ) %s";
+ conn.createStatement().execute(generateDDL(ddlFormat));
+ viewConn.createStatement().execute("CREATE VIEW " + viewOfTable + " ( VIEW_COL1 DECIMAL(10,2), VIEW_COL2 VARCHAR ) AS SELECT * FROM " + tableName);
+
+ PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
+ PTable table = phoenixConn.getTable(new PTableKey(null, tableName));
+ PName tenantId = isMultiTenant ? PNameFactory.newName("tenant1") : null;
+ assertFalse(table.isImmutableRows());
+ assertEquals(0, table.getUpdateCacheFrequency());
+ PTable viewTable = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable));
+ assertFalse(viewTable.isImmutableRows());
+ assertEquals(0, viewTable.getUpdateCacheFrequency());
+
+ conn.createStatement().execute("ALTER TABLE " + tableName + " SET IMMUTABLE_ROWS=true, UPDATE_CACHE_FREQUENCY=123");
+ // query the view to force the table cache to be updated
+ viewConn.createStatement().execute("SELECT * FROM "+viewOfTable);
+
+ phoenixConn = conn.unwrap(PhoenixConnection.class);
+ table = phoenixConn.getTable(new PTableKey(null, tableName));
+ assertTrue(table.isImmutableRows());
+ assertEquals(123, table.getUpdateCacheFrequency());
+
+ viewTable = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable));
+ assertTrue(viewTable.isImmutableRows());
+ assertEquals(123, viewTable.getUpdateCacheFrequency());
+ }
+ }
+
+ @Test
public void testDropColumnsFromBaseTableWithView() throws Exception {
try (Connection conn = DriverManager.getConnection(getUrl());
Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn ) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/1704545b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 9a7b9e3..9ade0f5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -78,7 +78,6 @@ import static org.apache.phoenix.util.SchemaUtil.getVarCharLength;
import static org.apache.phoenix.util.SchemaUtil.getVarChars;
import java.io.IOException;
-import java.sql.DriverManager;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
@@ -150,7 +149,6 @@ import org.apache.phoenix.coprocessor.generated.MetaDataProtos.GetVersionRequest
import org.apache.phoenix.coprocessor.generated.MetaDataProtos.GetVersionResponse;
import org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse;
import org.apache.phoenix.coprocessor.generated.MetaDataProtos.UpdateIndexStateRequest;
-import org.apache.phoenix.expression.ColumnExpression;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.KeyValueColumnExpression;
import org.apache.phoenix.expression.LiteralExpression;
@@ -201,6 +199,7 @@ import org.apache.phoenix.schema.SequenceKey;
import org.apache.phoenix.schema.SequenceNotFoundException;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableNotFoundException;
+import org.apache.phoenix.schema.TableProperty;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.tuple.ResultTuple;
import org.apache.phoenix.schema.types.PBinary;
@@ -2151,20 +2150,39 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
return false;
}
- private MetaDataMutationResult addColumnsToChildViews(PTable basePhysicalTable, List<Mutation> tableMetadata, List<Mutation> mutationsForAddingColumnsToViews, byte[] schemaName, byte[] tableName,
+ private MetaDataMutationResult addColumnsAndTablePropertiesToChildViews(PTable basePhysicalTable, List<Mutation> tableMetadata, List<Mutation> mutationsForAddingColumnsToViews, byte[] schemaName, byte[] tableName,
List<ImmutableBytesPtr> invalidateList, long clientTimeStamp, TableViewFinderResult childViewsResult,
HRegion region, List<RowLock> locks) throws IOException, SQLException {
- List<PutWithOrdinalPosition> columnPutsForBaseTable = new ArrayList<>(tableMetadata.size());
+ List<PutWithOrdinalPosition> columnPutsForBaseTable = Lists.newArrayListWithExpectedSize(tableMetadata.size());
+ List<Cell> tablePropertyCells = Lists.newArrayListWithExpectedSize(tableMetadata.size());
// Isolate the puts relevant to adding columns. Also figure out what kind of columns are being added.
for (Mutation m : tableMetadata) {
if (m instanceof Put) {
byte[][] rkmd = new byte[5][];
int pkCount = getVarChars(m.getRow(), rkmd);
+ // check if this put is for adding a column
if (pkCount > COLUMN_NAME_INDEX
&& Bytes.compareTo(schemaName, rkmd[SCHEMA_NAME_INDEX]) == 0
&& Bytes.compareTo(tableName, rkmd[TABLE_NAME_INDEX]) == 0) {
columnPutsForBaseTable.add(new PutWithOrdinalPosition((Put)m, getInteger((Put)m, TABLE_FAMILY_BYTES, ORDINAL_POSITION_BYTES)));
}
+ // check if the put is for a table property
+ else if (pkCount <= COLUMN_NAME_INDEX
+ && Bytes.compareTo(schemaName, rkmd[SCHEMA_NAME_INDEX]) == 0
+ && Bytes.compareTo(tableName, rkmd[TABLE_NAME_INDEX]) == 0) {
+ for (Cell cell : m.getFamilyCellMap().get(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES)) {
+ for (TableProperty tableProp : TableProperty.values()) {
+ byte[] propNameBytes = Bytes.toBytes(tableProp.getPropertyName());
+ if (Bytes.compareTo(propNameBytes, 0, propNameBytes.length, cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())==0
+ && tableProp.isValidOnView() && tableProp.isMutable()) {
+ Cell tablePropCell = CellUtil.createCell(cell.getRow(), CellUtil.cloneFamily(cell),
+ CellUtil.cloneQualifier(cell), cell.getTimestamp(), cell.getTypeByte(),
+ CellUtil.cloneValue(cell));
+ tablePropertyCells.add(tablePropCell);
+ }
+ }
+ }
+ }
}
}
// Sort the puts by ordinal position
@@ -2187,6 +2205,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
List<PColumn> viewPkCols = new ArrayList<>(view.getPKColumns());
boolean addingExistingPkCol = false;
int numCols = view.getColumns().size();
+ // add the new columns to the child view
for (PutWithOrdinalPosition p : columnPutsForBaseTable) {
Put baseTableColumnPut = p.put;
PColumn existingViewColumn = null;
@@ -2333,6 +2352,24 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
addViewIndexesHeaderRowMutations(mutationsForAddingColumnsToViews, invalidateList, clientTimeStamp, view,
deltaNumPkColsSoFar);
+ // set table properties in child view
+ if (!tablePropertyCells.isEmpty()) {
+ Put viewHeaderRowPut = new Put(viewKey, clientTimeStamp);
+ for (Cell tablePropertyCell : tablePropertyCells) {
+ viewHeaderRowPut.add(CellUtil.createCell(viewKey, CellUtil.cloneFamily(tablePropertyCell),
+ CellUtil.cloneQualifier(tablePropertyCell), clientTimeStamp, tablePropertyCell.getTypeByte(),
+ CellUtil.cloneValue(tablePropertyCell)));
+ }
+ byte[] viewSequencePtr = new byte[PLong.INSTANCE.getByteSize()];
+ PLong.INSTANCE.getCodec().encodeLong(view.getSequenceNumber() + 1, viewSequencePtr, 0);
+ viewHeaderRowPut.add(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
+ PhoenixDatabaseMetaData.TABLE_SEQ_NUM_BYTES, clientTimeStamp, viewSequencePtr);
+ // invalidate the view so that it is removed from the cache
+ invalidateList.add(new ImmutableBytesPtr(viewKey));
+
+ mutationsForAddingColumnsToViews.add(viewHeaderRowPut);
+ }
+
/*
* Increment the sequence number by 1 if:
* 1) For a diverged view, there were columns (pk columns) added to the view.
@@ -2790,7 +2827,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
EnvironmentEdgeManager.currentTimeMillis(), null);
} else {
mutationsForAddingColumnsToViews = new ArrayList<>(childViewsResult.getResults().size() * tableMetaData.size());
- MetaDataMutationResult mutationResult = addColumnsToChildViews(table, tableMetaData, mutationsForAddingColumnsToViews, schemaName, tableName, invalidateList, clientTimeStamp,
+ MetaDataMutationResult mutationResult = addColumnsAndTablePropertiesToChildViews(table, tableMetaData, mutationsForAddingColumnsToViews, schemaName, tableName, invalidateList, clientTimeStamp,
childViewsResult, region, locks);
// return if we were not able to add the column successfully
if (mutationResult!=null)
http://git-wip-us.apache.org/repos/asf/phoenix/blob/1704545b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
index 26a7718..4f24c92 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/TableProperty.java
@@ -156,4 +156,16 @@ public enum TableProperty {
}
}
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public boolean isValidOnView() {
+ return isValidOnView;
+ }
+
+ public boolean isMutable() {
+ return isMutable;
+ }
+
}
[19/42] phoenix git commit: Fail-fast iterators for
EncodedColumnQualifierCellsList. Use list iterators instead of get(index) for
navigating lists. Use HBase bytes utility for encoded column names. Fix test
failures for immutable tables and indexes.
Posted by td...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PName.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PName.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PName.java
index 0e1337c..8df6a95 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PName.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PName.java
@@ -83,6 +83,32 @@ public interface PName {
return 0;
}
};
+ public static PName ENCODED_EMPTY_COLUMN_NAME = new PName() {
+ @Override
+ public String getString() {
+ return String.valueOf(QueryConstants.ENCODED_EMPTY_COLUMN_NAME);
+ }
+
+ @Override
+ public byte[] getBytes() {
+ return QueryConstants.ENCODED_EMPTY_COLUMN_BYTES;
+ }
+
+ @Override
+ public String toString() {
+ return getString();
+ }
+
+ @Override
+ public ImmutableBytesPtr getBytesPtr() {
+ return QueryConstants.ENCODED_EMPTY_COLUMN_BYTES_PTR;
+ }
+
+ @Override
+ public int getEstimatedSize() {
+ return 0;
+ }
+ };
/**
* Get the client-side, normalized name as referenced
* in a SQL statement.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
index 01e8afe..d3b11b2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
@@ -17,7 +17,15 @@
*/
package org.apache.phoenix.schema;
+import static org.apache.phoenix.query.QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE;
+
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.annotation.Nullable;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
@@ -129,7 +137,7 @@ public interface PTable extends PMetaDataEntity {
* Link from a view to its parent table
*/
PARENT_TABLE((byte)3);
-
+
private final byte[] byteValue;
private final byte serializedValue;
@@ -153,6 +161,35 @@ public interface PTable extends PMetaDataEntity {
return LinkType.values()[serializedValue-1];
}
}
+
+ public enum StorageScheme {
+ ENCODED_COLUMN_NAMES((byte)1),
+ NON_ENCODED_COLUMN_NAMES((byte)2),
+ COLUMNS_STORED_IN_SINGLE_CELL((byte)3);
+
+ private final byte[] byteValue;
+ private final byte serializedValue;
+
+ StorageScheme(byte serializedValue) {
+ this.serializedValue = serializedValue;
+ this.byteValue = Bytes.toBytes(this.name());
+ }
+
+ public byte[] getBytes() {
+ return byteValue;
+ }
+
+ public byte getSerializedValue() {
+ return this.serializedValue;
+ }
+
+ public static StorageScheme fromSerializedValue(byte serializedValue) {
+ if (serializedValue < 1 || serializedValue > StorageScheme.values().length) {
+ return null;
+ }
+ return StorageScheme.values()[serializedValue-1];
+ }
+ }
long getTimeStamp();
long getSequenceNumber();
@@ -208,7 +245,16 @@ public interface PTable extends PMetaDataEntity {
* can be found
* @throws AmbiguousColumnException if multiple columns are found with the given name
*/
- PColumn getColumn(String name) throws ColumnNotFoundException, AmbiguousColumnException;
+ PColumn getPColumnForColumnName(String name) throws ColumnNotFoundException, AmbiguousColumnException;
+
+ /**
+ * Get the column with the given column qualifier.
+ * @param column qualifier bytes
+ * @return the PColumn with the given column qualifier
+ * @throws ColumnNotFoundException if no column with the given column qualifier can be found
+ * @throws AmbiguousColumnException if multiple columns are found with the given column qualifier
+ */
+ PColumn getPColumnForColumnQualifier(byte[] cf, byte[] cq) throws ColumnNotFoundException, AmbiguousColumnException;
/**
* Get the PK column with the given name.
@@ -345,7 +391,6 @@ public interface PTable extends PMetaDataEntity {
*/
int getRowTimestampColPos();
long getUpdateCacheFrequency();
-
boolean isNamespaceMapped();
/**
@@ -359,4 +404,92 @@ public interface PTable extends PMetaDataEntity {
* you are also not allowed to delete the table
*/
boolean isAppendOnlySchema();
+ StorageScheme getStorageScheme();
+ EncodedCQCounter getEncodedCQCounter();
+
+ /**
+ * Class to help track encoded column qualifier counters per column family.
+ */
+ public class EncodedCQCounter {
+
+ private final Map<String, Integer> familyCounters = new HashMap<>();
+
+ /**
+ * Copy constructor
+ * @param counterToCopy
+ * @return copy of the passed counter
+ */
+ public static EncodedCQCounter copy(EncodedCQCounter counterToCopy) {
+ EncodedCQCounter cqCounter = new EncodedCQCounter();
+ for (Entry<String, Integer> e : counterToCopy.values().entrySet()) {
+ cqCounter.setValue(e.getKey(), e.getValue());
+ }
+ return cqCounter;
+ }
+
+ public static final EncodedCQCounter NULL_COUNTER = new EncodedCQCounter() {
+
+ @Override
+ public Integer getNextQualifier(String columnFamily) {
+ return null;
+ }
+
+ @Override
+ public void setValue(String columnFamily, Integer value) {
+ }
+
+ @Override
+ public boolean increment(String columnFamily) {
+ return false;
+ }
+
+ @Override
+ public Map<String, Integer> values() {
+ return Collections.emptyMap();
+ }
+
+ };
+
+ /**
+ * Get the next qualifier to be used for the column family.
+ * This method also ends up initializing the counter if the
+ * column family already doesn't have one.
+ */
+ @Nullable
+ public Integer getNextQualifier(String columnFamily) {
+ Integer counter = familyCounters.get(columnFamily);
+ if (counter == null) {
+ counter = ENCODED_CQ_COUNTER_INITIAL_VALUE;
+ familyCounters.put(columnFamily, counter);
+ }
+ return counter;
+ }
+
+ public void setValue(String columnFamily, Integer value) {
+ familyCounters.put(columnFamily, value);
+ }
+
+ /**
+ *
+ * @param columnFamily
+ * @return true if the counter was incrememnted, false otherwise.
+ */
+ public boolean increment(String columnFamily) {
+ if (columnFamily == null) {
+ return false;
+ }
+ Integer counter = familyCounters.get(columnFamily);
+ if (counter == null) {
+ counter = ENCODED_CQ_COUNTER_INITIAL_VALUE;
+ }
+ counter++;
+ familyCounters.put(columnFamily, counter);
+ return true;
+ }
+
+ public Map<String, Integer> values() {
+ return Collections.unmodifiableMap(familyCounters);
+ }
+
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/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 98a0b99..1134e06 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
@@ -20,6 +20,7 @@ package org.apache.phoenix.schema;
import static org.apache.phoenix.hbase.index.util.KeyValueBuilder.addQuietly;
import static org.apache.phoenix.hbase.index.util.KeyValueBuilder.deleteQuietly;
import static org.apache.phoenix.schema.SaltingUtil.SALTING_COLUMN;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
import java.io.IOException;
import java.sql.DriverManager;
@@ -30,6 +31,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HConstants;
@@ -41,11 +43,14 @@ import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.ByteStringer;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
import org.apache.phoenix.compile.ExpressionCompiler;
import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.coprocessor.generated.PTableProtos;
import org.apache.phoenix.exception.DataExceedsCapacityException;
+import org.apache.phoenix.expression.ArrayConstructorExpression;
import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
import org.apache.phoenix.index.IndexMaintainer;
@@ -56,13 +61,16 @@ import org.apache.phoenix.parse.SQLParser;
import org.apache.phoenix.protobuf.ProtobufUtil;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
+import org.apache.phoenix.schema.tuple.BaseTuple;
import org.apache.phoenix.schema.types.PBinary;
import org.apache.phoenix.schema.types.PChar;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PDouble;
import org.apache.phoenix.schema.types.PFloat;
+import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.schema.types.PVarchar;
import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.SizedUtil;
@@ -79,6 +87,7 @@ import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+
/**
*
* Base class for PTable implementors. Provides abstraction for
@@ -106,7 +115,8 @@ public class PTableImpl implements PTable {
private List<PColumnFamily> families;
private Map<byte[], PColumnFamily> familyByBytes;
private Map<String, PColumnFamily> familyByString;
- private ListMultimap<String,PColumn> columnsByName;
+ private ListMultimap<String, PColumn> columnsByName;
+ private ListMultimap<Pair<String, Integer>, PColumn> kvColumnsByEncodedColumnNames;
private PName pkName;
private Integer bucketNum;
private RowKeySchema rowKeySchema;
@@ -138,6 +148,8 @@ public class PTableImpl implements PTable {
private boolean isNamespaceMapped;
private String autoPartitionSeqName;
private boolean isAppendOnlySchema;
+ private StorageScheme storageScheme;
+ private EncodedCQCounter encodedCQCounter;
public PTableImpl() {
this.indexes = Collections.emptyList();
@@ -169,8 +181,9 @@ public class PTableImpl implements PTable {
this.isNamespaceMapped = isNamespaceMapped;
}
+ // For indexes stored in shared physical tables
public PTableImpl(PName tenantId, PName schemaName, PName tableName, long timestamp, List<PColumnFamily> families,
- List<PColumn> columns, List<PName> physicalNames, Short viewIndexId, boolean multiTenant, boolean isNamespaceMpped) throws SQLException { // For indexes stored in shared physical tables
+ List<PColumn> columns, List<PName> physicalNames, Short viewIndexId, boolean multiTenant, boolean isNamespaceMpped, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
this.pkColumns = this.allColumns = Collections.emptyList();
this.rowKeySchema = RowKeySchema.EMPTY_SCHEMA;
this.indexes = Collections.emptyList();
@@ -184,7 +197,7 @@ public class PTableImpl implements PTable {
init(tenantId, this.schemaName, this.tableName, PTableType.INDEX, state, timeStamp, sequenceNumber, pkName, bucketNum, columns,
this.schemaName, parentTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName,
null, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType, baseColumnCount, rowKeyOrderOptimizable,
- isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMpped, null, false);
+ isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMpped, null, false, storageScheme, encodedCQCounter);
}
public PTableImpl(long timeStamp) { // For delete marker
@@ -228,7 +241,7 @@ public class PTableImpl implements PTable {
indexes, table.isImmutableRows(), physicalNames, table.getDefaultFamilyName(), viewStatement,
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), updateCacheFrequency,
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, long timeStamp, List<PTable> indexes, PName parentSchemaName, String viewStatement) throws SQLException {
@@ -238,7 +251,7 @@ public class PTableImpl implements PTable {
indexes, table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), viewStatement,
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(),
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, Collection<PColumn> columns) throws SQLException {
@@ -248,7 +261,7 @@ public class PTableImpl implements PTable {
table.getIndexes(), table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(),
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, long timeStamp, long sequenceNumber, Collection<PColumn> columns) throws SQLException {
@@ -258,7 +271,7 @@ public class PTableImpl implements PTable {
table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(),
table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(),
- table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, long timeStamp, long sequenceNumber, Collection<PColumn> columns, boolean isImmutableRows) throws SQLException {
@@ -268,7 +281,7 @@ public class PTableImpl implements PTable {
table.getIndexes(), isImmutableRows, table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(),
table.getIndexType(), table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(),
- table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, long timeStamp, long sequenceNumber, Collection<PColumn> columns, boolean isImmutableRows, boolean isWalDisabled,
@@ -279,7 +292,7 @@ public class PTableImpl implements PTable {
table.getIndexes(), isImmutableRows, table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
isWalDisabled, isMultitenant, storeNulls, table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), isTransactional, updateCacheFrequency, table.getIndexDisableTimestamp(),
- isNamespaceMapped, table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ isNamespaceMapped, table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, PIndexState state) throws SQLException {
@@ -290,7 +303,7 @@ public class PTableImpl implements PTable {
table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(),
- table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.getIndexDisableTimestamp(), table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table, boolean rowKeyOrderOptimizable) throws SQLException {
@@ -301,7 +314,7 @@ public class PTableImpl implements PTable {
table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), rowKeyOrderOptimizable, table.isTransactional(), table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(), table.isNamespaceMapped(),
- table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PTable table) throws SQLException {
@@ -312,7 +325,7 @@ public class PTableImpl implements PTable {
table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(), table.isMultiTenant(), table.getStoreNulls(), table.getViewType(), table.getViewIndexId(), table.getIndexType(),
table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), table.isTransactional(), table.getUpdateCacheFrequency(), table.getIndexDisableTimestamp(),
- table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema());
+ table.isNamespaceMapped(), table.getAutoPartitionSeqName(), table.isAppendOnlySchema(), table.getStorageScheme(), table.getEncodedCQCounter());
}
public static PTableImpl makePTable(PName tenantId, PName schemaName, PName tableName, PTableType type,
@@ -321,12 +334,12 @@ public class PTableImpl implements PTable {
boolean isImmutableRows, List<PName> physicalNames, PName defaultFamilyName, String viewExpression,
boolean disableWAL, boolean multiTenant, boolean storeNulls, ViewType viewType, Short viewIndexId,
IndexType indexType, boolean rowKeyOrderOptimizable, boolean isTransactional, long updateCacheFrequency,
- long indexDisableTimestamp, boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema) throws SQLException {
+ long indexDisableTimestamp, boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
return new PTableImpl(tenantId, schemaName, tableName, type, state, timeStamp, sequenceNumber, pkName, bucketNum, columns, dataSchemaName,
dataTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName,
viewExpression, disableWAL, multiTenant, storeNulls, viewType, viewIndexId,
indexType, QueryConstants.BASE_TABLE_BASE_COLUMN_COUNT, rowKeyOrderOptimizable, isTransactional,
- updateCacheFrequency,indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema);
+ updateCacheFrequency,indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema, storageScheme, encodedCQCounter);
}
public static PTableImpl makePTable(PName tenantId, PName schemaName, PName tableName, PTableType type,
@@ -336,13 +349,13 @@ public class PTableImpl implements PTable {
boolean disableWAL, boolean multiTenant, boolean storeNulls, ViewType viewType, Short viewIndexId,
IndexType indexType, boolean rowKeyOrderOptimizable, boolean isTransactional, long updateCacheFrequency,
int baseColumnCount, long indexDisableTimestamp, boolean isNamespaceMapped,
- String autoPartitionSeqName, boolean isAppendOnlySchema)
+ String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter)
throws SQLException {
return new PTableImpl(tenantId, schemaName, tableName, type, state, timeStamp, sequenceNumber, pkName,
bucketNum, columns, dataSchemaName, dataTableName, indexes, isImmutableRows, physicalNames,
defaultFamilyName, viewExpression, disableWAL, multiTenant, storeNulls, viewType, viewIndexId,
indexType, baseColumnCount, rowKeyOrderOptimizable, isTransactional, updateCacheFrequency,
- indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema);
+ indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema, storageScheme, encodedCQCounter);
}
private PTableImpl(PName tenantId, PName schemaName, PName tableName, PTableType type, PIndexState state,
@@ -351,11 +364,11 @@ public class PTableImpl implements PTable {
List<PName> physicalNames, PName defaultFamilyName, String viewExpression, boolean disableWAL, boolean multiTenant,
boolean storeNulls, ViewType viewType, Short viewIndexId, IndexType indexType,
int baseColumnCount, boolean rowKeyOrderOptimizable, boolean isTransactional, long updateCacheFrequency,
- long indexDisableTimestamp, boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema) throws SQLException {
+ long indexDisableTimestamp, boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
init(tenantId, schemaName, tableName, type, state, timeStamp, sequenceNumber, pkName, bucketNum, columns,
parentSchemaName, parentTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName,
viewExpression, disableWAL, multiTenant, storeNulls, viewType, viewIndexId, indexType, baseColumnCount, rowKeyOrderOptimizable,
- isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema);
+ isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoPartitionSeqName, isAppendOnlySchema, storageScheme, encodedCQCounter);
}
@Override
@@ -389,7 +402,7 @@ public class PTableImpl implements PTable {
List<PTable> indexes, boolean isImmutableRows, List<PName> physicalNames, PName defaultFamilyName, String viewExpression, boolean disableWAL,
boolean multiTenant, boolean storeNulls, ViewType viewType, Short viewIndexId,
IndexType indexType , int baseColumnCount, boolean rowKeyOrderOptimizable, boolean isTransactional, long updateCacheFrequency, long indexDisableTimestamp,
- boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema) throws SQLException {
+ boolean isNamespaceMapped, String autoPartitionSeqName, boolean isAppendOnlySchema, StorageScheme storageScheme, EncodedCQCounter encodedCQCounter) throws SQLException {
Preconditions.checkNotNull(schemaName);
Preconditions.checkArgument(tenantId==null || tenantId.getBytes().length > 0); // tenantId should be null or not empty
int estimatedSize = SizedUtil.OBJECT_SIZE * 2 + 23 * SizedUtil.POINTER_SIZE + 4 * SizedUtil.INT_SIZE + 2 * SizedUtil.LONG_SIZE + 2 * SizedUtil.INT_OBJECT_SIZE +
@@ -425,10 +438,12 @@ public class PTableImpl implements PTable {
this.isNamespaceMapped = isNamespaceMapped;
this.autoPartitionSeqName = autoPartitionSeqName;
this.isAppendOnlySchema = isAppendOnlySchema;
+ this.storageScheme = storageScheme;
List<PColumn> pkColumns;
PColumn[] allColumns;
this.columnsByName = ArrayListMultimap.create(columns.size(), 1);
+ this.kvColumnsByEncodedColumnNames = (EncodedColumnsUtil.usesEncodedColumnNames(storageScheme) ? ArrayListMultimap.<Pair<String, Integer>, PColumn>create(columns.size(), 1) : null);
int numPKColumns = 0;
if (bucketNum != null) {
// Add salt column to allColumns and pkColumns, but don't add to
@@ -454,7 +469,26 @@ public class PTableImpl implements PTable {
if (Objects.equal(familyName, dupColumn.getFamilyName())) {
count++;
if (count > 1) {
- throw new ColumnAlreadyExistsException(null, name.getString(), columnName);
+ throw new ColumnAlreadyExistsException(schemaName.getString(), name.getString(), columnName);
+ }
+ }
+ }
+ }
+ //TODO: samarth understand the implication of this.
+ if (kvColumnsByEncodedColumnNames != null) {
+ Integer cq = column.getEncodedColumnQualifier();
+ String cf = column.getFamilyName() != null ? column.getFamilyName().getString() : null;
+ if (cf != null && cq != null) {
+ Pair<String, Integer> pair = new Pair<>(cf, cq);
+ if (kvColumnsByEncodedColumnNames.put(pair, column)) {
+ int count = 0;
+ for (PColumn dupColumn : kvColumnsByEncodedColumnNames.get(pair)) {
+ if (Objects.equal(familyName, dupColumn.getFamilyName())) {
+ count++;
+ if (count > 1) {
+ throw new ColumnAlreadyExistsException(schemaName.getString(), name.getString(), columnName);
+ }
+ }
}
}
}
@@ -518,7 +552,7 @@ public class PTableImpl implements PTable {
.orderedBy(Bytes.BYTES_COMPARATOR);
for (int i = 0; i < families.length; i++) {
Map.Entry<PName,List<PColumn>> entry = iterator.next();
- PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue());
+ PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue(), EncodedColumnsUtil.usesEncodedColumnNames(storageScheme));
families[i] = family;
familyByString.put(family.getName().getString(), family);
familyByBytes.put(family.getName().getBytes(), family);
@@ -544,9 +578,9 @@ public class PTableImpl implements PTable {
for (PName name : this.physicalNames) {
estimatedSize += name.getEstimatedSize();
}
-
this.estimatedSize = estimatedSize;
this.baseColumnCount = baseColumnCount;
+ this.encodedCQCounter = encodedCQCounter;
}
@Override
@@ -736,7 +770,7 @@ public class PTableImpl implements PTable {
}
@Override
- public PColumn getColumn(String name) throws ColumnNotFoundException, AmbiguousColumnException {
+ public PColumn getPColumnForColumnName(String name) throws ColumnNotFoundException, AmbiguousColumnException {
List<PColumn> columns = columnsByName.get(name);
int size = columns.size();
if (size == 0) {
@@ -755,6 +789,38 @@ public class PTableImpl implements PTable {
}
return columns.get(0);
}
+
+ @Override
+ public PColumn getPColumnForColumnQualifier(byte[] cf, byte[] cq) throws ColumnNotFoundException, AmbiguousColumnException {
+ Preconditions.checkNotNull(cq);
+ if (!EncodedColumnsUtil.usesEncodedColumnNames(this) || cf == null) {
+ String columnName = (String)PVarchar.INSTANCE.toObject(cq);
+ return getPColumnForColumnName(columnName);
+ } else {
+ Integer qualifier = getEncodedColumnQualifier(cq);
+ String family = (String)PVarchar.INSTANCE.toObject(cf);
+ List<PColumn> columns = kvColumnsByEncodedColumnNames.get(new Pair<>(family, qualifier));
+ int size = columns.size();
+ if (size == 0) {
+ //TODO: samarth should we have a column qualifier not found exception?
+ throw new ColumnNotFoundException(Bytes.toString(cq));
+ }
+ //TODO: samarth I am not convinced if need this logic.
+// if (size > 1) {
+// for (PColumn column : columns) {
+// if (QueryConstants.DEFAULT_COLUMN_FAMILY.equals(column.getFamilyName().getString())) {
+// // Allow ambiguity with PK column or column in the default column family,
+// // since a PK column cannot be prefixed and a user would not know how to
+// // prefix a column in the default column family.
+// return column;
+// }
+// }
+// //TODO: samarth should we have a column qualifier not found exception?
+// throw new AmbiguousColumnException(columns.get(0).getName().getString());
+// }
+ return columns.get(0);
+ }
+ }
/**
*
@@ -775,6 +841,8 @@ public class PTableImpl implements PTable {
private Mutation deleteRow;
private final long ts;
private final boolean hasOnDupKey;
+ // map from column name to value
+ private Map<PColumn, byte[]> columnToValueMap;
public PRowImpl(KeyValueBuilder kvBuilder, ImmutableBytesWritable key, long ts, Integer bucketNum, boolean hasOnDupKey) {
this.kvBuilder = kvBuilder;
@@ -787,7 +855,7 @@ public class PTableImpl implements PTable {
this.keyPtr = new ImmutableBytesPtr(key);
this.key = ByteUtil.copyKeyBytesIfNecessary(key);
}
-
+ this.columnToValueMap = Maps.newHashMapWithExpectedSize(1);//TODO: samarth size it properly
newMutations();
}
@@ -809,13 +877,49 @@ public class PTableImpl implements PTable {
// Include only deleteRow mutation if present because it takes precedence over all others
mutations.add(deleteRow);
} else {
+ // store all columns for a given column family in a single cell instead of one column per cell in order to improve write performance
+ if (storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ Put put = new Put(this.key);
+ if (isWALDisabled()) {
+ put.setDurability(Durability.SKIP_WAL);
+ }
+ // the setValues Put contains one cell per column, we need to convert it to a Put that contains a cell with all columns for a given column family
+ for (PColumnFamily family : families) {
+ byte[] columnFamily = family.getName().getBytes();
+ Collection<PColumn> columns = family.getColumns();
+ int maxEncodedColumnQualifier = Integer.MIN_VALUE;
+ for (PColumn column : columns) {
+ maxEncodedColumnQualifier = Math.max(maxEncodedColumnQualifier, column.getEncodedColumnQualifier());
+ }
+ byte[][] colValues = new byte[maxEncodedColumnQualifier+1][];
+ for (PColumn column : columns) {
+ colValues[column.getEncodedColumnQualifier()] = columnToValueMap.get(column);
+ }
+
+ List<Expression> children = Lists.newArrayListWithExpectedSize(columns.size());
+ // create an expression list with all the columns
+ for (int i=0; i<colValues.length; ++i) {
+ children.add(new LiteralExpression(colValues[i]==null ? ByteUtil.EMPTY_BYTE_ARRAY : colValues[i] ));
+ }
+ // we use ArrayConstructorExpression to serialize multiple columns into a single byte[]
+ // construct the ArrayConstructorExpression with a variable length data type since columns can be of fixed or variable length
+ ArrayConstructorExpression arrayExpression = new ArrayConstructorExpression(children, PVarbinary.INSTANCE, rowKeyOrderOptimizable);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+ arrayExpression.evaluate(new BaseTuple() {}, ptr);
+ ImmutableBytesPtr colFamilyPtr = new ImmutableBytesPtr(columnFamily);
+ addQuietly(put, kvBuilder, kvBuilder.buildPut(keyPtr,
+ colFamilyPtr, colFamilyPtr, ts, ptr));
+ }
+ setValues = put;
+ }
// Because we cannot enforce a not null constraint on a KV column (since we don't know if the row exists when
- // we upsert it), se instead add a KV that is always emtpy. This allows us to imitate SQL semantics given the
+ // we upsert it), so instead add a KV that is always empty. This allows us to imitate SQL semantics given the
// way HBase works.
+ Pair<byte[], byte[]> emptyKvInfo = EncodedColumnsUtil.getEmptyKeyValueInfo(PTableImpl.this);
addQuietly(setValues, kvBuilder, kvBuilder.buildPut(keyPtr,
SchemaUtil.getEmptyColumnFamilyPtr(PTableImpl.this),
- QueryConstants.EMPTY_COLUMN_BYTES_PTR, ts,
- QueryConstants.EMPTY_COLUMN_VALUE_BYTES_PTR));
+ new ImmutableBytesPtr(emptyKvInfo.getFirst()), ts,
+ new ImmutableBytesPtr(emptyKvInfo.getSecond())));
mutations.add(setValues);
if (!unsetValues.isEmpty()) {
mutations.add(unsetValues);
@@ -844,7 +948,8 @@ public class PTableImpl implements PTable {
public void setValue(PColumn column, byte[] byteValue) {
deleteRow = null;
byte[] family = column.getFamilyName().getBytes();
- byte[] qualifier = column.getName().getBytes();
+ byte[] qualifier = getColumnQualifier(column);
+ ImmutableBytesPtr qualifierPtr = new ImmutableBytesPtr(qualifier);
PDataType<?> type = column.getDataType();
// Check null, since some types have no byte representation for null
if (byteValue == null) {
@@ -864,7 +969,7 @@ public class PTableImpl implements PTable {
// case of updates occurring due to the execution of the clause.
removeIfPresent(setValues, family, qualifier);
deleteQuietly(unsetValues, kvBuilder, kvBuilder.buildDeleteColumns(keyPtr, column
- .getFamilyName().getBytesPtr(), column.getName().getBytesPtr(), ts));
+ .getFamilyName().getBytesPtr(), qualifierPtr, ts));
} else {
ImmutableBytesWritable ptr = new ImmutableBytesWritable(byteValue);
Integer maxLength = column.getMaxLength();
@@ -877,9 +982,17 @@ public class PTableImpl implements PTable {
ptr.set(byteValue);
type.pad(ptr, maxLength, sortOrder);
removeIfPresent(unsetValues, family, qualifier);
- addQuietly(setValues, kvBuilder, kvBuilder.buildPut(keyPtr,
- column.getFamilyName().getBytesPtr(), column.getName().getBytesPtr(),
+ // store all columns for a given column family in a single cell instead of one column per cell in order to improve write performance
+ // we don't need to do anything with unsetValues as it is only used when storeNulls is false, storeNulls is always true when storeColsInSingleCell is true
+ if (storageScheme == StorageScheme.COLUMNS_STORED_IN_SINGLE_CELL) {
+ columnToValueMap.put(column, ptr.get());
+ }
+ else {
+ removeIfPresent(unsetValues, family, qualifier);
+ addQuietly(setValues, kvBuilder, kvBuilder.buildPut(keyPtr,
+ column.getFamilyName().getBytesPtr(), qualifierPtr,
ts, ptr));
+ }
}
}
@@ -912,6 +1025,11 @@ public class PTableImpl implements PTable {
deleteRow.setDurability(Durability.SKIP_WAL);
}
}
+
+ private byte[] getColumnQualifier(PColumn column) {
+ return EncodedColumnsUtil.getColumnQualifier(column, PTableImpl.this);
+ }
+
}
@Override
@@ -1072,116 +1190,126 @@ public class PTableImpl implements PTable {
public IndexType getIndexType() {
return indexType;
}
-
+
/**
* Construct a PTable instance from ProtoBuffered PTable instance
* @param table
*/
public static PTable createFromProto(PTableProtos.PTable table) {
- PName tenantId = null;
- if(table.hasTenantId()){
- tenantId = PNameFactory.newName(table.getTenantId().toByteArray());
- }
- PName schemaName = PNameFactory.newName(table.getSchemaNameBytes().toByteArray());
- PName tableName = PNameFactory.newName(table.getTableNameBytes().toByteArray());
- PTableType tableType = PTableType.values()[table.getTableType().ordinal()];
- PIndexState indexState = null;
- if (table.hasIndexState()) {
- indexState = PIndexState.fromSerializedValue(table.getIndexState());
- }
- Short viewIndexId = null;
- if(table.hasViewIndexId()){
- viewIndexId = (short)table.getViewIndexId();
- }
- IndexType indexType = IndexType.getDefault();
- if(table.hasIndexType()){
- indexType = IndexType.fromSerializedValue(table.getIndexType().toByteArray()[0]);
- }
- long sequenceNumber = table.getSequenceNumber();
- long timeStamp = table.getTimeStamp();
- long indexDisableTimestamp = table.getIndexDisableTimestamp();
- PName pkName = null;
- if (table.hasPkNameBytes()) {
- pkName = PNameFactory.newName(table.getPkNameBytes().toByteArray());
- }
- int bucketNum = table.getBucketNum();
- List<PColumn> columns = Lists.newArrayListWithExpectedSize(table.getColumnsCount());
- for (PTableProtos.PColumn curPColumnProto : table.getColumnsList()) {
- columns.add(PColumnImpl.createFromProto(curPColumnProto));
- }
- List<PTable> indexes = Lists.newArrayListWithExpectedSize(table.getIndexesCount());
- for (PTableProtos.PTable curPTableProto : table.getIndexesList()) {
- indexes.add(createFromProto(curPTableProto));
- }
+ PName tenantId = null;
+ if(table.hasTenantId()){
+ tenantId = PNameFactory.newName(table.getTenantId().toByteArray());
+ }
+ PName schemaName = PNameFactory.newName(table.getSchemaNameBytes().toByteArray());
+ PName tableName = PNameFactory.newName(table.getTableNameBytes().toByteArray());
+ PTableType tableType = PTableType.values()[table.getTableType().ordinal()];
+ PIndexState indexState = null;
+ if (table.hasIndexState()) {
+ indexState = PIndexState.fromSerializedValue(table.getIndexState());
+ }
+ Short viewIndexId = null;
+ if(table.hasViewIndexId()){
+ viewIndexId = (short)table.getViewIndexId();
+ }
+ IndexType indexType = IndexType.getDefault();
+ if(table.hasIndexType()){
+ indexType = IndexType.fromSerializedValue(table.getIndexType().toByteArray()[0]);
+ }
+ long sequenceNumber = table.getSequenceNumber();
+ long timeStamp = table.getTimeStamp();
+ long indexDisableTimestamp = table.getIndexDisableTimestamp();
+ PName pkName = null;
+ if (table.hasPkNameBytes()) {
+ pkName = PNameFactory.newName(table.getPkNameBytes().toByteArray());
+ }
+ int bucketNum = table.getBucketNum();
+ List<PColumn> columns = Lists.newArrayListWithExpectedSize(table.getColumnsCount());
+ for (PTableProtos.PColumn curPColumnProto : table.getColumnsList()) {
+ columns.add(PColumnImpl.createFromProto(curPColumnProto));
+ }
+ List<PTable> indexes = Lists.newArrayListWithExpectedSize(table.getIndexesCount());
+ for (PTableProtos.PTable curPTableProto : table.getIndexesList()) {
+ indexes.add(createFromProto(curPTableProto));
+ }
- boolean isImmutableRows = table.getIsImmutableRows();
- PName parentSchemaName = null;
- PName parentTableName = null;
- if (table.hasParentNameBytes()) {
- parentSchemaName = PNameFactory.newName(SchemaUtil.getSchemaNameFromFullName((table.getParentNameBytes().toByteArray())));
- parentTableName = PNameFactory.newName(SchemaUtil.getTableNameFromFullName(table.getParentNameBytes().toByteArray()));
- }
- PName defaultFamilyName = null;
- if (table.hasDefaultFamilyName()) {
- defaultFamilyName = PNameFactory.newName(table.getDefaultFamilyName().toByteArray());
- }
- boolean disableWAL = table.getDisableWAL();
- boolean multiTenant = table.getMultiTenant();
- boolean storeNulls = table.getStoreNulls();
- boolean isTransactional = table.getTransactional();
- ViewType viewType = null;
- String viewStatement = null;
- List<PName> physicalNames = Collections.emptyList();
- if (tableType == PTableType.VIEW) {
- viewType = ViewType.fromSerializedValue(table.getViewType().toByteArray()[0]);
- }
- if(table.hasViewStatement()){
- viewStatement = (String) PVarchar.INSTANCE.toObject(table.getViewStatement().toByteArray());
- }
- if (tableType == PTableType.VIEW || viewIndexId != null) {
- physicalNames = Lists.newArrayListWithExpectedSize(table.getPhysicalNamesCount());
- for(int i = 0; i < table.getPhysicalNamesCount(); i++){
- physicalNames.add(PNameFactory.newName(table.getPhysicalNames(i).toByteArray()));
+ boolean isImmutableRows = table.getIsImmutableRows();
+ PName parentSchemaName = null;
+ PName parentTableName = null;
+ if (table.hasParentNameBytes()) {
+ parentSchemaName = PNameFactory.newName(SchemaUtil.getSchemaNameFromFullName((table.getParentNameBytes().toByteArray())));
+ parentTableName = PNameFactory.newName(SchemaUtil.getTableNameFromFullName(table.getParentNameBytes().toByteArray()));
+ }
+ PName defaultFamilyName = null;
+ if (table.hasDefaultFamilyName()) {
+ defaultFamilyName = PNameFactory.newName(table.getDefaultFamilyName().toByteArray());
+ }
+ boolean disableWAL = table.getDisableWAL();
+ boolean multiTenant = table.getMultiTenant();
+ boolean storeNulls = table.getStoreNulls();
+ boolean isTransactional = table.getTransactional();
+ ViewType viewType = null;
+ String viewStatement = null;
+ List<PName> physicalNames = Collections.emptyList();
+ if (tableType == PTableType.VIEW) {
+ viewType = ViewType.fromSerializedValue(table.getViewType().toByteArray()[0]);
+ }
+ if(table.hasViewStatement()){
+ viewStatement = (String) PVarchar.INSTANCE.toObject(table.getViewStatement().toByteArray());
+ }
+ if (tableType == PTableType.VIEW || viewIndexId != null) {
+ physicalNames = Lists.newArrayListWithExpectedSize(table.getPhysicalNamesCount());
+ for(int i = 0; i < table.getPhysicalNamesCount(); i++) {
+ physicalNames.add(PNameFactory.newName(table.getPhysicalNames(i).toByteArray()));
+ }
+ }
+ int baseColumnCount = -1;
+ if (table.hasBaseColumnCount()) {
+ baseColumnCount = table.getBaseColumnCount();
}
- }
-
- int baseColumnCount = -1;
- if (table.hasBaseColumnCount()) {
- baseColumnCount = table.getBaseColumnCount();
- }
- boolean rowKeyOrderOptimizable = false;
- if (table.hasRowKeyOrderOptimizable()) {
- rowKeyOrderOptimizable = table.getRowKeyOrderOptimizable();
- }
- long updateCacheFrequency = 0;
- if (table.hasUpdateCacheFrequency()) {
- updateCacheFrequency = table.getUpdateCacheFrequency();
- }
- boolean isNamespaceMapped=false;
- if (table.hasIsNamespaceMapped()) {
- isNamespaceMapped = table.getIsNamespaceMapped();
- }
- String autoParititonSeqName = null;
- if (table.hasAutoParititonSeqName()) {
- autoParititonSeqName = table.getAutoParititonSeqName();
- }
- boolean isAppendOnlySchema = false;
- if (table.hasIsAppendOnlySchema()) {
- isAppendOnlySchema = table.getIsAppendOnlySchema();
- }
-
- try {
- PTableImpl result = new PTableImpl();
- result.init(tenantId, schemaName, tableName, tableType, indexState, timeStamp, sequenceNumber, pkName,
- (bucketNum == NO_SALTING) ? null : bucketNum, columns, parentSchemaName, parentTableName, indexes,
- isImmutableRows, physicalNames, defaultFamilyName, viewStatement, disableWAL,
- multiTenant, storeNulls, viewType, viewIndexId, indexType, baseColumnCount, rowKeyOrderOptimizable,
- isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoParititonSeqName, isAppendOnlySchema);
- return result;
- } catch (SQLException e) {
- throw new RuntimeException(e); // Impossible
- }
+ boolean rowKeyOrderOptimizable = false;
+ if (table.hasRowKeyOrderOptimizable()) {
+ rowKeyOrderOptimizable = table.getRowKeyOrderOptimizable();
+ }
+ long updateCacheFrequency = 0;
+ if (table.hasUpdateCacheFrequency()) {
+ updateCacheFrequency = table.getUpdateCacheFrequency();
+ }
+ boolean isNamespaceMapped=false;
+ if (table.hasIsNamespaceMapped()) {
+ isNamespaceMapped = table.getIsNamespaceMapped();
+ }
+ String autoParititonSeqName = null;
+ if (table.hasAutoParititonSeqName()) {
+ autoParititonSeqName = table.getAutoParititonSeqName();
+ }
+ boolean isAppendOnlySchema = false;
+ if (table.hasIsAppendOnlySchema()) {
+ isAppendOnlySchema = table.getIsAppendOnlySchema();
+ }
+ StorageScheme storageScheme = null;
+ if (table.hasStorageScheme()) {
+ storageScheme = StorageScheme.fromSerializedValue(table.getStorageScheme().toByteArray()[0]);
+ }
+ EncodedCQCounter encodedColumnQualifierCounter = EncodedColumnsUtil.usesEncodedColumnNames(storageScheme) ? new EncodedCQCounter() : EncodedCQCounter.NULL_COUNTER;
+ if (table.getEncodedCQCountersList() != null) {
+ encodedColumnQualifierCounter = new EncodedCQCounter();
+ for (org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter cqCounterFromProto : table.getEncodedCQCountersList()) {
+ encodedColumnQualifierCounter.setValue(cqCounterFromProto.getColFamily(), cqCounterFromProto.getCounter());
+ }
+ }
+
+ try {
+ PTableImpl result = new PTableImpl();
+ result.init(tenantId, schemaName, tableName, tableType, indexState, timeStamp, sequenceNumber, pkName,
+ (bucketNum == NO_SALTING) ? null : bucketNum, columns, parentSchemaName, parentTableName, indexes,
+ isImmutableRows, physicalNames, defaultFamilyName, viewStatement, disableWAL,
+ multiTenant, storeNulls, viewType, viewIndexId, indexType, baseColumnCount, rowKeyOrderOptimizable,
+ isTransactional, updateCacheFrequency, indexDisableTimestamp, isNamespaceMapped, autoParititonSeqName, isAppendOnlySchema, storageScheme, encodedColumnQualifierCounter);
+ return result;
+ } catch (SQLException e) {
+ throw new RuntimeException(e); // Impossible
+ }
}
public static PTableProtos.PTable toProto(PTable table) {
@@ -1259,10 +1387,22 @@ public class PTableImpl implements PTable {
builder.setUpdateCacheFrequency(table.getUpdateCacheFrequency());
builder.setIndexDisableTimestamp(table.getIndexDisableTimestamp());
builder.setIsNamespaceMapped(table.isNamespaceMapped());
- if (table.getAutoPartitionSeqName()!= null) {
+ if (table.getAutoPartitionSeqName() != null) {
builder.setAutoParititonSeqName(table.getAutoPartitionSeqName());
}
builder.setIsAppendOnlySchema(table.isAppendOnlySchema());
+ if (table.getStorageScheme() != null) {
+ builder.setStorageScheme(ByteStringer.wrap(new byte[]{table.getStorageScheme().getSerializedValue()}));
+ }
+ if (table.getEncodedCQCounter() != null) {
+ Map<String, Integer> values = table.getEncodedCQCounter().values();
+ for (Entry<String, Integer> cqCounter : values.entrySet()) {
+ org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.Builder cqBuilder = org.apache.phoenix.coprocessor.generated.PTableProtos.EncodedCQCounter.newBuilder();
+ cqBuilder.setColFamily(cqCounter.getKey());
+ cqBuilder.setCounter(cqCounter.getValue());
+ builder.addEncodedCQCounters(cqBuilder.build());
+ }
+ }
return builder.build();
}
@@ -1332,4 +1472,14 @@ public class PTableImpl implements PTable {
} else if (!key.equals(other.getKey())) return false;
return true;
}
+
+ @Override
+ public StorageScheme getStorageScheme() {
+ return storageScheme;
+ }
+
+ @Override
+ public EncodedCQCounter getEncodedCQCounter() {
+ return encodedCQCounter;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableKey.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableKey.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableKey.java
index 42699d9..017c75d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableKey.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableKey.java
@@ -28,7 +28,11 @@ public class PTableKey {
public PTableKey(PName tenantId, String name) {
Preconditions.checkNotNull(name);
this.tenantId = tenantId;
- this.name = name;
+ if (name.indexOf(QueryConstants.NAMESPACE_SEPARATOR) != -1) {
+ this.name = name.replace(QueryConstants.NAMESPACE_SEPARATOR, QueryConstants.NAME_SEPARATOR);
+ } else {
+ this.name = name;
+ }
}
public PName getTenantId() {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java
index 19dd1c1..9336938 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ProjectedColumn.java
@@ -39,6 +39,7 @@ public class ProjectedColumn extends DelegateColumn {
return name;
}
+ @Override
public PName getFamilyName() {
return familyName;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java
index 734a9ed..23cfd1b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java
@@ -38,7 +38,7 @@ public class SaltingUtil {
public static final String SALTING_COLUMN_NAME = "_SALT";
public static final String SALTED_ROW_KEY_NAME = "_SALTED_KEY";
public static final PColumnImpl SALTING_COLUMN = new PColumnImpl(
- PNameFactory.newName(SALTING_COLUMN_NAME), null, PBinary.INSTANCE, 1, 0, false, 0, SortOrder.getDefault(), 0, null, false, null, false, false);
+ PNameFactory.newName(SALTING_COLUMN_NAME), null, PBinary.INSTANCE, 1, 0, false, 0, SortOrder.getDefault(), 0, null, false, null, false, false, null);
public static final RowKeySchema VAR_BINARY_SALTED_SCHEMA = new RowKeySchemaBuilder(2)
.addField(SALTING_COLUMN, false, SortOrder.getDefault())
.addField(SchemaUtil.VAR_BINARY_DATUM, false, SortOrder.getDefault()).build();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/BaseTuple.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/BaseTuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/BaseTuple.java
index a8dc487..8028eb2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/BaseTuple.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/BaseTuple.java
@@ -17,11 +17,50 @@
*/
package org.apache.phoenix.schema.tuple;
+import java.util.List;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+
public abstract class BaseTuple implements Tuple {
+ @Override
+ public int size() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isImmutable() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getKey(ImmutableBytesWritable ptr) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Cell getValue(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Cell getValue(byte [] family, byte [] qualifier) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean getValue(byte [] family, byte [] qualifier, ImmutableBytesWritable ptr) {
+ throw new UnsupportedOperationException();
+ }
@Override
public long getSequenceValue(int index) {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public void setKeyValues(List<Cell> values) {
+ throw new UnsupportedOperationException();
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/DelegateTuple.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/DelegateTuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/DelegateTuple.java
index 58b1eda..3430f5b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/DelegateTuple.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/DelegateTuple.java
@@ -17,6 +17,8 @@
*/
package org.apache.phoenix.schema.tuple;
+import java.util.List;
+
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
@@ -61,4 +63,9 @@ public class DelegateTuple implements Tuple {
public long getSequenceValue(int index) {
return delegate.getSequenceValue(index);
}
+
+ @Override
+ public void setKeyValues(List<Cell> values) {
+ delegate.setKeyValues(values);
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java
new file mode 100644
index 0000000..f39bb1f
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/EncodedColumnQualiferCellsList.java
@@ -0,0 +1,569 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.schema.tuple;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.phoenix.query.QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE;
+import static org.apache.phoenix.query.QueryConstants.ENCODED_EMPTY_COLUMN_NAME;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
+
+import java.util.Collection;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+import javax.annotation.concurrent.NotThreadSafe;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.phoenix.schema.PTable.StorageScheme;
+
+/**
+ * List implementation that provides indexed based look up when the cell column qualifiers are positive numbers.
+ * These qualifiers are generated by using one of the column qualifier encoding schemes specified in {@link StorageScheme}.
+ * The api methods in this list assume that the caller wants to see
+ * and add only non null elements in the list.
+ * <p>
+ * Please note that this implementation doesn't implement all the optional methods of the
+ * {@link List} interface. Such unsupported methods could violate the basic invariance of the list that every cell with
+ * an encoded column qualifier has a fixed position in the list.
+ * </p>
+ * <p>
+ * An important performance characteristic of this list is that doing look up on the basis of index via {@link #get(int)}
+ * is an O(n) operation. This makes iterating through the list using {@link #get(int)} an O(n^2) operation.
+ * Instead, for iterating through the list, one should use the iterators created through {@link #iterator()} or
+ * {@link #listIterator()}. Do note that getting an element using {@link #getCellForColumnQualifier(int)} is an O(1) operation
+ * and should generally be the way for getting elements out of the list.
+ * </p>
+ */
+@NotThreadSafe
+public class EncodedColumnQualiferCellsList implements List<Cell> {
+
+ private int minQualifier;
+ private int maxQualifier;
+ private int nonReservedRangeOffset;
+ private final Cell[] array;
+ private int numNonNullElements;
+ private int firstNonNullElementIdx = -1;
+ private static final int RESERVED_RANGE_SIZE = ENCODED_CQ_COUNTER_INITIAL_VALUE - ENCODED_EMPTY_COLUMN_NAME;
+ // Used by iterators to figure out if the list was structurally modified.
+ private int modCount = 0;
+
+ public EncodedColumnQualiferCellsList(int minQ, int maxQ) {
+ checkArgument(minQ <= maxQ, "Invalid arguments. Min: " + minQ
+ + ". Max: " + maxQ);
+ this.minQualifier = minQ;
+ this.maxQualifier = maxQ;
+ int size = 0;
+ if (maxQ < ENCODED_CQ_COUNTER_INITIAL_VALUE) {
+ size = RESERVED_RANGE_SIZE;
+ } else if (minQ < ENCODED_CQ_COUNTER_INITIAL_VALUE) {
+ size = (maxQ - minQ + 1);
+ } else {
+ size = RESERVED_RANGE_SIZE + (maxQ - minQ + 1);
+ }
+ this.array = new Cell[size];
+ this.nonReservedRangeOffset = minQ > ENCODED_CQ_COUNTER_INITIAL_VALUE ? minQ - ENCODED_CQ_COUNTER_INITIAL_VALUE : 0;
+ }
+
+ @Override
+ public int size() {
+ return numNonNullElements;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return numNonNullElements == 0;
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return indexOf(o) >= 0;
+ }
+
+ @Override
+ public Object[] toArray() {
+ Object[] toReturn = new Object[numNonNullElements];
+ int counter = 0;
+ if (numNonNullElements > 0) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] != null) {
+ toReturn[counter++] = array[i];
+ }
+ }
+ }
+ return toReturn;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T[] toArray(T[] a) {
+ T[] toReturn =
+ (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(),
+ numNonNullElements);
+ int counter = 0;
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] != null) {
+ toReturn[counter++] = (T) array[i];
+ }
+ }
+ return toReturn;
+ }
+
+ @Override
+ public boolean add(Cell e) {
+ if (e == null) {
+ throw new NullPointerException();
+ }
+ int columnQualifier = getEncodedColumnQualifier(e.getQualifierArray(), e.getQualifierOffset(), e.getQualifierLength());
+
+ checkQualifierRange(columnQualifier);
+ int idx = getArrayIndex(columnQualifier);
+ if (array[idx] == null) {
+ numNonNullElements++;
+ }
+ array[idx] = e;
+ if (firstNonNullElementIdx == -1) {
+ firstNonNullElementIdx = idx;
+ } else if (idx < firstNonNullElementIdx) {
+ firstNonNullElementIdx = idx;
+ }
+ modCount++;
+ /*
+ * Note that we don't care about equality of the element being added with the element
+ * already present at the index.
+ */
+ return true;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ if (o == null) {
+ return false;
+ }
+ Cell e = (Cell) o;
+ int i = 0;
+ while (i < array.length) {
+ if (array[i] != null && array[i].equals(e)) {
+ array[i] = null;
+ numNonNullElements--;
+ if (numNonNullElements == 0) {
+ firstNonNullElementIdx = -1;
+ } else if (firstNonNullElementIdx == i) {
+ // the element being removed was the first non-null element we knew
+ while (i < array.length && (array[i]) == null) {
+ i++;
+ }
+ if (i < array.length) {
+ firstNonNullElementIdx = i;
+ } else {
+ firstNonNullElementIdx = -1;
+ }
+ }
+ modCount++;
+ return true;
+ }
+ i++;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ boolean containsAll = true;
+ Iterator<?> itr = c.iterator();
+ while (itr.hasNext()) {
+ containsAll &= (indexOf(itr.next()) >= 0);
+ }
+ return containsAll;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Cell> c) {
+ boolean changed = false;
+ for (Cell cell : c) {
+ if (c == null) {
+ throw new NullPointerException();
+ }
+ changed |= add(cell);
+ }
+ return changed;
+ }
+
+ @Override
+ public boolean addAll(int index, Collection<? extends Cell> c) {
+ throwGenericUnsupportedOperationException();
+ return false;
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ Iterator<?> itr = c.iterator();
+ boolean changed = false;
+ while (itr.hasNext()) {
+ changed |= remove(itr.next());
+ }
+ return changed;
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> collection) {
+ boolean changed = false;
+ // Optimize if the passed collection is an instance of EncodedColumnQualiferCellsList
+ if (collection instanceof EncodedColumnQualiferCellsList) {
+ EncodedColumnQualiferCellsList list = (EncodedColumnQualiferCellsList) collection;
+ ListIterator<Cell> listItr = this.listIterator();
+ while (listItr.hasNext()) {
+ Cell cellInThis = listItr.next();
+ int qualifier = getEncodedColumnQualifier(cellInThis.getQualifierArray(),
+ cellInThis.getQualifierOffset(), cellInThis.getQualifierLength());
+ try {
+ Cell cellInParam = list.getCellForColumnQualifier(qualifier);
+ if (cellInParam != null && cellInParam.equals(cellInThis)) {
+ continue;
+ }
+ listItr.remove();
+ changed = true;
+ } catch (IndexOutOfBoundsException expected) {
+ // this could happen when the qualifier of cellInParam lies out of
+ // the range of this list.
+ listItr.remove();
+ changed = true;
+ }
+ }
+ } else {
+ throw new UnsupportedOperationException(
+ "Operation only supported for collections of type EncodedColumnQualiferCellsList");
+ }
+ return changed;
+ }
+
+ @Override
+ public void clear() {
+ for (int i = 0; i < array.length; i++) {
+ array[i] = null;
+ }
+ firstNonNullElementIdx = -1;
+ numNonNullElements = 0;
+ modCount++;
+ }
+
+ @Override
+ public Cell get(int index) {
+ rangeCheck(index);
+ int numNonNullElementsFound = 0;
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] != null) {
+ numNonNullElementsFound++;
+ if (numNonNullElementsFound == index + 1) {
+ return array[i];
+ }
+ }
+ }
+ throw new IllegalStateException("There was no element present in the list at index "
+ + index + " even though number of elements in the list are " + size());
+ }
+
+ @Override
+ public Cell set(int index, Cell e) {
+ throwGenericUnsupportedOperationException();
+ return null;
+ }
+
+ @Override
+ public void add(int index, Cell element) {
+ throwGenericUnsupportedOperationException();
+ }
+
+ @Override
+ public Cell remove(int index) {
+ throwGenericUnsupportedOperationException();
+ return null;
+ }
+
+ @Override
+ public int indexOf(Object o) {
+ if (o == null || isEmpty()) {
+ return -1;
+ } else {
+ int numNonNull = -1;
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] != null) {
+ numNonNull++;
+ }
+ if (o.equals(array[i])) {
+ return numNonNull;
+ }
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public int lastIndexOf(Object o) {
+ if (o == null || isEmpty()) {
+ return -1;
+ }
+ int lastIndex = numNonNullElements;
+ for (int i = array.length - 1; i >= 0; i--) {
+ if (array[i] != null) {
+ lastIndex--;
+ }
+ if (o.equals(array[i])) {
+ return lastIndex;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public ListIterator<Cell> listIterator() {
+ return new ListItr();
+ }
+
+ @Override
+ public ListIterator<Cell> listIterator(int index) {
+ throwGenericUnsupportedOperationException();
+ return null;
+ }
+
+ @Override
+ public List<Cell> subList(int fromIndex, int toIndex) {
+ throwGenericUnsupportedOperationException();
+ return null;
+ }
+
+ @Override
+ public Iterator<Cell> iterator() {
+ return new Itr();
+ }
+
+ public Cell getCellForColumnQualifier(int columnQualifier) {
+ checkQualifierRange(columnQualifier);
+ int idx = getArrayIndex(columnQualifier);
+ Cell c = array[idx];
+ return c;
+ }
+
+ public Cell getFirstCell() {
+ if (firstNonNullElementIdx == -1) {
+ throw new NoSuchElementException("No elements present in the list");
+ }
+ return array[firstNonNullElementIdx];
+ }
+
+ private void checkQualifierRange(int qualifier) {
+ if (qualifier < ENCODED_CQ_COUNTER_INITIAL_VALUE) {
+ return; // space in the array for reserved range is always allocated.
+ }
+ if (qualifier < minQualifier || qualifier > maxQualifier) {
+ throw new IndexOutOfBoundsException("Qualifier " + qualifier
+ + " is out of the valid range - (" + minQualifier + ", " + maxQualifier + ")");
+ }
+ }
+
+ private void rangeCheck(int index) {
+ if (index < 0 || index >= size()) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ private int getArrayIndex(int columnQualifier) {
+ checkArgument(columnQualifier >= ENCODED_EMPTY_COLUMN_NAME);
+ if (columnQualifier < ENCODED_CQ_COUNTER_INITIAL_VALUE) {
+ return columnQualifier;
+ }
+ return columnQualifier - nonReservedRangeOffset;
+ }
+
+ private void throwGenericUnsupportedOperationException() {
+ throw new UnsupportedOperationException(
+ "Operation cannot be supported because it potentially violates the invariance contract of this list implementation");
+ }
+
+ private class Itr implements Iterator<Cell> {
+ protected int nextIndex = 0;
+ protected int lastRet = -1;
+ protected int expectedModCount = modCount;
+
+ private Itr() {
+ moveForward(true);
+ }
+
+ @Override
+ public boolean hasNext() {
+ return nextIndex != -1;
+ }
+
+ @Override
+ public Cell next() {
+ checkForCoModification();
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ Cell next = array[nextIndex];
+ lastRet = nextIndex;
+ moveForward(false);
+ modCount++;
+ expectedModCount = modCount;
+ return next;
+ }
+
+ @Override
+ public void remove() {
+ if (lastRet < 0) {
+ throw new IllegalStateException();
+ }
+ checkForCoModification();
+ array[lastRet] = null;
+ lastRet = -1;
+ numNonNullElements--;
+ modCount++;
+ expectedModCount = modCount;
+ }
+
+ protected void moveForward(boolean init) {
+ int i = init ? 0 : nextIndex + 1;
+ while (i < array.length && (array[i]) == null) {
+ i++;
+ }
+ if (i < array.length) {
+ nextIndex = i;
+ } else {
+ nextIndex = -1;
+ }
+ }
+
+ protected void checkForCoModification() {
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ }
+
+ }
+
+ private class ListItr extends Itr implements ListIterator<Cell> {
+ private int previousIndex = -1;
+
+ private ListItr() {
+ moveForward(true);
+ }
+
+ @Override
+ public boolean hasNext() {
+ return nextIndex != -1;
+ }
+
+ @Override
+ public boolean hasPrevious() {
+ return previousIndex != -1;
+ }
+
+ @Override
+ public Cell previous() {
+ if (previousIndex == -1) {
+ throw new NoSuchElementException();
+ }
+ checkForCoModification();
+ lastRet = previousIndex;
+ movePointersBackward();
+ return array[lastRet];
+ }
+
+ @Override
+ public int nextIndex() {
+ return nextIndex;
+ }
+
+ @Override
+ public int previousIndex() {
+ return previousIndex;
+ }
+
+ @Override
+ public void remove() {
+ if (lastRet == nextIndex) {
+ moveNextPointer(nextIndex);
+ }
+ super.remove();
+ expectedModCount = modCount;
+ }
+
+ @Override
+ public void set(Cell e) {
+ if (lastRet == -1) {
+ throw new IllegalStateException();
+ }
+ int columnQualifier = getEncodedColumnQualifier(e.getQualifierArray(), e.getQualifierOffset(), e.getQualifierLength());
+ int idx = getArrayIndex(columnQualifier);
+ if (idx != lastRet) {
+ throw new IllegalArgumentException("Cell " + e + " with column qualifier "
+ + columnQualifier + " belongs at index " + idx
+ + ". It cannot be added at the position " + lastRet
+ + " to which the previous next() or previous() was pointing to.");
+ }
+ EncodedColumnQualiferCellsList.this.add(e);
+ expectedModCount = modCount;
+ }
+
+ @Override
+ public void add(Cell e) {
+ throwGenericUnsupportedOperationException();
+ }
+
+ @Override
+ protected void moveForward(boolean init) {
+ if (!init) {
+ previousIndex = nextIndex;
+ }
+ int i = init ? 0 : nextIndex + 1;
+ moveNextPointer(i);
+ }
+
+ private void moveNextPointer(int i) {
+ while (i < array.length && (array[i]) == null) {
+ i++;
+ }
+ if (i < array.length) {
+ nextIndex = i;
+ } else {
+ nextIndex = -1;
+ }
+ }
+
+ private void movePointersBackward() {
+ nextIndex = previousIndex;
+ int i = previousIndex - 1;
+ movePreviousPointer(i);
+ }
+
+ private void movePreviousPointer(int i) {
+ for (; i >= 0; i--) {
+ if (array[i] != null) {
+ previousIndex = i;
+ break;
+ }
+ }
+ if (i < 0) {
+ previousIndex = -1;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/MultiKeyValueTuple.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/MultiKeyValueTuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/MultiKeyValueTuple.java
index 53f155b..d946870 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/MultiKeyValueTuple.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/MultiKeyValueTuple.java
@@ -36,6 +36,7 @@ public class MultiKeyValueTuple extends BaseTuple {
}
/** Caller must not modify the list that is passed here */
+ @Override
public void setKeyValues(List<Cell> values) {
this.values = values;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedMultiKeyValueTuple.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedMultiKeyValueTuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedMultiKeyValueTuple.java
new file mode 100644
index 0000000..08cafe0
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedMultiKeyValueTuple.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.schema.tuple;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.phoenix.util.EncodedColumnsUtil.getEncodedColumnQualifier;
+
+import java.util.List;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+
+/**
+ * Tuple that uses the
+ */
+public class PositionBasedMultiKeyValueTuple extends BaseTuple {
+ private EncodedColumnQualiferCellsList values;
+
+ public PositionBasedMultiKeyValueTuple() {}
+
+ public PositionBasedMultiKeyValueTuple(List<Cell> values) {
+ checkArgument(values instanceof EncodedColumnQualiferCellsList, "PositionBasedMultiKeyValueTuple only works with lists of type EncodedColumnQualiferCellsList");
+ this.values = (EncodedColumnQualiferCellsList)values;
+ }
+
+ /** Caller must not modify the list that is passed here */
+ @Override
+ public void setKeyValues(List<Cell> values) {
+ checkArgument(values instanceof EncodedColumnQualiferCellsList, "PositionBasedMultiKeyValueTuple only works with lists of type EncodedColumnQualiferCellsList");
+ this.values = (EncodedColumnQualiferCellsList)values;
+ }
+
+ @Override
+ public void getKey(ImmutableBytesWritable ptr) {
+ Cell value = values.getFirstCell();
+ ptr.set(value.getRowArray(), value.getRowOffset(), value.getRowLength());
+ }
+
+ @Override
+ public boolean isImmutable() {
+ return true;
+ }
+
+ @Override
+ public Cell getValue(byte[] family, byte[] qualifier) {
+ return values.getCellForColumnQualifier(getEncodedColumnQualifier(qualifier));
+ }
+
+ @Override
+ public String toString() {
+ return values.toString();
+ }
+
+ @Override
+ public int size() {
+ return values.size();
+ }
+
+ @Override
+ public Cell getValue(int index) {
+ return values.get(index);
+ }
+
+ @Override
+ public boolean getValue(byte[] family, byte[] qualifier,
+ ImmutableBytesWritable ptr) {
+ Cell kv = getValue(family, qualifier);
+ if (kv == null)
+ return false;
+ ptr.set(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
+ return true;
+ }}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/670b53a9/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedResultTuple.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedResultTuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedResultTuple.java
new file mode 100644
index 0000000..109cfc3
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/PositionBasedResultTuple.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.schema.tuple;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.util.EncodedColumnsUtil;
+
+public class PositionBasedResultTuple extends BaseTuple {
+ private final EncodedColumnQualiferCellsList cells;
+
+ public PositionBasedResultTuple(List<Cell> list) {
+ checkArgument(list instanceof EncodedColumnQualiferCellsList, "Invalid list type");
+ this.cells = (EncodedColumnQualiferCellsList)list;
+ }
+
+ @Override
+ public void getKey(ImmutableBytesWritable ptr) {
+ Cell value = cells.getFirstCell();
+ ptr.set(value.getRowArray(), value.getRowOffset(), value.getRowLength());
+ }
+
+ @Override
+ public boolean isImmutable() {
+ return true;
+ }
+
+ @Override
+ public KeyValue getValue(byte[] family, byte[] qualifier) {
+ int columnQualifier = EncodedColumnsUtil.getEncodedColumnQualifier(qualifier);
+ return org.apache.hadoop.hbase.KeyValueUtil.ensureKeyValue(cells.getCellForColumnQualifier(columnQualifier));
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("keyvalues=");
+ if(this.cells == null || this.cells.isEmpty()) {
+ sb.append("NONE");
+ return sb.toString();
+ }
+ sb.append("{");
+ boolean moreThanOne = false;
+ for(Cell kv : this.cells) {
+ if(moreThanOne) {
+ sb.append(", \n");
+ } else {
+ moreThanOne = true;
+ }
+ sb.append(kv.toString()+"/value="+Bytes.toString(kv.getValueArray(),
+ kv.getValueOffset(), kv.getValueLength()));
+ }
+ sb.append("}\n");
+ return sb.toString();
+ }
+
+ @Override
+ public int size() {
+ return cells.size();
+ }
+
+ @Override
+ public KeyValue getValue(int index) {
+ return org.apache.hadoop.hbase.KeyValueUtil.ensureKeyValue(index == 0 ? cells.getFirstCell() : cells.get(index));
+ }
+
+ @Override
+ public boolean getValue(byte[] family, byte[] qualifier,
+ ImmutableBytesWritable ptr) {
+ KeyValue kv = getValue(family, qualifier);
+ if (kv == null)
+ return false;
+ ptr.set(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
+ return true;
+ }
+
+ public Iterator<Cell> getTupleIterator() {
+ return new TupleIterator(cells.iterator());
+ }
+
+ private static class TupleIterator implements Iterator<Cell> {
+
+ private final Iterator<Cell> delegate;
+ private TupleIterator(Iterator<Cell> delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return delegate.hasNext();
+ }
+
+ @Override
+ public Cell next() {
+ return delegate.next();
+ }
+
+ @Override
+ public void remove() {
+ delegate.remove();
+ }
+
+ }
+}