phoenix git commit: PHOENIX-4414 Exception while using database metadata commands on tenant specific connection

2018-02-20 Thread mujtaba
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 df98ad3f3 -> d931f8c79


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/d931f8c7
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d931f8c7
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d931f8c7

Branch: refs/heads/5.x-HBase-2.0
Commit: d931f8c79f07693330f9130e56b767492dc25a2b
Parents: df98ad3
Author: Mujtaba 
Authored: Tue Feb 20 16:28:01 2018 -0800
Committer: Mujtaba 
Committed: Tue Feb 20 16:28:01 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/d931f8c7/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 fbe2479..0f52250 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
@@ -70,6 +70,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;
@@ -110,6 +111,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/d931f8c7/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 7ca178b..fde91a7 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
@@ -446,7 +446,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()) + "' ");
 }
 }
 }



[20/35] phoenix git commit: PHOENIX-4414 Exception while using database metadata commands on tenant specific connection

2018-01-31 Thread pboado
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/ffee8c0e
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ffee8c0e
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ffee8c0e

Branch: refs/heads/4.x-cdh5.11.2
Commit: ffee8c0e3359105da7cbfcd93e5e6291005a558b
Parents: 17d0329
Author: Mujtaba 
Authored: Tue Jan 9 22:50:21 2018 +
Committer: Pedro Boado 
Committed: Wed Jan 31 22:24:48 2018 +

--
 .../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/ffee8c0e/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 bb54fd4..ea83b41 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/ffee8c0e/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 c34d20d..23330d8 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()) + "' ");
 }
 }
 }



phoenix git commit: PHOENIX-4414 Exception while using database metadata commands on tenant specific connection

2018-01-09 Thread mujtaba
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 b49dcbde1 -> 3f196808a


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/3f196808
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3f196808
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3f196808

Branch: refs/heads/4.x-HBase-1.2
Commit: 3f196808adeee494413b32cba6828667ca33fcc6
Parents: b49dcbd
Author: Mujtaba 
Authored: Tue Jan 9 14:50:21 2018 -0800
Committer: Mujtaba 
Committed: Tue Jan 9 14:50:21 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/3f196808/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/3f196808/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 c34d20d..23330d8 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()) + "' ");
 }
 }
 }



phoenix git commit: PHOENIX-4414 Exception while using database metadata commands on tenant specific connection

2018-01-09 Thread mujtaba
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 8acdf98c1 -> 5e5f85093


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/5e5f8509
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/5e5f8509
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/5e5f8509

Branch: refs/heads/4.x-HBase-1.1
Commit: 5e5f85093044080012998946c1260e351d420a14
Parents: 8acdf98
Author: Mujtaba 
Authored: Tue Jan 9 14:49:54 2018 -0800
Committer: Mujtaba 
Committed: Tue Jan 9 14:49:54 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/5e5f8509/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/5e5f8509/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 c34d20d..23330d8 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()) + "' ");
 }
 }
 }



phoenix git commit: PHOENIX-4414 Exception while using database metadata commands on tenant specific connection

2018-01-09 Thread mujtaba
Repository: phoenix
Updated Branches:
  refs/heads/master b3854d2c1 -> 01642d5f9


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/01642d5f
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/01642d5f
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/01642d5f

Branch: refs/heads/master
Commit: 01642d5f948fb01f61e65d1bd58ff2661a8918db
Parents: b3854d2
Author: Mujtaba 
Authored: Tue Jan 9 14:49:13 2018 -0800
Committer: Mujtaba 
Committed: Tue Jan 9 14:49:13 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/01642d5f/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/01642d5f/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 c34d20d..23330d8 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()) + "' ");
 }
 }
 }



phoenix git commit: PHOENIX-4414 Exception while using database metadata commands on tenant specific connection

2018-01-09 Thread mujtaba
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 
Authored: Tue Jan 9 14:48:07 2018 -0800
Committer: Mujtaba 
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()) + "' ");
 }
 }
 }