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

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

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

    https://github.com/apache/phoenix/pull/34#discussion_r23973739
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java ---
    @@ -945,55 +963,79 @@ public MutationState createIndex(CreateIndexStatement 
statement, byte[][] splits
                         PDataType dataType = 
MetaDataUtil.getViewIndexIdDataType();
                         ColumnName colName = 
ColumnName.caseSensitiveColumnName(MetaDataUtil.getViewIndexIdColumnName());
                         allPkColumns.add(new Pair<ColumnName, 
SortOrder>(colName, SortOrder.getDefault()));
    -                    columnDefs.add(FACTORY.columnDef(colName, 
dataType.getSqlTypeName(), false, null, null, false, SortOrder.getDefault()));
    +                    columnDefs.add(FACTORY.columnDef(colName, 
dataType.getSqlTypeName(), false, null, null, false, SortOrder.getDefault(), 
null));
                     }
                     // First columns are the indexed ones
    -                for (Pair<ColumnName, SortOrder> pair : indexedPkColumns) {
    -                    ColumnName colName = pair.getFirst();
    -                    PColumn col = resolver.resolveColumn(null, 
colName.getFamilyName(), colName.getColumnName()).getColumn();
    -                    unusedPkColumns.remove(col);
    -                    // Ignore view constants for updatable views as we 
don't need these in the index
    -                    if (col.getViewConstant() == null) {
    -                        PDataType dataType = 
IndexUtil.getIndexColumnDataType(col);
    -                        colName = 
ColumnName.caseSensitiveColumnName(IndexUtil.getIndexColumnName(col));
    -                        allPkColumns.add(new Pair<ColumnName, 
SortOrder>(colName, pair.getSecond()));
    -                        columnDefs.add(FACTORY.columnDef(colName, 
dataType.getSqlTypeName(), col.isNullable(), col.getMaxLength(), 
col.getScale(), false, SortOrder.getDefault()));
    -                    }
    +                Set<ColumnName> indexedColumnNames = 
Sets.newHashSetWithExpectedSize(indexParseNodeAndSortOrderList.size());
    +                for (Pair<ParseNode, SortOrder> pair : 
indexParseNodeAndSortOrderList) {
    +                   ParseNode parseNode = pair.getFirst();
    +                       // compile the parseNode to get an expression
    +                    PhoenixStatement phoenixStatment = new 
PhoenixStatement(connection);
    +                    final StatementContext context = new 
StatementContext(phoenixStatment, resolver);
    +                    // normalize the parse node
    +                    parseNode = StatementNormalizer.normalize(parseNode, 
resolver);
    +                    ExpressionCompiler expressionCompiler = new 
ExpressionCompiler(context);
    +                    Expression expression = 
parseNode.accept(expressionCompiler);   
    +                    if (expressionCompiler.isAggregate()) {
    +                        throw new 
SQLExceptionInfo.Builder(SQLExceptionCode.AGGREGATE_EXPRESSION_NOT_ALLOWED_IN_INDEX).build().buildException();
    +                    }
    +                    if (expression.getDeterminism() != Determinism.ALWAYS) 
{
    +                        throw new 
SQLExceptionInfo.Builder(SQLExceptionCode.NON_DETERMINISTIC_EXPRESSION_NOT_ALLOWED_IN_INDEX).build().buildException();
    +                    }
    +                    // true for any constant (including a view constant), 
as we don't need these in the index
    +                    if (expression.isStateless()) {
    +                        continue;
    +                    }
    +                    unusedPkColumns.remove(expression);
    +                    
    +                    ColumnName colName = null;
    +                                   // if expression is KeyValueExpression 
set the column name correctly
    +                                   if (expression.getChildren().size() == 
0) {
    +                                           colName = expression
    +                                                           .accept(new 
StatelessTraverseAllExpressionVisitor<ColumnName>() {
    +                                                                   
@Override
    +                                                                   public 
ColumnName visit(
    +                                                                           
        KeyValueColumnExpression node) {
    +                                                                           
return ColumnName.caseSensitiveColumnName(Bytes.toString(IndexUtil
    +                                                                           
                .getIndexColumnName(node.getColumnFamily(), 
node.getColumnName())));
    +                                                                   }
    +                                                           });
    +                                   }
    +                                   colName = colName!=null ? colName : 
ColumnName.caseSensitiveColumnName(IndexUtil.getIndexColumnName(null, 
expression.toString().replaceAll("\"", "")));
    --- End diff --
    
    I don't get this still. Why do you have to remove all double quotes? That 
could be problematic, for example if a string constant contains a double quote. 


> Support functional indexes
> --------------------------
>
>                 Key: PHOENIX-514
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-514
>             Project: Phoenix
>          Issue Type: Task
>            Reporter: James Taylor
>            Assignee: Thomas D'Silva
>              Labels: enhancement
>
> Instead of only defining the set of columns from the data table that make up 
> an index, you should be able to use expressions.  For example:
>       CREATE INDEX upper_last_name_idx ON person (UPPER(last_name))
> Then in queries that use UPPER(last_name), we can replace them with column 
> references to the index table.



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

Reply via email to