[
https://issues.apache.org/jira/browse/PHOENIX-6186?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17231628#comment-17231628
]
ASF GitHub Bot commented on PHOENIX-6186:
-----------------------------------------
shahrs87 commented on a change in pull request #935:
URL: https://github.com/apache/phoenix/pull/935#discussion_r523037861
##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
##########
@@ -1326,7 +1328,69 @@ public void testAddingColumnsToTablesAndViews() throws
Exception {
assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM
+ 1);
}
}
-
+
+ @Test
+ public void testAddThenDropColumnTableDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ String tableDDL = "CREATE TABLE IF NOT EXISTS " + dataTableFullName +
" ("
+ + " ENTITY_ID integer NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (ENTITY_ID, COL1, COL2)"
+ + " ) " + generateDDLOptions("");
+
+ String columnAddDDL = "ALTER TABLE " + dataTableFullName + " ADD COL3
varchar(50) NULL ";
+ String columnDropDDL = "ALTER TABLE " + dataTableFullName + " DROP
COLUMN COL3 ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
Review comment:
just 1 minor nit. DriverManager has method getConnection without
Properties argument. We can use that in all newly added test cases since we
don't override any properties here. If it is too much change please feel free
to ignore also.
##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
##########
@@ -1326,7 +1328,69 @@ public void testAddingColumnsToTablesAndViews() throws
Exception {
assertSequenceNumber(schemaName, viewName, PTable.INITIAL_SEQ_NUM
+ 1);
}
}
-
+
+ @Test
+ public void testAddThenDropColumnTableDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ String tableDDL = "CREATE TABLE IF NOT EXISTS " + dataTableFullName +
" ("
+ + " ENTITY_ID integer NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (ENTITY_ID, COL1, COL2)"
+ + " ) " + generateDDLOptions("");
+
+ String columnAddDDL = "ALTER TABLE " + dataTableFullName + " ADD COL3
varchar(50) NULL ";
+ String columnDropDDL = "ALTER TABLE " + dataTableFullName + " DROP
COLUMN COL3 ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute(tableDDL);
+ //first get the original DDL timestamp when we created the table
+ long tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName, startTS,
+ conn);
+ Thread.sleep(1);
+ //now add a column and make sure the timestamp updates
+ conn.createStatement().execute(columnAddDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName,
+ tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(columnDropDDL);
+ CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName,
+ tableDDLTimestamp + 1 , conn);
+ }
+ }
+
+ @Test
+ public void testSetPropertyDoesntUpdateDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ String tableDDL = "CREATE TABLE IF NOT EXISTS " + dataTableFullName +
" ("
+ + " ENTITY_ID integer NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (ENTITY_ID, COL1, COL2)"
+ + " ) " + generateDDLOptions("");
+
+ String setPropertyDDL = "ALTER TABLE " + dataTableFullName +
+ " SET UPDATE_CACHE_FREQUENCY=300000 ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute(tableDDL);
+ //first get the original DDL timestamp when we created the table
+ long tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName, startTS,
+ conn);
+ Thread.sleep(1);
+ //now add a column and make sure the timestamp updates
Review comment:
is this comment carried forward from previous test and no longer
relevant here ?
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
##########
@@ -1216,5 +1218,248 @@ public void testDroppingIndexedColDropsViewIndex()
throws Exception {
assertNull(results.next());
}
}
-
+
+ @Test
+ public void testAddThenDropColumnTableDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String columnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String columnDropDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN
COL3 ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute(tableDDL);
+ //first get the original DDL timestamp when we created the table
+ long tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName, startTS,
+ conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(viewDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ //now add a column and make sure the timestamp updates
+ conn.createStatement().execute(columnAddDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(columnDropDDL);
+ CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1 , conn);
+ }
+ }
+
+ @Test
+ public void testLastDDLTimestampForDivergedViews() throws Exception {
+ //Phoenix allows users to "drop" columns from views that are inherited
from their ancestor
+ // views or tables. These columns are then excluded from the view
schema, and the view is
+ // considered "diverged" from its parents, and so no longer inherit
any additional schema
+ // changes that are applied to their ancestors. This test make sure
that this behavior
+ // extends to DDL timestamp
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String divergeDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN COL2";
+ String viewColumnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String viewColumnDropDDL = "ALTER VIEW " + viewFullName + " DROP
COLUMN COL3 ";
+ String tableColumnAddDDL = "ALTER TABLE " + dataTableFullName + " ADD
COL4 varchar" +
+ "(50) NULL";
+ String tableColumnDropDDL = "ALTER TABLE " + dataTableFullName + "
DROP COLUMN COL4 ";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(tableDDL);
+ conn.createStatement().execute(viewDDL);
+ long viewDDLTimestamp = getLastDDLTimestamp(conn, viewFullName);
+ Thread.sleep(1);
+ conn.createStatement().execute(divergeDDL);
+ //verify DDL timestamp changed
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(viewColumnAddDDL);
+ //verify DDL timestamp changed because we added a column to the
view
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
Review comment:
I understand it is strictly not required but should we sleep for 1
millisecond just to make sure that 1 ms passed between divergeDDL and
viewColumnAddDDL execution and the same argument applies for other ddl
statements that we execute subsequently in this test.
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
##########
@@ -1216,5 +1218,248 @@ public void testDroppingIndexedColDropsViewIndex()
throws Exception {
assertNull(results.next());
}
}
-
+
+ @Test
+ public void testAddThenDropColumnTableDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String columnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String columnDropDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN
COL3 ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute(tableDDL);
+ //first get the original DDL timestamp when we created the table
+ long tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName, startTS,
+ conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(viewDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ //now add a column and make sure the timestamp updates
+ conn.createStatement().execute(columnAddDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(columnDropDDL);
+ CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1 , conn);
+ }
+ }
+
+ @Test
+ public void testLastDDLTimestampForDivergedViews() throws Exception {
+ //Phoenix allows users to "drop" columns from views that are inherited
from their ancestor
+ // views or tables. These columns are then excluded from the view
schema, and the view is
+ // considered "diverged" from its parents, and so no longer inherit
any additional schema
+ // changes that are applied to their ancestors. This test make sure
that this behavior
+ // extends to DDL timestamp
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String divergeDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN COL2";
+ String viewColumnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String viewColumnDropDDL = "ALTER VIEW " + viewFullName + " DROP
COLUMN COL3 ";
+ String tableColumnAddDDL = "ALTER TABLE " + dataTableFullName + " ADD
COL4 varchar" +
+ "(50) NULL";
+ String tableColumnDropDDL = "ALTER TABLE " + dataTableFullName + "
DROP COLUMN COL4 ";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(tableDDL);
+ conn.createStatement().execute(viewDDL);
+ long viewDDLTimestamp = getLastDDLTimestamp(conn, viewFullName);
+ Thread.sleep(1);
+ conn.createStatement().execute(divergeDDL);
Review comment:
Does it make sense to add a check that after dropping column from view
it didn't change the ddlTimestamp of the base table ?
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
##########
@@ -1216,5 +1218,248 @@ public void testDroppingIndexedColDropsViewIndex()
throws Exception {
assertNull(results.next());
}
}
-
+
+ @Test
+ public void testAddThenDropColumnTableDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String columnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String columnDropDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN
COL3 ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute(tableDDL);
+ //first get the original DDL timestamp when we created the table
+ long tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName, startTS,
+ conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(viewDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ //now add a column and make sure the timestamp updates
+ conn.createStatement().execute(columnAddDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(columnDropDDL);
+ CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1 , conn);
+ }
+ }
+
+ @Test
+ public void testLastDDLTimestampForDivergedViews() throws Exception {
+ //Phoenix allows users to "drop" columns from views that are inherited
from their ancestor
+ // views or tables. These columns are then excluded from the view
schema, and the view is
+ // considered "diverged" from its parents, and so no longer inherit
any additional schema
+ // changes that are applied to their ancestors. This test make sure
that this behavior
+ // extends to DDL timestamp
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String divergeDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN COL2";
+ String viewColumnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String viewColumnDropDDL = "ALTER VIEW " + viewFullName + " DROP
COLUMN COL3 ";
+ String tableColumnAddDDL = "ALTER TABLE " + dataTableFullName + " ADD
COL4 varchar" +
+ "(50) NULL";
+ String tableColumnDropDDL = "ALTER TABLE " + dataTableFullName + "
DROP COLUMN COL4 ";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(tableDDL);
+ conn.createStatement().execute(viewDDL);
+ long viewDDLTimestamp = getLastDDLTimestamp(conn, viewFullName);
+ Thread.sleep(1);
+ conn.createStatement().execute(divergeDDL);
+ //verify DDL timestamp changed
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(viewColumnAddDDL);
+ //verify DDL timestamp changed because we added a column to the
view
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(viewColumnDropDDL);
+ //verify DDL timestamp changed because we dropped a column from
the view
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(tableColumnAddDDL);
+ //verify DDL timestamp DID NOT change because we added a column
from the base table
+ assertEquals(viewDDLTimestamp, getLastDDLTimestamp(conn,
viewFullName));
+ conn.createStatement().execute(tableColumnDropDDL);
+ assertEquals(viewDDLTimestamp, getLastDDLTimestamp(conn,
viewFullName));
+ }
+ }
+
+ @Test
+ public void testLastDDLTimestampWithChildViews() throws Exception {
+ Assume.assumeTrue(isMultiTenant);
Review comment:
Any reason why we want this test to run only if multiTenant is true ? I
am not that much aware of this testsuite.
If we want to ensure isMultiTenant is true then can we change the test name
to testLastDDLTimestampWith_Tenant_ChildViews to be more specific.
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
##########
@@ -1216,5 +1218,248 @@ public void testDroppingIndexedColDropsViewIndex()
throws Exception {
assertNull(results.next());
}
}
-
+
+ @Test
+ public void testAddThenDropColumnTableDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String columnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String columnDropDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN
COL3 ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute(tableDDL);
+ //first get the original DDL timestamp when we created the table
+ long tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName, startTS,
+ conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(viewDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ //now add a column and make sure the timestamp updates
+ conn.createStatement().execute(columnAddDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(columnDropDDL);
+ CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1 , conn);
+ }
+ }
+
+ @Test
+ public void testLastDDLTimestampForDivergedViews() throws Exception {
+ //Phoenix allows users to "drop" columns from views that are inherited
from their ancestor
+ // views or tables. These columns are then excluded from the view
schema, and the view is
+ // considered "diverged" from its parents, and so no longer inherit
any additional schema
+ // changes that are applied to their ancestors. This test make sure
that this behavior
+ // extends to DDL timestamp
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String divergeDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN COL2";
+ String viewColumnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String viewColumnDropDDL = "ALTER VIEW " + viewFullName + " DROP
COLUMN COL3 ";
+ String tableColumnAddDDL = "ALTER TABLE " + dataTableFullName + " ADD
COL4 varchar" +
+ "(50) NULL";
+ String tableColumnDropDDL = "ALTER TABLE " + dataTableFullName + "
DROP COLUMN COL4 ";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(tableDDL);
+ conn.createStatement().execute(viewDDL);
+ long viewDDLTimestamp = getLastDDLTimestamp(conn, viewFullName);
+ Thread.sleep(1);
+ conn.createStatement().execute(divergeDDL);
+ //verify DDL timestamp changed
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(viewColumnAddDDL);
+ //verify DDL timestamp changed because we added a column to the
view
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(viewColumnDropDDL);
+ //verify DDL timestamp changed because we dropped a column from
the view
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(tableColumnAddDDL);
+ //verify DDL timestamp DID NOT change because we added a column
from the base table
+ assertEquals(viewDDLTimestamp, getLastDDLTimestamp(conn,
viewFullName));
+ conn.createStatement().execute(tableColumnDropDDL);
+ assertEquals(viewDDLTimestamp, getLastDDLTimestamp(conn,
viewFullName));
+ }
+ }
+
+ @Test
+ public void testLastDDLTimestampWithChildViews() throws Exception {
+ Assume.assumeTrue(isMultiTenant);
+ Properties props = new Properties();
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String globalViewName = "V_" + generateUniqueName();
+ String tenantViewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String globalViewFullName = SchemaUtil.getTableName(schemaName,
globalViewName);
+ String tenantViewFullName = SchemaUtil.getTableName(schemaName,
tenantViewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
+ + " ) %s");
+
+ //create a table with a child global view, who then has a child tenant
view
+ String globalViewDDL =
+ "CREATE VIEW " + globalViewFullName + " AS SELECT * FROM " +
dataTableFullName;
+
+ String tenantViewDDL =
+ "CREATE VIEW " + tenantViewFullName + " AS SELECT * FROM " +
globalViewFullName;
+
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ long tableDDLTimestamp, globalViewDDLTimestamp;
+
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(tableDDL);
+ conn.createStatement().execute(globalViewDDL);
+ tableDDLTimestamp = getLastDDLTimestamp(conn, dataTableFullName);
+ globalViewDDLTimestamp = getLastDDLTimestamp(conn,
globalViewFullName);
+ }
+ props.setProperty(TENANT_ID_ATTRIB, TENANT1);
+ try (Connection tenantConn = DriverManager.getConnection(getUrl(),
props)) {
+ tenantConn.createStatement().execute(tenantViewDDL);
+ }
+ // First, check that adding a child view didn't change the timestamps
Review comment:
nit: could you please change the comment to be more specific.
` // First, check that adding a child view didn't change the timestamps of
base table `
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2802,7 +2827,8 @@ private MetaDataMutationResult mutateColumn(
getParentPhysicalTableName(table), table.getType());
result = mutator.validateAndAddMetadata(table, rowKeyMetaData,
tableMetadata,
- region, invalidateList, locks, clientTimeStamp,
clientVersion);
+ region, invalidateList, locks, clientTimeStamp,
clientVersion,
+ isAddingOrDroppingColumns);
Review comment:
nit: indentation mismatch.
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
##########
@@ -910,6 +911,41 @@ public void testTableDescriptorPriority() throws
SQLException, IOException {
}
}
+ @Test
+ public void testCreateTableDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ final String schemaName = generateUniqueName();
+ final String tableName = generateUniqueName();
+ final String dataTableFullName = SchemaUtil.getTableName(schemaName,
tableName);
+ String ddl =
+ "CREATE TABLE " + dataTableFullName + " (\n" + "ID1 VARCHAR(15)
NOT NULL,\n"
+ + "ID2 VARCHAR(15) NOT NULL,\n" + "CREATED_DATE DATE,\n"
+ + "CREATION_TIME BIGINT,\n" + "LAST_USED DATE,\n"
+ + "CONSTRAINT PK PRIMARY KEY (ID1, ID2)) ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute(ddl);
+ verifyLastDDLTimestamp(schemaName, tableName, dataTableFullName,
startTS, conn);
+ }
+ }
+
+ public static long verifyLastDDLTimestamp(String schemaName, String
tableName,
+ String dataTableFullName, long
startTS, Connection conn) throws SQLException {
+ return verifyLastDDLTimestamp("", schemaName, tableName,
dataTableFullName, startTS, conn);
+ }
+
+ public static long verifyLastDDLTimestamp(String tenantId, String
schemaName, String tableName,
+ String dataTableFullName, long
startTS, Connection conn) throws SQLException {
Review comment:
I don't see any usage of first 3 arguments `String tenantId, String
schemaName, String tableName`
Maybe you used them in earlier draft then removed them ?
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
##########
@@ -1216,5 +1218,248 @@ public void testDroppingIndexedColDropsViewIndex()
throws Exception {
assertNull(results.next());
}
}
-
+
+ @Test
+ public void testAddThenDropColumnTableDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String columnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String columnDropDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN
COL3 ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute(tableDDL);
+ //first get the original DDL timestamp when we created the table
+ long tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName, startTS,
+ conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(viewDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ //now add a column and make sure the timestamp updates
+ conn.createStatement().execute(columnAddDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(columnDropDDL);
+ CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1 , conn);
+ }
+ }
+
+ @Test
+ public void testLastDDLTimestampForDivergedViews() throws Exception {
+ //Phoenix allows users to "drop" columns from views that are inherited
from their ancestor
+ // views or tables. These columns are then excluded from the view
schema, and the view is
+ // considered "diverged" from its parents, and so no longer inherit
any additional schema
+ // changes that are applied to their ancestors. This test make sure
that this behavior
+ // extends to DDL timestamp
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String divergeDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN COL2";
+ String viewColumnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String viewColumnDropDDL = "ALTER VIEW " + viewFullName + " DROP
COLUMN COL3 ";
+ String tableColumnAddDDL = "ALTER TABLE " + dataTableFullName + " ADD
COL4 varchar" +
+ "(50) NULL";
+ String tableColumnDropDDL = "ALTER TABLE " + dataTableFullName + "
DROP COLUMN COL4 ";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(tableDDL);
+ conn.createStatement().execute(viewDDL);
+ long viewDDLTimestamp = getLastDDLTimestamp(conn, viewFullName);
+ Thread.sleep(1);
+ conn.createStatement().execute(divergeDDL);
+ //verify DDL timestamp changed
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
Review comment:
Acc to comment, shouldn't the argument for startTime be
"viewDDLTimestamp + 1" since we are assuming that timestamp should change.
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
##########
@@ -1216,5 +1218,248 @@ public void testDroppingIndexedColDropsViewIndex()
throws Exception {
assertNull(results.next());
}
}
-
+
+ @Test
+ public void testAddThenDropColumnTableDDLTimestamp() throws Exception {
+ Properties props = new Properties();
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String columnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String columnDropDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN
COL3 ";
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute(tableDDL);
+ //first get the original DDL timestamp when we created the table
+ long tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, dataTableName,
+ dataTableFullName, startTS,
+ conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(viewDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ //now add a column and make sure the timestamp updates
+ conn.createStatement().execute(columnAddDDL);
+ tableDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1, conn);
+ Thread.sleep(1);
+ conn.createStatement().execute(columnDropDDL);
+ CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName,
+ tableDDLTimestamp + 1 , conn);
+ }
+ }
+
+ @Test
+ public void testLastDDLTimestampForDivergedViews() throws Exception {
+ //Phoenix allows users to "drop" columns from views that are inherited
from their ancestor
+ // views or tables. These columns are then excluded from the view
schema, and the view is
+ // considered "diverged" from its parents, and so no longer inherit
any additional schema
+ // changes that are applied to their ancestors. This test make sure
that this behavior
+ // extends to DDL timestamp
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String viewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String viewFullName = SchemaUtil.getTableName(schemaName, viewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1)"
+ + " ) %s");
+
+ String viewDDL = "CREATE VIEW " + viewFullName + " AS SELECT * FROM "
+ dataTableFullName;
+
+ String divergeDDL = "ALTER VIEW " + viewFullName + " DROP COLUMN COL2";
+ String viewColumnAddDDL = "ALTER VIEW " + viewFullName + " ADD COL3
varchar(50) NULL ";
+ String viewColumnDropDDL = "ALTER VIEW " + viewFullName + " DROP
COLUMN COL3 ";
+ String tableColumnAddDDL = "ALTER TABLE " + dataTableFullName + " ADD
COL4 varchar" +
+ "(50) NULL";
+ String tableColumnDropDDL = "ALTER TABLE " + dataTableFullName + "
DROP COLUMN COL4 ";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(tableDDL);
+ conn.createStatement().execute(viewDDL);
+ long viewDDLTimestamp = getLastDDLTimestamp(conn, viewFullName);
+ Thread.sleep(1);
+ conn.createStatement().execute(divergeDDL);
+ //verify DDL timestamp changed
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(viewColumnAddDDL);
+ //verify DDL timestamp changed because we added a column to the
view
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(viewColumnDropDDL);
+ //verify DDL timestamp changed because we dropped a column from
the view
+ viewDDLTimestamp =
CreateTableIT.verifyLastDDLTimestamp(schemaName, viewName,
+ viewFullName, viewDDLTimestamp, conn);
+ conn.createStatement().execute(tableColumnAddDDL);
+ //verify DDL timestamp DID NOT change because we added a column
from the base table
+ assertEquals(viewDDLTimestamp, getLastDDLTimestamp(conn,
viewFullName));
+ conn.createStatement().execute(tableColumnDropDDL);
+ assertEquals(viewDDLTimestamp, getLastDDLTimestamp(conn,
viewFullName));
+ }
+ }
+
+ @Test
+ public void testLastDDLTimestampWithChildViews() throws Exception {
+ Assume.assumeTrue(isMultiTenant);
+ Properties props = new Properties();
+ String schemaName = SCHEMA1;
+ String dataTableName = "T_" + generateUniqueName();
+ String globalViewName = "V_" + generateUniqueName();
+ String tenantViewName = "V_" + generateUniqueName();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName,
dataTableName);
+ String globalViewFullName = SchemaUtil.getTableName(schemaName,
globalViewName);
+ String tenantViewFullName = SchemaUtil.getTableName(schemaName,
tenantViewName);
+
+ String tableDDL = generateDDL("CREATE TABLE IF NOT EXISTS " +
dataTableFullName + " ("
+ + " %s ID char(1) NOT NULL,"
+ + " COL1 integer NOT NULL,"
+ + " COL2 bigint NOT NULL,"
+ + " CONSTRAINT NAME_PK PRIMARY KEY (%s ID, COL1, COL2)"
+ + " ) %s");
+
+ //create a table with a child global view, who then has a child tenant
view
+ String globalViewDDL =
+ "CREATE VIEW " + globalViewFullName + " AS SELECT * FROM " +
dataTableFullName;
+
+ String tenantViewDDL =
+ "CREATE VIEW " + tenantViewFullName + " AS SELECT * FROM " +
globalViewFullName;
+
+ long startTS = EnvironmentEdgeManager.currentTimeMillis();
+ long tableDDLTimestamp, globalViewDDLTimestamp;
+
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(tableDDL);
+ conn.createStatement().execute(globalViewDDL);
+ tableDDLTimestamp = getLastDDLTimestamp(conn, dataTableFullName);
+ globalViewDDLTimestamp = getLastDDLTimestamp(conn,
globalViewFullName);
+ }
+ props.setProperty(TENANT_ID_ATTRIB, TENANT1);
+ try (Connection tenantConn = DriverManager.getConnection(getUrl(),
props)) {
+ tenantConn.createStatement().execute(tenantViewDDL);
+ }
+ // First, check that adding a child view didn't change the timestamps
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ long newTableDDLTimestamp = getLastDDLTimestamp(conn,
dataTableFullName);
+ assertEquals(tableDDLTimestamp, newTableDDLTimestamp);
+
+ long newGlobalViewDDLTimestamp = getLastDDLTimestamp(conn,
globalViewFullName);
+ assertEquals(globalViewDDLTimestamp, newGlobalViewDDLTimestamp);
+ }
+ Thread.sleep(1);
+ //now add / drop a column from the tenant view and make sure it
doesn't change its
+ // ancestors' timestamps
+ String tenantViewColumnAddDDL = "ALTER VIEW " + tenantViewFullName + "
ADD COL3 varchar" +
+ "(50) " + "NULL ";
+ String tenantViewColumnDropDDL = "ALTER VIEW " + tenantViewFullName +
" DROP COLUMN COL3 ";
+
+ try (Connection tenantConn = DriverManager.getConnection(getUrl(),
props)) {
+ tenantConn.createStatement().execute(tenantViewColumnAddDDL);
+ long newTableDDLTimestamp = getLastDDLTimestamp(tenantConn,
dataTableFullName);
+ assertEquals(tableDDLTimestamp, newTableDDLTimestamp);
+
+ long afterTenantColumnAddViewDDLTimestamp =
getLastDDLTimestamp(tenantConn,
+ globalViewFullName);
+ assertEquals(globalViewDDLTimestamp,
afterTenantColumnAddViewDDLTimestamp);
+
+ tenantConn.createStatement().execute(tenantViewColumnDropDDL);
+ //update the tenant view timestamp (we'll need it later)
+ long afterTenantColumnDropTableDDLTimestamp =
getLastDDLTimestamp(tenantConn,
+ dataTableFullName);
+ assertEquals(tableDDLTimestamp,
afterTenantColumnDropTableDDLTimestamp);
+
+ long afterTenantColumnDropViewDDLTimestamp =
getLastDDLTimestamp(tenantConn,
+ globalViewFullName);
+ assertEquals(globalViewDDLTimestamp,
afterTenantColumnDropViewDDLTimestamp);
+ }
+ Thread.sleep(1);
+ //now add / drop a column from the base table and make sure it changes
the timestamps for
+ // both the global view (its child) and the tenant view (its
grandchild)
+ String tableColumnAddDDL = "ALTER TABLE " + dataTableFullName + " ADD
COL4 varchar" +
+ "(50) " + "NULL ";
+ String tableColumnDropDDL = "ALTER TABLE " + dataTableFullName + "
DROP COLUMN COL4 ";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(tableColumnAddDDL);
+ tableDDLTimestamp = getLastDDLTimestamp(conn, dataTableFullName);
+ try (Connection tenantConn = DriverManager.getConnection(getUrl(),
props)) {
+ long tenantViewDDLTimestamp = getLastDDLTimestamp(tenantConn,
+ tenantViewFullName);
+ assertEquals(tableDDLTimestamp, tenantViewDDLTimestamp);
+ }
+ globalViewDDLTimestamp = getLastDDLTimestamp(conn,
+ globalViewFullName);
+ assertEquals(tableDDLTimestamp, globalViewDDLTimestamp);
+
+ conn.createStatement().execute(tableColumnDropDDL);
+ tableDDLTimestamp = getLastDDLTimestamp(conn, dataTableFullName);
+ try (Connection tenantConn = DriverManager.getConnection(getUrl(),
props)) {
+ long tenantViewDDLTimestamp = getLastDDLTimestamp(tenantConn,
+ tenantViewFullName);
+ assertEquals(tableDDLTimestamp, tenantViewDDLTimestamp);
+ }
+ globalViewDDLTimestamp = getLastDDLTimestamp(conn,
+ globalViewFullName);
+ assertEquals(tableDDLTimestamp, globalViewDDLTimestamp);
+ }
+
+ //now add / drop a column from the global view and make sure it
doesn't change its
+ // parent (the base table) but does change the timestamp for its child
(the tenant view)
+ String globalViewColumnAddDDL = "ALTER VIEW " + globalViewFullName + "
ADD COL5 varchar" +
+ "(50) " + "NULL ";
+ String globalViewColumnDropDDL = "ALTER VIEW " + globalViewFullName +
" DROP COLUMN COL5 ";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ conn.createStatement().execute(globalViewColumnAddDDL);
+ globalViewDDLTimestamp = getLastDDLTimestamp(conn,
globalViewFullName);
+ long newTableDDLTimestamp = getLastDDLTimestamp(conn,
+ dataTableFullName);
+ //table DDL timestamp shouldn't have changed
+ assertEquals(tableDDLTimestamp, newTableDDLTimestamp);
+ try (Connection tenantConn = DriverManager.getConnection(getUrl(),
props)) {
+ long tenantViewDDLTimestamp = getLastDDLTimestamp(tenantConn,
+ tenantViewFullName);
+ //but tenant timestamp should have changed
+ assertEquals(globalViewDDLTimestamp, tenantViewDDLTimestamp);
+ }
+
+ conn.createStatement().execute(globalViewColumnDropDDL);
+ globalViewDDLTimestamp = getLastDDLTimestamp(conn,
globalViewFullName);
+ newTableDDLTimestamp = getLastDDLTimestamp(conn,
+ dataTableFullName);
+ //table DDL timestamp shouldn't have changed
+ assertEquals(tableDDLTimestamp, newTableDDLTimestamp);
+ try (Connection tenantConn = DriverManager.getConnection(getUrl(),
props)) {
+ long tenantViewDDLTimestamp = getLastDDLTimestamp(tenantConn,
+ tenantViewFullName);
+ //but tenant timestamp should have changed
+ assertEquals(globalViewDDLTimestamp, tenantViewDDLTimestamp);
+ }
+ }
+
+ }
+
+ public static long getLastDDLTimestamp(Connection conn, String
dataTableFullName) throws SQLException {
Review comment:
Should we move this helper method to CreateTableIT since we are doing
almost same thing in CreateTableIT#verifyLastDDLTimestamp and additional
timestamp bounds verification.
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
##########
@@ -2285,6 +2286,7 @@ public MetaDataResponse call(MetaDataService instance)
throws IOException {
builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION,
PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
if (parentTable!=null)
builder.setParentTable(PTableImpl.toProto(parentTable));
+ builder.setAddingColumns(addingColumns);
Review comment:
Thank you for educating me. :)
##########
File path: phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
##########
@@ -107,6 +107,29 @@
HColumnDescriptor.KEEP_DELETED_CELLS,
HColumnDescriptor.REPLICATION_SCOPE);
+ public static Put getLastDDLTimestampUpdate(byte[] tableHeaderRowKey,
+ long clientTimestamp,
+ long lastDDLTimestamp) {
+ //use client timestamp as the timestamp of the Cell, to match the
other Cells that might
+ // be created by this DDL. But the actual value will be a _server_
timestamp
+ Put p = new Put(tableHeaderRowKey, clientTimestamp);
+ byte[] lastDDLTimestampBytes =
PLong.INSTANCE.toBytes(lastDDLTimestamp);
+ p.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
+ PhoenixDatabaseMetaData.LAST_DDL_TIMESTAMP_BYTES,
lastDDLTimestampBytes);
+ return p;
+ }
+
+ /**
+ * Checks if a table is meant to be queried directly (and hence is
relevant to external
+ * systems tracking Phoenix schema)
+ * @param tableType
+ * @return True if a table or view, false otherwise (such as for an index,
system table, or
+ * subquery)
+ */
+ public static boolean isTableQueryable(PTableType tableType) {
Review comment:
I am ok with the name just wanted to learn more context. thank you !
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
##########
@@ -3063,60 +3063,62 @@ public boolean isViewReferenced() {
*/
EncodedCQCounter cqCounterToBe = tableType == PTableType.VIEW ?
NULL_COUNTER : cqCounter;
PTable table = new PTableImpl.Builder()
- .setType(tableType)
Review comment:
I know this is a very nit pick.. but for split lines the spacing rule is
8 spaces. For conditional/loop statements body I agree it is 4 spaces.
----------------------------------------------------------------
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:
[email protected]
> Store table metadata last modified timestamp in PTable / System.Catalog
> -----------------------------------------------------------------------
>
> Key: PHOENIX-6186
> URL: https://issues.apache.org/jira/browse/PHOENIX-6186
> Project: Phoenix
> Issue Type: New Feature
> Reporter: Geoffrey Jacoby
> Assignee: Geoffrey Jacoby
> Priority: Major
> Fix For: 4.16.0
>
> Attachments: PHOENIX-6186-4.x.patch
>
>
> There are many reasons why it's useful to know when a particular table's
> metadata was last modified. It's helpful when solving cache coherency
> problems, and also in order to interact with external schema registries which
> may have multiple versions of a particular schema and require a timestamp to
> resolve ambiguities.
> This JIRA will add a last modified timestamp field to System.Catalog, to be
> updated both when creating a table/view and also when adding or removing a
> column. Changing purely internal Phoenix properties will not update the
> timestamp.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)