[ 
https://issues.apache.org/jira/browse/PHOENIX-4855?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16636248#comment-16636248
 ] 

ASF GitHub Bot commented on PHOENIX-4855:
-----------------------------------------

Github user ChinmaySKulkarni commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/339#discussion_r222145718
  
    --- Diff: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java 
---
    @@ -810,59 +827,65 @@ public void testDivergedViewsStayDiverged() throws 
Exception {
                 PTable table = PhoenixRuntime.getTableNoCache(viewConn, view1);
                 assertEquals(QueryConstants.DIVERGED_VIEW_BASE_COLUMN_COUNT, 
table.getBaseColumnCount());
                 
    +            try {
    +                viewConn.createStatement().execute("SELECT V2 FROM " + 
view1);
    +                fail("V2 should have been droppped");
    +            } catch (SQLException e) {
    +                
assertEquals(SQLExceptionCode.COLUMN_NOT_FOUND.getErrorCode(), 
e.getErrorCode());
    +            }
    +            
                 // Add a new regular column and pk column  to the base table
                 String alterBaseTable = "ALTER TABLE " + baseTable + " ADD V3 
VARCHAR, PK2 VARCHAR PRIMARY KEY";
                 conn.createStatement().execute(alterBaseTable);
                 
                 // Column V3 shouldn't have propagated to the diverged view.
    -            String sql = "SELECT V3 FROM " + view1;
                 try {
    -                viewConn.createStatement().execute(sql);
    +                viewConn.createStatement().execute("SELECT V3 FROM " + 
view1);
    --- End diff --
    
    Assert.fail in case this exception is not caught. Similarly for all other 
places where we expect an exception.


> Continue to write base table column metadata when creating a view in order to 
> support rollback
> ----------------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-4855
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-4855
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: Thomas D'Silva
>            Assignee: Thomas D'Silva
>            Priority: Major
>         Attachments: PHOENIX-4855-4.x-HBase-1.3.patch
>
>
> Currently we filter out the parent table columns while creating a view. If we 
> have to support rollback we still need to write the parent table column 
> metadata. 
> Instead of this we should filter out the duplicate columns in 
> {{MetaDataEndpointImpl.combineColumns}}
> {code}
> // Here we are passed the parent's columns to add to a view, PHOENIX-3534 
> allows for a splittable
>             // System.Catalog thus we only store the columns that are new to 
> the view, not the parents columns,
>             // thus here we remove everything that is ORDINAL.POSITION <= 
> baseColumnCount and update the
>             // ORDINAL.POSITIONS to be shifted accordingly.
>             // TODO PHOENIX-4767 remove the following code that removes the 
> base table column metadata in the next release 
>             if (PTableType.VIEW.equals(tableType) && 
> !ViewType.MAPPED.equals(viewType)) {
>                 boolean isSalted = MetaDataUtil.getSaltBuckets(tableMetadata, 
> GenericKeyValueBuilder.INSTANCE, new ImmutableBytesWritable()) > 0;
>                 int baseColumnCount = 
> MetaDataUtil.getBaseColumnCount(tableMetadata) - (isSalted ? 1 : 0);
>                 if (baseColumnCount > 0) {
>                     Iterator<Mutation> mutationIterator = 
> tableMetadata.iterator();
>                     while (mutationIterator.hasNext()) {
>                         Mutation mutation = mutationIterator.next();
>                         // if not null and ordinal position < base column 
> count remove this mutation
>                         ImmutableBytesWritable ptr = new 
> ImmutableBytesWritable();
>                         MetaDataUtil.getMutationValue(mutation, 
> PhoenixDatabaseMetaData.ORDINAL_POSITION_BYTES,
>                             GenericKeyValueBuilder.INSTANCE, ptr);
>                         if (MetaDataUtil.getMutationValue(mutation, 
> PhoenixDatabaseMetaData.ORDINAL_POSITION_BYTES,
>                             GenericKeyValueBuilder.INSTANCE, ptr)) {
>                             int ordinalValue = 
> PInteger.INSTANCE.getCodec().decodeInt(ptr, SortOrder.ASC);
>                             if (ordinalValue <= baseColumnCount) {
>                                 mutationIterator.remove();
>                             } else {
>                                 if (mutation instanceof Put) {
>                                     byte[] ordinalPositionBytes = new 
> byte[PInteger.INSTANCE.getByteSize()];
>                                     int newOrdinalValue = ordinalValue - 
> baseColumnCount;
>                                     PInteger.INSTANCE.getCodec()
>                                         .encodeInt(newOrdinalValue, 
> ordinalPositionBytes, 0);
>                                     byte[] family = 
> Iterables.getOnlyElement(mutation.getFamilyCellMap().keySet());
>                                     MetaDataUtil.mutatePutValue((Put) 
> mutation, family, PhoenixDatabaseMetaData.ORDINAL_POSITION_BYTES, 
> ordinalPositionBytes);
>                                 }
>                             }
>                         }
>                     }
>                 }
>             }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to