phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject phoenix git commit: PHOENIX-4546 Projected table cannot be read through ProjectedColumnExpression
Date Thu, 08 Feb 2018 07:12:06 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 907e90932 -> 76573d67b


PHOENIX-4546 Projected table cannot be read through ProjectedColumnExpression


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 76573d67be22114986dd2943b70b821e32c2d26b
Parents: 907e909
Author: Ankit Singhal <ankitsinghal59@gmail.com>
Authored: Thu Feb 8 12:41:56 2018 +0530
Committer: Ankit Singhal <ankitsinghal59@gmail.com>
Committed: Thu Feb 8 12:41:56 2018 +0530

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/DeleteIT.java    | 36 ++++++++++++++++++++
 .../compile/TupleProjectionCompiler.java        | 32 ++++++++++++-----
 2 files changed, 60 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/76573d67/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
index e111e7a..498aeff 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
@@ -710,6 +710,41 @@ public class DeleteIT extends ParallelStatsDisabledIT {
     public void testClientSideDeleteAutoCommitOn() throws Exception {
         testDeleteCount(true, 1000);
     }
+
+    @Test
+    public void testPointDeleteWithMultipleImmutableIndexes() throws Exception {
+        testPointDeleteWithMultipleImmutableIndexes(false);
+    }
+
+    @Test
+    public void testPointDeleteWithMultipleImmutableIndexesAfterAlter() throws Exception
{
+        testPointDeleteWithMultipleImmutableIndexes(true);
+    }
+
+    private void testPointDeleteWithMultipleImmutableIndexes(boolean alterTable) throws Exception
{
+        String tableName = generateUniqueName();
+        String commands = "CREATE TABLE IF NOT EXISTS " + tableName
+                + " (ID INTEGER PRIMARY KEY,double_id DOUBLE,varchar_id VARCHAR (30)) "
+                + (alterTable ? ";ALTER TABLE " + tableName + " set " : "") + "IMMUTABLE_ROWS=true;"
+                + "CREATE INDEX IF NOT EXISTS index_column_varchar_id ON " + tableName +
"(varchar_id);"
+                + "CREATE INDEX IF NOT EXISTS index_column_double_id ON " + tableName + "(double_id);"
+ "UPSERT INTO "
+                + tableName + " VALUES (9000000,0.5,'Sample text extra');" ;
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            Statement stm = conn.createStatement();
+            for (String sql : commands.split(";")) {
+                stm.execute(sql);
+            }
+            ResultSet rs = stm.executeQuery("select id,varchar_id,double_id from " + tableName
+ " WHERE ID=9000000");
+            assertTrue(rs.next());
+            assertEquals(9000000, rs.getInt(1));
+            assertEquals("Sample text extra", rs.getString(2));
+            assertEquals(0.5, rs.getDouble(3),0.01);
+            stm.execute("DELETE FROM " + tableName + " WHERE ID=9000000");
+            assertDeleted(conn, tableName, "index_column_varchar_id", "index_column_double_id",
null);
+            stm.close();
+        }
+    }
     
     private void testDeleteCount(boolean autoCommit, Integer limit) throws Exception {
         String tableName = generateUniqueName();
@@ -735,6 +770,7 @@ public class DeleteIT extends ParallelStatsDisabledIT {
         }
 
     }
+    
 
     @Test
     public void testClientSideDeleteShouldNotFailWhenSameColumnPresentInMultipleIndexes()

http://git-wip-us.apache.org/repos/asf/phoenix/blob/76573d67/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 9883de6..d0b900c 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
@@ -22,6 +22,7 @@ import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -103,6 +104,10 @@ public class TupleProjectionCompiler {
                     for (PColumn column : parentTableRef.getTable().getColumnFamily(familyName).getColumns())
{
                         NODE_FACTORY.column(null, '"' + IndexUtil.getIndexColumnName(column)
+ '"', null).accept(visitor);
                     }
+                }else{
+                    for (PColumn column : table.getColumnFamily(familyName).getColumns())
{
+                        NODE_FACTORY.column(TableName.create(null, familyName), '"' + column.getName().getString()
+ '"', null).accept(visitor);
+                    }
                 }
                 families.add(familyName);
             } else {
@@ -125,16 +130,22 @@ public class TupleProjectionCompiler {
                     position++, sourceColumn.isNullable(), sourceColumnRef, null);
             projectedColumns.add(column);
         }
+
+        List<ColumnRef> nonPkColumnRefList = new ArrayList<ColumnRef>(visitor.nonPkColumnRefSet);
         for (PColumn sourceColumn : table.getColumns()) {
             if (SchemaUtil.isPKColumn(sourceColumn))
                 continue;
             ColumnRef sourceColumnRef = new ColumnRef(tableRef, sourceColumn.getPosition());
             if (!isWildcard 
-                    && !visitor.columnRefSet.contains(sourceColumnRef)
+                    && !visitor.nonPkColumnRefSet.contains(sourceColumnRef)
                     && !families.contains(sourceColumn.getFamilyName().getString()))
                 continue;
-            PColumn column = new ProjectedColumn(sourceColumn.getName(), sourceColumn.getFamilyName(),

-                    position++, sourceColumn.isNullable(), sourceColumnRef, sourceColumn.getColumnQualifierBytes());
+
+            PColumn column = new ProjectedColumn(sourceColumn.getName(), sourceColumn.getFamilyName(),
+                    visitor.nonPkColumnRefSet.contains(sourceColumnRef)
+                            ? position + nonPkColumnRefList.indexOf(sourceColumnRef) : position++,
+                    sourceColumn.isNullable(), sourceColumnRef, sourceColumn.getColumnQualifierBytes());
+
             projectedColumns.add(column);
             // Wildcard or FamilyWildcard will be handled by ProjectionCompiler.
             if (!isWildcard && !families.contains(sourceColumn.getFamilyName()))
{
@@ -142,6 +153,7 @@ public class TupleProjectionCompiler {
             }
         }
         // add LocalIndexDataColumnRef
+        position = projectedColumns.size();
         for (LocalIndexDataColumnRef sourceColumnRef : visitor.localIndexColumnRefSet) {
             PColumn column = new ProjectedColumn(sourceColumnRef.getColumn().getName(), 
                     sourceColumnRef.getColumn().getFamilyName(), position++, 
@@ -192,19 +204,23 @@ public class TupleProjectionCompiler {
     // For extracting column references from single select statement
     private static class ColumnRefVisitor extends StatelessTraverseAllParseNodeVisitor {
         private final StatementContext context;
-        private final Set<ColumnRef> columnRefSet;
-        private final Set<LocalIndexDataColumnRef> localIndexColumnRefSet;
+        private final LinkedHashSet<ColumnRef> nonPkColumnRefSet;
+        private final LinkedHashSet<LocalIndexDataColumnRef> localIndexColumnRefSet;
         
         private ColumnRefVisitor(StatementContext context) {
             this.context = context;
-            this.columnRefSet = new HashSet<ColumnRef>();
-            this.localIndexColumnRefSet = new HashSet<LocalIndexDataColumnRef>();
+            this.nonPkColumnRefSet = new LinkedHashSet<ColumnRef>();
+            this.localIndexColumnRefSet = new LinkedHashSet<LocalIndexDataColumnRef>();
         }
 
         @Override
         public Void visit(ColumnParseNode node) throws SQLException {
             try {
-                columnRefSet.add(context.getResolver().resolveColumn(node.getSchemaName(),
node.getTableName(), node.getName()));
+                ColumnRef resolveColumn = context.getResolver().resolveColumn(node.getSchemaName(),
node.getTableName(),
+                        node.getName());
+                if (!SchemaUtil.isPKColumn(resolveColumn.getColumn())) {
+                    nonPkColumnRefSet.add(resolveColumn);
+                }
             } catch (ColumnNotFoundException e) {
                 if (context.getCurrentTable().getTable().getIndexType() == IndexType.LOCAL)
{
                     try {


Mime
View raw message