phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mujt...@apache.org
Subject phoenix git commit: PHOENIX-4414 Exception while using database metadata commands on tenant specific connection
Date Tue, 09 Jan 2018 22:48:52 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 488389e73 -> 28197051a


PHOENIX-4414 Exception while using database metadata commands on tenant specific connection


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/28197051
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/28197051
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/28197051

Branch: refs/heads/4.x-HBase-0.98
Commit: 28197051a1317f79485ab6b5e6a7e2399b124527
Parents: 488389e
Author: Mujtaba <mujtaba@apache.org>
Authored: Tue Jan 9 14:48:07 2018 -0800
Committer: Mujtaba <mujtaba@apache.org>
Committed: Tue Jan 9 14:48:07 2018 -0800

----------------------------------------------------------------------
 .../end2end/QueryDatabaseMetaDataIT.java        | 27 ++++++++++++++++++++
 .../phoenix/jdbc/PhoenixDatabaseMetaData.java   |  2 +-
 2 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/28197051/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
index f809e2c..8615bac 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
@@ -66,6 +66,7 @@ import org.apache.phoenix.schema.types.PChar;
 import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
@@ -106,6 +107,32 @@ public class QueryDatabaseMetaDataIT extends ParallelStatsDisabledIT
{
     }
 
     @Test
+    public void testMetadataTenantSpecific() throws SQLException {
+    	// create multi-tenant table
+    	String tableName = generateUniqueName();
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+        	String baseTableDdl = "CREATE TABLE %s (K1 VARCHAR NOT NULL, K2 VARCHAR NOT NULL,
V VARCHAR CONSTRAINT PK PRIMARY KEY(K1, K2)) MULTI_TENANT=true";
+        	conn.createStatement().execute(String.format(baseTableDdl, tableName));
+        }
+    	
+        // create tenant specific view and execute metdata data call with tenant specific
connection
+        String tenantId = generateUniqueName();
+        Properties tenantProps = new Properties();
+        tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+        try (Connection tenantConn = DriverManager.getConnection(getUrl(), tenantProps))
{
+        	String viewName = generateUniqueName();
+        	String viewDdl = "CREATE VIEW %s AS SELECT * FROM %s";
+        	tenantConn.createStatement().execute(String.format(viewDdl, viewName, tableName));
+        	DatabaseMetaData dbmd = tenantConn.getMetaData();
+        	ResultSet rs = dbmd.getTables(tenantId, "", viewName, null);
+            assertTrue(rs.next());
+            assertEquals(rs.getString("TABLE_NAME"), viewName);
+            assertEquals(PTableType.VIEW.toString(), rs.getString("TABLE_TYPE"));
+            assertFalse(rs.next());
+        }
+    }
+    
+    @Test
     public void testTableMetadataScan() throws SQLException {
         String tableAName = generateUniqueName() + "TABLE";
         String tableASchema = "";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/28197051/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
index 7ca336f..cb1232b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
@@ -445,7 +445,7 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData {
             appendConjunction(buf);
             buf.append(" TENANT_ID LIKE '" + StringUtil.escapeStringConstant(tenantIdPattern)
+ "' ");
             if (tenantId != null) {
-                buf.append(" and TENANT_ID + = '" + StringUtil.escapeStringConstant(tenantId.getString())
+ "' ");
+                buf.append(" and TENANT_ID = '" + StringUtil.escapeStringConstant(tenantId.getString())
+ "' ");
             }
         }
     }


Mime
View raw message