phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject phoenix git commit: PHOENIX-3349 DROP TABLE and DROP SEQUENCE not working with schemas
Date Tue, 18 Oct 2016 07:40:35 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.8-HBase-1.0 65849625e -> 02503b487


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/02503b48
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/02503b48
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/02503b48

Branch: refs/heads/4.8-HBase-1.0
Commit: 02503b48757d1006a7b50e13f0e2ea823736aaf2
Parents: 6584962
Author: Ankit Singhal <ankitsinghal59@gmail.com>
Authored: Tue Oct 18 13:10:27 2016 +0530
Committer: Ankit Singhal <ankitsinghal59@gmail.com>
Committed: Tue Oct 18 13:10:27 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/02503b48/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/02503b48/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/02503b48/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());
     }


Mime
View raw message