phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [14/22] phoenix git commit: PHOENIX-4859 Using local index in where statement for join (only rhs table) query fails(Rajeshbabu)
Date Mon, 15 Oct 2018 22:16:39 GMT
PHOENIX-4859 Using local index in where statement for join (only rhs table) query fails(Rajeshbabu)


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

Branch: refs/heads/omid2
Commit: 2ded8b64cdea48e89e7a0c936a59913a00345416
Parents: c90d090
Author: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Authored: Tue Oct 9 16:04:41 2018 +0530
Committer: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Committed: Tue Oct 9 16:04:41 2018 +0530

----------------------------------------------------------------------
 .../phoenix/end2end/index/LocalIndexIT.java     | 29 ++++++++++++++++++++
 .../phoenix/compile/ExpressionCompiler.java     |  2 +-
 .../apache/phoenix/compile/JoinCompiler.java    |  2 +-
 .../phoenix/compile/ProjectionCompiler.java     |  4 +--
 .../compile/TupleProjectionCompiler.java        |  2 +-
 .../phoenix/schema/LocalIndexDataColumnRef.java | 18 ++++++------
 6 files changed, 44 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/2ded8b64/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
index ed1cf45..e260969 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -684,6 +684,35 @@ public class LocalIndexIT extends BaseLocalIndexIT {
         conn1.close();
     }
 
+    @Test
+    public void testLocalIndexSelfJoin() throws Exception {
+      String tableName = generateUniqueName();
+      String indexName = "IDX_" + generateUniqueName();
+      Connection conn1 = DriverManager.getConnection(getUrl());
+      if (isNamespaceMapped) {
+          conn1.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + schemaName);
+      }
+        String ddl =
+                "CREATE TABLE "
+                        + tableName
+                        + " (customer_id integer primary key, postal_code varchar, country_code
varchar)";
+        conn1.createStatement().execute(ddl);
+        conn1.createStatement().execute("UPSERT INTO " + tableName + " values(1,'560103','IN')");
+        conn1.commit();
+        conn1.createStatement().execute(
+            "CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(postal_code)");
+        ResultSet rs =
+                conn1.createStatement()
+                        .executeQuery(
+                            "SELECT * from "
+                                    + tableName
+                                    + " c1, "
+                                    + tableName
+                                    + " c2 where c1.customer_id=c2.customer_id and c2.postal_code='560103'");
+        assertTrue(rs.next());
+        conn1.close();
+    }
+
     private void copyLocalIndexHFiles(Configuration conf, HRegionInfo fromRegion, HRegionInfo
toRegion, boolean move)
             throws IOException {
         Path root = FSUtils.getRootDir(conf);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2ded8b64/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
index 9daa744..077e1af 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
@@ -376,7 +376,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
             // operation given that we know the join is local.
             if (context.getCurrentTable().getTable().getIndexType() == IndexType.LOCAL) {
                 try {
-                    return new LocalIndexDataColumnRef(context, node.getName());
+                    return new LocalIndexDataColumnRef(context, context.getCurrentTable(),
node.getName());
                 } catch (ColumnFamilyNotFoundException c) {
                     throw e;
                 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2ded8b64/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index 36bfc5f..880fa72 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -869,7 +869,7 @@ public class JoinCompiler {
                     if (columnRef.getTableRef().equals(tableRef)
                             && (!retainPKColumns || !SchemaUtil.isPKColumn(columnRef.getColumn())))
{
                         if (columnRef instanceof LocalIndexColumnRef) {
-                            sourceColumns.add(new LocalIndexDataColumnRef(context, IndexUtil.getIndexColumnName(columnRef.getColumn())));
+                            sourceColumns.add(new LocalIndexDataColumnRef(context, tableRef,
IndexUtil.getIndexColumnName(columnRef.getColumn())));
                         } else {
                             sourceColumns.add(columnRef);
                         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2ded8b64/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 f85b5a8..1b97b50 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
@@ -218,7 +218,7 @@ public class ProjectionCompiler {
             } catch (ColumnNotFoundException e) {
                 if (index.getIndexType() == IndexType.LOCAL) {
                     try {
-                        ref = new LocalIndexDataColumnRef(context, indexColName);
+                        ref = new LocalIndexDataColumnRef(context, tableRef, indexColName);
                         indexColumn = ref.getColumn();
                     } catch (ColumnFamilyNotFoundException c) {
                         throw e;
@@ -291,7 +291,7 @@ public class ProjectionCompiler {
             } catch (ColumnNotFoundException e) {
                 if (index.getIndexType() == IndexType.LOCAL) {
                     try {
-                        ref = new LocalIndexDataColumnRef(context, indexColName);
+                        ref = new LocalIndexDataColumnRef(context, tableRef, indexColName);
                         indexColumn = ref.getColumn();
                         indexColumnFamily =
                                 indexColumn.getFamilyName() == null ? null

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2ded8b64/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
index a2937bf..dc85bd3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/TupleProjectionCompiler.java
@@ -225,7 +225,7 @@ public class TupleProjectionCompiler {
             } catch (ColumnNotFoundException e) {
                 if (context.getCurrentTable().getTable().getIndexType() == IndexType.LOCAL)
{
                     try {
-                        localIndexColumnRefSet.add(new LocalIndexDataColumnRef(context, node.getName()));
+                        localIndexColumnRefSet.add(new LocalIndexDataColumnRef(context, context.getCurrentTable(),
node.getName()));
                     } catch (ColumnFamilyNotFoundException c) {
                         throw e;
                     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2ded8b64/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java
b/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java
index 0061331..87f0999 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java
@@ -33,15 +33,17 @@ public class LocalIndexDataColumnRef extends ColumnRef {
     final private Set<PColumn> columns;
     private static final ParseNodeFactory FACTORY = new ParseNodeFactory();
 
-    public LocalIndexDataColumnRef(StatementContext context, String indexColumnName) throws
MetaDataEntityNotFoundException, SQLException {
+    public LocalIndexDataColumnRef(StatementContext context, TableRef tRef, String indexColumnName)
+            throws MetaDataEntityNotFoundException, SQLException {
         super(FromCompiler.getResolver(
-            FACTORY.namedTable(null, TableName.create(context.getCurrentTable().getTable()
-                    .getSchemaName().getString(), context.getCurrentTable().getTable()
-                    .getParentTableName().getString())), context.getConnection(), false).resolveTable(
-            context.getCurrentTable().getTable().getSchemaName().getString(),
-            context.getCurrentTable().getTable().getParentTableName().getString()), IndexUtil
-                .getDataColumnFamilyName(indexColumnName), IndexUtil
-                .getDataColumnName(indexColumnName));
+            FACTORY.namedTable(
+                null,
+                TableName.create(tRef.getTable().getSchemaName().getString(), tRef.getTable()
+                        .getParentTableName().getString())), context.getConnection(), false)
+                .resolveTable(tRef.getTable().getSchemaName().getString(),
+                    tRef.getTable().getParentTableName().getString()),
+                IndexUtil.getDataColumnFamilyName(indexColumnName), IndexUtil
+                        .getDataColumnName(indexColumnName));
         position = context.getDataColumnPosition(this.getColumn());
         columns = context.getDataColumns();
     }


Mime
View raw message