[ 
https://issues.apache.org/jira/browse/PHOENIX-1367?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Thomas D'Silva updated PHOENIX-1367:
------------------------------------
    Attachment: PHOENIX-1367-4.x-HBase-0.98-v3.patch

I have attached a v3 patch to fix the issues we found. 

the following change was made in IndexMaintainer to ensure the index row key is 
generated correctly for fixed length, nullable columns. 

{code}
-                       this.indexedExpressions.add(expression);
+                       try {
+                           // Surround constant with cast so that we can still 
know the original type. Otherwise, if we lose the type,
+                           // (for example when VARCHAR becomes CHAR), it can 
lead to problems in the type translation we do between data tables and indexes.
+                           if (column.isNullable() && 
ExpressionUtil.isConstant(expression)) {
+                               expression = 
CoerceExpression.create(expression, indexColumn.getDataType());
+                           }
+                        this.indexedExpressions.add(expression);
+                    } catch (SQLException e) {
+                        throw new RuntimeException(e); // Impossible
+                    }
{code}

I changed PTableImpl.getParentName to return the physical name if the parent 
name is null
{code}
-        return parentName;
+        // a view on a table will not have a parent name but will have a 
physical table name (which is the parent)
+        return parentName!=null ? parentName : getPhysicalName();
{code}

I also modified the index that is added to a child view , to use a new name and 
set the tenantId and update cache frequency to never. This ensures we don't 
remove the existing index from the client cache. 

{code}
-                String viewStatement = 
IndexUtil.rewriteViewStatement(connection, index, physicalTable, 
view.getViewStatement());
-                index = PTableImpl.makePTable(index, viewStatement);
-                indexesToAdd.add(index);
+                String viewStatement = 
IndexUtil.rewriteViewStatement(connection, index, parentTable, 
view.getViewStatement());
+                PName modifiedIndexName = 
PNameFactory.newName(index.getName().getString() + 
QueryConstants.NAME_SEPARATOR + view.getName().getString());
+                // add the index table with a new name so that it does not 
conflict with the existing index table 
+                // also set update cache frequency to never since the renamed 
index is not present on the server 
+                indexesToAdd.add(PTableImpl.makePTable(index, 
modifiedIndexName, viewStatement, Long.MAX_VALUE, view.getTenantId()));
{code}

> VIEW derived from another VIEW doesn't use parent VIEW indexes
> --------------------------------------------------------------
>
>                 Key: PHOENIX-1367
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1367
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: James Taylor
>            Assignee: Thomas D'Silva
>             Fix For: 4.9.0, 4.8.1
>
>         Attachments: PHOENIX-1367-4.x-HBase-0.98-v3.patch, 
> PHOENIX-1369-4.x-HBase-0.98-v2.patch, PHOENIX-1369-4.x-HBase-0.98-v3.patch, 
> PHOENIX-1369-4.x-HBase-0.98.patch, PHOENIX_1367.test.patch
>
>
> If a VIEW has an index and another VIEW is derived from it, the child view 
> will not use the parent view's indexes.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to