Repository: phoenix
Updated Branches:
  refs/heads/4.8-HBase-1.1 2657dc600 -> 8bb749361


PHOENIX-3349 DROP TABLE and DROP SEQUENCE not working with schemas


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/8bb74936
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8bb74936
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8bb74936

Branch: refs/heads/4.8-HBase-1.1
Commit: 8bb74936177df17ca2bfb633005a28e20cfa84c6
Parents: 2657dc6
Author: Ankit Singhal <ankitsingha...@gmail.com>
Authored: Tue Oct 18 13:09:28 2016 +0530
Committer: Ankit Singhal <ankitsingha...@gmail.com>
Committed: Tue Oct 18 13:09:28 2016 +0530

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/UseSchemaIT.java | 39 ++++++++++++++++++++
 .../apache/phoenix/compile/SequenceManager.java |  3 ++
 .../apache/phoenix/schema/MetaDataClient.java   |  6 ++-
 3 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8bb74936/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
index cec23ed..f419f08 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
@@ -111,6 +111,45 @@ public class UseSchemaIT extends BaseHBaseManagedTimeIT {
         rs = conn.createStatement().executeQuery("select schema_name from 
test");
         assertTrue(rs.next());
         assertEquals(schema, rs.getString(1));
+        conn.createStatement().execute("DROP TABLE test");
+        conn.close();
+    }
+    
+    @Test
+    public void testSequences() throws Exception {
+        Properties props = new Properties();
+        String schema = "TEST_SCHEMA_1";
+        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);
+        String sequenceName = "TEST_SEQ_1";
+        ddl = "create SEQUENCE "+schema + "." + sequenceName + " START WITH 
100 INCREMENT BY 2 CACHE 10";
+        conn.createStatement().execute(ddl);
+        String query = "SELECT NEXT VALUE FOR "+schema + "." + sequenceName;
+        ResultSet rs = conn.createStatement().executeQuery(query);
+        assertTrue(rs.next());
+        assertEquals("100", rs.getString(1));
+        conn.createStatement().execute("DROP Sequence " + schema + "." + 
sequenceName);
+        
+        schema = "TEST_SCHEMA_2";
+        sequenceName = "TEST_SEQ_2";
+        ddl = "CREATE SCHEMA " + schema;
+        conn.createStatement().execute(ddl);
+        conn.createStatement().execute("use " + schema);
+        ddl = "create SEQUENCE "+ sequenceName + " START WITH 100 INCREMENT BY 
2 CACHE 10";
+        conn.createStatement().execute(ddl);
+        query = "SELECT NEXT VALUE FOR "+sequenceName;
+        rs = conn.createStatement().executeQuery(query);
+        assertTrue(rs.next());
+        assertEquals("100", rs.getString(1));
+        query = "SELECT CURRENT VALUE FOR "+sequenceName;
+        rs = conn.createStatement().executeQuery(query);
+        assertTrue(rs.next());
+        assertEquals("100", rs.getString(1));
+        conn.createStatement().execute("DROP Sequence " + sequenceName);
         conn.close();
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8bb74936/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java
index 5ec8cd2..4159be1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java
@@ -124,6 +124,9 @@ public class SequenceManager {
         PName tenantName = statement.getConnection().getTenantId();
         String tenantId = tenantName == null ? null : tenantName.getString();
         TableName tableName = node.getTableName();
+        if (tableName.getSchemaName() == null && 
statement.getConnection().getSchema() != null) {
+            tableName = 
TableName.create(statement.getConnection().getSchema(), 
tableName.getTableName());
+        }
         int nSaltBuckets = 
statement.getConnection().getQueryServices().getSequenceSaltBuckets();
         ParseNode numToAllocateNode = node.getNumToAllocateNode();
         

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8bb74936/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 28ed11d..cde8e69 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
@@ -1483,7 +1483,8 @@ public class MetaDataClient {
     public MutationState dropSequence(DropSequenceStatement statement) throws 
SQLException {
         Long scn = connection.getSCN();
         long timestamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
-        String schemaName = statement.getSequenceName().getSchemaName();
+        String schemaName = connection.getSchema() != null && 
statement.getSequenceName().getSchemaName() == null
+                ? connection.getSchema() : 
statement.getSequenceName().getSchemaName();
         String sequenceName = statement.getSequenceName().getTableName();
         String tenantId = connection.getTenantId() == null ? null : 
connection.getTenantId().getString();
         try {
@@ -2412,7 +2413,8 @@ public class MetaDataClient {
     }
 
     public MutationState dropTable(DropTableStatement statement) throws 
SQLException {
-        String schemaName = statement.getTableName().getSchemaName();
+        String schemaName = connection.getSchema() != null && 
statement.getTableName().getSchemaName() == null
+                ? connection.getSchema() : 
statement.getTableName().getSchemaName();
         String tableName = statement.getTableName().getTableName();
         return dropTable(schemaName, tableName, null, 
statement.getTableType(), statement.ifExists(), statement.cascade());
     }

Reply via email to