phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject [8/8] phoenix git commit: PHOENIX-1311 HBase namespaces surfaced in phoenix
Date Thu, 14 Apr 2016 10:43:38 GMT
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/7e432be7
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/7e432be7
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/7e432be7

Branch: refs/heads/4.x-HBase-0.98
Commit: 7e432be79ff3f05143ef3bd86ac278c132d0ec15
Parents: 366e7a7
Author: Ankit Singhal <ankitsinghal59@gmail.com>
Authored: Thu Apr 14 16:09:55 2016 +0530
Committer: Ankit Singhal <ankitsinghal59@gmail.com>
Committed: Thu Apr 14 16:09:55 2016 +0530

----------------------------------------------------------------------
 .../apache/phoenix/end2end/CreateSchemaIT.java  |   83 +
 .../apache/phoenix/end2end/CreateTableIT.java   |   70 +-
 .../apache/phoenix/end2end/DropSchemaIT.java    |  110 +
 .../end2end/NamespaceSchemaMappingIT.java       |  117 +
 .../phoenix/end2end/PhoenixRuntimeIT.java       |    2 +-
 .../end2end/QueryDatabaseMetaDataIT.java        |   12 +-
 .../org/apache/phoenix/end2end/UpgradeIT.java   |   87 +
 .../org/apache/phoenix/end2end/UseSchemaIT.java |  134 +
 .../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       |  361 +-
 .../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  |   55 +-
 .../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  |   14 +-
 .../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 |    5 +
 .../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 +-
 .../org/apache/phoenix/util/UpgradeUtil.java    |  177 +
 .../phoenix/execute/CorrelatePlanTest.java      |    2 +-
 .../execute/LiteralResultIteratorPlanTest.java  |    2 +-
 .../java/org/apache/phoenix/query/BaseTest.java |   23 +-
 .../query/ParallelIteratorsSplitTest.java       |   11 +
 .../org/apache/phoenix/util/JDBCUtilTest.java   |    8 +
 phoenix-protocol/src/main/MetaDataService.proto |   39 +-
 phoenix-protocol/src/main/PSchema.proto         |   30 +
 phoenix-protocol/src/main/PTable.proto          |    1 +
 82 files changed, 7673 insertions(+), 1289 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateSchemaIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateSchemaIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateSchemaIT.java
new file mode 100644
index 0000000..4cf9eb4
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateSchemaIT.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.NewerSchemaAlreadyExistsException;
+import org.apache.phoenix.schema.SchemaAlreadyExistsException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.Test;
+
+public class CreateSchemaIT extends BaseClientManagedTimeIT {
+
+    @Test
+    public void testCreateSchema() throws Exception {
+        long ts = nextTimestamp();
+        Properties props = new Properties();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
+        String ddl = "CREATE SCHEMA TEST_SCHEMA";
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);
+                HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();)
{
+            conn.createStatement().execute(ddl);
+            assertNotNull(admin.getNamespaceDescriptor("TEST_SCHEMA"));
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute(ddl);
+            fail();
+        } catch (SchemaAlreadyExistsException e) {
+            // expected
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts - 20));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.createStatement().execute(ddl);
+            fail();
+        } catch (NewerSchemaAlreadyExistsException e) {
+            // expected
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 100));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            conn.createStatement().execute("CREATE SCHEMA " + SchemaUtil.SCHEMA_FOR_DEFAULT_NAMESPACE);
+            fail();
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.SCHEMA_NOT_ALLOWED.getErrorCode(), e.getErrorCode());
+        }
+        try {
+            conn.createStatement().execute("CREATE SCHEMA " + SchemaUtil.HBASE_NAMESPACE);
+            fail();
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.SCHEMA_NOT_ALLOWED.getErrorCode(), e.getErrorCode());
+        }
+        conn.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
index b0370e8..af25373 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
@@ -19,6 +19,8 @@ package org.apache.phoenix.end2end;
 
 import static org.apache.hadoop.hbase.HColumnDescriptor.DEFAULT_REPLICATION_SCOPE;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -35,9 +37,12 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.query.KeyRange;
+import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.NewerTableAlreadyExistsException;
+import org.apache.phoenix.schema.SchemaNotFoundException;
 import org.apache.phoenix.schema.TableAlreadyExistsException;
 import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.SchemaUtil;
 import org.junit.Test;
 
 
@@ -65,10 +70,12 @@ public class CreateTableIT extends BaseClientManagedTimeIT {
     @Test
     public void testCreateTable() throws Exception {
         long ts = nextTimestamp();
+        String schemaName = "TEST";
+        String tableName = schemaName + ".M_INTERFACE_JOB";
         Properties props = new Properties();
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
-        Connection conn = DriverManager.getConnection(getUrl(), props);
-        String ddl = "CREATE TABLE m_interface_job(                data.addtime VARCHAR ,\n"
+ 
+        
+        String ddl = "CREATE TABLE " + tableName + "(                data.addtime VARCHAR
,\n" + 
                 "                data.dir VARCHAR ,\n" + 
                 "                data.end_time VARCHAR ,\n" + 
                 "                data.file VARCHAR ,\n" + 
@@ -93,18 +100,41 @@ public class CreateTableIT extends BaseClientManagedTimeIT {
                 "                data.type VARCHAR ,\n" + 
                 "                id INTEGER not null primary key desc\n" + 
                 "                ) ";
-        conn.createStatement().execute(ddl);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute(ddl);
+        }
+        HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin();
+        assertNotNull(admin.getTableDescriptor(Bytes.toBytes(tableName)));
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
-        conn = DriverManager.getConnection(getUrl(), props);
-        try {
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
             conn.createStatement().execute(ddl);
             fail();
         } catch (TableAlreadyExistsException e) {
             // expected
         }
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
-        conn = DriverManager.getConnection(getUrl(), props);
-        conn.createStatement().execute("DROP TABLE m_interface_job");
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute("DROP TABLE " + tableName);
+        }
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.TRUE.toString());
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute("CREATE SCHEMA " + schemaName);
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute(ddl);
+            assertNotEquals(null,
+                    admin.getTableDescriptor(SchemaUtil.getPhysicalTableName(tableName.getBytes(),
true).getName()));
+        } finally {
+            admin.close();
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 50));
+        props.setProperty(QueryServices.DROP_METADATA_ATTRIB, Boolean.TRUE.toString());
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute("DROP TABLE " + tableName);
+        }
     }
 
     @Test
@@ -435,4 +465,30 @@ public class CreateTableIT extends BaseClientManagedTimeIT {
         }
         connAt20.close();
     }
+
+    @Test
+    public void testCreateTableWithoutSchema() throws Exception {
+        String createSchemaDDL = "CREATE SCHEMA T_SCHEMA";
+        String createTableDDL = "CREATE TABLE T_SCHEMA.TEST(pk INTEGER PRIMARY KEY)";
+        String dropTableDDL = "DROP TABLE T_SCHEMA.TEST";
+        Properties props = new Properties();
+        props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            try {
+                conn.createStatement().execute(createTableDDL);
+                fail();
+            } catch (SchemaNotFoundException snfe) {
+                //expected
+            }
+            conn.createStatement().execute(createSchemaDDL);
+            conn.createStatement().execute(createTableDDL);
+            conn.createStatement().execute(dropTableDDL);
+        }
+        props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(false));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute(createTableDDL);
+        } catch (SchemaNotFoundException e) {
+            fail();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropSchemaIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropSchemaIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropSchemaIT.java
new file mode 100644
index 0000000..665c0a8
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropSchemaIT.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.NamespaceDescriptor;
+import org.apache.hadoop.hbase.NamespaceNotFoundException;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.SchemaNotFoundException;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.Test;
+
+public class DropSchemaIT extends BaseClientManagedTimeIT {
+
+    @Test
+    public void testDropSchema() throws Exception {
+        long ts = nextTimestamp();
+        String schema = "TEST_SCHEMA";
+        String tableName = "TEST";
+        Properties props = new Properties();
+        String ddl = "DROP SCHEMA " + schema;
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
+        props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute("CREATE SCHEMA " + schema);
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute("CREATE TABLE " + schema + "." + tableName + "(id
INTEGER PRIMARY KEY)");
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 15));
+        HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+
+            try {
+                conn.createStatement().execute(ddl);
+                fail();
+            } catch (SQLException e) {
+                e.printStackTrace();
+                assertEquals(e.getErrorCode(), SQLExceptionCode.CANNOT_MUTATE_SCHEMA.getErrorCode());
+            }
+            assertNotNull(admin.getNamespaceDescriptor(schema));
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts - 20));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute(ddl);
+            fail();
+        } catch (SchemaNotFoundException e) {
+            // expected
+        }
+        assertNotNull(admin.getNamespaceDescriptor(schema));
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute("DROP TABLE " + schema + "." + tableName);
+            //Dropping table manually because Drop_meta_attrib is not working
+            admin.disableTable(TableName.valueOf(schema, tableName));
+            admin.deleteTable(TableName.valueOf(schema, tableName));
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 50));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute(ddl);
+            try {
+                admin.getNamespaceDescriptor(schema);
+                fail();
+            } catch (NamespaceNotFoundException ne) {
+                // expected
+            }
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            conn.createStatement().execute("DROP SCHEMA IF EXISTS " + schema);
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);) {
+            admin.createNamespace(NamespaceDescriptor.create(schema).build());
+            conn.createStatement().execute("DROP SCHEMA IF EXISTS " + schema);
+            assertNotNull(admin.getNamespaceDescriptor(schema));
+        }
+        admin.close();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/NamespaceSchemaMappingIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NamespaceSchemaMappingIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NamespaceSchemaMappingIT.java
new file mode 100644
index 0000000..43b62dd
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NamespaceSchemaMappingIT.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.NamespaceDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.Test;
+/*
+ * since 4.8
+ */
+public class NamespaceSchemaMappingIT extends BaseHBaseManagedTimeIT {
+    /**
+     * Tests that when: There is a table created with older version of phoenix and a table
created with newer version
+     * having {@code QueryServices#IS_NAMESPACE_MAPPING_ENABLED} true, then there is only
a flag
+     * {@code PhoenixDatabaseMetaData#IS_NAMESPACE_MAPPED} differentiates that whether schema
of the table is mapped to
+     * namespace or not
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testBackWardCompatibility() throws Exception {
+
+        String namespace = "TEST_SCHEMA";
+        String schemaName = namespace;
+        String tableName = "TEST";
+
+        String phoenixFullTableName = schemaName + "." + tableName;
+        String hbaseFullTableName = schemaName + ":" + tableName;
+        HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
+        admin.createNamespace(NamespaceDescriptor.create(namespace).build());
+        HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(namespace, tableName));
+        desc.addFamily(new HColumnDescriptor(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES));
+        admin.createTable(desc);
+        desc = new HTableDescriptor(TableName.valueOf(phoenixFullTableName));
+        desc.addFamily(new HColumnDescriptor(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES));
+        admin.createTable(desc);
+
+        Put put = new Put(PVarchar.INSTANCE.toBytes(phoenixFullTableName));
+        put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES,
+                QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
+        HTable phoenixSchematable = new HTable(admin.getConfiguration(), phoenixFullTableName);
+        phoenixSchematable.put(put);
+        phoenixSchematable.close();
+        put = new Put(PVarchar.INSTANCE.toBytes(hbaseFullTableName));
+        put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES,
+                QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
+        phoenixSchematable.close();
+        HTable namespaceMappedtable = new HTable(admin.getConfiguration(), hbaseFullTableName);
+        namespaceMappedtable.put(put);
+        namespaceMappedtable.close();
+        Properties props = new Properties();
+        props.setProperty(QueryServices.DROP_METADATA_ATTRIB, Boolean.TRUE.toString());
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        String ddl = "create table " + phoenixFullTableName + "(tableName varchar primary
key)";
+        conn.createStatement().execute(ddl);
+        String query = "select tableName from " + phoenixFullTableName;
+
+        ResultSet rs = conn.createStatement().executeQuery(query);
+        assertTrue(rs.next());
+        assertEquals(phoenixFullTableName, rs.getString(1));
+
+        HTable metatable = new HTable(admin.getConfiguration(),
+                SchemaUtil.getPhysicalName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES,
+                        (conn.unwrap(PhoenixConnection.class).getQueryServices().getProps())));
+        Put p = new Put(SchemaUtil.getTableKey(null, schemaName, tableName));
+        p.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.IS_NAMESPACE_MAPPED_BYTES,
+                PBoolean.INSTANCE.toBytes(true));
+        metatable.put(p);
+        metatable.close();
+
+        PhoenixConnection phxConn = (conn.unwrap(PhoenixConnection.class));
+        phxConn.getQueryServices().clearCache();
+        rs = conn.createStatement().executeQuery(query);
+        assertTrue(rs.next());
+        assertEquals(hbaseFullTableName, rs.getString(1));
+        admin.disableTable(phoenixFullTableName);
+        admin.deleteTable(phoenixFullTableName);
+        conn.createStatement().execute("DROP TABLE " + phoenixFullTableName);
+        admin.close();
+        conn.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
index 3cab7fa..3ba43e9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
@@ -143,5 +143,5 @@ public class PhoenixRuntimeIT extends BaseHBaseManagedTimeIT {
         assertTenantIds(e7, htable7, new FirstKeyOnlyFilter(), new String[] {"t1", "t2"}
);
         
     }
-
+    
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
index ba83e6a..f62bf0f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
@@ -174,12 +174,10 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT
{
 
     @Test
     public void testSchemaMetadataScan() throws SQLException {
-        long ts = nextTimestamp();
-        ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, null, ts);
-        ensureTableCreated(getUrl(), PTSDB_NAME, null, ts);
         Properties props = new Properties();
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 5));
+        props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
         Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement().execute("CREATE SCHEMA " + CUSTOM_ENTITY_DATA_SCHEMA_NAME);
         DatabaseMetaData dbmd = conn.getMetaData();
         ResultSet rs;
         rs = dbmd.getSchemas(null, CUSTOM_ENTITY_DATA_SCHEMA_NAME);
@@ -190,14 +188,8 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT
{
 
         rs = dbmd.getSchemas(null, null);
         assertTrue(rs.next());
-        assertEquals(rs.getString("TABLE_SCHEM"),null);
-        assertEquals(rs.getString("TABLE_CATALOG"),null);
-        assertTrue(rs.next());
         assertEquals(rs.getString("TABLE_SCHEM"),CUSTOM_ENTITY_DATA_SCHEMA_NAME);
         assertEquals(rs.getString("TABLE_CATALOG"),null);
-        assertTrue(rs.next());
-        assertEquals(rs.getString("TABLE_SCHEM"),PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA);
-        assertEquals(rs.getString("TABLE_CATALOG"),null);
         assertFalse(rs.next());
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
index 094816c..1c86039 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpgradeIT.java
@@ -26,20 +26,26 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Properties;
+import java.util.Set;
 
 import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.RowMutations;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.UpgradeUtil;
@@ -111,6 +117,86 @@ public class UpgradeIT extends BaseHBaseManagedTimeIT {
         testViewUpgrade(true, TENANT_ID, "SAMESCHEMA", "TABLEWITHVIEW5", "SAMESCHEMA", "VIEW5",
             ColumnDiff.LESS);
     }
+
+    @Test
+    public void testMapTableToNamespaceDuringUpgrade()
+            throws SQLException, IOException, IllegalArgumentException, InterruptedException
{
+        String[] strings = new String[] { "a", "b", "c", "d" };
+
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String schemaName = "TEST";
+            String phoenixFullTableName = schemaName + ".S_NEW";
+            String indexName = "IDX";
+            String localIndexName = "LIDX";
+            String[] tableNames = new String[] { phoenixFullTableName, schemaName + "." +
indexName,
+                    schemaName + "." + localIndexName, "diff.v", "test.v" };
+            conn.createStatement().execute("CREATE TABLE " + phoenixFullTableName
+                    + "(k VARCHAR PRIMARY KEY, v INTEGER, f INTEGER, g INTEGER NULL, h INTEGER
NULL)");
+            PreparedStatement upsertStmt = conn
+                    .prepareStatement("UPSERT INTO " + phoenixFullTableName + " VALUES(?,
?, 0, 0, 0)");
+            int i = 1;
+            for (String str : strings) {
+                upsertStmt.setString(1, str);
+                upsertStmt.setInt(2, i++);
+                upsertStmt.execute();
+            }
+            conn.commit();
+            // creating local index
+            conn.createStatement()
+                    .execute("create local index " + localIndexName + " on " + phoenixFullTableName
+ "(K)");
+            // creating global index
+            conn.createStatement().execute("create index " + indexName + " on " + phoenixFullTableName
+ "(k)");
+            // creating view in schema 'diff'
+            conn.createStatement().execute("CREATE VIEW diff.v (col VARCHAR) AS SELECT *
FROM " + phoenixFullTableName);
+            // creating view in schema 'test'
+            conn.createStatement().execute("CREATE VIEW test.v (col VARCHAR) AS SELECT *
FROM " + phoenixFullTableName);
+            // Creating index on views
+            conn.createStatement().execute("create index v_idx on diff.v(col)");
+            conn.createStatement().execute("create index v_idx on test.v(col)");
+
+            // validate data
+            for (String tableName : tableNames) {
+                ResultSet rs = conn.createStatement().executeQuery("select * from " + tableName);
+                for (String str : strings) {
+                    assertTrue(rs.next());
+                    assertEquals(str, rs.getString(1));
+                }
+            }
+
+            HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            assertTrue(admin.tableExists(phoenixFullTableName));
+            assertTrue(admin.tableExists(MetaDataUtil.getLocalIndexPhysicalName(Bytes.toBytes(phoenixFullTableName))));
+            assertTrue(admin.tableExists(schemaName + QueryConstants.NAME_SEPARATOR + indexName));
+            assertTrue(admin.tableExists(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(phoenixFullTableName))));
+            Properties props = new Properties();
+            props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
+            admin.close();
+            PhoenixConnection phxConn = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class);
+            UpgradeUtil.upgradeTable(phxConn, phoenixFullTableName);
+            Set<String> viewNames = MetaDataUtil.getViewNames(phxConn, phoenixFullTableName);
+            for (String viewName : viewNames) {
+                UpgradeUtil.upgradeTable(phxConn, viewName);
+            }
+            admin = phxConn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+            String hbaseTableName = SchemaUtil.getPhysicalTableName(Bytes.toBytes(phoenixFullTableName),
true)
+                    .getNameAsString();
+            assertTrue(admin.tableExists(hbaseTableName));
+            assertTrue(admin.tableExists(MetaDataUtil.getLocalIndexPhysicalName(Bytes.toBytes(hbaseTableName))));
+            assertTrue(admin.tableExists(schemaName + QueryConstants.NAMESPACE_SEPARATOR
+ indexName));
+            assertTrue(admin.tableExists(MetaDataUtil.getViewIndexPhysicalName(Bytes.toBytes(hbaseTableName))));
+            i = 0;
+            // validate data
+            for (String tableName : tableNames) {
+                ResultSet rs = phxConn.createStatement().executeQuery("select * from " +
tableName);
+                for (String str : strings) {
+                    assertTrue(rs.next());
+                    assertEquals(str, rs.getString(1));
+                }
+            }
+            phxConn.close();
+            admin.close();
+        }
+    }
     
     @Test
     public void testSettingBaseColumnCountForMultipleViewsOnTable() throws Exception {
@@ -329,4 +415,5 @@ public class UpgradeIT extends BaseHBaseManagedTimeIT {
         }
         return DriverManager.getConnection(getUrl());
     }
+    
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
new file mode 100644
index 0000000..793d165
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.NamespaceDescriptor;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.Test;
+
+public class UseSchemaIT extends BaseHBaseManagedTimeIT {
+
+    @Test
+    public void testUseSchema() throws Exception {
+        Properties props = new Properties();
+        props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        String ddl = "CREATE SCHEMA IF NOT EXISTS TEST_SCHEMA";
+        conn.createStatement().execute(ddl);
+        ddl = "create table test_schema.test(id varchar primary key)";
+        conn.createStatement().execute(ddl);
+        conn.createStatement().execute("use test_schema");
+        String query = "select count(*) from test";
+        ResultSet rs = conn.createStatement().executeQuery(query);
+        assertTrue(rs.next());
+        assertEquals(0, rs.getInt(1));
+        try {
+            conn.createStatement().execute("use test");
+            fail();
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.SCHEMA_NOT_FOUND.getErrorCode(), e.getErrorCode());
+        }
+        conn.createStatement().execute("use default");
+        ddl = "create table IF NOT EXISTS test(schema_name varchar primary key)";
+        conn.createStatement().execute(ddl);
+        conn.createStatement().executeUpdate("upsert into test values('"+SchemaUtil.SCHEMA_FOR_DEFAULT_NAMESPACE+"')");
+        conn.commit();
+        rs = conn.createStatement().executeQuery("select schema_name from test");
+        assertTrue(rs.next());
+        assertEquals(SchemaUtil.SCHEMA_FOR_DEFAULT_NAMESPACE, rs.getString(1));
+        conn.close();
+    }
+
+    @Test
+    public void testSchemaInJdbcUrl() throws Exception {
+        Properties props = new Properties();
+        String schema = "TEST_SCHEMA";
+        props.setProperty(QueryServices.SCHEMA_ATTRIB, schema);
+        props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.setAutoCommit(true);
+        String ddl = "CREATE SCHEMA IF NOT EXISTS " + schema;
+        conn.createStatement().execute(ddl);
+        ddl = "create table IF NOT EXISTS " + schema + ".test(schema_name varchar primary
key)";
+        conn.createStatement().execute(ddl);
+        conn.createStatement().executeUpdate("upsert into " + schema + ".test values('" +
schema + "')");
+        String query = "select schema_name from test";
+        ResultSet rs = conn.createStatement().executeQuery(query);
+        assertTrue(rs.next());
+        assertEquals(schema, rs.getString(1));
+
+        schema = "test";
+        ddl = "CREATE SCHEMA " + schema;
+        conn.createStatement().execute(ddl);
+        conn.createStatement().execute("use " + schema);
+        ddl = "create table test(schema_name varchar primary key)";
+        conn.createStatement().execute(ddl);
+        conn.createStatement().executeUpdate("upsert into test values('" + schema + "')");
+        rs = conn.createStatement().executeQuery("select schema_name from test");
+        assertTrue(rs.next());
+        assertEquals(schema, rs.getString(1));
+        conn.close();
+    }
+
+    @Test
+    public void testMappedView() throws Exception {
+        Properties props = new Properties();
+        String schema = "TEST_SCHEMA_V";
+        String tableName = "TEST";
+        String fullTablename = schema + QueryConstants.NAME_SEPARATOR + tableName;
+        props.setProperty(QueryServices.SCHEMA_ATTRIB, schema);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
+        admin.createNamespace(NamespaceDescriptor.create(schema).build());
+        HTableDescriptor desc = new HTableDescriptor(fullTablename);
+        desc.addFamily(new HColumnDescriptor(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES));
+        admin.createTable(desc);
+        Put put = new Put(PVarchar.INSTANCE.toBytes(fullTablename));
+        put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES,
+                QueryConstants.EMPTY_COLUMN_VALUE_BYTES);
+        HTable phoenixSchematable = new HTable(admin.getConfiguration(), fullTablename);
+        phoenixSchematable.put(put);
+        phoenixSchematable.close();
+        conn.createStatement().execute("CREATE VIEW " + tableName + " (tablename VARCHAR
PRIMARY KEY)");
+        ResultSet rs = conn.createStatement().executeQuery("select tablename from " + tableName);
+        assertTrue(rs.next());
+        assertEquals(fullTablename, rs.getString(1));
+        admin.close();
+        conn.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7e432be7/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
index 146fb1f..c87d82d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
@@ -34,18 +34,24 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.List;
+import java.util.Properties;
 
+import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.KeyRange;
+import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.schema.ColumnAlreadyExistsException;
 import org.apache.phoenix.schema.ReadOnlyTableException;
 import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.QueryUtil;
+import org.apache.phoenix.util.SchemaUtil;
 import org.junit.Test;
 
 
+
 public class ViewIT extends BaseViewIT {
 	
     public ViewIT(boolean transactional) {
@@ -325,16 +331,37 @@ public class ViewIT extends BaseViewIT {
         assertEquals(5, count);
     }
 
+    
+    @Test
+    public void testViewAndTableInDifferentSchemasWithNamespaceMappingEnabled() throws Exception
{
+        testViewAndTableInDifferentSchemas(true);
+    }
+
     @Test
     public void testViewAndTableInDifferentSchemas() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        String fullTableName = "s1.t"+tableSuffix;
+        testViewAndTableInDifferentSchemas(false);
+
+    }
+
+    public void testViewAndTableInDifferentSchemas(boolean isNamespaceMapped) throws Exception
{
+        Properties props = new Properties();
+        props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(isNamespaceMapped));
+        Connection conn = DriverManager.getConnection(getUrl(),props);
+        String fullTableName = "s1.t" + tableSuffix + (isNamespaceMapped ? "_N" : "");
+        if (isNamespaceMapped) {
+            conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS s1");
+        }
 		String ddl = "CREATE TABLE " + fullTableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 DATE)"
+ tableDDLOptions;
+        HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
         conn.createStatement().execute(ddl);
+        assertTrue(admin.tableExists(SchemaUtil.getPhysicalTableName(SchemaUtil.normalizeIdentifier(fullTableName),
+                conn.unwrap(PhoenixConnection.class).getQueryServices().getProps())));
         ddl = "CREATE VIEW s2.v1 (v2 VARCHAR) AS SELECT * FROM " + fullTableName + " WHERE
k > 5";
         conn.createStatement().execute(ddl);
         ddl = "CREATE VIEW v2 (v2 VARCHAR) AS SELECT * FROM " + fullTableName + " WHERE k
> 5";
         conn.createStatement().execute(ddl);
+        conn.createStatement().executeQuery("SELECT * FROM s2.v1");
+        conn.createStatement().executeQuery("SELECT * FROM v2");
         ddl = "DROP VIEW v1";
         try {
             conn.createStatement().execute(ddl);


Mime
View raw message