You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/02/03 23:13:37 UTC
git commit: Allow tenant-specific table to query base multi-tenant
table
Updated Branches:
refs/heads/master 473ca2a7c -> fc96ccb91
Allow tenant-specific table to query base multi-tenant table
Project: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/commit/fc96ccb9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/tree/fc96ccb9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/diff/fc96ccb9
Branch: refs/heads/master
Commit: fc96ccb91050ebedc1315a6b6e1c6367b4cd4ed9
Parents: 473ca2a
Author: James Taylor <ja...@apache.org>
Authored: Mon Feb 3 14:13:30 2014 -0800
Committer: James Taylor <ja...@apache.org>
Committed: Mon Feb 3 14:13:30 2014 -0800
----------------------------------------------------------------------
.../apache/phoenix/compile/FromCompiler.java | 25 +++++++-------------
.../apache/phoenix/schema/MetaDataClient.java | 16 +++++++------
.../end2end/TenantSpecificTablesDMLTest.java | 15 +++++++-----
3 files changed, 26 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/fc96ccb9/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
index ec46560..24765c6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/FromCompiler.java
@@ -101,7 +101,7 @@ public class FromCompiler {
NamedTableNode tableNode = NamedTableNode.create(null, baseTable, Collections.<ColumnDef>emptyList());
// Always use non-tenant-specific connection here
try {
- SingleTableColumnResolver visitor = new SingleTableColumnResolver(connection, tableNode, false, true);
+ SingleTableColumnResolver visitor = new SingleTableColumnResolver(connection, tableNode, false);
return visitor;
} catch (TableNotFoundException e) {
// Used for mapped VIEW, since we won't be able to resolve that.
@@ -142,7 +142,7 @@ public class FromCompiler {
throws SQLException {
List<TableNode> fromNodes = statement.getFrom();
if (fromNodes.size() == 1)
- return new SingleTableColumnResolver(connection, (NamedTableNode)fromNodes.get(0), false, false);
+ return new SingleTableColumnResolver(connection, (NamedTableNode)fromNodes.get(0), false);
MultiTableColumnResolver visitor = new MultiTableColumnResolver(connection);
for (TableNode node : fromNodes) {
@@ -152,13 +152,13 @@ public class FromCompiler {
}
public static ColumnResolver getResolver(NamedTableNode tableNode, PhoenixConnection connection) throws SQLException {
- SingleTableColumnResolver visitor = new SingleTableColumnResolver(connection, tableNode, false, false);
+ SingleTableColumnResolver visitor = new SingleTableColumnResolver(connection, tableNode, false);
return visitor;
}
public static ColumnResolver getResolver(SingleTableSQLStatement statement, PhoenixConnection connection,
List<ColumnDef> dyn_columns) throws SQLException {
- SingleTableColumnResolver visitor = new SingleTableColumnResolver(connection, statement.getTable(), true, false);
+ SingleTableColumnResolver visitor = new SingleTableColumnResolver(connection, statement.getTable(), true);
return visitor;
}
@@ -186,7 +186,7 @@ public class FromCompiler {
tableRefs = ImmutableList.of(new TableRef(alias, theTable, timeStamp, !table.getDynamicColumns().isEmpty()));
}
- public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode table, boolean updateCacheOnlyIfAutoCommit, boolean allowMultiTenant) throws SQLException {
+ public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode table, boolean updateCacheOnlyIfAutoCommit) throws SQLException {
super(connection);
alias = table.getAlias();
TableName tableNameNode = table.getName();
@@ -206,16 +206,7 @@ public class FromCompiler {
result = client.updateCache(schemaName, tableName);
timeStamp = result.getMutationTime();
}
- PTable theTable;
- try {
- theTable = connection.getPMetaData().getTable(fullTableName);
- } catch (TableNotFoundException e) {
- if (allowMultiTenant && result != null && result.getTable() != null) {
- theTable = result.getTable();
- } else {
- throw e;
- }
- }
+ PTable theTable = connection.getPMetaData().getTable(fullTableName);
// If dynamic columns have been specified add them to the table declaration
if (!table.getDynamicColumns().isEmpty()) {
theTable = this.addDynamicColumns(table.getDynamicColumns(), theTable);
@@ -229,8 +220,8 @@ public class FromCompiler {
sqlE = new TableNotFoundException(e,timeStamp);
}
// If we haven't already tried, update our cache and retry
- // Only loop back if the cache was updated or we got a result back and we're allowed to multi-tenant tables
- if (retry && ((result = client.updateCache(schemaName, tableName)).wasUpdated() || (result.getTable() != null && allowMultiTenant))) {
+ // Only loop back if the cache was updated
+ if (retry && (result = client.updateCache(schemaName, tableName)).wasUpdated()) {
timeStamp = result.getMutationTime();
retry = false;
didRetry = true;
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/fc96ccb9/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 695c67e..9240186 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -280,12 +280,14 @@ public class MetaDataClient {
PTable resultTable = result.getTable();
// We found an updated table, so update our cache
if (resultTable != null) {
- // Don't cache the table unless it has the same tenantId
- // as the connection or it's not multi-tenant.
- if (tryCount == 0 || !resultTable.isMultiTenant()) {
- connection.addTable(resultTable);
- return result;
- }
+ // Cache table, even if multi-tenant table found for null tenant_id
+ // These may be accessed by tenant-specific connections, as the
+ // tenant_id will always be added to mask other tenants data.
+ // Otherwise, a tenant would be required to create a VIEW first
+ // which is not really necessary unless you want to filter or add
+ // columns
+ connection.addTable(resultTable);
+ return result;
} else {
// if (result.getMutationCode() == MutationCode.NEWER_TABLE_FOUND) {
// TODO: No table exists at the clientTimestamp, but a newer one exists.
@@ -488,7 +490,7 @@ public class MetaDataClient {
ColumnResolver resolver = FromCompiler.getResolver(statement, connection);
tableRef = resolver.getTables().get(0);
PTable dataTable = tableRef.getTable();
- if (dataTable.getType() == PTableType.VIEW) {
+ if (dataTable.getType() == PTableType.VIEW && dataTable.getViewType() != ViewType.MAPPED) {
throw new SQLFeatureNotSupportedException("Creating an index on a view is not supported currently, but will be soon");
}
int hbaseVersion = connection.getQueryServices().getLowestClusterHBaseVersion();
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/fc96ccb9/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDMLTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDMLTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDMLTest.java
index dac2f1a..3709c93 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDMLTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/TenantSpecificTablesDMLTest.java
@@ -318,14 +318,17 @@ public class TenantSpecificTablesDMLTest extends BaseTenantSpecificTablesTest {
}
@Test
- public void testBaseTableCannotBeUsedInStatementsInMultitenantConnections() throws Exception {
+ public void testBaseTableCanBeUsedInStatementsInMultitenantConnections() throws Exception {
Connection conn = DriverManager.getConnection(PHOENIX_JDBC_TENANT_SPECIFIC_URL);
try {
- try {
- conn.createStatement().execute("select * from " + PARENT_TABLE_NAME);
- fail();
- }
- catch (TableNotFoundException expected) {};
+ ResultSet rs = conn.createStatement().executeQuery("select * from " + PARENT_TABLE_NAME);
+ assertFalse(rs.next());
+ conn.setAutoCommit(true);
+ conn.createStatement().executeUpdate("upsert into " + PARENT_TABLE_NAME + " (tenant_type_id, id, user) values ('" + TENANT_TYPE_ID + "', 1, 'Billy Gibbons')");
+ rs = conn.createStatement().executeQuery("select user from " + PARENT_TABLE_NAME);
+ assertTrue(rs.next());
+ assertEquals(rs.getString(1),"Billy Gibbons");
+ assertFalse(rs.next());
}
finally {
conn.close();