phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sama...@apache.org
Subject phoenix git commit: PHOENIX-2123 Diverged view prevents schema propagation to the entire view hierarchy
Date Wed, 15 Jul 2015 20:34:00 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.0 ca6fef244 -> fe31f8f49


PHOENIX-2123 Diverged view prevents schema propagation to the entire view hierarchy


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

Branch: refs/heads/4.x-HBase-1.0
Commit: fe31f8f49bb854eae8497df2f11a481275fe1315
Parents: ca6fef2
Author: Samarth <samarth.jain@salesforce.com>
Authored: Wed Jul 15 13:33:38 2015 -0700
Committer: Samarth <samarth.jain@salesforce.com>
Committed: Wed Jul 15 13:33:38 2015 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/AlterTableIT.java    | 34 +++++++++++---------
 .../coprocessor/MetaDataEndpointImpl.java       |  7 ++--
 .../org/apache/phoenix/util/UpgradeUtil.java    |  6 ++--
 3 files changed, 24 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/fe31f8f4/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 607f52a..1758dd4 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
@@ -2575,36 +2575,38 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT
{
     }
     
     @Test
-    public void testDivorcedViewsStayDivorced() throws Exception {
-        String baseTable = "testDivorcedViewsStayDivorced";
-        String viewName = baseTable + "_view";
+    public void testDivergedViewsStayDiverged() throws Exception {
+        String baseTable = "testDivergedViewsStayDiverged";
+        String view1 = baseTable + "_view1";
+        String view2 = baseTable + "_view2";
         try (Connection conn = DriverManager.getConnection(getUrl())) {
             String tableDDL = "CREATE TABLE " + baseTable + " (PK1 VARCHAR NOT NULL PRIMARY
KEY, V1 VARCHAR, V2 VARCHAR)";
             conn.createStatement().execute(tableDDL);
             
-            String viewDDL = "CREATE VIEW " + viewName + " AS SELECT * FROM " + baseTable;
+            String viewDDL = "CREATE VIEW " + view1 + " AS SELECT * FROM " + baseTable;
+            conn.createStatement().execute(viewDDL);
+            
+            viewDDL = "CREATE VIEW " + view2 + " AS SELECT * FROM " + baseTable;
             conn.createStatement().execute(viewDDL);
             
-            // Drop the column inherited from base table to divorce the view
-            String dropColumn = "ALTER VIEW " + viewName + " DROP COLUMN V2";
+            // Drop the column inherited from base table to make it diverged
+            String dropColumn = "ALTER VIEW " + view1 + " DROP COLUMN V2";
             conn.createStatement().execute(dropColumn);
             
             String alterBaseTable = "ALTER TABLE " + baseTable + " ADD V3 VARCHAR";
-            try {
-            	conn.createStatement().execute(alterBaseTable);
-	            fail();
-	        }
-	        catch (SQLException e) {
-	        	assertEquals("Unexpected exception", CANNOT_MUTATE_TABLE.getErrorCode(), e.getErrorCode());
-	        }
-            
-            // Column V3 shouldn't have propagated to the divorced view.
-            String sql = "SELECT V3 FROM " + viewName;
+            conn.createStatement().execute(alterBaseTable);
+	        
+            // Column V3 shouldn't have propagated to the diverged view.
+            String sql = "SELECT V3 FROM " + view1;
             try {
                 conn.createStatement().execute(sql);
             } catch (SQLException e) {
                 assertEquals(SQLExceptionCode.COLUMN_NOT_FOUND.getErrorCode(), e.getErrorCode());
             }
+            
+            // However, column V3 should have propagated to the non-diverged view.
+            sql = "SELECT V3 FROM " + view2;
+            conn.createStatement().execute(sql);
         } 
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/fe31f8f4/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 32ce536..98f724f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -1693,11 +1693,10 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements
Coprocesso
             RowLock viewRowLock = acquireLock(region, viewKey, locks);
             PTable view = doGetTable(viewKey, clientTimeStamp, viewRowLock);
             if (view.getBaseColumnCount() == QueryConstants.DIVERGED_VIEW_BASE_COLUMN_COUNT)
{
-                // if a view has divorced itself from the base table, we don't allow schema
changes
+                // if a view has diverged from the base table, we don't allow schema changes
                 // to be propagated to it.
-                // FIXME: we should allow the update, but just not propagate it to this view
-                // The one exception is PK changes which need to be propagated to diverged
views as well
-            	return new MetaDataMutationResult(MutationCode.UNALLOWED_TABLE_MUTATION, EnvironmentEdgeManager.currentTimeMillis(),
null);
+                // FIXME: We should allow PK changes to be propagated to a diverged view
See PHOENIX-2110
+                continue;
             }
             int numColsAddedToBaseTable = 0;
             int numColsAddedToView = 0;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/fe31f8f4/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
index d7e74ca..46a70f2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
@@ -637,9 +637,9 @@ public class UpgradeUtil {
                              * two till one of the following happens: 
                              * 
                              * 1) We run into a view column which is different from column
in the base physical table.
-                             * This means that the view has divorced itself from the base
physical table. In such a case
+                             * This means that the view has diverged from the base physical
table. In such a case
                              * we will set a special value for the base column count. That
special value will also be used
-                             * on the server side to filter out the divorced view so that
meta-data changes on the base 
+                             * on the server side to filter out the diverged view so that
meta-data changes on the base 
                              * physical table are not propagated to it.
                              * 
                              * 2) Every physical table column is present in the view. In
that case we set the base column count
@@ -667,7 +667,7 @@ public class UpgradeUtil {
                                     clearCache = true;
                                 }
                             } else {
-                                // special value to denote that the view has divorced itself
from the base physical table.
+                                // special value to denote that the view has diverged from
the base physical table.
                                 upsertBaseColumnCountInHeaderRow(metaConnection, viewTenantId,
viewSchema, viewName, DIVERGED_VIEW_BASE_COLUMN_COUNT);
                                 baseColumnCountUpserted = true;
                                 clearCache = true;


Mime
View raw message