phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject phoenix git commit: Fix for TableNotFoundException when optimizing SELECT * FROM a tenant-specific table
Date Thu, 12 Feb 2015 22:21:25 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master f925a4034 -> d4f7b71a1


Fix for TableNotFoundException when optimizing SELECT * FROM a tenant-specific table


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

Branch: refs/heads/master
Commit: d4f7b71a18859d201c3cab74acdff29702cddb76
Parents: f925a40
Author: Thomas D'Silva <twdsilva@gmail.com>
Authored: Tue Feb 10 21:06:43 2015 -0800
Committer: Thomas <tdsilva@salesforce.com>
Committed: Thu Feb 12 13:10:18 2015 -0800

----------------------------------------------------------------------
 .../index/GlobalIndexOptimizationIT.java        |  2 +-
 .../phoenix/compile/ProjectionCompiler.java     | 28 ++++++++++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d4f7b71a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
index e4ba2c6..7fb879e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexOptimizationIT.java
@@ -105,7 +105,7 @@ public class GlobalIndexOptimizationIT extends BaseHBaseManagedTimeIT
{
             conn1.commit();
             createIndex(TestUtil.DEFAULT_INDEX_TABLE_NAME, TestUtil.DEFAULT_DATA_TABLE_NAME,
"v1");
             
-            String query = "SELECT /*+ INDEX(" + TestUtil.DEFAULT_DATA_TABLE_NAME + " " +
TestUtil.DEFAULT_INDEX_TABLE_NAME + ")*/ t_id, k1, k2, k3, V1 FROM " + TestUtil.DEFAULT_DATA_TABLE_NAME
+" where v1='a'";
+            String query = "SELECT /*+ INDEX(" + TestUtil.DEFAULT_DATA_TABLE_NAME + " " +
TestUtil.DEFAULT_INDEX_TABLE_NAME + ")*/ * FROM " + TestUtil.DEFAULT_DATA_TABLE_NAME +" where
v1='a'";
             ResultSet rs = conn1.createStatement().executeQuery("EXPLAIN "+ query);
             
             String expected = 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d4f7b71a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
index 6b518b9..27fe0f9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
@@ -74,6 +74,7 @@ import org.apache.phoenix.schema.PColumnFamily;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTable.ViewType;
 import org.apache.phoenix.schema.PTableKey;
@@ -170,24 +171,35 @@ public class ProjectionCompiler {
         PhoenixConnection conn = context.getConnection();
         PName tenantId = conn.getTenantId();
         String tableName = index.getParentName().getString();
-        PTable table = conn.getMetaDataCache().getTable(new PTableKey(tenantId, tableName));
-        int tableOffset = table.getBucketNum() == null ? 0 : 1;
-        int minTablePKOffset = getMinPKOffset(table, tenantId);
+        PTable dataTable = null;
+        try {
+        	dataTable = conn.getMetaDataCache().getTable(new PTableKey(tenantId, tableName));
+        } catch (TableNotFoundException e) {
+            if (tenantId != null) { 
+            	// Check with null tenantId 
+            	dataTable = conn.getMetaDataCache().getTable(new PTableKey(null, tableName));
+            }
+            else {
+            	throw e;
+            }
+        }
+        int tableOffset = dataTable.getBucketNum() == null ? 0 : 1;
+        int minTablePKOffset = getMinPKOffset(dataTable, tenantId);
         int minIndexPKOffset = getMinPKOffset(index, tenantId);
         if (index.getIndexType() != IndexType.LOCAL) {
-            if (index.getColumns().size()-minIndexPKOffset != table.getColumns().size()-minTablePKOffset)
{
+            if (index.getColumns().size()-minIndexPKOffset != dataTable.getColumns().size()-minTablePKOffset)
{
                 // We'll end up not using this by the optimizer, so just throw
                 throw new ColumnNotFoundException(WildcardParseNode.INSTANCE.toString());
             }
         }
-        for (int i = tableOffset, j = tableOffset; i < table.getColumns().size(); i++)
{
-            PColumn column = table.getColumns().get(i);
+        for (int i = tableOffset, j = tableOffset; i < dataTable.getColumns().size();
i++) {
+            PColumn column = dataTable.getColumns().get(i);
             // Skip tenant ID column (which may not be the first column, but is the first
PK column)
             if (SchemaUtil.isPKColumn(column) && j++ < minTablePKOffset) {
                 tableOffset++;
                 continue;
             }
-            PColumn tableColumn = table.getColumns().get(i);
+            PColumn tableColumn = dataTable.getColumns().get(i);
             String indexColName = IndexUtil.getIndexColumnName(tableColumn);
             PColumn indexColumn = null;
             ColumnRef ref = null;
@@ -221,7 +233,7 @@ public class ProjectionCompiler {
             // appear as a column in an index
             projectedExpressions.add(expression);
             boolean isCaseSensitive = !SchemaUtil.normalizeIdentifier(colName).equals(colName);
-            ExpressionProjector projector = new ExpressionProjector(colName, tableRef.getTableAlias()
== null ? table.getName().getString() : tableRef.getTableAlias(), expression, isCaseSensitive);
+            ExpressionProjector projector = new ExpressionProjector(colName, tableRef.getTableAlias()
== null ? dataTable.getName().getString() : tableRef.getTableAlias(), expression, isCaseSensitive);
             projectedColumns.add(projector);
         }
     }


Mime
View raw message