tkhurana commented on code in PR #1823:
URL: https://github.com/apache/phoenix/pull/1823#discussion_r1488553793
##########
phoenix-core/src/test/java/org/apache/phoenix/cache/ServerMetadataCacheTest.java:
##########
@@ -1591,8 +1593,93 @@ public void
testAncestorLastDDLMapPopulatedInDifferentClient() throws Exception
}
}
+ /**
+ * Test that tenant connections are able to learn about state change of an
inherited index
+ * on their tenant views with different names.
+ */
+ @Test
+ public void testInheritedIndexOnTenantViewsDifferentNames() throws
Exception {
+ testInheritedIndexOnTenantViews(false);
+ }
+
+ /**
+ * Test that tenant connections are able to learn about state change of an
inherited index
+ * on their tenant views with same names.
+ */
+ @Test
+ public void testInheritedIndexOnTenantViewsSameNames() throws Exception {
+ testInheritedIndexOnTenantViews(true);
+ }
+
+ public void testInheritedIndexOnTenantViews(boolean sameTenantViewNames)
throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String url = QueryUtil.getConnectionUrl(props, config, "client1");
+ ConnectionQueryServices cqs = driver.getConnectionQueryServices(url,
props);
+ String baseTableName = generateUniqueName();
+ String globalViewName = generateUniqueName();
+ String globalViewIndexName = generateUniqueName();
+ String tenantViewName1 = generateUniqueName();
+ String tenantViewName2 = sameTenantViewNames ? tenantViewName1 :
generateUniqueName();
+ try (Connection conn = cqs.connect(url, props)) {
+ // create table, view and view index
+ conn.createStatement().execute("CREATE TABLE " + baseTableName +
+ " (TENANT_ID CHAR(9) NOT NULL, KP CHAR(3) NOT NULL, PK
CHAR(3) NOT NULL, KV CHAR(2), KV2 CHAR(2) " +
+ "CONSTRAINT PK PRIMARY KEY(TENANT_ID, KP, PK))
MULTI_TENANT=true,UPDATE_CACHE_FREQUENCY=NEVER");
+ conn.createStatement().execute("CREATE VIEW " + globalViewName +
+ " AS SELECT * FROM " + baseTableName + " WHERE KP =
'001'");
+ conn.createStatement().execute("CREATE INDEX " +
globalViewIndexName + " on " +
+ globalViewName + " (KV) " + " INCLUDE (KV2) ASYNC");
+ String tenantId1 = "tenantId1";
+ String tenantId2 = "tenantId2";
+ Properties tenantProps1 = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Properties tenantProps2 = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ tenantProps1.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB,
tenantId1);
+ tenantProps2.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB,
tenantId2);
+
+ //create tenant views and upsert one row, this updates all the
timestamps in the client's cache
+ try (Connection tenantConn1 = cqs.connect(url, tenantProps1);
+ Connection tenantConn2 = cqs.connect(url, tenantProps2)) {
+ tenantConn1.createStatement().execute("CREATE VIEW " +
tenantViewName1 + " AS SELECT * FROM " + globalViewName);
+ tenantConn1.createStatement().execute("UPSERT INTO " +
tenantViewName1 + " (PK, KV, KV2) VALUES " + "('PK1', 'KV', '01')");
+ tenantConn1.commit();
+
+ tenantConn2.createStatement().execute("CREATE VIEW " +
tenantViewName2 + " AS SELECT * FROM " + globalViewName);
+ tenantConn2.createStatement().execute("UPSERT INTO " +
tenantViewName2 + " (PK, KV, KV2) VALUES " + "('PK2', 'KV', '02')");
+ tenantConn2.commit();
+ }
+ // build global view index
+ IndexToolIT.runIndexTool(false, "", globalViewName,
+ globalViewIndexName);
+
+ // query on secondary key should use inherited index for all
tenant views.
+ try (Connection tenantConn1 = cqs.connect(url, tenantProps1);
+ Connection tenantConn2 = cqs.connect(url, tenantProps2)) {
+
+ String query1 = "SELECT KV2 FROM " + tenantViewName1 + "
WHERE KV = 'KV'";
+ String query2 = "SELECT KV2 FROM " + tenantViewName2 + "
WHERE KV = 'KV'";
+
+ ResultSet rs =
tenantConn1.createStatement().executeQuery(query1);
+ assertPlan((PhoenixResultSet) rs, "", tenantViewName1 + "#" +
globalViewIndexName);
Review Comment:
Small nit: Instead of using `#` use the constant
`CHILD_VIEW_INDEX_NAME_SEPARATOR` in the test code. There are multiple places
where `#` is being used.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]