yanxinyi commented on a change in pull request #606: PHOENIX-5543: Implement
SHOW TABLES/SCHEMAS sql commands
URL: https://github.com/apache/phoenix/pull/606#discussion_r341771929
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLIT.java
##########
@@ -430,14 +431,43 @@ private void validateTenantViewIsDropped(Connection
connTenant) throws SQLExcept
//Expected
}
}
-
+
+ @Test
+ public void testShowTablesMultiTenant() throws Exception {
+ // Each tenant should only be able list tables corresponding to their
TENANT_ID
+ String tenantId2 = "T_" + generateUniqueName();
+ String secondTenantConnectionURL =
PHOENIX_JDBC_TENANT_SPECIFIC_URL.replace(TENANT_ID, tenantId2);
+ String tenantTable2 = "V_" + generateUniqueName();
+ createTestTable(secondTenantConnectionURL,
TENANT_TABLE_DDL.replace(TENANT_TABLE_NAME, tenantTable2));
+
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ // Non-tenant connections should list all the tables.
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ Set<String> tables = new HashSet<>();
+ ResultSet rs = conn.prepareStatement("show tables").executeQuery();
+ while (rs.next()) tables.add(rs.getString("TABLE_NAME"));
+ assertTrue(tables.contains(PARENT_TABLE_NAME));
+ assertTrue(tables.contains(TENANT_TABLE_NAME));
+ assertTrue(tables.contains(tenantTable2));
+ }
+ // Tenant specific connections should not list tables from other
tenants.
+ try (Connection conn =
DriverManager.getConnection(secondTenantConnectionURL, props)) {
+ Set<String> tables = new HashSet<>();
+ ResultSet rs = conn.prepareStatement("show tables").executeQuery();
+ while (rs.next()) tables.add(rs.getString("TABLE_NAME"));
+ assertTrue(tables.contains(PARENT_TABLE_NAME));
+ assertFalse(tables.contains(TENANT_TABLE_NAME));
+ assertTrue(tables.contains(tenantTable2));
+ }
+ }
+
@Test
public void testTableMetadataScan() throws Exception {
// create a tenant table with same name for a different tenant to make
sure we are not picking it up in metadata scans for TENANT_ID
String tenantId2 = "T_" + generateUniqueName();
- String secondTenatConnectionURL =
PHOENIX_JDBC_TENANT_SPECIFIC_URL.replace(TENANT_ID, tenantId2);
+ String secondTenantConnectionURL =
PHOENIX_JDBC_TENANT_SPECIFIC_URL.replace(TENANT_ID, tenantId2);
Review comment:
nice fix for the typo
----------------------------------------------------------------
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]
With regards,
Apache Git Services