[7/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix
http://git-wip-us.apache.org/repos/asf/phoenix/blob/de9a2c7b/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 4246229..2d79f36 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 @@ -30,6 +30,8 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Properties; @@ -72,19 +74,38 @@ import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.MetaDataUtil; import org.apache.phoenix.util.QueryUtil; import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SchemaUtil; import org.apache.phoenix.util.StringUtil; import org.apache.phoenix.util.TestUtil; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.google.common.collect.Maps; +@RunWith(Parameterized.class) public class LocalIndexIT extends BaseHBaseManagedTimeIT { private static CountDownLatch latch1 = new CountDownLatch(1); private static CountDownLatch latch2 = new CountDownLatch(1); private static final int WAIT_TIME_SECONDS = 60; +private String schemaName="TEST"; +private boolean isNamespaceMapped; +private String tableName = schemaName + ".T"; +private String indexTableName = schemaName + ".I"; +private String indexName = "I"; +private String indexPhysicalTableName; +private TableName physicalTableName; +public LocalIndexIT(boolean isNamespaceMapped) { +this.isNamespaceMapped = isNamespaceMapped; +this.physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); +this.indexPhysicalTableName = Bytes + .toString(MetaDataUtil.getLocalIndexPhysicalName(physicalTableName.getName())); +} + @BeforeClass @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class) public static void doSetup() throws Exception { @@ -96,7 +117,10 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT { } private void createBaseTable(String tableName, Integer saltBuckets, String splits) throws SQLException { -Connection conn = DriverManager.getConnection(getUrl()); +Connection conn = getConnection(); +if (isNamespaceMapped) { +conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + schemaName); +} String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" + "k1 INTEGER NOT NULL,\n" + "k2 INTEGER NOT NULL,\n" + @@ -108,79 +132,94 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT { conn.createStatement().execute(ddl); conn.close(); } - + +@Parameters(name = "isNamespaceMapped = {0}") +public static Collection data() { +return Arrays.asList(true, false); +} + @Test public void testLocalIndexRoundTrip() throws Exception { -createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null); +createBaseTable(tableName, null, null); Connection conn1 = DriverManager.getConnection(getUrl()); -conn1.createStatement().execute("CREATE LOCAL INDEX " + TestUtil.DEFAULT_INDEX_TABLE_NAME + " ON " + TestUtil.DEFAULT_DATA_TABLE_NAME + "(v1)"); -conn1.createStatement().executeQuery("SELECT * FROM " + TestUtil.DEFAULT_DATA_TABLE_FULL_NAME).next(); -PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new PTableKey(null,TestUtil.DEFAULT_INDEX_TABLE_NAME)); +conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); +conn1.createStatement().executeQuery("SELECT * FROM " + tableName).next(); +PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, indexTableName)); assertEquals(IndexType.LOCAL, localIndex.getIndexType()); assertNotNull(localIndex.getViewIndexId()); } - + @Test public void testLocalIndexCreationWithSplitsShouldFail() throws Exception { -createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null); -Connection conn1 = DriverManager.getConnection(getUrl()); -Connection conn2 = DriverManager.getConnection(getUrl()); +createBaseTable(tableName, null, null); +Connection conn1 = getConnection(); +Connection conn2 = getConnection(); try { -
[4/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix
http://git-wip-us.apache.org/repos/asf/phoenix/blob/de9a2c7b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PSchemaProtos.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PSchemaProtos.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PSchemaProtos.java new file mode 100644 index 000..d7dc720 --- /dev/null +++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PSchemaProtos.java @@ -0,0 +1,666 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: PSchema.proto + +package org.apache.phoenix.coprocessor.generated; + +public final class PSchemaProtos { + private PSchemaProtos() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + public interface PSchemaOrBuilder + extends com.google.protobuf.MessageOrBuilder { + +// required string schemaName = 1; +/** + * required string schemaName = 1; + */ +boolean hasSchemaName(); +/** + * required string schemaName = 1; + */ +java.lang.String getSchemaName(); +/** + * required string schemaName = 1; + */ +com.google.protobuf.ByteString +getSchemaNameBytes(); + +// required int64 timeStamp = 2; +/** + * required int64 timeStamp = 2; + */ +boolean hasTimeStamp(); +/** + * required int64 timeStamp = 2; + */ +long getTimeStamp(); + } + /** + * Protobuf type {@code PSchema} + */ + public static final class PSchema extends + com.google.protobuf.GeneratedMessage + implements PSchemaOrBuilder { +// Use PSchema.newBuilder() to construct. +private PSchema(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); +} +private PSchema(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + +private static final PSchema defaultInstance; +public static PSchema getDefaultInstance() { + return defaultInstance; +} + +public PSchema getDefaultInstanceForType() { + return defaultInstance; +} + +private final com.google.protobuf.UnknownFieldSet unknownFields; +@java.lang.Override +public final com.google.protobuf.UnknownFieldSet +getUnknownFields() { + return this.unknownFields; +} +private PSchema( +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_ |= 0x0001; + schemaName_ = input.readBytes(); + break; +} +case 16: { + bitField0_ |= 0x0002; + timeStamp_ = input.readInt64(); + 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.PSchemaProtos.internal_static_PSchema_descriptor; +} + +protected com.google.protobuf.GeneratedMessage.FieldAccessorTable +internalGetFieldAccessorTable() { + return org.apache.phoenix.coprocessor.generated.PSchemaProtos.internal_static_PSchema_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.apache.phoenix.coprocessor.generated.PSchemaProtos.PSchema.class, org.apache.phoenix.coprocessor.generated.PSchemaProtos.PSchema.Builder.class); +} + +public static com.google.protobuf.Parser PARSER = +new com.google.protobuf.AbstractParser() { + public PSchema parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite
[8/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix
PHOENIX-1311 HBase namespaces surfaced in phoenix Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/de9a2c7b Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/de9a2c7b Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/de9a2c7b Branch: refs/heads/master Commit: de9a2c7b0249cd5a1a75374aa5244d5ee076f3c1 Parents: 0490484 Author: Ankit SinghalAuthored: Thu Apr 14 15:11:03 2016 +0530 Committer: Ankit Singhal Committed: Thu Apr 14 15:11:03 2016 +0530 -- .../apache/phoenix/end2end/CreateSchemaIT.java | 83 + .../apache/phoenix/end2end/CreateTableIT.java | 70 +- .../apache/phoenix/end2end/DropSchemaIT.java| 110 + .../end2end/NamespaceSchemaMappingIT.java | 115 + .../phoenix/end2end/PhoenixRuntimeIT.java |2 +- .../end2end/QueryDatabaseMetaDataIT.java| 12 +- .../org/apache/phoenix/end2end/UpgradeIT.java | 87 + .../org/apache/phoenix/end2end/UseSchemaIT.java | 133 + .../java/org/apache/phoenix/end2end/ViewIT.java | 31 +- .../phoenix/end2end/index/LocalIndexIT.java | 450 +- .../end2end/index/MutableIndexFailureIT.java| 48 +- .../phoenix/end2end/index/ViewIndexIT.java | 57 +- .../org/apache/phoenix/tx/TxCheckpointIT.java |5 +- phoenix-core/src/main/antlr3/PhoenixSQL.g | 22 + .../ipc/controller/MetadataRpcController.java | 12 +- .../apache/phoenix/compile/ColumnResolver.java | 10 + .../phoenix/compile/CreateSchemaCompiler.java | 65 + .../apache/phoenix/compile/FromCompiler.java| 166 +- .../apache/phoenix/compile/JoinCompiler.java| 11 +- .../apache/phoenix/compile/PostDDLCompiler.java | 24 +- .../compile/TupleProjectionCompiler.java| 24 +- .../apache/phoenix/compile/UnionCompiler.java | 11 +- .../coprocessor/MetaDataEndpointImpl.java | 360 +- .../phoenix/coprocessor/MetaDataProtocol.java | 28 +- .../coprocessor/generated/MetaDataProtos.java | 4211 +++--- .../coprocessor/generated/PSchemaProtos.java| 666 +++ .../coprocessor/generated/PTableProtos.java | 104 +- .../phoenix/exception/SQLExceptionCode.java | 21 +- .../hbase/index/master/IndexMasterObserver.java |8 +- .../write/ParallelWriterIndexCommitter.java |2 +- .../TrackingParallelWriterIndexCommitter.java |2 +- .../index/PhoenixIndexFailurePolicy.java|8 +- .../phoenix/iterate/ChunkedResultIterator.java |6 +- .../phoenix/iterate/ParallelIterators.java |2 +- .../apache/phoenix/iterate/SerialIterators.java |2 +- .../apache/phoenix/jdbc/PhoenixConnection.java | 51 +- .../phoenix/jdbc/PhoenixDatabaseMetaData.java |8 +- .../apache/phoenix/jdbc/PhoenixStatement.java | 88 +- .../phoenix/mapreduce/AbstractBulkLoadTool.java | 15 +- .../phoenix/mapreduce/CsvBulkImportUtil.java|7 + .../mapreduce/MultiHfileOutputFormat.java |4 +- .../phoenix/mapreduce/index/IndexTool.java | 15 +- .../phoenix/parse/CreateSchemaStatement.java| 25 + .../phoenix/parse/DropSchemaStatement.java | 38 + .../java/org/apache/phoenix/parse/PSchema.java | 86 + .../apache/phoenix/parse/ParseNodeFactory.java | 12 + .../phoenix/parse/UseSchemaStatement.java | 19 + .../apache/phoenix/protobuf/ProtobufUtil.java | 16 +- .../phoenix/query/ConnectionQueryServices.java | 16 +- .../query/ConnectionQueryServicesImpl.java | 378 +- .../query/ConnectionlessQueryServicesImpl.java | 43 +- .../query/DelegateConnectionQueryServices.java | 43 +- .../apache/phoenix/query/MetaDataMutated.java |5 +- .../apache/phoenix/query/QueryConstants.java|7 + .../org/apache/phoenix/query/QueryServices.java |4 + .../phoenix/query/QueryServicesOptions.java | 11 +- .../apache/phoenix/schema/DelegateTable.java|5 + .../apache/phoenix/schema/MetaDataClient.java | 204 +- .../NewerSchemaAlreadyExistsException.java | 26 + .../org/apache/phoenix/schema/PMetaData.java|2 + .../apache/phoenix/schema/PMetaDataImpl.java| 51 +- .../java/org/apache/phoenix/schema/PTable.java |6 + .../org/apache/phoenix/schema/PTableImpl.java | 58 +- .../org/apache/phoenix/schema/PTableKey.java|2 + .../schema/SchemaAlreadyExistsException.java| 53 + .../phoenix/schema/SchemaNotFoundException.java | 52 + .../stats/StatisticsCollectorFactory.java |5 + .../phoenix/schema/stats/StatisticsWriter.java |6 +- .../java/org/apache/phoenix/util/IndexUtil.java |2 +- .../java/org/apache/phoenix/util/JDBCUtil.java |5 + .../org/apache/phoenix/util/MetaDataUtil.java | 106 +- .../org/apache/phoenix/util/PhoenixRuntime.java | 79 +- .../org/apache/phoenix/util/SchemaUtil.java | 141 +-
[7/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix
http://git-wip-us.apache.org/repos/asf/phoenix/blob/70f76539/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 4246229..2d79f36 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 @@ -30,6 +30,8 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Properties; @@ -72,19 +74,38 @@ import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.MetaDataUtil; import org.apache.phoenix.util.QueryUtil; import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SchemaUtil; import org.apache.phoenix.util.StringUtil; import org.apache.phoenix.util.TestUtil; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.google.common.collect.Maps; +@RunWith(Parameterized.class) public class LocalIndexIT extends BaseHBaseManagedTimeIT { private static CountDownLatch latch1 = new CountDownLatch(1); private static CountDownLatch latch2 = new CountDownLatch(1); private static final int WAIT_TIME_SECONDS = 60; +private String schemaName="TEST"; +private boolean isNamespaceMapped; +private String tableName = schemaName + ".T"; +private String indexTableName = schemaName + ".I"; +private String indexName = "I"; +private String indexPhysicalTableName; +private TableName physicalTableName; +public LocalIndexIT(boolean isNamespaceMapped) { +this.isNamespaceMapped = isNamespaceMapped; +this.physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); +this.indexPhysicalTableName = Bytes + .toString(MetaDataUtil.getLocalIndexPhysicalName(physicalTableName.getName())); +} + @BeforeClass @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class) public static void doSetup() throws Exception { @@ -96,7 +117,10 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT { } private void createBaseTable(String tableName, Integer saltBuckets, String splits) throws SQLException { -Connection conn = DriverManager.getConnection(getUrl()); +Connection conn = getConnection(); +if (isNamespaceMapped) { +conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + schemaName); +} String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" + "k1 INTEGER NOT NULL,\n" + "k2 INTEGER NOT NULL,\n" + @@ -108,79 +132,94 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT { conn.createStatement().execute(ddl); conn.close(); } - + +@Parameters(name = "isNamespaceMapped = {0}") +public static Collection data() { +return Arrays.asList(true, false); +} + @Test public void testLocalIndexRoundTrip() throws Exception { -createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null); +createBaseTable(tableName, null, null); Connection conn1 = DriverManager.getConnection(getUrl()); -conn1.createStatement().execute("CREATE LOCAL INDEX " + TestUtil.DEFAULT_INDEX_TABLE_NAME + " ON " + TestUtil.DEFAULT_DATA_TABLE_NAME + "(v1)"); -conn1.createStatement().executeQuery("SELECT * FROM " + TestUtil.DEFAULT_DATA_TABLE_FULL_NAME).next(); -PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new PTableKey(null,TestUtil.DEFAULT_INDEX_TABLE_NAME)); +conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); +conn1.createStatement().executeQuery("SELECT * FROM " + tableName).next(); +PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, indexTableName)); assertEquals(IndexType.LOCAL, localIndex.getIndexType()); assertNotNull(localIndex.getViewIndexId()); } - + @Test public void testLocalIndexCreationWithSplitsShouldFail() throws Exception { -createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null); -Connection conn1 = DriverManager.getConnection(getUrl()); -Connection conn2 = DriverManager.getConnection(getUrl()); +createBaseTable(tableName, null, null); +Connection conn1 = getConnection(); +Connection conn2 = getConnection(); try { -
[1/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix
Repository: phoenix Updated Branches: refs/heads/4.x-HBase-0.98 366e7a779 -> 7e432be79 http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/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 523f684..dbc65d4 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 @@ -41,7 +41,9 @@ import java.util.TreeSet; import javax.annotation.Nullable; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding; import org.apache.hadoop.hbase.util.Bytes; import org.apache.phoenix.exception.SQLExceptionCode; @@ -52,14 +54,19 @@ import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData; 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.AmbiguousColumnException; import org.apache.phoenix.schema.ColumnFamilyNotFoundException; import org.apache.phoenix.schema.ColumnNotFoundException; +import org.apache.phoenix.schema.MetaDataClient; import org.apache.phoenix.schema.PColumn; import org.apache.phoenix.schema.PColumnFamily; import org.apache.phoenix.schema.PDatum; import org.apache.phoenix.schema.PName; +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.RowKeySchema.RowKeySchemaBuilder; import org.apache.phoenix.schema.SaltingUtil; @@ -115,6 +122,10 @@ public class SchemaUtil { }; public static final RowKeySchema VAR_BINARY_SCHEMA = new RowKeySchemaBuilder(1).addField(VAR_BINARY_DATUM, false, SortOrder.getDefault()).build(); +public static final String SCHEMA_FOR_DEFAULT_NAMESPACE = "DEFAULT"; +public static final String HBASE_NAMESPACE = "HBASE"; +public static final List NOT_ALLOWED_SCHEMA_LIST = Arrays.asList(SCHEMA_FOR_DEFAULT_NAMESPACE, +HBASE_NAMESPACE); /** * May not be instantiated @@ -236,6 +247,12 @@ public class SchemaUtil { return ByteUtil.concat(tenantId, QueryConstants.SEPARATOR_BYTE_ARRAY, functionName); } +public static byte[] getKeyForSchema(String tenantId, String schemaName) { +return ByteUtil.concat(tenantId == null ? ByteUtil.EMPTY_BYTE_ARRAY : Bytes.toBytes(tenantId), +QueryConstants.SEPARATOR_BYTE_ARRAY, +schemaName == null ? ByteUtil.EMPTY_BYTE_ARRAY : Bytes.toBytes(schemaName)); +} + public static byte[] getTableKey(String tenantId, String schemaName, String tableName) { return ByteUtil.concat(tenantId == null ? ByteUtil.EMPTY_BYTE_ARRAY : Bytes.toBytes(tenantId), QueryConstants.SEPARATOR_BYTE_ARRAY, schemaName == null ? ByteUtil.EMPTY_BYTE_ARRAY : Bytes.toBytes(schemaName), QueryConstants.SEPARATOR_BYTE_ARRAY, Bytes.toBytes(tableName)); } @@ -253,6 +270,11 @@ public class SchemaUtil { return cf + QueryConstants.NAME_SEPARATOR + cq; } +private static String getName(String name, boolean caseSensitive) { +String cq = caseSensitive ? "\"" + name + "\"" : name; +return cq; +} + public static String getTableName(byte[] schemaName, byte[] tableName) { return getName(schemaName, tableName); } @@ -276,9 +298,13 @@ public class SchemaUtil { } return getName(familyName, columnName, false); } +if ((familyName == null || familyName.isEmpty()) && (columnName == null || columnName.isEmpty()) +&& (tableName == null || tableName.equals(MetaDataClient.EMPTY_TABLE))) { return getName(schemaName, +false); } if ((familyName == null || familyName.isEmpty()) && (columnName == null || columnName.isEmpty())) { return getName(schemaName, tableName, false); } + return getName(getName(schemaName, tableName, false), getName(familyName, columnName, false), false); } @@ -414,19 +440,24 @@ public class SchemaUtil { } public static boolean isMetaTable(byte[] tableName) { -return Bytes.compareTo(tableName, SYSTEM_CATALOG_NAME_BYTES) == 0; +return Bytes.compareTo(tableName, SYSTEM_CATALOG_NAME_BYTES) == 0 || Bytes.compareTo(tableName, +SchemaUtil.getPhysicalTableName(SYSTEM_CATALOG_NAME_BYTES, true).getName()) == 0; } public static boolean
[7/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix
http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/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 8c804bb..68fcae3 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 @@ -30,6 +30,8 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Properties; @@ -73,19 +75,38 @@ import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.MetaDataUtil; import org.apache.phoenix.util.QueryUtil; import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SchemaUtil; import org.apache.phoenix.util.StringUtil; import org.apache.phoenix.util.TestUtil; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import com.google.common.collect.Maps; +@RunWith(Parameterized.class) public class LocalIndexIT extends BaseHBaseManagedTimeIT { private static CountDownLatch latch1 = new CountDownLatch(1); private static CountDownLatch latch2 = new CountDownLatch(1); private static final int WAIT_TIME_SECONDS = 60; +private String schemaName="TEST"; +private boolean isNamespaceMapped; +private String tableName = schemaName + ".T"; +private String indexTableName = schemaName + ".I"; +private String indexName = "I"; +private String indexPhysicalTableName; +private TableName physicalTableName; +public LocalIndexIT(boolean isNamespaceMapped) { +this.isNamespaceMapped = isNamespaceMapped; +this.physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); +this.indexPhysicalTableName = Bytes + .toString(MetaDataUtil.getLocalIndexPhysicalName(physicalTableName.getName())); +} + @BeforeClass @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class) public static void doSetup() throws Exception { @@ -97,7 +118,10 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT { } private void createBaseTable(String tableName, Integer saltBuckets, String splits) throws SQLException { -Connection conn = DriverManager.getConnection(getUrl()); +Connection conn = getConnection(); +if (isNamespaceMapped) { +conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + schemaName); +} String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" + "k1 INTEGER NOT NULL,\n" + "k2 INTEGER NOT NULL,\n" + @@ -109,79 +133,94 @@ public class LocalIndexIT extends BaseHBaseManagedTimeIT { conn.createStatement().execute(ddl); conn.close(); } - + +@Parameters(name = "isNamespaceMapped = {0}") +public static Collection data() { +return Arrays.asList(true, false); +} + @Test public void testLocalIndexRoundTrip() throws Exception { -createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null); +createBaseTable(tableName, null, null); Connection conn1 = DriverManager.getConnection(getUrl()); -conn1.createStatement().execute("CREATE LOCAL INDEX " + TestUtil.DEFAULT_INDEX_TABLE_NAME + " ON " + TestUtil.DEFAULT_DATA_TABLE_NAME + "(v1)"); -conn1.createStatement().executeQuery("SELECT * FROM " + TestUtil.DEFAULT_DATA_TABLE_FULL_NAME).next(); -PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new PTableKey(null,TestUtil.DEFAULT_INDEX_TABLE_NAME)); +conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); +conn1.createStatement().executeQuery("SELECT * FROM " + tableName).next(); +PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, indexTableName)); assertEquals(IndexType.LOCAL, localIndex.getIndexType()); assertNotNull(localIndex.getViewIndexId()); } - + @Test public void testLocalIndexCreationWithSplitsShouldFail() throws Exception { -createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null); -Connection conn1 = DriverManager.getConnection(getUrl()); -Connection conn2 = DriverManager.getConnection(getUrl()); +createBaseTable(tableName, null, null); +Connection conn1 = getConnection(); +Connection conn2 = getConnection(); try { -
[6/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix
http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSchemaCompiler.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSchemaCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSchemaCompiler.java new file mode 100644 index 000..40d1fee --- /dev/null +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSchemaCompiler.java @@ -0,0 +1,65 @@ +/* + * 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.compile; + +import java.sql.SQLException; +import java.util.Collections; + +import org.apache.phoenix.execute.MutationState; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.jdbc.PhoenixStatement; +import org.apache.phoenix.parse.CreateSchemaStatement; +import org.apache.phoenix.schema.MetaDataClient; + +public class CreateSchemaCompiler { +private final PhoenixStatement statement; + +public CreateSchemaCompiler(PhoenixStatement statement) { +this.statement = statement; +} + +public MutationPlan compile(final CreateSchemaStatement create) throws SQLException { +final PhoenixConnection connection = statement.getConnection(); +final StatementContext context = new StatementContext(statement); +final MetaDataClient client = new MetaDataClient(connection); + +return new BaseMutationPlan(context, create.getOperation()) { + +@Override +public MutationState execute() throws SQLException { +try { +return client.createSchema(create); +} finally { +if (client.getConnection() != connection) { +client.getConnection().close(); +} +} +} + +@Override +public ExplainPlan getExplainPlan() throws SQLException { +return new ExplainPlan(Collections.singletonList("CREATE SCHEMA")); +} + +@Override +public StatementContext getContext() { +return context; +} +}; +} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/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 ffe9621..a2fc371 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 @@ -42,6 +42,7 @@ import org.apache.phoenix.parse.FamilyWildcardParseNode; import org.apache.phoenix.parse.JoinTableNode; import org.apache.phoenix.parse.NamedTableNode; import org.apache.phoenix.parse.PFunction; +import org.apache.phoenix.parse.PSchema; import org.apache.phoenix.parse.ParseNode; import org.apache.phoenix.parse.ParseNodeFactory; import org.apache.phoenix.parse.SelectStatement; @@ -51,6 +52,7 @@ import org.apache.phoenix.parse.TableNode; import org.apache.phoenix.parse.TableNodeVisitor; import org.apache.phoenix.parse.TableWildcardParseNode; import org.apache.phoenix.parse.UDFParseNode; +import org.apache.phoenix.parse.UseSchemaStatement; import org.apache.phoenix.parse.WildcardParseNode; import org.apache.phoenix.query.ConnectionQueryServices; import org.apache.phoenix.query.QueryConstants; @@ -73,6 +75,7 @@ import org.apache.phoenix.schema.PTableImpl; import org.apache.phoenix.schema.PTableKey; import org.apache.phoenix.schema.PTableType; import org.apache.phoenix.schema.ProjectedColumn; +import org.apache.phoenix.schema.SchemaNotFoundException; import org.apache.phoenix.schema.SortOrder; import org.apache.phoenix.schema.TableNotFoundException; import org.apache.phoenix.schema.TableRef; @@ -124,17 +127,36 @@ public class FromCompiler { public PFunction resolveFunction(String functionName) throws