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

    https://github.com/apache/phoenix/pull/34#discussion_r23278372
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/compile/IndexColumnExpressionCompiler.java
 ---
    @@ -0,0 +1,311 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements. See the NOTICE
    + * file distributed with this work for additional information regarding 
copyright ownership. The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the "License"); you may 
not use this file except in compliance with the
    + * License. You may obtain a copy of the License at 
http://www.apache.org/licenses/LICENSE-2.0 Unless required by
    + * applicable law or agreed to in writing, software distributed under the 
License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
implied. See the License for the specific language
    + * governing permissions and limitations under the License.
    + */
    +package org.apache.phoenix.compile;
    +
    +import java.sql.SQLException;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.Map;
    +
    +import org.apache.hadoop.hbase.client.Scan;
    +import org.apache.phoenix.compile.GroupByCompiler.GroupBy;
    +import org.apache.phoenix.expression.ColumnExpression;
    +import org.apache.phoenix.expression.Expression;
    +import org.apache.phoenix.parse.AddParseNode;
    +import org.apache.phoenix.parse.AndParseNode;
    +import org.apache.phoenix.parse.ArrayAllComparisonNode;
    +import org.apache.phoenix.parse.ArrayAnyComparisonNode;
    +import org.apache.phoenix.parse.ArrayElemRefNode;
    +import org.apache.phoenix.parse.CaseParseNode;
    +import org.apache.phoenix.parse.CastParseNode;
    +import org.apache.phoenix.parse.ColumnDef;
    +import org.apache.phoenix.parse.ColumnParseNode;
    +import org.apache.phoenix.parse.ComparisonParseNode;
    +import org.apache.phoenix.parse.DivideParseNode;
    +import org.apache.phoenix.parse.FunctionParseNode;
    +import org.apache.phoenix.parse.ModulusParseNode;
    +import org.apache.phoenix.parse.MultiplyParseNode;
    +import org.apache.phoenix.parse.NamedTableNode;
    +import org.apache.phoenix.parse.NotParseNode;
    +import org.apache.phoenix.parse.OrParseNode;
    +import org.apache.phoenix.parse.ParseNode;
    +import org.apache.phoenix.parse.ParseNodeFactory;
    +import org.apache.phoenix.parse.RowValueConstructorParseNode;
    +import org.apache.phoenix.parse.SQLParser;
    +import org.apache.phoenix.parse.StringConcatParseNode;
    +import org.apache.phoenix.parse.SubtractParseNode;
    +import org.apache.phoenix.parse.TableName;
    +import org.apache.phoenix.schema.PColumn;
    +import org.apache.phoenix.schema.PTable;
    +import org.apache.phoenix.schema.PTableType;
    +import org.apache.phoenix.schema.types.PDataType;
    +import org.apache.phoenix.util.IndexUtil;
    +
    +import com.google.common.collect.Maps;
    +
    +/**
    + * Visitor that checks if nodes other than ColumnParseNode are present as 
an expression in an index. If the expression
    + * is present, then the node is not visited but processed as a 
ColumnParseNode.
    + */
    +public class IndexColumnExpressionCompiler extends ExpressionCompiler {
    +
    +    private static final ParseNodeFactory FACTORY = new ParseNodeFactory();
    +    private final Map<String, Expression> expressionMap;
    +
    +    IndexColumnExpressionCompiler(StatementContext context) {
    +        this(context, GroupBy.EMPTY_GROUP_BY, false);
    +    }
    +
    +    IndexColumnExpressionCompiler(StatementContext context, boolean 
resolveViewConstants) {
    +        this(context, GroupBy.EMPTY_GROUP_BY, resolveViewConstants);
    +    }
    +
    +    IndexColumnExpressionCompiler(StatementContext context, GroupBy 
groupBy) {
    +        this(context, groupBy, false);
    +    }
    +
    +    IndexColumnExpressionCompiler(StatementContext context, GroupBy 
groupBy, boolean resolveViewConstants) {
    +        super(context, groupBy, resolveViewConstants);
    +        expressionMap = 
Maps.newHashMapWithExpectedSize(context.getCurrentTable().getTable().getColumns().size());
    +        for (PColumn column : 
context.getCurrentTable().getTable().getColumns()) {
    --- End diff --
    
    I meant to create a map from <Functional Expression> -> <Index Column 
Expression> where you use this to look for occurrences of the functional 
expression to replace with a reference to the column expression in the index 
table. You'd do a get into the map from the 
ExpressionCompiler.wrapGroupByExpression() which is called on each visitLeave 
method. If you find an entry, you use the ColumnExpression into the index 
table, otherwise, you use the original expression. This is the expression you 
provide as an argument to super.wrapGroupByExpression(). Let's talk in person 
tomorrow if this doesn't make sense.


---
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