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

Thomas D'Silva commented on PHOENIX-3295:
-----------------------------------------

[~jamestaylor] the original KeyValue expression is used in one other place in 
IndexMaintainer to build the indexedColumnsInfo. We need it to look up the 
PColumn to get the original data column name. Instead of storing the original 
kv expression we should be able to construct it using the col family and index 
of ArrayColumnExpression would that work?
fyi [~samarthjain]

{code}
private Void addDataColInfo(final PTable dataTable, Expression expression) {
                        Preconditions.checkArgument(expression instanceof 
ArrayColumnExpression
                                || expression instanceof 
KeyValueColumnExpression);

                        KeyValueColumnExpression colExpression = null;
                        if (expression instanceof ArrayColumnExpression) {
                            colExpression =
                                    ((ArrayColumnExpression) 
expression).getKeyValueExpression();
                        } else {
                            colExpression = ((KeyValueColumnExpression) 
expression);
                        }
                        byte[] cf = colExpression.getColumnFamily();
                        byte[] cq = colExpression.getColumnQualifier();
                        try {
                            PColumn dataColumn =
                                    cf == null ? 
dataTable.getPColumnForColumnQualifier(null, cq)
                                            : dataTable.getColumnFamily(cf)
                                                    
.getPColumnForColumnQualifier(cq);
                            indexedColumnsInfo.add(new 
Pair<>(dataColumn.getFamilyName()
                                    .getString(), 
dataColumn.getName().getString()));
                        } catch (ColumnNotFoundException | 
ColumnFamilyNotFoundException
                                | AmbiguousColumnException e) {
                            throw new RuntimeException(e);
                        }
                        return null;
                    }{code}

> Remove ReplaceArrayColumnWithKeyValueColumnExpressionVisitor 
> -------------------------------------------------------------
>
>                 Key: PHOENIX-3295
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-3295
>             Project: Phoenix
>          Issue Type: Improvement
>            Reporter: Thomas D'Silva
>            Assignee: Thomas D'Silva
>         Attachments: PHOENIX-3295.patch
>
>
> ReplaceArrayColumnWithKeyValueColumnExpressionVisitor is only used in one 
> place in IndexUtil.generateIndexData because we use a ValueGetter to get the 
> value of the data table column using the original data table column 
> reference. This is also why ArrayColumnExpression needs to keep track of the 
> original key value column expression. 
> If we don't replace the array column expression with the original column 
> expression when it looks up the column by the qualifier it won't find it. 
> {code}
> ValueGetter valueGetter = new ValueGetter() {
>                       
>                       @Override
>                         public byte[] getRowKey() {
>                               return dataMutation.getRow();
>                       }
>         
>                         @Override
>                         public ImmutableBytesWritable 
> getLatestValue(ColumnReference ref) {
>                             // Always return null for our empty key value, as 
> this will cause the index
>                             // maintainer to always treat this Put as a new 
> row.
>                             if (isEmptyKeyValue(table, ref)) {
>                                 return null;
>                             }
>                             byte[] family = ref.getFamily();
>                             byte[] qualifier = ref.getQualifier();
>                             RowMutationState rowMutationState = 
> valuesMap.get(ptr);
>                             PColumn column = null;
>                             try {
>                                 column = 
> table.getColumnFamily(family).getPColumnForColumnQualifier(qualifier);
>                             } catch (ColumnNotFoundException e) {
>                             } catch (ColumnFamilyNotFoundException e) {
>                             }
>                             if (rowMutationState!=null && column!=null) {
>                                 byte[] value = 
> rowMutationState.getColumnValues().get(column);
>                                 ImmutableBytesPtr ptr = new 
> ImmutableBytesPtr();
>                                 ptr.set(value==null ? 
> ByteUtil.EMPTY_BYTE_ARRAY : value);
>                                 
> SchemaUtil.padData(table.getName().getString(), column, ptr);
>                                 return ptr;
>                             }
>                             return null;
>                         }
>                         
>                     };
> {code}



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

Reply via email to