You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/10/09 17:00:21 UTC

[GitHub] [phoenix] jpisaac opened a new pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

jpisaac opened a new pull request #916:
URL: https://github.com/apache/phoenix/pull/916


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] jpisaac commented on a change in pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
jpisaac commented on a change in pull request #916:
URL: https://github.com/apache/phoenix/pull/916#discussion_r512394047



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
##########
@@ -2077,6 +2077,13 @@ private PTable createTableInternal(CreateTableStatement statement, byte[][] spli
                     }
                 }
 
+                // Cannot set PHOENIX_TTL if parent has already defined it.
+                if (tableType == VIEW  && parent != null && parent.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {

Review comment:
       This check is during the createTable flow. Moreover the current code does allow for easy client side checks for TableProperty changes during alter command.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] jpisaac commented on a change in pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
jpisaac commented on a change in pull request #916:
URL: https://github.com/apache/phoenix/pull/916#discussion_r512393224



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2639,6 +2646,20 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
                         QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK);
                 }
             }
+            if (settingNewPhoenixTTLAttribute(tableMetadata, PHOENIX_TTL_BYTES)) {
+                // Disallow if the parent has PHOENIX_TTL set.
+                if (parentTable != null &&  parentTable.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {
+                    isSchemaMutationAllowed = false;
+                }
+
+                // Since we do not allow propagation of PHOENIX_TTL values during ALTER for now.
+                // If a child view exists and the parent previously had a PHOENIX_TTL value set then that

Review comment:
       As discussed offline, changing the comment will bring more clarity. The checks are for "this" view's parent and its children




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] ChinmaySKulkarni commented on a change in pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
ChinmaySKulkarni commented on a change in pull request #916:
URL: https://github.com/apache/phoenix/pull/916#discussion_r509545181



##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java
##########
@@ -61,22 +62,31 @@
     private static final Logger LOGGER = LoggerFactory.getLogger(ViewTTLIT.class);
     private static final String ORG_ID_FMT = "00D0x000%s";
     private static final String ID_FMT = "00A0y000%07d";
-    private static final String PHOENIX_TTL_HEADER_SQL =  "SELECT PHOENIX_TTL FROM SYSTEM.CATALOG "
-            + "WHERE %s AND TABLE_SCHEM = '%s' AND TABLE_NAME = '%s' AND TABLE_TYPE = '%s'";
+    private static final String
+            PHOENIX_TTL_HEADER_SQL =
+            "SELECT PHOENIX_TTL FROM SYSTEM.CATALOG "
+                    + "WHERE %s AND TABLE_SCHEM = '%s' AND TABLE_NAME = '%s' AND TABLE_TYPE = '%s'";
+
+    private static final String
+            ALTER_PHOENIX_TTL_SQL =
+            "ALTER VIEW \"%s\".\"%s\" set PHOENIX_TTL=%s";
 
-    private static final String ALTER_PHOENIX_TTL_SQL = "ALTER VIEW %s.%s set PHOENIX_TTL=%d";
+    private static final String

Review comment:
       nit: Modify formatting to avoid extra line

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java
##########
@@ -61,22 +62,31 @@
     private static final Logger LOGGER = LoggerFactory.getLogger(ViewTTLIT.class);
     private static final String ORG_ID_FMT = "00D0x000%s";
     private static final String ID_FMT = "00A0y000%07d";
-    private static final String PHOENIX_TTL_HEADER_SQL =  "SELECT PHOENIX_TTL FROM SYSTEM.CATALOG "
-            + "WHERE %s AND TABLE_SCHEM = '%s' AND TABLE_NAME = '%s' AND TABLE_TYPE = '%s'";
+    private static final String
+            PHOENIX_TTL_HEADER_SQL =
+            "SELECT PHOENIX_TTL FROM SYSTEM.CATALOG "
+                    + "WHERE %s AND TABLE_SCHEM = '%s' AND TABLE_NAME = '%s' AND TABLE_TYPE = '%s'";
+
+    private static final String
+            ALTER_PHOENIX_TTL_SQL =

Review comment:
       nit: Modify formatting to avoid extra line

##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2639,6 +2646,20 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
                         QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK);
                 }
             }
+            if (settingNewPhoenixTTLAttribute(tableMetadata, PHOENIX_TTL_BYTES)) {

Review comment:
       In fact, since we only allow setting PHOENIX_TTL on views we should enter this `if` block only if PTableType== VIEW (maybe add it inside the `settingNewPhoenixTTLAttribute()` method itself so we can change it in the future if required).

##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2639,6 +2646,20 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
                         QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK);
                 }
             }
+            if (settingNewPhoenixTTLAttribute(tableMetadata, PHOENIX_TTL_BYTES)) {
+                // Disallow if the parent has PHOENIX_TTL set.
+                if (parentTable != null &&  parentTable.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {
+                    isSchemaMutationAllowed = false;
+                }
+
+                // Since we do not allow propagation of PHOENIX_TTL values during ALTER for now.
+                // If a child view exists and the parent previously had a PHOENIX_TTL value set then that

Review comment:
       We aren't checking the "and the parent previously had a PHOENIX_TTL value set " part. Shouldn't we do that too?

##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/AddColumnMutator.java
##########
@@ -59,6 +59,8 @@
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.DECIMAL_DIGITS_BYTES;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.FAMILY_NAME_INDEX;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MULTI_TENANT_BYTES;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PHOENIX_TTL_BYTES;

Review comment:
       Unused imports?

##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2639,6 +2646,20 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
                         QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK);
                 }
             }
+            if (settingNewPhoenixTTLAttribute(tableMetadata, PHOENIX_TTL_BYTES)) {
+                // Disallow if the parent has PHOENIX_TTL set.
+                if (parentTable != null &&  parentTable.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {
+                    isSchemaMutationAllowed = false;
+                }
+
+                // Since we do not allow propagation of PHOENIX_TTL values during ALTER for now.
+                // If a child view exists and the parent previously had a PHOENIX_TTL value set then that
+                // implies that the child view too has a valid PHOENIX_TTL (non zero).
+                // In this case we do not allow for ALTER of the parent view PHOENIX_TTL value.
+                if (!childViews.isEmpty()) {

Review comment:
       What if we're setting the TTL for the first time for a parent view i.e. it was PHOENIX_TTL_NOT_DEFINED first and now we're setting it for the first time ever. This check will disallow that too. Is that intended?

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java
##########
@@ -61,22 +62,31 @@
     private static final Logger LOGGER = LoggerFactory.getLogger(ViewTTLIT.class);
     private static final String ORG_ID_FMT = "00D0x000%s";
     private static final String ID_FMT = "00A0y000%07d";
-    private static final String PHOENIX_TTL_HEADER_SQL =  "SELECT PHOENIX_TTL FROM SYSTEM.CATALOG "
-            + "WHERE %s AND TABLE_SCHEM = '%s' AND TABLE_NAME = '%s' AND TABLE_TYPE = '%s'";
+    private static final String
+            PHOENIX_TTL_HEADER_SQL =
+            "SELECT PHOENIX_TTL FROM SYSTEM.CATALOG "
+                    + "WHERE %s AND TABLE_SCHEM = '%s' AND TABLE_NAME = '%s' AND TABLE_TYPE = '%s'";
+
+    private static final String
+            ALTER_PHOENIX_TTL_SQL =
+            "ALTER VIEW \"%s\".\"%s\" set PHOENIX_TTL=%s";
 
-    private static final String ALTER_PHOENIX_TTL_SQL = "ALTER VIEW %s.%s set PHOENIX_TTL=%d";
+    private static final String
+            ALTER_SQL_WITH_NO_TTL =
+            "ALTER VIEW \"%s\".\"%s\" ADD IF NOT EXISTS %s CHAR(10)";
 
     // Scans the HBase rows directly for the view ttl related header rows column and asserts
-    private void assertViewHeaderRowsHavePhoenixTTLRelatedCells(String schemaName, long minTimestamp,
-            boolean rawScan, int expectedRows) throws IOException, SQLException {
+    private void assertViewHeaderRowsHavePhoenixTTLRelatedCells(String schemaName,
+            long minTimestamp, boolean rawScan, int expectedRows) throws IOException, SQLException {
 
         FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
-        RowFilter schemaNameFilter = new RowFilter(
-                CompareFilter.CompareOp.EQUAL,
-                new SubstringComparator(schemaName)
-        );
-        QualifierFilter phoenixTTLQualifierFilter = new QualifierFilter(CompareFilter.CompareOp.EQUAL,
-                new BinaryComparator(PhoenixDatabaseMetaData.PHOENIX_TTL_BYTES));
+        RowFilter
+                schemaNameFilter =
+                new RowFilter(CompareFilter.CompareOp.EQUAL, new SubstringComparator(schemaName));
+        QualifierFilter

Review comment:
       Similar here. Can you please check if your IDE has the Phoenix IDE settings?

##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2925,6 +2954,23 @@ private void clearRemoteTableFromCache(long clientTimeStamp, byte[] schemaName,
         }
     }
 
+    // Checks whether a non-zero PHOENIX_TTL value is being set.
+    private boolean settingNewPhoenixTTLAttribute(List<Mutation> tableMetadata, byte[] phoenixTtlBytes) {

Review comment:
       Can you rename this to `settingNewPhoenixTTLAttributeForView()` to indicate it only applies to views and then also add the check for the same inside the method?

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java
##########
@@ -119,283 +137,556 @@ private String stripQuotes(String name) {
         return name.replace("\"", "");
     }
 
+    private SchemaBuilder createLevel2TenantViewWithGlobalLevelTTL(
+            TenantViewOptions tenantViewOptions, TenantViewIndexOptions tenantViewIndexOptions)
+            throws Exception {
+        // Define the test schema.
+        // 1. Table with columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
+        // 2. GlobalView with columns => (ID, COL4, COL5, COL6), PK => (ID)
+        // 3. Tenant with columns => (ZID, COL7, COL8, COL9), PK => (ZID)
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+
+        TableOptions tableOptions = TableOptions.withDefaults();
+        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+
+        GlobalViewOptions globalViewOptions = GlobalViewOptions.withDefaults();
+        // Phoenix TTL is set to 300s => 300000 ms
+        globalViewOptions.setTableProps("PHOENIX_TTL=300");
+
+        SchemaBuilder.GlobalViewIndexOptions
+                globalViewIndexOptions =
+                SchemaBuilder.GlobalViewIndexOptions.withDefaults();
+        globalViewIndexOptions.setLocal(false);
+
+        TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
+        if (tenantViewOptions != null) {
+            tenantViewWithOverrideOptions = tenantViewOptions;
+        }
+        TenantViewIndexOptions
+                tenantViewIndexOverrideOptions =
+                TenantViewIndexOptions.withDefaults();
+        if (tenantViewIndexOptions != null) {
+            tenantViewIndexOverrideOptions = tenantViewIndexOptions;
+        }
+        schemaBuilder.withTableOptions(tableOptions).withGlobalViewOptions(globalViewOptions)
+                .withGlobalViewIndexOptions(globalViewIndexOptions)
+                .withTenantViewOptions(tenantViewWithOverrideOptions)
+                .withTenantViewIndexOptions(tenantViewIndexOverrideOptions).buildWithNewTenant();
+        return schemaBuilder;
+    }
+
+    private SchemaBuilder createLevel2TenantViewWithTenantLevelTTL(
+            TenantViewOptions tenantViewOptions, TenantViewIndexOptions tenantViewIndexOptions)
+            throws Exception {
+        // Define the test schema.
+        // 1. Table with columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
+        // 2. GlobalView with columns => (ID, COL4, COL5, COL6), PK => (ID)
+        // 3. Tenant with columns => (ZID, COL7, COL8, COL9), PK => (ZID)
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+
+        TableOptions tableOptions = TableOptions.withDefaults();
+        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+
+        GlobalViewOptions globalViewOptions = GlobalViewOptions.withDefaults();
+
+        SchemaBuilder.GlobalViewIndexOptions
+                globalViewIndexOptions =
+                SchemaBuilder.GlobalViewIndexOptions.withDefaults();
+        globalViewIndexOptions.setLocal(false);
+
+        TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
+        // Phoenix TTL is set to 300s => 300000 ms
+        tenantViewWithOverrideOptions.setTableProps("PHOENIX_TTL=300");
+        if (tenantViewOptions != null) {
+            tenantViewWithOverrideOptions = tenantViewOptions;
+        }
+        TenantViewIndexOptions
+                tenantViewIndexOverrideOptions =
+                TenantViewIndexOptions.withDefaults();
+        if (tenantViewIndexOptions != null) {
+            tenantViewIndexOverrideOptions = tenantViewIndexOptions;
+        }
+        schemaBuilder.withTableOptions(tableOptions).withGlobalViewOptions(globalViewOptions)
+                .withGlobalViewIndexOptions(globalViewIndexOptions)
+                .withTenantViewOptions(tenantViewWithOverrideOptions)
+                .withTenantViewIndexOptions(tenantViewIndexOverrideOptions).buildWithNewTenant();
+        return schemaBuilder;
+    }
+
+    private SchemaBuilder createLevel1TenantView(TenantViewOptions tenantViewOptions,
+            TenantViewIndexOptions tenantViewIndexOptions) throws Exception {
+        // Define the test schema.
+        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
+        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+
+        TableOptions tableOptions = TableOptions.withDefaults();
+        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+
+        TenantViewOptions tenantViewOverrideOptions = TenantViewOptions.withDefaults();
+        if (tenantViewOptions != null) {
+            tenantViewOverrideOptions = tenantViewOptions;
+        }
+        TenantViewIndexOptions
+                tenantViewIndexOverrideOptions =
+                TenantViewIndexOptions.withDefaults();
+        if (tenantViewIndexOptions != null) {
+            tenantViewIndexOverrideOptions = tenantViewIndexOptions;
+        }
+
+        schemaBuilder.withTableOptions(tableOptions)
+                .withTenantViewOptions(tenantViewOverrideOptions)
+                .withTenantViewIndexOptions(tenantViewIndexOverrideOptions).buildNewView();
+        return schemaBuilder;
+    }
 
     /**
      * -----------------
      * Test methods
      * -----------------
      */
 
-    @Test
-    public void testWithBasicGlobalViewWithNoPhoenixTTLDefined() throws Exception {
+    @Test public void testWithBasicGlobalViewWithNoPhoenixTTLDefined() throws Exception {
 
-        long startTime = System.currentTimeMillis();
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         // Define the test schema.
         // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
         // 2. GlobalView with default columns => (ID, COL4, COL5, COL6), PK => (ID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-        schemaBuilder
-                .withTableDefaults()
-                .withGlobalViewDefaults()
-                .build();
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+        schemaBuilder.withTableDefaults().withGlobalViewDefaults().build();
 
         // Expected 2 rows - one for Table and GlobalView each.
-        // Since the PHOENIX_TTL property values are not being set, we expect the view header columns to show up in raw scans only.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 2);
+        // Since the PHOENIX_TTL property values are not being set,
+        // we expect the view header columns to show up in raw scans only.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 2);
     }
 
-
-
-    @Test
-    public void testPhoenixTTLWithTableLevelTTLFails() throws Exception {
+    @Test public void testPhoenixTTLWithTableLevelTTLFails() throws Exception {
 
         // Define the test schema.
         // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
         // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
 
         TableOptions tableOptions = TableOptions.withDefaults();
         tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true,TTL=100");
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         tenantViewOptions.setTableProps("PHOENIX_TTL=1000");
         try {
-            schemaBuilder
-                    .withTableOptions(tableOptions)
-                    .withTenantViewOptions(tenantViewOptions)
+            schemaBuilder.withTableOptions(tableOptions).withTenantViewOptions(tenantViewOptions)
                     .buildNewView();
             fail();
         } catch (SQLException e) {
-            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL_FOR_TABLE_WITH_TTL.getErrorCode(), e.getErrorCode());
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL_FOR_TABLE_WITH_TTL
+                    .getErrorCode(), e.getErrorCode());
         }
     }
 
-    @Test
-    public void testPhoenixTTLWithViewIndexFails() throws Exception {
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLWithViewIndexFails() throws Exception {
 
         TenantViewIndexOptions tenantViewIndexOptions = TenantViewIndexOptions.withDefaults();
         tenantViewIndexOptions.setIndexProps("PHOENIX_TTL=1000");
         try {
-            schemaBuilder
-                    .withTableOptions(tableOptions)
-                    .withTenantViewDefaults()
-                    .withTenantViewIndexOptions(tenantViewIndexOptions)
-                    .buildNewView();
+            final SchemaBuilder
+                    schemaBuilder =
+                    createLevel1TenantView(null, tenantViewIndexOptions);
             fail();
         } catch (SQLException e) {
-            assertEquals(SQLExceptionCode.PHOENIX_TTL_SUPPORTED_FOR_VIEWS_ONLY.getErrorCode(), e.getErrorCode());
+            assertEquals(SQLExceptionCode.PHOENIX_TTL_SUPPORTED_FOR_VIEWS_ONLY.getErrorCode(),
+                    e.getErrorCode());
         }
     }
 
-    @Test
-    public void testPhoenixTTLForLevelOneView() throws Exception {
-        long startTime = System.currentTimeMillis();
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLForLevelOneView() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         // Phoenix TTL is set to 120s => 120000 ms
         tenantViewOptions.setTableProps("PHOENIX_TTL=120");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withTenantViewOptions(tenantViewOptions)
-                .withTenantViewIndexDefaults()
-                .buildNewView();
 
+        final SchemaBuilder schemaBuilder = createLevel1TenantView(tenantViewOptions, null);
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 2 rows - one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 120000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 120000);
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 120000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 120000);
 
     }
 
-    @Test
-    public void testPhoenixTTLForLevelTwoView() throws Exception {
-        long startTime = System.currentTimeMillis();
+    @Test public void testPhoenixTTLForLevelTwoView() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. GlobalView with default columns => (ID, COL4, COL5, COL6), PK => (ID)
-        // 3. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
-
-        PhoenixTestBuilder.SchemaBuilder.GlobalViewOptions
-                globalViewOptions = PhoenixTestBuilder.SchemaBuilder.GlobalViewOptions.withDefaults();
-        // Phoenix TTL is set to 300s => 300000 ms
-        globalViewOptions.setTableProps("PHOENIX_TTL=300");
-
-        PhoenixTestBuilder.SchemaBuilder.GlobalViewIndexOptions
-                globalViewIndexOptions =
-                PhoenixTestBuilder.SchemaBuilder.GlobalViewIndexOptions.withDefaults();
-        globalViewIndexOptions.setLocal(false);
-
-        TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
-        // Phoenix TTL is set to 120s => 120000 ms
-        tenantViewWithOverrideOptions.setTableProps("PHOENIX_TTL=120");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withGlobalViewOptions(globalViewOptions)
-                .withGlobalViewIndexOptions(globalViewIndexOptions)
-                .withTenantViewOptions(tenantViewWithOverrideOptions)
-                .withTenantViewIndexDefaults()
-                .buildWithNewTenant();
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithGlobalLevelTTL(null, null);
 
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String globalViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                globalViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
         String indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 4 rows - one for GlobalView, one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 4);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName, PTableType.VIEW.getSerializedValue(), 300000);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName, PTableType.INDEX.getSerializedValue(), 300000);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 120000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 120000);
-
-        // Without override
-        startTime = System.currentTimeMillis();
-
-        TenantViewOptions tenantViewWithoutOverrideOptions = TenantViewOptions.withDefaults();
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withGlobalViewOptions(globalViewOptions)
-                .withGlobalViewIndexOptions(globalViewIndexOptions)
-                .withTenantViewOptions(tenantViewWithoutOverrideOptions)
-                .withTenantViewIndexDefaults()
-                .buildWithNewTenant();
-
-        tenantId = schemaBuilder.getDataOptions().getTenantId();
-        schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        globalViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
-        tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
-        indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
-
-
-        // Expected 2 rows - one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName, PTableType.VIEW.getSerializedValue(), 300000);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName, PTableType.INDEX.getSerializedValue(), 300000);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be same as the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 300000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 300000);
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 4);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+        // Since the PHOENIX_TTL property values are not being overridden,
+        // we expect the TTL value to be same as the global view.
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
     }
 
-    @Test
-    public void testPhoenixTTLForWhenTTLIsZero() throws Exception {
-        long startTime = System.currentTimeMillis();
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLForWhenTTLIsZero() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         // Client can also specify PHOENIX_TTL=NONE
         tenantViewOptions.setTableProps("PHOENIX_TTL=0");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withTenantViewOptions(tenantViewOptions)
-                .withTenantViewIndexDefaults()
-                .buildNewView();
+        final SchemaBuilder schemaBuilder = createLevel1TenantView(tenantViewOptions, null);
 
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 3 deleted rows - one for Table, one for TenantView and ViewIndex each.
         // Since the PHOENIX_TTL property values are not being set or being set to zero,
         // we expect the view header columns to show up in raw scans only.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 0);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 0);
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 0);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 0);
 
     }
 
-    @Test
-    public void testPhoenixTTLWithAlterView() throws Exception {
-        long startTime = System.currentTimeMillis();
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLWithAlterView() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         // Client can also specify PHOENIX_TTL=0
         tenantViewOptions.setTableProps("PHOENIX_TTL=NONE");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withTenantViewOptions(tenantViewOptions)
-                .withTenantViewIndexDefaults()
-                .buildNewView();
+        final SchemaBuilder schemaBuilder = createLevel1TenantView(tenantViewOptions, null);
 
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 3 deleted rows - one for Table, one for TenantView and ViewIndex each.
         // Since the PHOENIX_TTL property values are not being set or being set to zero,
         // we expect the view header columns to show up in raw scans only.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 0);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 0);
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 0);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 0);
 
         String tenantURL = getUrl() + ';' + TENANT_ID_ATTRIB + '=' + tenantId;
         try (Connection connection = DriverManager.getConnection(tenantURL)) {
-            Statement stmt = connection.createStatement();
+            try (Statement stmt = connection.createStatement()) {
+                // Phoenix TTL is set to 120s => 120000 ms
+                String
+                        sql =
+                        String.format(ALTER_PHOENIX_TTL_SQL, schemaName, tenantViewName, "120");
+                stmt.execute(sql);
+            }
+        }
+
+        // Expected 2 rows - one for TenantView and ViewIndex each.
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 120000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 120000);
+
+    }
+
+    @Test public void testCreateViewWithParentPhoenixTTLFails() throws Exception {
+        try {
+            TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
             // Phoenix TTL is set to 120s => 120000 ms
-            String sql = String.format(ALTER_PHOENIX_TTL_SQL, schemaName, tenantViewName, 120);
-            stmt.execute(sql);
+            tenantViewWithOverrideOptions.setTableProps("PHOENIX_TTL=120");
+            final SchemaBuilder
+                    schemaBuilder =
+                    createLevel2TenantViewWithGlobalLevelTTL(tenantViewWithOverrideOptions, null);
+            fail();
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL.getErrorCode(),
+                    e.getErrorCode());
         }
+    }
+
+    @Test public void testAlterViewWithParentPhoenixTTLFails() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
+
+        // Phoenix TTL is set to 300s
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithGlobalLevelTTL(null, null);
+
+        String tenantId = schemaBuilder.getDataOptions().getTenantId();
+        String

Review comment:
       nit: Same formatting issues here potentially.

##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2639,6 +2646,20 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
                         QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK);
                 }
             }
+            if (settingNewPhoenixTTLAttribute(tableMetadata, PHOENIX_TTL_BYTES)) {

Review comment:
       Circumvent this check if the tableType != VIEW to prevent unnecessary iteration of the list of mutations in non-view cases.

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java
##########
@@ -119,283 +137,556 @@ private String stripQuotes(String name) {
         return name.replace("\"", "");
     }
 
+    private SchemaBuilder createLevel2TenantViewWithGlobalLevelTTL(
+            TenantViewOptions tenantViewOptions, TenantViewIndexOptions tenantViewIndexOptions)
+            throws Exception {
+        // Define the test schema.
+        // 1. Table with columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
+        // 2. GlobalView with columns => (ID, COL4, COL5, COL6), PK => (ID)
+        // 3. Tenant with columns => (ZID, COL7, COL8, COL9), PK => (ZID)
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+
+        TableOptions tableOptions = TableOptions.withDefaults();
+        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+
+        GlobalViewOptions globalViewOptions = GlobalViewOptions.withDefaults();
+        // Phoenix TTL is set to 300s => 300000 ms
+        globalViewOptions.setTableProps("PHOENIX_TTL=300");
+
+        SchemaBuilder.GlobalViewIndexOptions
+                globalViewIndexOptions =
+                SchemaBuilder.GlobalViewIndexOptions.withDefaults();
+        globalViewIndexOptions.setLocal(false);
+
+        TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
+        if (tenantViewOptions != null) {
+            tenantViewWithOverrideOptions = tenantViewOptions;
+        }
+        TenantViewIndexOptions
+                tenantViewIndexOverrideOptions =
+                TenantViewIndexOptions.withDefaults();
+        if (tenantViewIndexOptions != null) {
+            tenantViewIndexOverrideOptions = tenantViewIndexOptions;
+        }
+        schemaBuilder.withTableOptions(tableOptions).withGlobalViewOptions(globalViewOptions)
+                .withGlobalViewIndexOptions(globalViewIndexOptions)
+                .withTenantViewOptions(tenantViewWithOverrideOptions)
+                .withTenantViewIndexOptions(tenantViewIndexOverrideOptions).buildWithNewTenant();
+        return schemaBuilder;
+    }
+
+    private SchemaBuilder createLevel2TenantViewWithTenantLevelTTL(
+            TenantViewOptions tenantViewOptions, TenantViewIndexOptions tenantViewIndexOptions)
+            throws Exception {
+        // Define the test schema.
+        // 1. Table with columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
+        // 2. GlobalView with columns => (ID, COL4, COL5, COL6), PK => (ID)
+        // 3. Tenant with columns => (ZID, COL7, COL8, COL9), PK => (ZID)
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+
+        TableOptions tableOptions = TableOptions.withDefaults();
+        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+
+        GlobalViewOptions globalViewOptions = GlobalViewOptions.withDefaults();
+
+        SchemaBuilder.GlobalViewIndexOptions
+                globalViewIndexOptions =
+                SchemaBuilder.GlobalViewIndexOptions.withDefaults();
+        globalViewIndexOptions.setLocal(false);
+
+        TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
+        // Phoenix TTL is set to 300s => 300000 ms
+        tenantViewWithOverrideOptions.setTableProps("PHOENIX_TTL=300");
+        if (tenantViewOptions != null) {
+            tenantViewWithOverrideOptions = tenantViewOptions;
+        }
+        TenantViewIndexOptions
+                tenantViewIndexOverrideOptions =
+                TenantViewIndexOptions.withDefaults();
+        if (tenantViewIndexOptions != null) {
+            tenantViewIndexOverrideOptions = tenantViewIndexOptions;
+        }
+        schemaBuilder.withTableOptions(tableOptions).withGlobalViewOptions(globalViewOptions)
+                .withGlobalViewIndexOptions(globalViewIndexOptions)
+                .withTenantViewOptions(tenantViewWithOverrideOptions)
+                .withTenantViewIndexOptions(tenantViewIndexOverrideOptions).buildWithNewTenant();
+        return schemaBuilder;
+    }
+
+    private SchemaBuilder createLevel1TenantView(TenantViewOptions tenantViewOptions,
+            TenantViewIndexOptions tenantViewIndexOptions) throws Exception {
+        // Define the test schema.
+        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
+        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+
+        TableOptions tableOptions = TableOptions.withDefaults();
+        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+
+        TenantViewOptions tenantViewOverrideOptions = TenantViewOptions.withDefaults();
+        if (tenantViewOptions != null) {
+            tenantViewOverrideOptions = tenantViewOptions;
+        }
+        TenantViewIndexOptions
+                tenantViewIndexOverrideOptions =
+                TenantViewIndexOptions.withDefaults();
+        if (tenantViewIndexOptions != null) {
+            tenantViewIndexOverrideOptions = tenantViewIndexOptions;
+        }
+
+        schemaBuilder.withTableOptions(tableOptions)
+                .withTenantViewOptions(tenantViewOverrideOptions)
+                .withTenantViewIndexOptions(tenantViewIndexOverrideOptions).buildNewView();
+        return schemaBuilder;
+    }
 
     /**
      * -----------------
      * Test methods
      * -----------------
      */
 
-    @Test
-    public void testWithBasicGlobalViewWithNoPhoenixTTLDefined() throws Exception {
+    @Test public void testWithBasicGlobalViewWithNoPhoenixTTLDefined() throws Exception {
 
-        long startTime = System.currentTimeMillis();
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         // Define the test schema.
         // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
         // 2. GlobalView with default columns => (ID, COL4, COL5, COL6), PK => (ID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-        schemaBuilder
-                .withTableDefaults()
-                .withGlobalViewDefaults()
-                .build();
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+        schemaBuilder.withTableDefaults().withGlobalViewDefaults().build();
 
         // Expected 2 rows - one for Table and GlobalView each.
-        // Since the PHOENIX_TTL property values are not being set, we expect the view header columns to show up in raw scans only.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 2);
+        // Since the PHOENIX_TTL property values are not being set,
+        // we expect the view header columns to show up in raw scans only.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 2);
     }
 
-
-
-    @Test
-    public void testPhoenixTTLWithTableLevelTTLFails() throws Exception {
+    @Test public void testPhoenixTTLWithTableLevelTTLFails() throws Exception {
 
         // Define the test schema.
         // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
         // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
 
         TableOptions tableOptions = TableOptions.withDefaults();
         tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true,TTL=100");
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         tenantViewOptions.setTableProps("PHOENIX_TTL=1000");
         try {
-            schemaBuilder
-                    .withTableOptions(tableOptions)
-                    .withTenantViewOptions(tenantViewOptions)
+            schemaBuilder.withTableOptions(tableOptions).withTenantViewOptions(tenantViewOptions)
                     .buildNewView();
             fail();
         } catch (SQLException e) {
-            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL_FOR_TABLE_WITH_TTL.getErrorCode(), e.getErrorCode());
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL_FOR_TABLE_WITH_TTL
+                    .getErrorCode(), e.getErrorCode());
         }
     }
 
-    @Test
-    public void testPhoenixTTLWithViewIndexFails() throws Exception {
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLWithViewIndexFails() throws Exception {
 
         TenantViewIndexOptions tenantViewIndexOptions = TenantViewIndexOptions.withDefaults();
         tenantViewIndexOptions.setIndexProps("PHOENIX_TTL=1000");
         try {
-            schemaBuilder
-                    .withTableOptions(tableOptions)
-                    .withTenantViewDefaults()
-                    .withTenantViewIndexOptions(tenantViewIndexOptions)
-                    .buildNewView();
+            final SchemaBuilder
+                    schemaBuilder =
+                    createLevel1TenantView(null, tenantViewIndexOptions);
             fail();
         } catch (SQLException e) {
-            assertEquals(SQLExceptionCode.PHOENIX_TTL_SUPPORTED_FOR_VIEWS_ONLY.getErrorCode(), e.getErrorCode());
+            assertEquals(SQLExceptionCode.PHOENIX_TTL_SUPPORTED_FOR_VIEWS_ONLY.getErrorCode(),
+                    e.getErrorCode());
         }
     }
 
-    @Test
-    public void testPhoenixTTLForLevelOneView() throws Exception {
-        long startTime = System.currentTimeMillis();
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLForLevelOneView() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         // Phoenix TTL is set to 120s => 120000 ms
         tenantViewOptions.setTableProps("PHOENIX_TTL=120");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withTenantViewOptions(tenantViewOptions)
-                .withTenantViewIndexDefaults()
-                .buildNewView();
 
+        final SchemaBuilder schemaBuilder = createLevel1TenantView(tenantViewOptions, null);
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 2 rows - one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 120000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 120000);
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 120000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 120000);
 
     }
 
-    @Test
-    public void testPhoenixTTLForLevelTwoView() throws Exception {
-        long startTime = System.currentTimeMillis();
+    @Test public void testPhoenixTTLForLevelTwoView() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. GlobalView with default columns => (ID, COL4, COL5, COL6), PK => (ID)
-        // 3. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
-
-        PhoenixTestBuilder.SchemaBuilder.GlobalViewOptions
-                globalViewOptions = PhoenixTestBuilder.SchemaBuilder.GlobalViewOptions.withDefaults();
-        // Phoenix TTL is set to 300s => 300000 ms
-        globalViewOptions.setTableProps("PHOENIX_TTL=300");
-
-        PhoenixTestBuilder.SchemaBuilder.GlobalViewIndexOptions
-                globalViewIndexOptions =
-                PhoenixTestBuilder.SchemaBuilder.GlobalViewIndexOptions.withDefaults();
-        globalViewIndexOptions.setLocal(false);
-
-        TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
-        // Phoenix TTL is set to 120s => 120000 ms
-        tenantViewWithOverrideOptions.setTableProps("PHOENIX_TTL=120");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withGlobalViewOptions(globalViewOptions)
-                .withGlobalViewIndexOptions(globalViewIndexOptions)
-                .withTenantViewOptions(tenantViewWithOverrideOptions)
-                .withTenantViewIndexDefaults()
-                .buildWithNewTenant();
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithGlobalLevelTTL(null, null);
 
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String globalViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                globalViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
         String indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 4 rows - one for GlobalView, one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 4);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName, PTableType.VIEW.getSerializedValue(), 300000);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName, PTableType.INDEX.getSerializedValue(), 300000);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 120000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 120000);
-
-        // Without override
-        startTime = System.currentTimeMillis();
-
-        TenantViewOptions tenantViewWithoutOverrideOptions = TenantViewOptions.withDefaults();
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withGlobalViewOptions(globalViewOptions)
-                .withGlobalViewIndexOptions(globalViewIndexOptions)
-                .withTenantViewOptions(tenantViewWithoutOverrideOptions)
-                .withTenantViewIndexDefaults()
-                .buildWithNewTenant();
-
-        tenantId = schemaBuilder.getDataOptions().getTenantId();
-        schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        globalViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
-        tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
-        indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
-
-
-        // Expected 2 rows - one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName, PTableType.VIEW.getSerializedValue(), 300000);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName, PTableType.INDEX.getSerializedValue(), 300000);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be same as the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 300000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 300000);
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 4);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+        // Since the PHOENIX_TTL property values are not being overridden,
+        // we expect the TTL value to be same as the global view.
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
     }
 
-    @Test
-    public void testPhoenixTTLForWhenTTLIsZero() throws Exception {
-        long startTime = System.currentTimeMillis();
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLForWhenTTLIsZero() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         // Client can also specify PHOENIX_TTL=NONE
         tenantViewOptions.setTableProps("PHOENIX_TTL=0");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withTenantViewOptions(tenantViewOptions)
-                .withTenantViewIndexDefaults()
-                .buildNewView();
+        final SchemaBuilder schemaBuilder = createLevel1TenantView(tenantViewOptions, null);
 
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 3 deleted rows - one for Table, one for TenantView and ViewIndex each.
         // Since the PHOENIX_TTL property values are not being set or being set to zero,
         // we expect the view header columns to show up in raw scans only.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 0);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 0);
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 0);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 0);
 
     }
 
-    @Test
-    public void testPhoenixTTLWithAlterView() throws Exception {
-        long startTime = System.currentTimeMillis();
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLWithAlterView() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         // Client can also specify PHOENIX_TTL=0
         tenantViewOptions.setTableProps("PHOENIX_TTL=NONE");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withTenantViewOptions(tenantViewOptions)
-                .withTenantViewIndexDefaults()
-                .buildNewView();
+        final SchemaBuilder schemaBuilder = createLevel1TenantView(tenantViewOptions, null);
 
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 3 deleted rows - one for Table, one for TenantView and ViewIndex each.
         // Since the PHOENIX_TTL property values are not being set or being set to zero,
         // we expect the view header columns to show up in raw scans only.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 0);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 0);
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 0);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 0);
 
         String tenantURL = getUrl() + ';' + TENANT_ID_ATTRIB + '=' + tenantId;
         try (Connection connection = DriverManager.getConnection(tenantURL)) {
-            Statement stmt = connection.createStatement();
+            try (Statement stmt = connection.createStatement()) {
+                // Phoenix TTL is set to 120s => 120000 ms
+                String
+                        sql =
+                        String.format(ALTER_PHOENIX_TTL_SQL, schemaName, tenantViewName, "120");
+                stmt.execute(sql);
+            }
+        }
+
+        // Expected 2 rows - one for TenantView and ViewIndex each.
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 120000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 120000);
+
+    }
+
+    @Test public void testCreateViewWithParentPhoenixTTLFails() throws Exception {
+        try {
+            TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
             // Phoenix TTL is set to 120s => 120000 ms
-            String sql = String.format(ALTER_PHOENIX_TTL_SQL, schemaName, tenantViewName, 120);
-            stmt.execute(sql);
+            tenantViewWithOverrideOptions.setTableProps("PHOENIX_TTL=120");
+            final SchemaBuilder
+                    schemaBuilder =
+                    createLevel2TenantViewWithGlobalLevelTTL(tenantViewWithOverrideOptions, null);
+            fail();
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL.getErrorCode(),
+                    e.getErrorCode());
         }
+    }
+
+    @Test public void testAlterViewWithParentPhoenixTTLFails() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
+
+        // Phoenix TTL is set to 300s
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithGlobalLevelTTL(null, null);
+
+        String tenantId = schemaBuilder.getDataOptions().getTenantId();
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                globalViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+
+        // Expected 4 rows - one for GlobalView, one for TenantView and ViewIndex each.
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 4);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+        // Since the PHOENIX_TTL property values are not being overridden,
+        // we expect the TTL value to be same as the global view.
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+
+        String tenantURL = getUrl() + ';' + TENANT_ID_ATTRIB + '=' + tenantId;
+        try (Connection connection = DriverManager.getConnection(tenantURL)) {
+            try (Statement stmt = connection.createStatement()) {
+                // Phoenix TTL is set to 120s => 120000 ms
+                String
+                        sql =
+                        String.format(ALTER_PHOENIX_TTL_SQL, schemaName, tenantViewName, "120");
+                stmt.execute(sql);
+                fail();
+            }
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL.getErrorCode(),
+                    e.getErrorCode());
+        }
+    }
+
+    @Test public void testAlterViewWithChildLevelPhoenixTTLFails() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
+
+        // Phoenix TTL is set to 300s
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithTenantLevelTTL(null, null);
+
+        String tenantId = schemaBuilder.getDataOptions().getTenantId();
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                globalViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 2 rows - one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 120000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 120000);
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+
+        try (Connection connection = DriverManager.getConnection(getUrl())) {
+            try (Statement stmt = connection.createStatement()) {
+                // Phoenix TTL is set to 120s => 120000 ms
+                String
+                        sql =
+                        String.format(ALTER_PHOENIX_TTL_SQL, schemaName, globalViewName, "120");
+                stmt.execute(sql);
+                fail();
+            }
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL.getErrorCode(),
+                    e.getErrorCode());
+        }
+    }
+
+    @Test public void testAlterViewWithNoPhoenixTTLSucceed() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
+
+        // Phoenix TTL is set to 300s
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithTenantLevelTTL(null, null);
+
+        String tenantId = schemaBuilder.getDataOptions().getTenantId();
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                globalViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+
+        // Expected 2 rows - one for TenantView and ViewIndex each.
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+
+        // ALTER global view
+        try (Connection connection = DriverManager.getConnection(getUrl())) {
+            try (Statement stmt = connection.createStatement()) {
+                String
+                        sql =
+                        String.format(ALTER_SQL_WITH_NO_TTL, schemaName, globalViewName, "COL_30");
+                stmt.execute(sql);
+            }
+        } catch (SQLException e) {
+            fail();
+        }
+
+        // ALTER tenant view
+        String tenantURL = getUrl() + ';' + TENANT_ID_ATTRIB + '=' + tenantId;
+        try (Connection connection = DriverManager.getConnection(tenantURL)) {
+            try (Statement stmt = connection.createStatement()) {
+                String
+                        sql =
+                        String.format(ALTER_SQL_WITH_NO_TTL, schemaName, tenantViewName, "COL_100");
+                stmt.execute(sql);
+            }
+        } catch (SQLException e) {

Review comment:
       Remove catch block since it's unnecessary.

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewTTLIT.java
##########
@@ -119,283 +137,556 @@ private String stripQuotes(String name) {
         return name.replace("\"", "");
     }
 
+    private SchemaBuilder createLevel2TenantViewWithGlobalLevelTTL(
+            TenantViewOptions tenantViewOptions, TenantViewIndexOptions tenantViewIndexOptions)
+            throws Exception {
+        // Define the test schema.
+        // 1. Table with columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
+        // 2. GlobalView with columns => (ID, COL4, COL5, COL6), PK => (ID)
+        // 3. Tenant with columns => (ZID, COL7, COL8, COL9), PK => (ZID)
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+
+        TableOptions tableOptions = TableOptions.withDefaults();
+        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+
+        GlobalViewOptions globalViewOptions = GlobalViewOptions.withDefaults();
+        // Phoenix TTL is set to 300s => 300000 ms
+        globalViewOptions.setTableProps("PHOENIX_TTL=300");
+
+        SchemaBuilder.GlobalViewIndexOptions
+                globalViewIndexOptions =
+                SchemaBuilder.GlobalViewIndexOptions.withDefaults();
+        globalViewIndexOptions.setLocal(false);
+
+        TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
+        if (tenantViewOptions != null) {
+            tenantViewWithOverrideOptions = tenantViewOptions;
+        }
+        TenantViewIndexOptions
+                tenantViewIndexOverrideOptions =
+                TenantViewIndexOptions.withDefaults();
+        if (tenantViewIndexOptions != null) {
+            tenantViewIndexOverrideOptions = tenantViewIndexOptions;
+        }
+        schemaBuilder.withTableOptions(tableOptions).withGlobalViewOptions(globalViewOptions)
+                .withGlobalViewIndexOptions(globalViewIndexOptions)
+                .withTenantViewOptions(tenantViewWithOverrideOptions)
+                .withTenantViewIndexOptions(tenantViewIndexOverrideOptions).buildWithNewTenant();
+        return schemaBuilder;
+    }
+
+    private SchemaBuilder createLevel2TenantViewWithTenantLevelTTL(
+            TenantViewOptions tenantViewOptions, TenantViewIndexOptions tenantViewIndexOptions)
+            throws Exception {
+        // Define the test schema.
+        // 1. Table with columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
+        // 2. GlobalView with columns => (ID, COL4, COL5, COL6), PK => (ID)
+        // 3. Tenant with columns => (ZID, COL7, COL8, COL9), PK => (ZID)
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+
+        TableOptions tableOptions = TableOptions.withDefaults();
+        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+
+        GlobalViewOptions globalViewOptions = GlobalViewOptions.withDefaults();
+
+        SchemaBuilder.GlobalViewIndexOptions
+                globalViewIndexOptions =
+                SchemaBuilder.GlobalViewIndexOptions.withDefaults();
+        globalViewIndexOptions.setLocal(false);
+
+        TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
+        // Phoenix TTL is set to 300s => 300000 ms
+        tenantViewWithOverrideOptions.setTableProps("PHOENIX_TTL=300");
+        if (tenantViewOptions != null) {
+            tenantViewWithOverrideOptions = tenantViewOptions;
+        }
+        TenantViewIndexOptions
+                tenantViewIndexOverrideOptions =
+                TenantViewIndexOptions.withDefaults();
+        if (tenantViewIndexOptions != null) {
+            tenantViewIndexOverrideOptions = tenantViewIndexOptions;
+        }
+        schemaBuilder.withTableOptions(tableOptions).withGlobalViewOptions(globalViewOptions)
+                .withGlobalViewIndexOptions(globalViewIndexOptions)
+                .withTenantViewOptions(tenantViewWithOverrideOptions)
+                .withTenantViewIndexOptions(tenantViewIndexOverrideOptions).buildWithNewTenant();
+        return schemaBuilder;
+    }
+
+    private SchemaBuilder createLevel1TenantView(TenantViewOptions tenantViewOptions,
+            TenantViewIndexOptions tenantViewIndexOptions) throws Exception {
+        // Define the test schema.
+        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
+        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+
+        TableOptions tableOptions = TableOptions.withDefaults();
+        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+
+        TenantViewOptions tenantViewOverrideOptions = TenantViewOptions.withDefaults();
+        if (tenantViewOptions != null) {
+            tenantViewOverrideOptions = tenantViewOptions;
+        }
+        TenantViewIndexOptions
+                tenantViewIndexOverrideOptions =
+                TenantViewIndexOptions.withDefaults();
+        if (tenantViewIndexOptions != null) {
+            tenantViewIndexOverrideOptions = tenantViewIndexOptions;
+        }
+
+        schemaBuilder.withTableOptions(tableOptions)
+                .withTenantViewOptions(tenantViewOverrideOptions)
+                .withTenantViewIndexOptions(tenantViewIndexOverrideOptions).buildNewView();
+        return schemaBuilder;
+    }
 
     /**
      * -----------------
      * Test methods
      * -----------------
      */
 
-    @Test
-    public void testWithBasicGlobalViewWithNoPhoenixTTLDefined() throws Exception {
+    @Test public void testWithBasicGlobalViewWithNoPhoenixTTLDefined() throws Exception {
 
-        long startTime = System.currentTimeMillis();
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         // Define the test schema.
         // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
         // 2. GlobalView with default columns => (ID, COL4, COL5, COL6), PK => (ID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-        schemaBuilder
-                .withTableDefaults()
-                .withGlobalViewDefaults()
-                .build();
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
+        schemaBuilder.withTableDefaults().withGlobalViewDefaults().build();
 
         // Expected 2 rows - one for Table and GlobalView each.
-        // Since the PHOENIX_TTL property values are not being set, we expect the view header columns to show up in raw scans only.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 2);
+        // Since the PHOENIX_TTL property values are not being set,
+        // we expect the view header columns to show up in raw scans only.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 2);
     }
 
-
-
-    @Test
-    public void testPhoenixTTLWithTableLevelTTLFails() throws Exception {
+    @Test public void testPhoenixTTLWithTableLevelTTLFails() throws Exception {
 
         // Define the test schema.
         // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
         // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
+        final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl());
 
         TableOptions tableOptions = TableOptions.withDefaults();
         tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true,TTL=100");
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         tenantViewOptions.setTableProps("PHOENIX_TTL=1000");
         try {
-            schemaBuilder
-                    .withTableOptions(tableOptions)
-                    .withTenantViewOptions(tenantViewOptions)
+            schemaBuilder.withTableOptions(tableOptions).withTenantViewOptions(tenantViewOptions)
                     .buildNewView();
             fail();
         } catch (SQLException e) {
-            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL_FOR_TABLE_WITH_TTL.getErrorCode(), e.getErrorCode());
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL_FOR_TABLE_WITH_TTL
+                    .getErrorCode(), e.getErrorCode());
         }
     }
 
-    @Test
-    public void testPhoenixTTLWithViewIndexFails() throws Exception {
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLWithViewIndexFails() throws Exception {
 
         TenantViewIndexOptions tenantViewIndexOptions = TenantViewIndexOptions.withDefaults();
         tenantViewIndexOptions.setIndexProps("PHOENIX_TTL=1000");
         try {
-            schemaBuilder
-                    .withTableOptions(tableOptions)
-                    .withTenantViewDefaults()
-                    .withTenantViewIndexOptions(tenantViewIndexOptions)
-                    .buildNewView();
+            final SchemaBuilder
+                    schemaBuilder =
+                    createLevel1TenantView(null, tenantViewIndexOptions);
             fail();
         } catch (SQLException e) {
-            assertEquals(SQLExceptionCode.PHOENIX_TTL_SUPPORTED_FOR_VIEWS_ONLY.getErrorCode(), e.getErrorCode());
+            assertEquals(SQLExceptionCode.PHOENIX_TTL_SUPPORTED_FOR_VIEWS_ONLY.getErrorCode(),
+                    e.getErrorCode());
         }
     }
 
-    @Test
-    public void testPhoenixTTLForLevelOneView() throws Exception {
-        long startTime = System.currentTimeMillis();
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLForLevelOneView() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         // Phoenix TTL is set to 120s => 120000 ms
         tenantViewOptions.setTableProps("PHOENIX_TTL=120");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withTenantViewOptions(tenantViewOptions)
-                .withTenantViewIndexDefaults()
-                .buildNewView();
 
+        final SchemaBuilder schemaBuilder = createLevel1TenantView(tenantViewOptions, null);
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 2 rows - one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 120000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 120000);
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 120000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 120000);
 
     }
 
-    @Test
-    public void testPhoenixTTLForLevelTwoView() throws Exception {
-        long startTime = System.currentTimeMillis();
+    @Test public void testPhoenixTTLForLevelTwoView() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. GlobalView with default columns => (ID, COL4, COL5, COL6), PK => (ID)
-        // 3. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
-
-        PhoenixTestBuilder.SchemaBuilder.GlobalViewOptions
-                globalViewOptions = PhoenixTestBuilder.SchemaBuilder.GlobalViewOptions.withDefaults();
-        // Phoenix TTL is set to 300s => 300000 ms
-        globalViewOptions.setTableProps("PHOENIX_TTL=300");
-
-        PhoenixTestBuilder.SchemaBuilder.GlobalViewIndexOptions
-                globalViewIndexOptions =
-                PhoenixTestBuilder.SchemaBuilder.GlobalViewIndexOptions.withDefaults();
-        globalViewIndexOptions.setLocal(false);
-
-        TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
-        // Phoenix TTL is set to 120s => 120000 ms
-        tenantViewWithOverrideOptions.setTableProps("PHOENIX_TTL=120");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withGlobalViewOptions(globalViewOptions)
-                .withGlobalViewIndexOptions(globalViewIndexOptions)
-                .withTenantViewOptions(tenantViewWithOverrideOptions)
-                .withTenantViewIndexDefaults()
-                .buildWithNewTenant();
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithGlobalLevelTTL(null, null);
 
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String globalViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                globalViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
         String indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 4 rows - one for GlobalView, one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 4);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName, PTableType.VIEW.getSerializedValue(), 300000);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName, PTableType.INDEX.getSerializedValue(), 300000);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 120000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 120000);
-
-        // Without override
-        startTime = System.currentTimeMillis();
-
-        TenantViewOptions tenantViewWithoutOverrideOptions = TenantViewOptions.withDefaults();
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withGlobalViewOptions(globalViewOptions)
-                .withGlobalViewIndexOptions(globalViewIndexOptions)
-                .withTenantViewOptions(tenantViewWithoutOverrideOptions)
-                .withTenantViewIndexDefaults()
-                .buildWithNewTenant();
-
-        tenantId = schemaBuilder.getDataOptions().getTenantId();
-        schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        globalViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
-        tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
-        indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
-
-
-        // Expected 2 rows - one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName, PTableType.VIEW.getSerializedValue(), 300000);
-        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName, PTableType.INDEX.getSerializedValue(), 300000);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be same as the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 300000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 300000);
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 4);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+        // Since the PHOENIX_TTL property values are not being overridden,
+        // we expect the TTL value to be same as the global view.
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
     }
 
-    @Test
-    public void testPhoenixTTLForWhenTTLIsZero() throws Exception {
-        long startTime = System.currentTimeMillis();
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLForWhenTTLIsZero() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         // Client can also specify PHOENIX_TTL=NONE
         tenantViewOptions.setTableProps("PHOENIX_TTL=0");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withTenantViewOptions(tenantViewOptions)
-                .withTenantViewIndexDefaults()
-                .buildNewView();
+        final SchemaBuilder schemaBuilder = createLevel1TenantView(tenantViewOptions, null);
 
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 3 deleted rows - one for Table, one for TenantView and ViewIndex each.
         // Since the PHOENIX_TTL property values are not being set or being set to zero,
         // we expect the view header columns to show up in raw scans only.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 0);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 0);
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 0);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 0);
 
     }
 
-    @Test
-    public void testPhoenixTTLWithAlterView() throws Exception {
-        long startTime = System.currentTimeMillis();
-
-        // Define the test schema.
-        // 1. Table with default columns => (ORG_ID, KP, COL1, COL2, COL3), PK => (ORG_ID, KP)
-        // 2. Tenant with default columns => (ZID, COL7, COL8, COL9), PK => (ZID)
-        final PhoenixTestBuilder.SchemaBuilder schemaBuilder = new PhoenixTestBuilder.SchemaBuilder(getUrl());
-
-        TableOptions tableOptions = TableOptions.withDefaults();
-        tableOptions.setTableProps("COLUMN_ENCODED_BYTES=0,MULTI_TENANT=true");
+    @Test public void testPhoenixTTLWithAlterView() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
 
         TenantViewOptions tenantViewOptions = TenantViewOptions.withDefaults();
         // Client can also specify PHOENIX_TTL=0
         tenantViewOptions.setTableProps("PHOENIX_TTL=NONE");
-        schemaBuilder
-                .withTableOptions(tableOptions)
-                .withTenantViewOptions(tenantViewOptions)
-                .withTenantViewIndexDefaults()
-                .buildNewView();
+        final SchemaBuilder schemaBuilder = createLevel1TenantView(tenantViewOptions, null);
 
         String tenantId = schemaBuilder.getDataOptions().getTenantId();
-        String schemaName = stripQuotes(SchemaUtil.getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String tenantViewName = stripQuotes(SchemaUtil.getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
-        String indexOnTenantViewName = String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 3 deleted rows - one for Table, one for TenantView and ViewIndex each.
         // Since the PHOENIX_TTL property values are not being set or being set to zero,
         // we expect the view header columns to show up in raw scans only.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 0);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 0);
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, true, 3);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 0);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 0);
 
         String tenantURL = getUrl() + ';' + TENANT_ID_ATTRIB + '=' + tenantId;
         try (Connection connection = DriverManager.getConnection(tenantURL)) {
-            Statement stmt = connection.createStatement();
+            try (Statement stmt = connection.createStatement()) {
+                // Phoenix TTL is set to 120s => 120000 ms
+                String
+                        sql =
+                        String.format(ALTER_PHOENIX_TTL_SQL, schemaName, tenantViewName, "120");
+                stmt.execute(sql);
+            }
+        }
+
+        // Expected 2 rows - one for TenantView and ViewIndex each.
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 120000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 120000);
+
+    }
+
+    @Test public void testCreateViewWithParentPhoenixTTLFails() throws Exception {
+        try {
+            TenantViewOptions tenantViewWithOverrideOptions = TenantViewOptions.withDefaults();
             // Phoenix TTL is set to 120s => 120000 ms
-            String sql = String.format(ALTER_PHOENIX_TTL_SQL, schemaName, tenantViewName, 120);
-            stmt.execute(sql);
+            tenantViewWithOverrideOptions.setTableProps("PHOENIX_TTL=120");
+            final SchemaBuilder
+                    schemaBuilder =
+                    createLevel2TenantViewWithGlobalLevelTTL(tenantViewWithOverrideOptions, null);
+            fail();
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL.getErrorCode(),
+                    e.getErrorCode());
         }
+    }
+
+    @Test public void testAlterViewWithParentPhoenixTTLFails() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
+
+        // Phoenix TTL is set to 300s
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithGlobalLevelTTL(null, null);
+
+        String tenantId = schemaBuilder.getDataOptions().getTenantId();
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                globalViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+
+        // Expected 4 rows - one for GlobalView, one for TenantView and ViewIndex each.
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 4);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, globalViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns("", schemaName, indexOnGlobalViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+        // Since the PHOENIX_TTL property values are not being overridden,
+        // we expect the TTL value to be same as the global view.
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+
+        String tenantURL = getUrl() + ';' + TENANT_ID_ATTRIB + '=' + tenantId;
+        try (Connection connection = DriverManager.getConnection(tenantURL)) {
+            try (Statement stmt = connection.createStatement()) {
+                // Phoenix TTL is set to 120s => 120000 ms
+                String
+                        sql =
+                        String.format(ALTER_PHOENIX_TTL_SQL, schemaName, tenantViewName, "120");
+                stmt.execute(sql);
+                fail();
+            }
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL.getErrorCode(),
+                    e.getErrorCode());
+        }
+    }
+
+    @Test public void testAlterViewWithChildLevelPhoenixTTLFails() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
+
+        // Phoenix TTL is set to 300s
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithTenantLevelTTL(null, null);
+
+        String tenantId = schemaBuilder.getDataOptions().getTenantId();
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                globalViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
 
         // Expected 2 rows - one for TenantView and ViewIndex each.
-        // Since the PHOENIX_TTL property values are being set, we expect the view header columns to show up in regular scans too.
-        assertViewHeaderRowsHavePhoenixTTLRelatedCells(schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
-        // Since the PHOENIX_TTL property values are not being overriden, we expect the TTL value to be different from the global view.
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName, PTableType.VIEW.getSerializedValue(), 120000);
-        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName, PTableType.INDEX.getSerializedValue(), 120000);
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+
+        try (Connection connection = DriverManager.getConnection(getUrl())) {
+            try (Statement stmt = connection.createStatement()) {
+                // Phoenix TTL is set to 120s => 120000 ms
+                String
+                        sql =
+                        String.format(ALTER_PHOENIX_TTL_SQL, schemaName, globalViewName, "120");
+                stmt.execute(sql);
+                fail();
+            }
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.CANNOT_SET_OR_ALTER_PHOENIX_TTL.getErrorCode(),
+                    e.getErrorCode());
+        }
+    }
+
+    @Test public void testAlterViewWithNoPhoenixTTLSucceed() throws Exception {
+        long startTime = EnvironmentEdgeManager.currentTimeMillis();
+
+        // Phoenix TTL is set to 300s
+        final SchemaBuilder schemaBuilder = createLevel2TenantViewWithTenantLevelTTL(null, null);
+
+        String tenantId = schemaBuilder.getDataOptions().getTenantId();
+        String
+                schemaName =
+                stripQuotes(SchemaUtil
+                        .getSchemaNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String
+                globalViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityGlobalViewName()));
+        String
+                tenantViewName =
+                stripQuotes(SchemaUtil
+                        .getTableNameFromFullName(schemaBuilder.getEntityTenantViewName()));
+        String indexOnGlobalViewName = String.format("IDX_%s", globalViewName);
+        String
+                indexOnTenantViewName =
+                String.format("IDX_%s", stripQuotes(schemaBuilder.getEntityKeyPrefix()));
+
+        // Expected 2 rows - one for TenantView and ViewIndex each.
+        // Since the PHOENIX_TTL property values are being set,
+        // we expect the view header columns to show up in regular scans too.
+        assertViewHeaderRowsHavePhoenixTTLRelatedCells(
+                schemaBuilder.getTableOptions().getSchemaName(), startTime, false, 2);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, tenantViewName,
+                PTableType.VIEW.getSerializedValue(), 300000);
+        assertSyscatHavePhoenixTTLRelatedColumns(tenantId, schemaName, indexOnTenantViewName,
+                PTableType.INDEX.getSerializedValue(), 300000);
+
+        // ALTER global view
+        try (Connection connection = DriverManager.getConnection(getUrl())) {
+            try (Statement stmt = connection.createStatement()) {
+                String
+                        sql =
+                        String.format(ALTER_SQL_WITH_NO_TTL, schemaName, globalViewName, "COL_30");
+                stmt.execute(sql);
+            }
+        } catch (SQLException e) {

Review comment:
       This `catch` block is unnecessary, you can remove it.

##########
File path: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
##########
@@ -2077,6 +2077,13 @@ private PTable createTableInternal(CreateTableStatement statement, byte[][] spli
                     }
                 }
 
+                // Cannot set PHOENIX_TTL if parent has already defined it.
+                if (tableType == VIEW  && parent != null && parent.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {

Review comment:
       We're doing this check and still doing a similar one on the server. Do we need both?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] gjacoby126 closed pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
gjacoby126 closed pull request #916:
URL: https://github.com/apache/phoenix/pull/916


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] gjacoby126 commented on pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
gjacoby126 commented on pull request #916:
URL: https://github.com/apache/phoenix/pull/916#issuecomment-720788103


   JIRA appears to be closed as fixed. Closing PR. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] jpisaac commented on a change in pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
jpisaac commented on a change in pull request #916:
URL: https://github.com/apache/phoenix/pull/916#discussion_r512392228



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2639,6 +2646,20 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
                         QueryServices.ALLOW_SPLITTABLE_SYSTEM_CATALOG_ROLLBACK);
                 }
             }
+            if (settingNewPhoenixTTLAttribute(tableMetadata, PHOENIX_TTL_BYTES)) {
+                // Disallow if the parent has PHOENIX_TTL set.
+                if (parentTable != null &&  parentTable.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {
+                    isSchemaMutationAllowed = false;
+                }
+
+                // Since we do not allow propagation of PHOENIX_TTL values during ALTER for now.
+                // If a child view exists and the parent previously had a PHOENIX_TTL value set then that
+                // implies that the child view too has a valid PHOENIX_TTL (non zero).
+                // In this case we do not allow for ALTER of the parent view PHOENIX_TTL value.
+                if (!childViews.isEmpty()) {

Review comment:
       Will change the comment to be less confusing.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] stoty commented on pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
stoty commented on pull request #916:
URL: https://github.com/apache/phoenix/pull/916#issuecomment-717021826


   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime | Comment |
   |:----:|----------:|--------:|:--------|
   | +0 :ok: |  reexec  |   0m 35s |  Docker mode activated.  |
   ||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  1s |  No case conflicting files found.  |
   | +1 :green_heart: |  hbaseanti  |   0m  0s |  Patch does not have any anti-patterns.  |
   | +1 :green_heart: |  @author  |   0m  0s |  The patch does not contain any @author tags.  |
   | -1 :x: |  test4tests  |   0m  0s |  The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.  |
   ||| _ 4.x Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  10m 50s |  4.x passed  |
   | +1 :green_heart: |  compile  |   0m 56s |  4.x passed  |
   | +1 :green_heart: |  checkstyle  |   2m 14s |  4.x passed  |
   | +1 :green_heart: |  javadoc  |   0m 46s |  4.x passed  |
   | +0 :ok: |  spotbugs  |   2m 56s |  phoenix-core in 4.x has 953 extant spotbugs warnings.  |
   ||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   5m 59s |  the patch passed  |
   | +1 :green_heart: |  compile  |   1m 12s |  the patch passed  |
   | +1 :green_heart: |  javac  |   1m 12s |  the patch passed  |
   | -1 :x: |  checkstyle  |   2m 23s |  phoenix-core: The patch generated 57 new + 5253 unchanged - 34 fixed = 5310 total (was 5287)  |
   | +1 :green_heart: |  whitespace  |   0m  0s |  The patch has no whitespace issues.  |
   | +1 :green_heart: |  javadoc  |   0m 51s |  the patch passed  |
   | +1 :green_heart: |  spotbugs  |   4m  5s |  the patch passed  |
   ||| _ Other Tests _ |
   | -1 :x: |  unit  | 133m 21s |  phoenix-core in the patch failed.  |
   | +1 :green_heart: |  asflicense  |   0m 33s |  The patch does not generate ASF License warnings.  |
   |  |   | 169m 20s |   |
   
   
   | Reason | Tests |
   |-------:|:------|
   | Failed junit tests | phoenix.end2end.index.GlobalMutableNonTxIndexIT |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.40 ServerAPI=1.40 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/3/artifact/yetus-general-check/output/Dockerfile |
   | GITHUB PR | https://github.com/apache/phoenix/pull/916 |
   | Optional Tests | dupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile |
   | uname | Linux 9345c7de816f 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev/phoenix-personality.sh |
   | git revision | 4.x / ac0538b |
   | Default Java | Private Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08 |
   | checkstyle | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/3/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt |
   | unit | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/3/artifact/yetus-general-check/output/patch-unit-phoenix-core.txt |
   |  Test Results | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/3/testReport/ |
   | Max. process+thread count | 6942 (vs. ulimit of 30000) |
   | modules | C: phoenix-core U: phoenix-core |
   | Console output | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/3/console |
   | versions | git=2.7.4 maven=3.3.9 spotbugs=4.1.3 |
   | Powered by | Apache Yetus 0.12.0 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] jpisaac closed pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
jpisaac closed pull request #916:
URL: https://github.com/apache/phoenix/pull/916


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] yanxinyi commented on a change in pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
yanxinyi commented on a change in pull request #916:
URL: https://github.com/apache/phoenix/pull/916#discussion_r504227350



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2621,6 +2625,13 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
                 List<ImmutableBytesPtr> invalidateList = new ArrayList<ImmutableBytesPtr>();
                 invalidateList.add(cacheKey);
                 PTable table = getTableFromCache(cacheKey, clientTimeStamp, clientVersion);
+
+                // Disallow if the parent has PHOENIX_TTL set.
+                if (parentTable != null &&  parentTable.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {

Review comment:
       just want to confirm that we don't support more than 2 level case. For example, we have a global view V1 of the TTL set. The V2 is a view on top of the V1. If we create a new V3 on of the v2 with a TTL value, this won't catch and allow the V3 view to have a TTL value, which might conflict with V1 TTL.
   
   better to document somewhere to notice other ppl




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] stoty commented on pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
stoty commented on pull request #916:
URL: https://github.com/apache/phoenix/pull/916#issuecomment-718221802


   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime | Comment |
   |:----:|----------:|--------:|:--------|
   | +0 :ok: |  reexec  |   0m 46s |  Docker mode activated.  |
   ||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  No case conflicting files found.  |
   | +1 :green_heart: |  hbaseanti  |   0m  0s |  Patch does not have any anti-patterns.  |
   | +1 :green_heart: |  @author  |   0m  0s |  The patch does not contain any @author tags.  |
   | -1 :x: |  test4tests  |   0m  0s |  The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.  |
   ||| _ 4.x Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  11m 16s |  4.x passed  |
   | +1 :green_heart: |  compile  |   0m 55s |  4.x passed  |
   | +1 :green_heart: |  checkstyle  |   2m 22s |  4.x passed  |
   | +1 :green_heart: |  javadoc  |   0m 44s |  4.x passed  |
   | +0 :ok: |  spotbugs  |   3m  6s |  phoenix-core in 4.x has 953 extant spotbugs warnings.  |
   ||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   5m 41s |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 54s |  the patch passed  |
   | +1 :green_heart: |  javac  |   0m 54s |  the patch passed  |
   | -1 :x: |  checkstyle  |   2m 45s |  phoenix-core: The patch generated 21 new + 5287 unchanged - 0 fixed = 5308 total (was 5287)  |
   | +1 :green_heart: |  whitespace  |   0m  0s |  The patch has no whitespace issues.  |
   | +1 :green_heart: |  javadoc  |   0m 42s |  the patch passed  |
   | +1 :green_heart: |  spotbugs  |   3m  1s |  the patch passed  |
   ||| _ Other Tests _ |
   | -1 :x: |  unit  | 123m 38s |  phoenix-core in the patch failed.  |
   | +1 :green_heart: |  asflicense  |   0m 38s |  The patch does not generate ASF License warnings.  |
   |  |   | 159m  9s |   |
   
   
   | Reason | Tests |
   |-------:|:------|
   | Failed junit tests | phoenix.end2end.UpsertSelectIT |
   |   | phoenix.end2end.AlterTableWithViewsIT |
   |   | phoenix.end2end.DropIndexedColsIT |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.40 ServerAPI=1.40 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/4/artifact/yetus-general-check/output/Dockerfile |
   | GITHUB PR | https://github.com/apache/phoenix/pull/916 |
   | Optional Tests | dupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile |
   | uname | Linux 09a9e4931dde 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev/phoenix-personality.sh |
   | git revision | 4.x / ac0538b |
   | Default Java | Private Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08 |
   | checkstyle | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/4/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt |
   | unit | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/4/artifact/yetus-general-check/output/patch-unit-phoenix-core.txt |
   |  Test Results | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/4/testReport/ |
   | Max. process+thread count | 7250 (vs. ulimit of 30000) |
   | modules | C: phoenix-core U: phoenix-core |
   | Console output | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/4/console |
   | versions | git=2.7.4 maven=3.3.9 spotbugs=4.1.3 |
   | Powered by | Apache Yetus 0.12.0 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] stoty commented on pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
stoty commented on pull request #916:
URL: https://github.com/apache/phoenix/pull/916#issuecomment-706382073


   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime | Comment |
   |:----:|----------:|--------:|:--------|
   | +0 :ok: |  reexec  |   0m 28s |  Docker mode activated.  |
   ||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  No case conflicting files found.  |
   | +1 :green_heart: |  hbaseanti  |   0m  0s |  Patch does not have any anti-patterns.  |
   | +1 :green_heart: |  @author  |   0m  0s |  The patch does not contain any @author tags.  |
   | -1 :x: |  test4tests  |   0m  0s |  The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.  |
   ||| _ 4.x Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  27m  2s |  4.x passed  |
   | +1 :green_heart: |  compile  |   0m 58s |  4.x passed  |
   | +1 :green_heart: |  checkstyle  |   2m 45s |  4.x passed  |
   | +1 :green_heart: |  javadoc  |   0m 43s |  4.x passed  |
   | +0 :ok: |  spotbugs  |   2m 52s |  phoenix-core in 4.x has 957 extant spotbugs warnings.  |
   ||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  22m 57s |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 55s |  the patch passed  |
   | +1 :green_heart: |  javac  |   0m 55s |  the patch passed  |
   | -1 :x: |  checkstyle  |   2m 49s |  phoenix-core: The patch generated 27 new + 5445 unchanged - 4 fixed = 5472 total (was 5449)  |
   | +1 :green_heart: |  whitespace  |   0m  0s |  The patch has no whitespace issues.  |
   | +1 :green_heart: |  javadoc  |   0m 43s |  the patch passed  |
   | +1 :green_heart: |  spotbugs  |   3m  3s |  the patch passed  |
   ||| _ Other Tests _ |
   | -1 :x: |  unit  | 124m  4s |  phoenix-core in the patch failed.  |
   | +1 :green_heart: |  asflicense  |   0m 37s |  The patch does not generate ASF License warnings.  |
   |  |   | 192m 37s |   |
   
   
   | Reason | Tests |
   |-------:|:------|
   | Failed junit tests | phoenix.end2end.RowValueConstructorOffsetIT |
   |   | phoenix.end2end.AlterTableWithViewsIT |
   |   | phoenix.end2end.ConcurrentMutationsExtendedIT |
   |   | phoenix.end2end.DerivedTableIT |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.40 ServerAPI=1.40 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/artifact/yetus-general-check/output/Dockerfile |
   | GITHUB PR | https://github.com/apache/phoenix/pull/916 |
   | Optional Tests | dupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile |
   | uname | Linux b072fbaa2ce8 4.15.0-60-generic #67-Ubuntu SMP Thu Aug 22 16:55:30 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev/phoenix-personality.sh |
   | git revision | 4.x / fc3d25c |
   | Default Java | Private Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08 |
   | checkstyle | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt |
   | unit | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/artifact/yetus-general-check/output/patch-unit-phoenix-core.txt |
   |  Test Results | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/testReport/ |
   | Max. process+thread count | 6934 (vs. ulimit of 30000) |
   | modules | C: phoenix-core U: phoenix-core |
   | Console output | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/console |
   | versions | git=2.7.4 maven=3.3.9 spotbugs=4.1.3 |
   | Powered by | Apache Yetus 0.12.0 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] jpisaac commented on pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
jpisaac commented on pull request #916:
URL: https://github.com/apache/phoenix/pull/916#issuecomment-706294931


   @yanxinyi @ChinmaySKulkarni 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] stoty commented on pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
stoty commented on pull request #916:
URL: https://github.com/apache/phoenix/pull/916#issuecomment-716842752


   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime | Comment |
   |:----:|----------:|--------:|:--------|
   | +0 :ok: |  reexec  |   5m 18s |  Docker mode activated.  |
   ||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  No case conflicting files found.  |
   | +1 :green_heart: |  hbaseanti  |   0m  0s |  Patch does not have any anti-patterns.  |
   | +1 :green_heart: |  @author  |   0m  0s |  The patch does not contain any @author tags.  |
   | -1 :x: |  test4tests  |   0m  0s |  The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.  |
   ||| _ 4.x Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  12m 11s |  4.x passed  |
   | +1 :green_heart: |  compile  |   1m  3s |  4.x passed  |
   | +1 :green_heart: |  checkstyle  |   2m 37s |  4.x passed  |
   | +1 :green_heart: |  javadoc  |   0m 59s |  4.x passed  |
   | +0 :ok: |  spotbugs  |   3m 53s |  phoenix-core in 4.x has 954 extant spotbugs warnings.  |
   ||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   7m 22s |  the patch passed  |
   | +1 :green_heart: |  compile  |   1m 12s |  the patch passed  |
   | +1 :green_heart: |  javac  |   1m 12s |  the patch passed  |
   | -1 :x: |  checkstyle  |   2m 29s |  phoenix-core: The patch generated 28 new + 5288 unchanged - 0 fixed = 5316 total (was 5288)  |
   | +1 :green_heart: |  whitespace  |   0m  0s |  The patch has no whitespace issues.  |
   | +1 :green_heart: |  javadoc  |   0m 54s |  the patch passed  |
   | +1 :green_heart: |  spotbugs  |   3m 56s |  the patch passed  |
   ||| _ Other Tests _ |
   | -1 :x: |  unit  | 130m  2s |  phoenix-core in the patch failed.  |
   | +1 :green_heart: |  asflicense  |   0m 36s |  The patch does not generate ASF License warnings.  |
   |  |   | 175m 25s |   |
   
   
   | Reason | Tests |
   |-------:|:------|
   | Failed junit tests | phoenix.end2end.CaseStatementIT |
   |   | phoenix.end2end.OrphanViewToolIT |
   |   | phoenix.end2end.OrderByWithServerClientSpoolingDisabledIT |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.40 ServerAPI=1.40 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/artifact/yetus-general-check/output/Dockerfile |
   | GITHUB PR | https://github.com/apache/phoenix/pull/916 |
   | Optional Tests | dupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile |
   | uname | Linux 76c0bc3a23a7 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev/phoenix-personality.sh |
   | git revision | 4.x / 135692c |
   | Default Java | Private Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08 |
   | checkstyle | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt |
   | unit | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/artifact/yetus-general-check/output/patch-unit-phoenix-core.txt |
   |  Test Results | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/testReport/ |
   | Max. process+thread count | 7005 (vs. ulimit of 30000) |
   | modules | C: phoenix-core U: phoenix-core |
   | Console output | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/1/console |
   | versions | git=2.7.4 maven=3.3.9 spotbugs=4.1.3 |
   | Powered by | Apache Yetus 0.12.0 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] stoty commented on pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
stoty commented on pull request #916:
URL: https://github.com/apache/phoenix/pull/916#issuecomment-710724390


   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime | Comment |
   |:----:|----------:|--------:|:--------|
   | +0 :ok: |  reexec  |   4m 16s |  Docker mode activated.  |
   ||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  No case conflicting files found.  |
   | +1 :green_heart: |  hbaseanti  |   0m  0s |  Patch does not have any anti-patterns.  |
   | +1 :green_heart: |  @author  |   0m  0s |  The patch does not contain any @author tags.  |
   | -1 :x: |  test4tests  |   0m  0s |  The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.  |
   ||| _ 4.x Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  26m 20s |  4.x passed  |
   | +1 :green_heart: |  compile  |   0m 56s |  4.x passed  |
   | +1 :green_heart: |  checkstyle  |   2m 44s |  4.x passed  |
   | +1 :green_heart: |  javadoc  |   0m 44s |  4.x passed  |
   | +0 :ok: |  spotbugs  |   2m 47s |  phoenix-core in 4.x has 956 extant spotbugs warnings.  |
   ||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  22m 52s |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 55s |  the patch passed  |
   | +1 :green_heart: |  javac  |   0m 55s |  the patch passed  |
   | -1 :x: |  checkstyle  |   2m 33s |  phoenix-core: The patch generated 32 new + 5445 unchanged - 4 fixed = 5477 total (was 5449)  |
   | +1 :green_heart: |  whitespace  |   0m  0s |  The patch has no whitespace issues.  |
   | +1 :green_heart: |  javadoc  |   0m 44s |  the patch passed  |
   | +1 :green_heart: |  spotbugs  |   3m 45s |  the patch passed  |
   ||| _ Other Tests _ |
   | -1 :x: |  unit  | 127m 26s |  phoenix-core in the patch failed.  |
   | +1 :green_heart: |  asflicense  |   0m 36s |  The patch does not generate ASF License warnings.  |
   |  |   | 199m 22s |   |
   
   
   | Reason | Tests |
   |-------:|:------|
   | Failed junit tests | phoenix.end2end.AlterTableWithViewsIT |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.40 ServerAPI=1.40 base: https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/2/artifact/yetus-general-check/output/Dockerfile |
   | GITHUB PR | https://github.com/apache/phoenix/pull/916 |
   | Optional Tests | dupname asflicense javac javadoc unit spotbugs hbaseanti checkstyle compile |
   | uname | Linux 3b7e04256ddc 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev/phoenix-personality.sh |
   | git revision | 4.x / 2359f54 |
   | Default Java | Private Build-1.8.0_242-8u242-b08-0ubuntu3~16.04-b08 |
   | checkstyle | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/2/artifact/yetus-general-check/output/diff-checkstyle-phoenix-core.txt |
   | unit | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/2/artifact/yetus-general-check/output/patch-unit-phoenix-core.txt |
   |  Test Results | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/2/testReport/ |
   | Max. process+thread count | 7321 (vs. ulimit of 30000) |
   | modules | C: phoenix-core U: phoenix-core |
   | Console output | https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-916/2/console |
   | versions | git=2.7.4 maven=3.3.9 spotbugs=4.1.3 |
   | Powered by | Apache Yetus 0.12.0 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] jpisaac commented on a change in pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
jpisaac commented on a change in pull request #916:
URL: https://github.com/apache/phoenix/pull/916#discussion_r506722736



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2621,6 +2625,13 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
                 List<ImmutableBytesPtr> invalidateList = new ArrayList<ImmutableBytesPtr>();
                 invalidateList.add(cacheKey);
                 PTable table = getTableFromCache(cacheKey, clientTimeStamp, clientVersion);
+
+                // Disallow if the parent has PHOENIX_TTL set.
+                if (parentTable != null &&  parentTable.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {

Review comment:
       @yanxinyi  Currently the PHOENIX_TTL value is stored with every view and at every level - so in this case V2 would have the same PHOENIX_TTL value as of V1. So when creating V3 the parentTable.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED. 
   
   But realized as was going thru this that I need an additional check to ensure that the PHOENIX_TTL is being altered




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] jpisaac commented on a change in pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
jpisaac commented on a change in pull request #916:
URL: https://github.com/apache/phoenix/pull/916#discussion_r512394047



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
##########
@@ -2077,6 +2077,13 @@ private PTable createTableInternal(CreateTableStatement statement, byte[][] spli
                     }
                 }
 
+                // Cannot set PHOENIX_TTL if parent has already defined it.
+                if (tableType == VIEW  && parent != null && parent.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {

Review comment:
       This check is during the createTable flow. Moreover the current code does not allow for easy client-side checks for TableProperty changes during alter command.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] jpisaac commented on pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
jpisaac commented on pull request #916:
URL: https://github.com/apache/phoenix/pull/916#issuecomment-716754717


   @yanxinyi @ChinmaySKulkarni rebased and fixed conflicts


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] jpisaac commented on pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
jpisaac commented on pull request #916:
URL: https://github.com/apache/phoenix/pull/916#issuecomment-716962568


   @ChinmaySKulkarni @yanxinyi Addressed review comments and rebased to resolve merge conflicts.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [phoenix] yanxinyi commented on a change in pull request #916: PHOENIX-6171 Child views should not be allowed to override the parent view PHOENIX_TTL attribute.

Posted by GitBox <gi...@apache.org>.
yanxinyi commented on a change in pull request #916:
URL: https://github.com/apache/phoenix/pull/916#discussion_r504227350



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2621,6 +2625,13 @@ private MetaDataMutationResult doDropTable(byte[] key, byte[] tenantId, byte[] s
                 List<ImmutableBytesPtr> invalidateList = new ArrayList<ImmutableBytesPtr>();
                 invalidateList.add(cacheKey);
                 PTable table = getTableFromCache(cacheKey, clientTimeStamp, clientVersion);
+
+                // Disallow if the parent has PHOENIX_TTL set.
+                if (parentTable != null &&  parentTable.getPhoenixTTL() != PHOENIX_TTL_NOT_DEFINED) {

Review comment:
       just want to confirm that we don't support more than 2 level case. For example, we have a global view V1 of the TTL set. The V2 is a view on top of the V1. If we create a new V3 on of the v2 with a TTL value, this won't catch and allow the V3 view to have a TTL value, which might conflict with V1 TTL.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org