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

    https://github.com/apache/phoenix/pull/34#discussion_r22993089
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java ---
    @@ -326,6 +322,48 @@ private IndexMaintainer(PTable dataTable, PTable 
index) {
             // TODO: check whether index is immutable or not. Currently it's 
always false so checking
             // data table is with immutable rows or not.
             this.immutableRows = dataTable.isImmutableRows();
    +        int indexColByteSize = 0;
    +        for (int i = indexPosOffset; i < index.getPKColumns().size(); i++) 
{
    +            PColumn indexColumn = index.getPKColumns().get(i);
    +            int indexPos = i - indexPosOffset;
    +            Expression expression = null;
    +            try {
    +                ParseNode parseNode  = 
SQLParser.parseCondition(indexColumn.getExpressionStr());
    +                ColumnResolver resolver = FromCompiler.getResolver(new 
TableRef(dataTable));
    +                StatementContext context = new StatementContext(new 
PhoenixStatement(null), resolver);
    +                expression = parseNode.accept(new 
ExpressionCompiler(context));
    +            } catch (SQLException e) {
    +                throw new RuntimeException(e); // Impossible
    +            }
    +            if ( 
ColumnExpression.class.isAssignableFrom(expression.getClass()) ) {
    +                   // get the column of the data table that corresponds to 
this index column
    +               PColumn column = IndexUtil.getDataColumn(dataTable, 
indexColumn.getName().getString());
    +               boolean isPKColumn = SchemaUtil.isPKColumn(column);
    +               if (isPKColumn) {
    +                   int dataPkPos = 
dataTable.getPKColumns().indexOf(column) - (dataTable.getBucketNum() == null ? 
0 : 1) - (this.isMultiTenant ? 1 : 0);
    +                   this.rowKeyMetaData.setIndexPkPosition(dataPkPos, 
indexPos);
    +               } else {
    +                   indexColByteSize += column.getDataType().isFixedWidth() 
? SchemaUtil.getFixedByteSize(column) : 
ValueSchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
    +                   this.indexedExpressions.add(expression);
    +               }
    +               if (indexColumn.getSortOrder() == SortOrder.DESC) {
    --- End diff --
    
    Move this if outside, as it'll apply for functional indexes as well. In the 
grammar, when you declare an indexed column as DESC, then this will be true. 
Setting this bit let's us know that we need to invert the bits after evaluating 
the expression.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to