Repository: phoenix
Updated Branches:
  refs/heads/3.0 8eaf08e09 -> d8766cf77


PHOENIX-1268 Misleading exception when attempting to drop system table


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

Branch: refs/heads/3.0
Commit: ba81f7c2561343c9c5e4dede0407aa588c13835a
Parents: 48a2482
Author: James Taylor <jtay...@salesforce.com>
Authored: Sun Sep 21 13:44:12 2014 -0700
Committer: James Taylor <jtay...@salesforce.com>
Committed: Sun Sep 21 13:44:12 2014 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/AlterTableIT.java  | 18 ++++++++++++++++++
 phoenix-core/src/main/antlr3/PhoenixSQL.g         |  2 +-
 2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ba81f7c2/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index ecdee66..ee96304 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -108,6 +108,24 @@ public class AlterTableIT extends BaseHBaseManagedTimeIT {
     }
 
     @Test
+    public void testDropSystemTable() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+
+        try {
+            try {
+                conn.createStatement().executeUpdate(
+                        "DROP TABLE " + 
PhoenixDatabaseMetaData.SYSTEM_CATALOG);
+                fail("Should not be allowed to drop a system table");
+            } catch (SQLException e) {
+                
assertEquals(SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode(), 
e.getErrorCode());
+            }
+        } finally {
+            conn.close();
+        }
+    }
+
+    @Test
     public void testAddVarCharColToPK() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ba81f7c2/phoenix-core/src/main/antlr3/PhoenixSQL.g
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/antlr3/PhoenixSQL.g 
b/phoenix-core/src/main/antlr3/PhoenixSQL.g
index 6cc8d57..a900628 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -471,7 +471,7 @@ column_names returns [List<ColumnName> ret]
 // Parse a drop table statement.
 drop_table_node returns [DropTableStatement ret]
     :   DROP (v=VIEW | TABLE) (IF ex=EXISTS)? t=from_table_name (c=CASCADE)?
-        {ret = factory.dropTable(t, v==null ? PTableType.TABLE : 
PTableType.VIEW, ex!=null, c!=null); }
+        {ret = factory.dropTable(t, v==null ? 
(QueryConstants.SYSTEM_SCHEMA_NAME.equals(t.getSchemaName()) ? 
PTableType.SYSTEM : PTableType.TABLE) : PTableType.VIEW, ex!=null, c!=null); }
     ;
 
 // Parse a drop index statement

Reply via email to