Return-Path: X-Original-To: apmail-phoenix-dev-archive@minotaur.apache.org Delivered-To: apmail-phoenix-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9785017591 for ; Wed, 28 Jan 2015 06:45:57 +0000 (UTC) Received: (qmail 4209 invoked by uid 500); 28 Jan 2015 06:45:58 -0000 Delivered-To: apmail-phoenix-dev-archive@phoenix.apache.org Received: (qmail 4151 invoked by uid 500); 28 Jan 2015 06:45:58 -0000 Mailing-List: contact dev-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list dev@phoenix.apache.org Received: (qmail 4139 invoked by uid 99); 28 Jan 2015 06:45:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Jan 2015 06:45:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 28 Jan 2015 06:45:56 +0000 Received: (qmail 3957 invoked by uid 99); 28 Jan 2015 06:45:36 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Jan 2015 06:45:36 +0000 Date: Wed, 28 Jan 2015 06:45:36 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@phoenix.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (PHOENIX-514) Support functional indexes MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/PHOENIX-514?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14294786#comment-14294786 ] 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_r23668579 --- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java --- @@ -945,20 +960,40 @@ public MutationState createIndex(CreateIndexStatement statement, byte[][] splits PDataType dataType = MetaDataUtil.getViewIndexIdDataType(); ColumnName colName = ColumnName.caseSensitiveColumnName(MetaDataUtil.getViewIndexIdColumnName()); allPkColumns.add(new Pair(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 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(colName, pair.getSecond())); - columnDefs.add(FACTORY.columnDef(colName, dataType.getSqlTypeName(), col.isNullable(), col.getMaxLength(), col.getScale(), false, SortOrder.getDefault())); - } + for (Pair pair : indexParseNodeAndSortOrderList) { + ParseNode parseNode = pair.getFirst(); + ColumnName colName = null; + // if it is a column + if (parseNode instanceof ColumnParseNode) { + ColumnParseNode colParseNode = (ColumnParseNode)parseNode; + PColumn col = resolver.resolveColumn(null, colParseNode.getTableName(), colParseNode.getName()).getColumn(); + unusedPkColumns.remove(col); + // Ignore view constants for updatable views as we don't need these in the index + if (col.getViewConstant() != null) + continue; + colName = ColumnName.caseSensitiveColumnName(IndexUtil.getIndexColumnName(col)); + } + // compile the parseNode to get an expression + PhoenixStatement phoenixStatment = new PhoenixStatement(connection); + final StatementContext context = new StatementContext(phoenixStatment, 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(); + } + + PDataType dataType = IndexUtil.getIndexColumnDataType(expression.isNullable(), expression.getDataType()); + colName = colName != null ? colName : + ColumnName.caseSensitiveColumnName(IndexUtil.getIndexColumnName(null, expression.toString().replaceAll("\"", ""))); + allPkColumns.add(new Pair(colName, pair.getSecond())); + // TODO set the max length and scale correctly --- End diff -- Remove TODO > 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)