You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/04/17 03:28:42 UTC
git commit: Add local index to grammar and metadata
Repository: incubator-phoenix
Updated Branches:
refs/heads/local-index ce47be1be -> 73e1c0864
Add local index to grammar and metadata
Project: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/commit/73e1c086
Tree: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/tree/73e1c086
Diff: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/diff/73e1c086
Branch: refs/heads/local-index
Commit: 73e1c08641797feaa0fbac10078a3f17ec0cc0ca
Parents: ce47be1
Author: James Taylor <ja...@apache.org>
Authored: Wed Apr 16 18:28:18 2014 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Wed Apr 16 18:28:18 2014 -0700
----------------------------------------------------------------------
.../phoenix/end2end/index/LocalIndexIT.java | 58 ++++++++++
phoenix-core/src/main/antlr3/PhoenixSQL.g | 7 +-
.../phoenix/compile/CreateIndexCompiler.java | 5 +
.../apache/phoenix/compile/JoinCompiler.java | 4 +-
.../coprocessor/MetaDataEndpointImpl.java | 11 +-
.../coprocessor/generated/PTableProtos.java | 107 +++++++++++++++++--
.../phoenix/exception/SQLExceptionCode.java | 4 +-
.../phoenix/expression/ExpressionType.java | 5 +-
.../function/SQLIndexTypeFunction.java | 77 +++++++++++++
.../phoenix/jdbc/PhoenixDatabaseMetaData.java | 8 +-
.../apache/phoenix/jdbc/PhoenixStatement.java | 10 +-
.../phoenix/parse/CreateIndexStatement.java | 10 +-
.../apache/phoenix/parse/ParseNodeFactory.java | 5 +-
.../query/ConnectionQueryServicesImpl.java | 5 +-
.../apache/phoenix/query/QueryConstants.java | 4 +-
.../apache/phoenix/schema/MetaDataClient.java | 73 ++++++++-----
.../java/org/apache/phoenix/schema/PTable.java | 37 +++++++
.../org/apache/phoenix/schema/PTableImpl.java | 36 +++++--
phoenix-protocol/src/main/PTable.proto | 1 +
pom.xml | 4 +-
20 files changed, 402 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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
new file mode 100644
index 0000000..4589259
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -0,0 +1,58 @@
+/*
+ * 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.index;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.PTableKey;
+import org.junit.Test;
+
+public class LocalIndexIT extends BaseIndexIT {
+ private void createBaseTable(String tableName, Integer saltBuckets) throws SQLException {
+ Connection conn = DriverManager.getConnection(getUrl());
+ String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" +
+ "k1 INTEGER NOT NULL,\n" +
+ "k2 INTEGER NOT NULL,\n" +
+ "v1 VARCHAR,\n" +
+ "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2))\n"
+ + (saltBuckets == null ? "" : (",salt_buckets="+saltBuckets));
+ conn.createStatement().execute(ddl);
+ conn.close();
+ }
+
+ @Test
+ public void testLocalIndexRoundTrip() throws Exception {
+ createBaseTable(DATA_TABLE_NAME, null);
+ Connection conn1 = DriverManager.getConnection(getUrl());
+ Connection conn2 = DriverManager.getConnection(getUrl());
+ conn1.createStatement().execute("CREATE LOCAL INDEX " + INDEX_TABLE_NAME + " ON " + DATA_TABLE_NAME + "(v1)");
+ conn2.createStatement().executeQuery("SELECT * FROM " + DATA_TABLE_FULL_NAME).next();
+ PTable localIndex = conn2.unwrap(PhoenixConnection.class).getMetaDataCache().getTable(new PTableKey(null,INDEX_TABLE_NAME));
+ assertEquals(IndexType.LOCAL, localIndex.getIndexType());
+ assertNotNull(localIndex.getViewIndexId());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 4f1d107..0cf2e04 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -98,7 +98,7 @@ tokens
VALUE='value';
FOR='for';
CACHE='cache';
- DERIVE='derive';
+ LOCAL='local';
}
@@ -141,6 +141,7 @@ import org.apache.phoenix.schema.IllegalDataException;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.PIndexState;
import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.util.SchemaUtil;
}
@@ -378,12 +379,12 @@ create_view_node returns [CreateTableStatement ret]
// Parse a create index statement.
create_index_node returns [CreateIndexStatement ret]
- : CREATE INDEX (IF NOT ex=EXISTS)? i=index_name ON t=from_table_name
+ : CREATE l=LOCAL? INDEX (IF NOT ex=EXISTS)? i=index_name ON t=from_table_name
(LPAREN pk=index_pk_constraint RPAREN)
(INCLUDE (LPAREN icrefs=column_names RPAREN))?
(p=fam_properties)?
(SPLIT ON v=value_expression_list)?
- {ret = factory.createIndex(i, factory.namedTable(null,t), pk, icrefs, v, p, ex!=null, getBindCount()); }
+ {ret = factory.createIndex(i, factory.namedTable(null,t), pk, icrefs, v, p, ex!=null, l==null ? IndexType.getDefault() : IndexType.LOCAL, getBindCount()); }
;
// Parse a create sequence statement.
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateIndexCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateIndexCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateIndexCompiler.java
index 0c6b808..22b22e8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateIndexCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateIndexCompiler.java
@@ -32,6 +32,7 @@ import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.CreateIndexStatement;
import org.apache.phoenix.parse.ParseNode;
import org.apache.phoenix.schema.MetaDataClient;
+import org.apache.phoenix.schema.PTable.IndexType;
public class CreateIndexCompiler {
private final PhoenixStatement statement;
@@ -47,6 +48,10 @@ public class CreateIndexCompiler {
final StatementContext context = new StatementContext(statement, resolver, scan);
ExpressionCompiler expressionCompiler = new ExpressionCompiler(context);
List<ParseNode> splitNodes = create.getSplitNodes();
+ if (!splitNodes.isEmpty() && create.getIndexType() == IndexType.LOCAL) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_SPLIT_LOCAL_INDEX)
+ .build().buildException();
+ }
final byte[][] splits = new byte[splitNodes.size()][];
for (int i = 0; i < splits.length; i++) {
ParseNode node = splitNodes.get(i);
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 6136e4e..bc6ce93 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
@@ -665,7 +665,7 @@ public class JoinCompiler {
PTable t = PTableImpl.makePTable(table.getTenantId(), PNameFactory.newName(PROJECTED_TABLE_SCHEMA), table.getName(), PTableType.JOIN,
table.getIndexState(), table.getTimeStamp(), table.getSequenceNumber(), table.getPKName(),
retainPKColumns ? table.getBucketNum() : null, projectedColumns, table.getParentTableName(),
- table.getIndexes(), table.isImmutableRows(), Collections.<PName>emptyList(), null, null, table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId());
+ table.getIndexes(), table.isImmutableRows(), Collections.<PName>emptyList(), null, null, table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId(), table.getIndexType());
return new ProjectedPTableWrapper(t, columnNameMap, sourceExpressions);
}
@@ -1179,7 +1179,7 @@ public class JoinCompiler {
}
PTable t = 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(), left.getBucketNum(), merged,
- left.getParentTableName(), left.getIndexes(), left.isImmutableRows(), Collections.<PName>emptyList(), null, null, PTable.DEFAULT_DISABLE_WAL, left.isMultiTenant(), left.getViewType(), left.getViewIndexId());
+ left.getParentTableName(), left.getIndexes(), left.isImmutableRows(), Collections.<PName>emptyList(), null, null, PTable.DEFAULT_DISABLE_WAL, left.isMultiTenant(), left.getViewType(), left.getViewIndexId(), left.getIndexType());
ListMultimap<String, String> mergedMap = ArrayListMultimap.<String, String>create();
mergedMap.putAll(this.getColumnNameMap());
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 dcda21e..3f4892b 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
@@ -31,6 +31,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL_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_STATE_BYTES;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INDEX_TYPE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IS_VIEW_REFERENCED_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.LINK_TYPE_BYTES;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MULTI_TENANT_BYTES;
@@ -115,6 +116,7 @@ import org.apache.phoenix.schema.PIndexState;
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.LinkType;
import org.apache.phoenix.schema.PTable.ViewType;
import org.apache.phoenix.schema.PTableImpl;
@@ -169,6 +171,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private static final KeyValue MULTI_TENANT_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, MULTI_TENANT_BYTES);
private static final KeyValue VIEW_TYPE_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, VIEW_TYPE_BYTES);
private static final KeyValue VIEW_INDEX_ID_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, VIEW_INDEX_ID_BYTES);
+ private static final KeyValue INDEX_TYPE_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, INDEX_TYPE_BYTES);
private static final List<KeyValue> TABLE_KV_COLUMNS = Arrays.<KeyValue>asList(
TABLE_TYPE_KV,
TABLE_SEQ_NUM_KV,
@@ -183,7 +186,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
DISABLE_WAL_KV,
MULTI_TENANT_KV,
VIEW_TYPE_KV,
- VIEW_INDEX_ID_KV
+ VIEW_INDEX_ID_KV,
+ INDEX_TYPE_KV
);
static {
Collections.sort(TABLE_KV_COLUMNS, KeyValue.COMPARATOR);
@@ -202,6 +206,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
private static final int MULTI_TENANT_INDEX = TABLE_KV_COLUMNS.indexOf(MULTI_TENANT_KV);
private static final int VIEW_TYPE_INDEX = TABLE_KV_COLUMNS.indexOf(VIEW_TYPE_KV);
private static final int VIEW_INDEX_ID_INDEX = TABLE_KV_COLUMNS.indexOf(VIEW_INDEX_ID_KV);
+ private static final int INDEX_TYPE_INDEX = TABLE_KV_COLUMNS.indexOf(INDEX_TYPE_KV);
// KeyValues for Column
private static final KeyValue DECIMAL_DIGITS_KV = KeyValue.createFirstOnRow(ByteUtil.EMPTY_BYTE_ARRAY, TABLE_FAMILY_BYTES, DECIMAL_DIGITS_BYTES);
@@ -625,6 +630,8 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
ViewType viewType = viewTypeKv == null ? null : ViewType.fromSerializedValue(viewTypeKv.getValueArray()[viewTypeKv.getValueOffset()]);
Cell viewIndexIdKv = tableKeyValues[VIEW_INDEX_ID_INDEX];
Short viewIndexId = viewIndexIdKv == null ? null : (Short)MetaDataUtil.getViewIndexIdDataType().getCodec().decodeShort(viewIndexIdKv.getValueArray(), viewIndexIdKv.getValueOffset(), SortOrder.getDefault());
+ Cell indexTypeKv = tableKeyValues[INDEX_TYPE_INDEX];
+ IndexType indexType = indexTypeKv == null ? null : IndexType.fromSerializedValue(indexTypeKv.getValueArray()[indexTypeKv.getValueOffset()]);
List<PColumn> columns = Lists.newArrayListWithExpectedSize(columnCount);
List<PTable> indexes = new ArrayList<PTable>();
@@ -657,7 +664,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
return PTableImpl.makePTable(tenantId, schemaName, tableName, tableType, indexState, timeStamp,
tableSeqNum, pkName, saltBucketNum, columns, tableType == INDEX ? dataTableName : null,
indexes, isImmutableRows, physicalTables, defaultFamilyName, viewStatement, disableWAL,
- multiTenant, viewType, viewIndexId);
+ multiTenant, viewType, viewIndexId, indexType);
}
private PTable buildDeletedTable(byte[] key, ImmutableBytesPtr cacheKey, HRegion region,
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 ea4d135..ef0ece2 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
@@ -2514,6 +2514,16 @@ public final class PTableProtos {
* <code>optional int32 viewIndexId = 21;</code>
*/
int getViewIndexId();
+
+ // optional bytes indexType = 22;
+ /**
+ * <code>optional bytes indexType = 22;</code>
+ */
+ boolean hasIndexType();
+ /**
+ * <code>optional bytes indexType = 22;</code>
+ */
+ com.google.protobuf.ByteString getIndexType();
}
/**
* Protobuf type {@code PTable}
@@ -2689,6 +2699,11 @@ public final class PTableProtos {
viewIndexId_ = input.readInt32();
break;
}
+ case 178: {
+ bitField0_ |= 0x00020000;
+ indexType_ = input.readBytes();
+ break;
+ }
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -3171,6 +3186,22 @@ public final class PTableProtos {
return viewIndexId_;
}
+ // optional bytes indexType = 22;
+ public static final int INDEXTYPE_FIELD_NUMBER = 22;
+ private com.google.protobuf.ByteString indexType_;
+ /**
+ * <code>optional bytes indexType = 22;</code>
+ */
+ public boolean hasIndexType() {
+ return ((bitField0_ & 0x00020000) == 0x00020000);
+ }
+ /**
+ * <code>optional bytes indexType = 22;</code>
+ */
+ public com.google.protobuf.ByteString getIndexType() {
+ return indexType_;
+ }
+
private void initFields() {
schemaNameBytes_ = com.google.protobuf.ByteString.EMPTY;
tableNameBytes_ = com.google.protobuf.ByteString.EMPTY;
@@ -3193,6 +3224,7 @@ public final class PTableProtos {
physicalNames_ = java.util.Collections.emptyList();
tenantId_ = com.google.protobuf.ByteString.EMPTY;
viewIndexId_ = 0;
+ indexType_ = com.google.protobuf.ByteString.EMPTY;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -3323,6 +3355,9 @@ public final class PTableProtos {
if (((bitField0_ & 0x00010000) == 0x00010000)) {
output.writeInt32(21, viewIndexId_);
}
+ if (((bitField0_ & 0x00020000) == 0x00020000)) {
+ output.writeBytes(22, indexType_);
+ }
getUnknownFields().writeTo(output);
}
@@ -3421,6 +3456,10 @@ public final class PTableProtos {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(21, viewIndexId_);
}
+ if (((bitField0_ & 0x00020000) == 0x00020000)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(22, indexType_);
+ }
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
return size;
@@ -3537,6 +3576,11 @@ public final class PTableProtos {
result = result && (getViewIndexId()
== other.getViewIndexId());
}
+ result = result && (hasIndexType() == other.hasIndexType());
+ if (hasIndexType()) {
+ result = result && getIndexType()
+ .equals(other.getIndexType());
+ }
result = result &&
getUnknownFields().equals(other.getUnknownFields());
return result;
@@ -3634,6 +3678,10 @@ public final class PTableProtos {
hash = (37 * hash) + VIEWINDEXID_FIELD_NUMBER;
hash = (53 * hash) + getViewIndexId();
}
+ if (hasIndexType()) {
+ hash = (37 * hash) + INDEXTYPE_FIELD_NUMBER;
+ hash = (53 * hash) + getIndexType().hashCode();
+ }
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
@@ -3800,6 +3848,8 @@ public final class PTableProtos {
bitField0_ = (bitField0_ & ~0x00080000);
viewIndexId_ = 0;
bitField0_ = (bitField0_ & ~0x00100000);
+ indexType_ = com.google.protobuf.ByteString.EMPTY;
+ bitField0_ = (bitField0_ & ~0x00200000);
return this;
}
@@ -3928,6 +3978,10 @@ public final class PTableProtos {
to_bitField0_ |= 0x00010000;
}
result.viewIndexId_ = viewIndexId_;
+ if (((from_bitField0_ & 0x00200000) == 0x00200000)) {
+ to_bitField0_ |= 0x00020000;
+ }
+ result.indexType_ = indexType_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -4085,6 +4139,9 @@ public final class PTableProtos {
if (other.hasViewIndexId()) {
setViewIndexId(other.getViewIndexId());
}
+ if (other.hasIndexType()) {
+ setIndexType(other.getIndexType());
+ }
this.mergeUnknownFields(other.getUnknownFields());
return this;
}
@@ -5587,6 +5644,42 @@ public final class PTableProtos {
return this;
}
+ // optional bytes indexType = 22;
+ private com.google.protobuf.ByteString indexType_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * <code>optional bytes indexType = 22;</code>
+ */
+ public boolean hasIndexType() {
+ return ((bitField0_ & 0x00200000) == 0x00200000);
+ }
+ /**
+ * <code>optional bytes indexType = 22;</code>
+ */
+ public com.google.protobuf.ByteString getIndexType() {
+ return indexType_;
+ }
+ /**
+ * <code>optional bytes indexType = 22;</code>
+ */
+ public Builder setIndexType(com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00200000;
+ indexType_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional bytes indexType = 22;</code>
+ */
+ public Builder clearIndexType() {
+ bitField0_ = (bitField0_ & ~0x00200000);
+ indexType_ = getDefaultInstance().getIndexType();
+ onChanged();
+ return this;
+ }
+
// @@protoc_insertion_point(builder_scope:PTable)
}
@@ -5629,7 +5722,7 @@ public final class PTableProtos {
" \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\016viewReferenc" +
"ed\030\013 \001(\010\"*\n\013PTableStats\022\013\n\003key\030\001 \002(\t\022\016\n\006" +
- "values\030\002 \003(\014\"\367\003\n\006PTable\022\027\n\017schemaNameByt" +
+ "values\030\002 \003(\014\"\212\004\n\006PTable\022\027\n\017schemaNameByt" +
"es\030\001 \002(\014\022\026\n\016tableNameBytes\030\002 \002(\014\022\036\n\ttabl" +
"eType\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\ttimeStam" +
@@ -5641,11 +5734,11 @@ public final class PTableProtos {
"milyName\030\016 \001(\014\022\022\n\ndisableWAL\030\017 \002(\010\022\023\n\013mu" +
"ltiTenant\030\020 \002(\010\022\020\n\010viewType\030\021 \001(\014\022\025\n\rvie" +
"wStatement\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*A",
- "\n\nPTableType\022\n\n\006SYSTEM\020\000\022\010\n\004USER\020\001\022\010\n\004VI" +
- "EW\020\002\022\t\n\005INDEX\020\003\022\010\n\004JOIN\020\004B@\n(org.apache." +
- "phoenix.coprocessor.generatedB\014PTablePro" +
- "tosH\001\210\001\001\240\001\001"
+ "\020\n\010tenantId\030\024 \001(\014\022\023\n\013viewIndexId\030\025 \001(\005\022\021",
+ "\n\tindexType\030\026 \001(\014*A\n\nPTableType\022\n\n\006SYSTE" +
+ "M\020\000\022\010\n\004USER\020\001\022\010\n\004VIEW\020\002\022\t\n\005INDEX\020\003\022\010\n\004JO" +
+ "IN\020\004B@\n(org.apache.phoenix.coprocessor.g" +
+ "eneratedB\014PTableProtosH\001\210\001\001\240\001\001"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -5669,7 +5762,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", "GuidePosts", "DataTableNameBytes", "DefaultFamilyName", "DisableWAL", "MultiTenant", "ViewType", "ViewStatement", "PhysicalNames", "TenantId", "ViewIndexId", });
+ new java.lang.String[] { "SchemaNameBytes", "TableNameBytes", "TableType", "IndexState", "SequenceNumber", "TimeStamp", "PkNameBytes", "BucketNum", "Columns", "Indexes", "IsImmutableRows", "GuidePosts", "DataTableNameBytes", "DefaultFamilyName", "DisableWAL", "MultiTenant", "ViewType", "ViewStatement", "PhysicalNames", "TenantId", "ViewIndexId", "IndexType", });
return null;
}
};
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 d9e23f5..f74ae9d 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
@@ -210,7 +210,7 @@ public enum SQLExceptionCode {
INSUFFICIENT_MULTI_TENANT_COLUMNS(1040, "42Y96", "A MULTI_TENANT table must have two or more PK columns with the first column being NOT NULL and of type VARCHAR or CHAR."),
VIEW_WHERE_IS_CONSTANT(1045, "43A02", "WHERE clause in VIEW should not evaluate to a constant."),
CANNOT_UPDATE_VIEW_COLUMN(1046, "43A03", "Column updated in VIEW may not differ from value specified in WHERE clause."),
- TOO_MANY_VIEW_INDEXES(1047, "43A04", "Too many indexes have already been created on the physical table."),
+ TOO_MANY_INDEXES(1047, "43A04", "Too many indexes have already been created on the physical table."),
/** Sequence related */
SEQUENCE_ALREADY_EXIST(1200, "42Z00", "Sequence already exists.", new Factory() {
@@ -249,6 +249,8 @@ public enum SQLExceptionCode {
SPLIT_POINT_NOT_CONSTANT(1105, "XCL04", "Split points must be constants."),
BATCH_EXCEPTION(1106, "XCL05", "Exception while executing batch."),
EXECUTE_UPDATE_WITH_NON_EMPTY_BATCH(1107, "XCL06", "An executeUpdate is prohibited when the batch is not empty. Use clearBatch to empty the batch first."),
+ CANNOT_SPLIT_LOCAL_INDEX(1108,"XCL07", "Local index may not be pre-split"),
+ CANNOT_SALT_LOCAL_INDEX(1109,"XCL08", "Local index may not be salted"),
/**
* Implementation defined class. Phoenix internal error. (errorcode 20, sqlstate INT).
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 657f8fe..ffd790d 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
@@ -51,6 +51,7 @@ import org.apache.phoenix.expression.function.RoundDateExpression;
import org.apache.phoenix.expression.function.RoundDecimalExpression;
import org.apache.phoenix.expression.function.RoundFunction;
import org.apache.phoenix.expression.function.RoundTimestampExpression;
+import org.apache.phoenix.expression.function.SQLIndexTypeFunction;
import org.apache.phoenix.expression.function.SQLTableTypeFunction;
import org.apache.phoenix.expression.function.SQLViewTypeFunction;
import org.apache.phoenix.expression.function.SqlTypeNameFunction;
@@ -153,7 +154,9 @@ public enum ExpressionType {
ArrayLengthFunction(ArrayLengthFunction.class),
ArrayConstructorExpression(ArrayConstructorExpression.class),
SQLViewTypeFunction(SQLViewTypeFunction.class),
- ExternalSqlTypeIdFunction(ExternalSqlTypeIdFunction.class);
+ ExternalSqlTypeIdFunction(ExternalSqlTypeIdFunction.class),
+ SQLIndexTypeFunction(SQLIndexTypeFunction.class);
+
ExpressionType(Class<? extends Expression> clazz) {
this.clazz = clazz;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLIndexTypeFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLIndexTypeFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLIndexTypeFunction.java
new file mode 100644
index 0000000..617e977
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLIndexTypeFunction.java
@@ -0,0 +1,77 @@
+/*
+ * 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.function;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+
+/**
+ *
+ * Function used to get the SQL view type name from the serialized view type.
+ * Usage:
+ * SQLViewType('v') will return 'VIEW' based on
+ * {@link java.sql.DatabaseMetaData#getTableTypes()}
+ *
+ *
+ * @since 2.2
+ */
+@BuiltInFunction(name=SQLIndexTypeFunction.NAME, args= {
+ @Argument(allowedTypes=PDataType.UNSIGNED_TINYINT)} )
+public class SQLIndexTypeFunction extends ScalarFunction {
+ public static final String NAME = "SQLIndexType";
+
+ public SQLIndexTypeFunction() {
+ }
+
+ public SQLIndexTypeFunction(List<Expression> children) throws SQLException {
+ super(children);
+ }
+
+ @Override
+ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+ Expression child = children.get(0);
+ if (!child.evaluate(tuple, ptr)) {
+ return false;
+ }
+ if (ptr.getLength() == 0) {
+ return true;
+ }
+ IndexType viewType = IndexType.fromSerializedValue(ptr.get()[ptr.getOffset()]);
+ ptr.set(viewType.getBytes());
+ return true;
+ }
+
+ @Override
+ public PDataType getDataType() {
+ return PDataType.VARCHAR;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 7b2f6da..a4cf615 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
@@ -38,6 +38,7 @@ import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.expression.RowKeyColumnExpression;
import org.apache.phoenix.expression.function.ExternalSqlTypeIdFunction;
import org.apache.phoenix.expression.function.IndexStateNameFunction;
+import org.apache.phoenix.expression.function.SQLIndexTypeFunction;
import org.apache.phoenix.expression.function.SQLTableTypeFunction;
import org.apache.phoenix.expression.function.SQLViewTypeFunction;
import org.apache.phoenix.expression.function.SqlTypeNameFunction;
@@ -174,6 +175,8 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData, org.apache.pho
public static final byte[] MULTI_TENANT_BYTES = Bytes.toBytes(MULTI_TENANT);
public static final String VIEW_TYPE = "VIEW_TYPE";
public static final byte[] VIEW_TYPE_BYTES = Bytes.toBytes(VIEW_TYPE);
+ public static final String INDEX_TYPE = "INDEX_TYPE";
+ public static final byte[] INDEX_TYPE_BYTES = Bytes.toBytes(INDEX_TYPE);
public static final String LINK_TYPE = "LINK_TYPE";
public static final byte[] LINK_TYPE_BYTES = Bytes.toBytes(LINK_TYPE);
public static final String ARRAY_SIZE = "ARRAY_SIZE";
@@ -205,7 +208,7 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData, org.apache.pho
public static final String KEY_SEQ = "KEY_SEQ";
public static final byte[] KEY_SEQ_BYTES = Bytes.toBytes(KEY_SEQ);
public static final String SUPERTABLE_NAME = "SUPERTABLE_NAME";
-
+
public static final String TYPE_ID = "TYPE_ID";
private final PhoenixConnection connection;
@@ -855,7 +858,8 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData, org.apache.pho
SALT_BUCKETS + "," +
MULTI_TENANT + "," +
VIEW_STATEMENT + "," +
- SQLViewTypeFunction.NAME + "(" + VIEW_TYPE + ") AS " + VIEW_TYPE +
+ SQLViewTypeFunction.NAME + "(" + VIEW_TYPE + ") AS " + VIEW_TYPE + "," +
+ SQLIndexTypeFunction.NAME + "(" + INDEX_TYPE + ") AS " + INDEX_TYPE +
" from " + SYSTEM_CATALOG + " " + SYSTEM_CATALOG_ALIAS +
" where " + COLUMN_NAME + " is null" +
" and " + COLUMN_FAMILY + " is null");
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 ff1c953..ea6ffbe 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
@@ -100,6 +100,7 @@ import org.apache.phoenix.schema.MetaDataClient;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.PDatum;
import org.apache.phoenix.schema.PIndexState;
+import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.RowKeyValueAccessor;
import org.apache.phoenix.schema.SortOrder;
@@ -440,8 +441,8 @@ public class PhoenixStatement implements Statement, SQLCloseable, org.apache.pho
private static class ExecutableCreateIndexStatement extends CreateIndexStatement implements CompilableStatement {
public ExecutableCreateIndexStatement(NamedNode indexName, NamedTableNode dataTable, PrimaryKeyConstraint pkConstraint, List<ColumnName> includeColumns, List<ParseNode> splits,
- ListMultimap<String,Pair<String,Object>> props, boolean ifNotExists, int bindCount) {
- super(indexName, dataTable, pkConstraint, includeColumns, splits, props, ifNotExists, bindCount);
+ ListMultimap<String,Pair<String,Object>> props, boolean ifNotExists, IndexType indexType, int bindCount) {
+ super(indexName, dataTable, pkConstraint, includeColumns, splits, props, ifNotExists, indexType, bindCount);
}
@SuppressWarnings("unchecked")
@@ -721,8 +722,9 @@ public class PhoenixStatement implements Statement, SQLCloseable, org.apache.pho
}
@Override
- public CreateIndexStatement createIndex(NamedNode indexName, NamedTableNode dataTable, PrimaryKeyConstraint pkConstraint, List<ColumnName> includeColumns, List<ParseNode> splits, ListMultimap<String,Pair<String,Object>> props, boolean ifNotExists, int bindCount) {
- return new ExecutableCreateIndexStatement(indexName, dataTable, pkConstraint, includeColumns, splits, props, ifNotExists, bindCount);
+ public CreateIndexStatement createIndex(NamedNode indexName, NamedTableNode dataTable, PrimaryKeyConstraint pkConstraint, List<ColumnName> includeColumns, List<ParseNode> splits,
+ ListMultimap<String,Pair<String,Object>> props, boolean ifNotExists, IndexType indexType, int bindCount) {
+ return new ExecutableCreateIndexStatement(indexName, dataTable, pkConstraint, includeColumns, splits, props, ifNotExists, indexType, bindCount);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java
index cc2d971..f688ceb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/CreateIndexStatement.java
@@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.List;
import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.schema.PTable.IndexType;
import com.google.common.collect.ListMultimap;
@@ -32,10 +33,11 @@ public class CreateIndexStatement extends SingleTableStatement {
private final List<ParseNode> splitNodes;
private final ListMultimap<String,Pair<String,Object>> props;
private final boolean ifNotExists;
+ private final IndexType indexType;
public CreateIndexStatement(NamedNode indexTableName, NamedTableNode dataTable,
PrimaryKeyConstraint indexConstraint, List<ColumnName> includeColumns, List<ParseNode> splits,
- ListMultimap<String,Pair<String,Object>> props, boolean ifNotExists, int bindCount) {
+ ListMultimap<String,Pair<String,Object>> props, boolean ifNotExists, IndexType indexType, int bindCount) {
super(dataTable, bindCount);
this.indexTableName =TableName.create(dataTable.getName().getSchemaName(),indexTableName.getName());
this.indexConstraint = indexConstraint == null ? PrimaryKeyConstraint.EMPTY : indexConstraint;
@@ -43,6 +45,7 @@ public class CreateIndexStatement extends SingleTableStatement {
this.splitNodes = splits == null ? Collections.<ParseNode>emptyList() : splits;
this.props = props;
this.ifNotExists = ifNotExists;
+ this.indexType = indexType;
}
public PrimaryKeyConstraint getIndexConstraint() {
@@ -69,4 +72,9 @@ public class CreateIndexStatement extends SingleTableStatement {
return ifNotExists;
}
+
+ public IndexType getIndexType() {
+ return indexType;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 41f4c6c..7e2465c 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
@@ -41,6 +41,7 @@ import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo;
import org.apache.phoenix.parse.JoinTableNode.JoinType;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.PIndexState;
+import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TypeMismatchException;
@@ -264,8 +265,8 @@ public class ParseNodeFactory {
return new CreateTableStatement(tableName, props, columns, pkConstraint, splits, tableType, ifNotExists, baseTableName, tableTypeIdNode, bindCount);
}
- public CreateIndexStatement createIndex(NamedNode indexName, NamedTableNode dataTable, PrimaryKeyConstraint pkConstraint, List<ColumnName> includeColumns, List<ParseNode> splits, ListMultimap<String,Pair<String,Object>> props, boolean ifNotExists, int bindCount) {
- return new CreateIndexStatement(indexName, dataTable, pkConstraint, includeColumns, splits, props, ifNotExists, bindCount);
+ public CreateIndexStatement createIndex(NamedNode indexName, NamedTableNode dataTable, PrimaryKeyConstraint pkConstraint, List<ColumnName> includeColumns, List<ParseNode> splits, ListMultimap<String,Pair<String,Object>> props, boolean ifNotExists, IndexType indexType, int bindCount) {
+ return new CreateIndexStatement(indexName, dataTable, pkConstraint, includeColumns, splits, props, ifNotExists, indexType, bindCount);
}
public CreateSequenceStatement createSequence(TableName tableName, ParseNode startsWith, ParseNode incrementBy, ParseNode cacheSize, boolean ifNotExits, int bindCount){
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 1faf52f..bd7c9d4 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
@@ -1051,13 +1051,14 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
byte[] tableName = physicalTableName != null ? physicalTableName : SchemaUtil.getTableNameAsBytes(schemaBytes, tableBytes);
if ((tableType == PTableType.VIEW && physicalTableName != null) || (tableType != PTableType.VIEW && physicalTableName == null)) {
// For views this will ensure that metadata already exists
+ // For tables and indexes, this will create the metadata if it doesn't already exist
ensureTableCreated(tableName, tableType, tableProps, families, splits, true);
}
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
- if (tableType == PTableType.INDEX && physicalTableName != null) { // Index on view
+ if (tableType == PTableType.INDEX) { // Index on view
// Physical index table created up front for multi tenant
// TODO: if viewIndexId is Short.MIN_VALUE, then we don't need to attempt to create it
- if (!MetaDataUtil.isMultiTenant(m, kvBuilder, ptr)) {
+ if (physicalTableName != null && !MetaDataUtil.isMultiTenant(m, kvBuilder, ptr)) {
ensureViewIndexTableCreated(tenantIdBytes.length == 0 ? null : PNameFactory.newName(tenantIdBytes), physicalTableName, MetaDataUtil.getClientTimeStamp(m));
}
} else if (tableType == PTableType.TABLE && MetaDataUtil.isMultiTenant(m, kvBuilder, ptr)) { // Create view index table up front for multi tenant tables
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 06bccce..25f1bc8 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
@@ -36,8 +36,10 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IMMUTABLE_ROWS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INCREMENT_BY;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INDEX_STATE;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INDEX_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IS_AUTOINCREMENT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IS_NULLABLE;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IS_VIEW_REFERENCED;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.KEY_SEQ;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.LINK_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MULTI_TENANT;
@@ -70,7 +72,6 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TYPE_NAME;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TYPE_SEQUENCE;
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.IS_VIEW_REFERENCED;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_STATEMENT;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE;
@@ -206,6 +207,7 @@ public interface QueryConstants {
SCOPE_TABLE + " VARCHAR," +
SOURCE_DATA_TYPE + " SMALLINT," +
IS_AUTOINCREMENT + " VARCHAR," +
+ INDEX_TYPE + " UNSIGNED_TINYINT," +
"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" +
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 77e309a..6d02bad 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
@@ -33,6 +33,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DEFAULT_COLUMN_FAM
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DISABLE_WAL;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IMMUTABLE_ROWS;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INDEX_STATE;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.INDEX_TYPE;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.IS_VIEW_REFERENCED;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.KEY_SEQ;
import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.LINK_TYPE;
@@ -113,6 +114,7 @@ import org.apache.phoenix.parse.TableName;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTable.LinkType;
import org.apache.phoenix.schema.PTable.ViewType;
import org.apache.phoenix.util.ByteUtil;
@@ -151,8 +153,9 @@ public class MetaDataClient {
DISABLE_WAL + "," +
MULTI_TENANT + "," +
VIEW_TYPE + "," +
- VIEW_INDEX_ID +
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ VIEW_INDEX_ID + "," +
+ INDEX_TYPE +
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String CREATE_LINK =
"UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
TENANT_ID + "," +
@@ -419,7 +422,7 @@ public class MetaDataClient {
}
public MutationState createTable(CreateTableStatement statement, byte[][] splits, PTable parent, String viewStatement, ViewType viewType, byte[][] viewColumnConstants, BitSet isViewColumnReferenced) throws SQLException {
- PTable table = createTableInternal(statement, splits, parent, viewStatement, viewType, viewColumnConstants, isViewColumnReferenced, null);
+ PTable table = createTableInternal(statement, splits, parent, viewStatement, viewType, viewColumnConstants, isViewColumnReferenced, null, null);
if (table == null || table.getType() == PTableType.VIEW) {
return new MutationState(0,connection);
}
@@ -526,8 +529,8 @@ public class MetaDataClient {
TableRef tableRef = null;
PTable table = null;
boolean retry = true;
- Short viewIndexId = null;
- boolean allocateViewIndexId = false;
+ Short indexId = null;
+ boolean allocateIndexId = false;
while (true) {
try {
ColumnResolver resolver = FromCompiler.getResolverForMutation(statement, connection);
@@ -568,8 +571,13 @@ public class MetaDataClient {
allPkColumns.add(new Pair<ColumnName, SortOrder>(colName, col.getSortOrder()));
columnDefs.add(FACTORY.columnDef(colName, dataType.getSqlTypeName(), col.isNullable(), col.getMaxLength(), col.getScale(), false, SortOrder.getDefault()));
}
- if (dataTable.getType() == PTableType.VIEW && dataTable.getViewType() != ViewType.MAPPED) {
- allocateViewIndexId = true;
+ /*
+ * Allocate an index ID in two circumstances:
+ * 1) for a local index, as all local indexes will reside in the same HBase table
+ * 2) for a view on an index.
+ */
+ if (statement.getIndexType() == IndexType.LOCAL || (dataTable.getType() == PTableType.VIEW && dataTable.getViewType() != ViewType.MAPPED)) {
+ allocateIndexId = true;
// Next add index ID column
PDataType dataType = MetaDataUtil.getViewIndexIdDataType();
ColumnName colName = ColumnName.caseSensitiveColumnName(MetaDataUtil.getViewIndexIdColumnName());
@@ -626,9 +634,9 @@ public class MetaDataClient {
}
}
- // Don't re-allocate viewIndexId on ConcurrentTableMutationException,
+ // Don't re-allocate indexId on ConcurrentTableMutationException,
// as there's no need to burn another sequence value.
- if (allocateViewIndexId && viewIndexId == null) {
+ if (allocateIndexId && indexId == null) {
Long scn = connection.getSCN();
long timestamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
PName tenantId = connection.getTenantId();
@@ -646,10 +654,10 @@ public class MetaDataClient {
}
long seqValue = seqValues[0];
if (seqValue > Short.MAX_VALUE) {
- throw new SQLExceptionInfo.Builder(SQLExceptionCode.TOO_MANY_VIEW_INDEXES)
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.TOO_MANY_INDEXES)
.setSchemaName(SchemaUtil.getSchemaNameFromFullName(physicalName.getString())).setTableName(SchemaUtil.getTableNameFromFullName(physicalName.getString())).build().buildException();
}
- viewIndexId = (short) seqValue;
+ indexId = (short) seqValue;
}
// Set DEFAULT_COLUMN_FAMILY_NAME of index to match data table
// We need this in the props so that the correct column family is created
@@ -657,7 +665,7 @@ public class MetaDataClient {
statement.getProps().put("", new Pair<String,Object>(DEFAULT_COLUMN_FAMILY_NAME,dataTable.getDefaultFamilyName().getString()));
}
CreateTableStatement tableStatement = FACTORY.createTable(indexTableName, statement.getProps(), columnDefs, pk, statement.getSplitNodes(), PTableType.INDEX, statement.ifNotExists(), null, null, statement.getBindCount());
- table = createTableInternal(tableStatement, splits, dataTable, null, null, null, null, viewIndexId);
+ table = createTableInternal(tableStatement, splits, dataTable, null, null, null, null, indexId, statement.getIndexType());
break;
} catch (ConcurrentTableMutationException e) { // Can happen if parent data table changes while above is in progress
if (retry) {
@@ -725,7 +733,7 @@ public class MetaDataClient {
return null;
}
- private PTable createTableInternal(CreateTableStatement statement, byte[][] splits, final PTable parent, String viewStatement, ViewType viewType, final byte[][] viewColumnConstants, final BitSet isViewColumnReferenced, Short viewIndexId) throws SQLException {
+ private PTable createTableInternal(CreateTableStatement statement, byte[][] splits, final PTable parent, String viewStatement, ViewType viewType, final byte[][] viewColumnConstants, final BitSet isViewColumnReferenced, Short indexId, IndexType indexType) throws SQLException {
final PTableType tableType = statement.getTableType();
boolean wasAutoCommit = connection.getAutoCommit();
connection.rollback();
@@ -751,10 +759,10 @@ public class MetaDataClient {
// 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
// from the table to the index, though.
- if (parent.getType() == PTableType.VIEW && parent.getViewType() != ViewType.MAPPED) {
+ if (indexType == IndexType.LOCAL || (parent.getType() == PTableType.VIEW && parent.getViewType() != ViewType.MAPPED)) {
PName physicalName = parent.getPhysicalName();
saltBucketNum = parent.getBucketNum();
- addSaltColumn = (saltBucketNum != null);
+ addSaltColumn = (saltBucketNum != null && indexType != IndexType.LOCAL);
defaultFamilyName = parent.getDefaultFamilyName() == null ? null : parent.getDefaultFamilyName().getString();
// Set physical name of view index table
physicalNames = Collections.singletonList(PNameFactory.newName(MetaDataUtil.getViewIndexPhysicalName(physicalName.getBytes())));
@@ -824,10 +832,12 @@ public class MetaDataClient {
}
// Can't set any of these on views or shared indexes on views
- if (tableType != PTableType.VIEW && viewIndexId == null) {
+ if (tableType != PTableType.VIEW && indexId == null) {
saltBucketNum = (Integer) tableProps.remove(PhoenixDatabaseMetaData.SALT_BUCKETS);
- if (saltBucketNum != null && (saltBucketNum < 0 || saltBucketNum > SaltingUtil.MAX_BUCKET_NUM)) {
- throw new SQLExceptionInfo.Builder(SQLExceptionCode.INVALID_BUCKET_NUM).build().buildException();
+ if (saltBucketNum != null) {
+ if (saltBucketNum < 0 || saltBucketNum > SaltingUtil.MAX_BUCKET_NUM) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.INVALID_BUCKET_NUM).build().buildException();
+ }
}
// Salt the index table if the data table is salted
if (saltBucketNum == null) {
@@ -858,7 +868,11 @@ public class MetaDataClient {
disableWAL = disableWALProp;
}
// Delay this check as it is supported to have IMMUTABLE_ROWS and SALT_BUCKETS defined on views
- if ((statement.getTableType() == PTableType.VIEW || viewIndexId != null) && !tableProps.isEmpty()) {
+ if ((statement.getTableType() == PTableType.VIEW || indexId != null) && !tableProps.isEmpty()) {
+ // TODO: do this check in CreateIndexCompiler
+ if (indexType == IndexType.LOCAL && saltBucketNum != null) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_SALT_LOCAL_INDEX).build().buildException();
+ }
throw new SQLExceptionInfo.Builder(SQLExceptionCode.VIEW_WITH_PROPERTIES).build().buildException();
}
if (removedProp) {
@@ -869,7 +883,7 @@ public class MetaDataClient {
List<PColumn> columns;
LinkedHashSet<PColumn> pkColumns;
- if (tenantId != null && (tableType != PTableType.VIEW && viewIndexId == null)) {
+ if (tenantId != null && (tableType != PTableType.VIEW && indexId == null)) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_TENANT_SPECIFIC_TABLE)
.setSchemaName(schemaName).setTableName(tableName).build().buildException();
}
@@ -1047,9 +1061,9 @@ public class MetaDataClient {
null, MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM,
PNameFactory.newName(QueryConstants.SYSTEM_TABLE_PK_NAME), null, columns, null, Collections.<PTable>emptyList(),
isImmutableRows, Collections.<PName>emptyList(),
- defaultFamilyName == null ? null : PNameFactory.newName(defaultFamilyName), null, Boolean.TRUE.equals(disableWAL), false, null, viewIndexId);
+ defaultFamilyName == null ? null : PNameFactory.newName(defaultFamilyName), null, Boolean.TRUE.equals(disableWAL), false, null, indexId, indexType);
connection.addTable(table);
- } else if (tableType == PTableType.INDEX && viewIndexId == null) {
+ } else if (tableType == PTableType.INDEX && indexId == null) {
if (tableProps.get(HTableDescriptor.MAX_FILESIZE) == null) {
int nIndexRowKeyColumns = isPK ? 1 : pkColumnsNames.size();
int nIndexKeyValueColumns = columns.size() - nIndexRowKeyColumns;
@@ -1133,10 +1147,15 @@ public class MetaDataClient {
} else {
tableUpsert.setByte(16, viewType.getSerializedValue());
}
- if (viewIndexId == null) {
+ if (indexId == null) {
tableUpsert.setNull(17, Types.SMALLINT);
} else {
- tableUpsert.setShort(17, viewIndexId);
+ tableUpsert.setShort(17, indexId);
+ }
+ if (indexType == null) {
+ tableUpsert.setNull(18, Types.TINYINT);
+ } else {
+ tableUpsert.setByte(18, indexType.getSerializedValue());
}
tableUpsert.execute();
@@ -1155,7 +1174,7 @@ public class MetaDataClient {
QueryServices.ROW_KEY_ORDER_SALTED_TABLE_ATTRIB, QueryServicesOptions.DEFAULT_ROW_KEY_ORDER_SALTED_TABLE));
MetaDataMutationResult result = connection.getQueryServices().createTable(
tableMetaData,
- viewType == ViewType.MAPPED || viewIndexId != null ? physicalNames.get(0).getBytes() : null,
+ viewType == ViewType.MAPPED || indexId != null ? physicalNames.get(0).getBytes() : null,
tableType, tableProps, familyPropList, splits);
MutationCode code = result.getMutationCode();
switch(code) {
@@ -1180,7 +1199,7 @@ public class MetaDataClient {
tenantId, PNameFactory.newName(schemaName), PNameFactory.newName(tableName), tableType, indexState, result.getMutationTime(),
PTable.INITIAL_SEQ_NUM, pkName == null ? null : PNameFactory.newName(pkName), saltBucketNum, columns,
dataTableName == null ? null : PNameFactory.newName(dataTableName), Collections.<PTable>emptyList(), isImmutableRows, physicalNames,
- defaultFamilyName == null ? null : PNameFactory.newName(defaultFamilyName), viewStatement, Boolean.TRUE.equals(disableWAL), multiTenant, viewType, viewIndexId);
+ defaultFamilyName == null ? null : PNameFactory.newName(defaultFamilyName), viewStatement, Boolean.TRUE.equals(disableWAL), multiTenant, viewType, indexId, indexType);
connection.addTable(table);
return table;
}
@@ -1261,12 +1280,10 @@ public class MetaDataClient {
Long scn = connection.getSCN();
long clientTimeStamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
List<Mutation> tableMetaData = Lists.newArrayListWithExpectedSize(2);
- @SuppressWarnings("deprecation") // FIXME: Remove when unintentionally deprecated method is fixed (HBASE-7870).
Delete tableDelete = new Delete(key, clientTimeStamp);
tableMetaData.add(tableDelete);
if (parentTableName != null) {
byte[] linkKey = MetaDataUtil.getParentLinkKey(tenantIdStr, schemaName, parentTableName, tableName);
- @SuppressWarnings("deprecation") // FIXME: Remove when unintentionally deprecated method is fixed (HBASE-7870).
Delete linkDelete = new Delete(linkKey, clientTimeStamp);
tableMetaData.add(linkDelete);
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 74a9373..cbf0dad 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
@@ -80,6 +80,42 @@ public interface PTable {
}
}
+ public enum IndexType {
+ GLOBAL((byte)1),
+ LOCAL((byte)2);
+
+ private final byte[] byteValue;
+ private final byte serializedValue;
+
+ IndexType(byte serializedValue) {
+ this.serializedValue = serializedValue;
+ this.byteValue = Bytes.toBytes(this.name());
+ }
+
+ public byte[] getBytes() {
+ return byteValue;
+ }
+
+ public byte getSerializedValue() {
+ return this.serializedValue;
+ }
+
+ public static IndexType getDefault() {
+ return GLOBAL;
+ }
+
+ public static IndexType fromToken(String token) {
+ return IndexType.valueOf(token.trim().toUpperCase());
+ }
+
+ public static IndexType fromSerializedValue(byte serializedValue) {
+ if (serializedValue < 1 || serializedValue > IndexType.values().length) {
+ throw new IllegalArgumentException("Invalid IndexType " + serializedValue);
+ }
+ return IndexType.values()[serializedValue-1];
+ }
+ }
+
public enum LinkType {
/**
* Link from a table to its index table
@@ -279,4 +315,5 @@ public interface PTable {
PTableKey getKey();
int getEstimatedSize();
+ IndexType getIndexType();
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/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 07d9781..709882a 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
@@ -115,6 +115,7 @@ public class PTableImpl implements PTable {
private ViewType viewType;
private Short viewIndexId;
private int estimatedSize;
+ private IndexType indexType;
public PTableImpl() {
}
@@ -172,28 +173,28 @@ public class PTableImpl implements PTable {
return new PTableImpl(
table.getTenantId(), table.getSchemaName(), table.getTableName(), table.getType(), table.getIndexState(), timeStamp,
table.getSequenceNumber() + 1, table.getPKName(), table.getBucketNum(), getColumnsToClone(table), table.getParentTableName(), indexes,
- table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId());
+ table.isImmutableRows(), table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId(), table.getIndexType());
}
public static PTableImpl makePTable(PTable table, List<PColumn> columns) throws SQLException {
return new PTableImpl(
table.getTenantId(), table.getSchemaName(), table.getTableName(), table.getType(), table.getIndexState(), table.getTimeStamp(),
table.getSequenceNumber(), table.getPKName(), table.getBucketNum(), columns, table.getParentTableName(), table.getIndexes(), table.isImmutableRows(),
- table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId());
+ table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId(), table.getIndexType());
}
public static PTableImpl makePTable(PTable table, long timeStamp, long sequenceNumber, List<PColumn> columns) throws SQLException {
return new PTableImpl(
table.getTenantId(), table.getSchemaName(), table.getTableName(), table.getType(), table.getIndexState(), timeStamp,
sequenceNumber, table.getPKName(), table.getBucketNum(), columns, table.getParentTableName(), table.getIndexes(), table.isImmutableRows(),
- table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId());
+ table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId(), table.getIndexType());
}
public static PTableImpl makePTable(PTable table, long timeStamp, long sequenceNumber, List<PColumn> columns, boolean isImmutableRows) throws SQLException {
return new PTableImpl(
table.getTenantId(), table.getSchemaName(), table.getTableName(), table.getType(), table.getIndexState(), timeStamp,
sequenceNumber, table.getPKName(), table.getBucketNum(), columns, table.getParentTableName(), table.getIndexes(),
- isImmutableRows, table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId());
+ isImmutableRows, table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId(), table.getIndexType());
}
public static PTableImpl makePTable(PTable table, PIndexState state) throws SQLException {
@@ -201,21 +202,21 @@ public class PTableImpl implements PTable {
table.getTenantId(), table.getSchemaName(), table.getTableName(), table.getType(), state, table.getTimeStamp(),
table.getSequenceNumber(), table.getPKName(), table.getBucketNum(), getColumnsToClone(table),
table.getParentTableName(), table.getIndexes(), table.isImmutableRows(),
- table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId());
+ table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(), table.isWALDisabled(), table.isMultiTenant(), table.getViewType(), table.getViewIndexId(), table.getIndexType());
}
public static PTableImpl makePTable(PName tenantId, PName schemaName, PName tableName, PTableType type, PIndexState state, long timeStamp, long sequenceNumber,
PName pkName, Integer bucketNum, List<PColumn> columns, PName dataTableName, List<PTable> indexes, boolean isImmutableRows,
- List<PName> physicalNames, PName defaultFamilyName, String viewExpression, boolean disableWAL, boolean multiTenant, ViewType viewType, Short viewIndexId) throws SQLException {
+ List<PName> physicalNames, PName defaultFamilyName, String viewExpression, boolean disableWAL, boolean multiTenant, ViewType viewType, Short viewIndexId, IndexType indexType) throws SQLException {
return new PTableImpl(tenantId, schemaName, tableName, type, state, timeStamp, sequenceNumber, pkName, bucketNum, columns, dataTableName,
- indexes, isImmutableRows, physicalNames, defaultFamilyName, viewExpression, disableWAL, multiTenant, viewType, viewIndexId);
+ indexes, isImmutableRows, physicalNames, defaultFamilyName, viewExpression, disableWAL, multiTenant, viewType, viewIndexId, indexType);
}
private PTableImpl(PName tenantId, PName schemaName, PName tableName, PTableType type, PIndexState state, long timeStamp, long sequenceNumber,
PName pkName, Integer bucketNum, List<PColumn> columns, PName dataTableName, List<PTable> indexes, boolean isImmutableRows,
- List<PName> physicalNames, PName defaultFamilyName, String viewExpression, boolean disableWAL, boolean multiTenant, ViewType viewType, Short viewIndexId) throws SQLException {
+ List<PName> physicalNames, PName defaultFamilyName, String viewExpression, boolean disableWAL, boolean multiTenant, ViewType viewType, Short viewIndexId, IndexType indexType) throws SQLException {
init(tenantId, schemaName, tableName, type, state, timeStamp, sequenceNumber, pkName, bucketNum, columns,
- new PTableStatsImpl(), dataTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName, viewExpression, disableWAL, multiTenant, viewType, viewIndexId);
+ new PTableStatsImpl(), dataTableName, indexes, isImmutableRows, physicalNames, defaultFamilyName, viewExpression, disableWAL, multiTenant, viewType, viewIndexId, indexType);
}
@Override
@@ -237,7 +238,7 @@ public class PTableImpl implements PTable {
private void init(PName tenantId, PName schemaName, PName tableName, PTableType type, PIndexState state, long timeStamp, long sequenceNumber,
PName pkName, Integer bucketNum, List<PColumn> columns, PTableStats stats, PName parentTableName, List<PTable> indexes,
boolean isImmutableRows, List<PName> physicalNames, PName defaultFamilyName, String viewExpression, boolean disableWAL, boolean multiTenant,
- ViewType viewType, Short viewIndexId) throws SQLException {
+ ViewType viewType, Short viewIndexId, IndexType indexType) 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 +
@@ -264,6 +265,7 @@ public class PTableImpl implements PTable {
this.multiTenant = multiTenant;
this.viewType = viewType;
this.viewIndexId = viewIndexId;
+ this.indexType = indexType;
List<PColumn> pkColumns;
PColumn[] allColumns;
@@ -802,6 +804,11 @@ public class PTableImpl implements PTable {
return tenantId;
}
+ @Override
+ public IndexType getIndexType() {
+ return indexType;
+ }
+
/**
* Construct a PTable instance from ProtoBuffered PTable instance
* @param table
@@ -822,6 +829,10 @@ public class PTableImpl implements PTable {
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();
PName pkName = null;
@@ -877,7 +888,7 @@ public class PTableImpl implements PTable {
PTableImpl result = new PTableImpl();
result.init(tenantId, schemaName, tableName, tableType, indexState, timeStamp, sequenceNumber, pkName,
(bucketNum == NO_SALTING) ? null : bucketNum, columns, stats, dataTableName,indexes, isImmutableRows,
- physicalNames, defaultFamilyName, viewStatement, disableWAL, multiTenant, viewType, viewIndexId);
+ physicalNames, defaultFamilyName, viewStatement, disableWAL, multiTenant, viewType, viewIndexId, indexType);
return result;
} catch (SQLException e) {
throw new RuntimeException(e); // Impossible
@@ -899,6 +910,9 @@ public class PTableImpl implements PTable {
if(table.getViewIndexId() != null) {
builder.setViewIndexId(table.getViewIndexId());
}
+ if(table.getIndexType() != null) {
+ builder.setIndexType(HBaseZeroCopyByteString.wrap(new byte[]{table.getIndexType().getSerializedValue()}));
+ }
}
builder.setSequenceNumber(table.getSequenceNumber());
builder.setTimeStamp(table.getTimeStamp());
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/phoenix-protocol/src/main/PTable.proto
----------------------------------------------------------------------
diff --git a/phoenix-protocol/src/main/PTable.proto b/phoenix-protocol/src/main/PTable.proto
index 96bb52e..20c63e1 100644
--- a/phoenix-protocol/src/main/PTable.proto
+++ b/phoenix-protocol/src/main/PTable.proto
@@ -73,4 +73,5 @@ message PTable {
repeated bytes physicalNames = 19;
optional bytes tenantId = 20;
optional int32 viewIndexId = 21;
+ optional bytes indexType = 22;
}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/73e1c086/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 37bb269..f16e0eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,8 +67,8 @@
<test.output.tofile>true</test.output.tofile>
<!-- Hadoop Versions -->
- <hbase-hadoop1.version>0.99.0-hadoop1-SNAPSHOT</hbase-hadoop1.version>
- <hbase-hadoop2.version>0.99.0-hadoop2-SNAPSHOT</hbase-hadoop2.version>
+ <hbase-hadoop1.version>0.98.1-hadoop1</hbase-hadoop1.version>
+ <hbase-hadoop2.version>0.98.1-hadoop2</hbase-hadoop2.version>
<hadoop-one.version>1.0.4</hadoop-one.version>
<hadoop-two.version>2.2.0</hadoop-two.version>