You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by je...@apache.org on 2014/03/05 23:54:54 UTC

[08/50] [abbrv] PHOENIX-95 Use catalog argument for tenant in JDBC metadata APIs (JamesTaylor)

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/6142ff42/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLTest.java
index edbcff9..b0be8ca 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLTest.java
@@ -22,16 +22,15 @@ import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_DROP_PK;
 import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MODIFY_VIEW_PK;
 import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE;
 import static org.apache.phoenix.exception.SQLExceptionCode.TABLE_UNDEFINED;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TYPE_SCHEMA;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TYPE_SEQUENCE;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TYPE_TABLE;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE;
 import static org.apache.phoenix.schema.PTableType.SYSTEM;
 import static org.apache.phoenix.schema.PTableType.TABLE;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -43,7 +42,6 @@ import java.sql.SQLException;
 import java.util.Properties;
 
 import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.schema.ColumnAlreadyExistsException;
@@ -351,14 +349,15 @@ public class TenantSpecificTablesDDLTest extends BaseTenantSpecificTablesTest {
         Properties props = new Properties();
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(nextTimestamp()));
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        try {   
+        try {
+            // empty string means global tenant id
             // make sure connections w/o tenant id only see non-tenant-specific tables, both SYSTEM and USER
             DatabaseMetaData meta = conn.getMetaData();
-            ResultSet rs = meta.getTables(null, null, null, null);
+            ResultSet rs = meta.getTables("", null, null, null);
             assertTrue(rs.next());
-            assertTableMetaData(rs, TYPE_SCHEMA, TYPE_TABLE, SYSTEM);
+            assertTableMetaData(rs, SYSTEM_CATALOG_SCHEMA, SYSTEM_CATALOG_TABLE, SYSTEM);
             assertTrue(rs.next());
-            assertTableMetaData(rs, TYPE_SCHEMA, TYPE_SEQUENCE, SYSTEM);
+            assertTableMetaData(rs, SYSTEM_CATALOG_SCHEMA, TYPE_SEQUENCE, SYSTEM);
             assertTrue(rs.next());
             assertTableMetaData(rs, null, PARENT_TABLE_NAME, TABLE);
             assertTrue(rs.next());
@@ -366,26 +365,36 @@ public class TenantSpecificTablesDDLTest extends BaseTenantSpecificTablesTest {
             assertFalse(rs.next());
             
             // make sure connections w/o tenant id only see non-tenant-specific columns
-            rs = meta.getColumns(null, null, null, null);
+            rs = meta.getColumns("", null, null, null);
             while (rs.next()) {
                 assertNotEquals(TENANT_TABLE_NAME, rs.getString("TABLE_NAME"));
             }
             
+            // null means across all tenant_ids
             rs = meta.getSuperTables(null, null, StringUtil.escapeLike(TENANT_TABLE_NAME));
             assertTrue(rs.next());
-            assertEquals(TENANT_ID, rs.getString(PhoenixDatabaseMetaData.TENANT_ID));
-            assertEquals(TENANT_TABLE_NAME, rs.getString(PhoenixDatabaseMetaData.TABLE_NAME_NAME));
-            assertEquals("SELECT * FROM \"" + PARENT_TABLE_NAME + "\" WHERE " + "TENANT_TYPE_ID = 'abc'", Bytes.toString(rs.getBytes(PhoenixDatabaseMetaData.VIEW_STATEMENT)));
+            assertEquals(TENANT_ID, rs.getString(PhoenixDatabaseMetaData.COLUMN_FAMILY));
+            assertEquals(TENANT_TABLE_NAME, rs.getString(PhoenixDatabaseMetaData.TABLE_NAME));
+            assertEquals(PARENT_TABLE_NAME, rs.getString(PhoenixDatabaseMetaData.SUPERTABLE_NAME));
             assertFalse(rs.next());
-            rs = meta.getSuperTables(null, null, null);
+            conn.close();
+            
+            // Global connection sees all tenant tables
+            conn = DriverManager.getConnection(getUrl());
+            rs = conn.getMetaData().getSuperTables(TENANT_ID, null, null);
+            assertTrue(rs.next());
+            assertEquals(TENANT_ID, rs.getString(PhoenixDatabaseMetaData.COLUMN_FAMILY));
+            assertEquals(TENANT_TABLE_NAME, rs.getString(PhoenixDatabaseMetaData.TABLE_NAME));
+            assertEquals(PARENT_TABLE_NAME, rs.getString(PhoenixDatabaseMetaData.SUPERTABLE_NAME));
             assertTrue(rs.next());
-            assertEquals(TENANT_ID, rs.getString(PhoenixDatabaseMetaData.TENANT_ID));
-            assertEquals(TENANT_TABLE_NAME, rs.getString(PhoenixDatabaseMetaData.TABLE_NAME_NAME));
-            assertEquals("SELECT * FROM \"" + PARENT_TABLE_NAME + "\" WHERE " + "TENANT_TYPE_ID = 'abc'", Bytes.toString(rs.getBytes(PhoenixDatabaseMetaData.VIEW_STATEMENT)));
+            assertEquals(TENANT_ID, rs.getString(PhoenixDatabaseMetaData.COLUMN_FAMILY));
+            assertEquals(TENANT_TABLE_NAME_NO_TENANT_TYPE_ID, rs.getString(PhoenixDatabaseMetaData.TABLE_NAME));
+            assertEquals(PARENT_TABLE_NAME_NO_TENANT_TYPE_ID, rs.getString(PhoenixDatabaseMetaData.SUPERTABLE_NAME));
+            assertFalse(rs.next());
+            
+            rs = conn.getMetaData().getCatalogs();
             assertTrue(rs.next());
-            assertEquals(TENANT_ID, rs.getString(PhoenixDatabaseMetaData.TENANT_ID));
-            assertEquals(TENANT_TABLE_NAME_NO_TENANT_TYPE_ID, rs.getString(PhoenixDatabaseMetaData.TABLE_NAME_NAME));
-            assertNull(rs.getString(PhoenixDatabaseMetaData.VIEW_STATEMENT));
+            assertEquals(TENANT_ID, rs.getString(PhoenixDatabaseMetaData.COLUMN_FAMILY));
             assertFalse(rs.next());
         }
         finally {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/6142ff42/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/IndexTestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
index 602c0f1..df17cf3 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
@@ -18,12 +18,12 @@
 package org.apache.phoenix.end2end.index;
 
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_NAME;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_CAT_NAME;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME_NAME;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_FAMILY;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TENANT_ID;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TYPE_SCHEMA;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TYPE_TABLE;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE;
 
 import java.sql.Connection;
 import java.sql.PreparedStatement;
@@ -58,11 +58,11 @@ public class IndexTestUtil {
 
     // the normal db metadata interface is insufficient for all fields needed for an
     // index table test.
-    private static final String SELECT_DATA_INDEX_ROW = "SELECT " + TABLE_CAT_NAME
+    private static final String SELECT_DATA_INDEX_ROW = "SELECT " + COLUMN_FAMILY
             + " FROM "
-            + TYPE_SCHEMA + ".\"" + TYPE_TABLE
+            + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE
             + "\" WHERE "
-            + TENANT_ID + " IS NULL AND " + TABLE_SCHEM_NAME + "=? AND " + TABLE_NAME_NAME + "=? AND " + COLUMN_NAME + " IS NULL AND " + TABLE_CAT_NAME + "=?";
+            + TENANT_ID + " IS NULL AND " + TABLE_SCHEM + "=? AND " + TABLE_NAME + "=? AND " + COLUMN_NAME + " IS NULL AND " + COLUMN_FAMILY + "=?";
     
     public static ResultSet readDataTableIndexRow(Connection conn, String schemaName, String tableName, String indexName) throws SQLException {
         PreparedStatement stmt = conn.prepareStatement(SELECT_DATA_INDEX_ROW);

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/6142ff42/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index ab3d3f4..2bcc8d9 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -325,7 +325,7 @@ public class TestUtil {
 
     public static void clearMetaDataCache(Connection conn) throws Throwable {
         PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
-        HTableInterface htable = pconn.getQueryServices().getTable(PhoenixDatabaseMetaData.TYPE_TABLE_NAME_BYTES);
+        HTableInterface htable = pconn.getQueryServices().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_BYTES);
         htable.coprocessorExec(MetaDataProtocol.class, HConstants.EMPTY_START_ROW,
                 HConstants.EMPTY_END_ROW, new Batch.Call<MetaDataProtocol, Void>() {
             @Override