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 51128180E2 for ; Tue, 2 Jun 2015 13:29:30 +0000 (UTC) Received: (qmail 72155 invoked by uid 500); 2 Jun 2015 13:29:30 -0000 Delivered-To: apmail-phoenix-dev-archive@phoenix.apache.org Received: (qmail 72097 invoked by uid 500); 2 Jun 2015 13:29:30 -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 72086 invoked by uid 99); 2 Jun 2015 13:29:30 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2015 13:29:30 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id B422ACABB1 for ; Tue, 2 Jun 2015 13:29:29 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.971 X-Spam-Level: X-Spam-Status: No, score=0.971 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id PT5a7BZnuNVc for ; Tue, 2 Jun 2015 13:29:20 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 574AF2054B for ; Tue, 2 Jun 2015 13:29:19 +0000 (UTC) Received: (qmail 71239 invoked by uid 99); 2 Jun 2015 13:29:18 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2015 13:29:18 +0000 Date: Tue, 2 Jun 2015 13:29:18 +0000 (UTC) From: "alex kamil (JIRA)" To: dev@phoenix.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (PHOENIX-1978) UDF ArgumentTypeMismatchException MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/PHOENIX-1978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14569091#comment-14569091 ] alex kamil commented on PHOENIX-1978: ------------------------------------- thanks [~rajeshbabu]. Applied the patch and it seems to work. Is it possible to add this to 4.4.1 release. > UDF ArgumentTypeMismatchException > --------------------------------- > > Key: PHOENIX-1978 > URL: https://issues.apache.org/jira/browse/PHOENIX-1978 > Project: Phoenix > Issue Type: Bug > Reporter: alex kamil > Assignee: Rajeshbabu Chintaguntla > Fix For: 4.4.1 > > Attachments: PHOENIX-1978.patch > > > I created a sample UDF with Phoenix 4.4 by copying ARRAY_ELEM function (https://github.com/apache/phoenix/blob/master/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java) and removing the BuiltInFunction annotation > after deploying to the server and running the following queries it throws an exception below > create function UDF_ARRAY_ELEM(VARCHAR ARRAY, INTEGER) returns "VARCHAR" as 'com.test.ArrayIndexFunction' using jar '/tmp/udf.jar' > CREATE TABLE TESTTABLE10(ID VARCHAR NOT NULL, NAME VARCHAR ARRAY, CITY VARCHAR ARRAY CONSTRAINT pk PRIMARY KEY (ID) ) > UPSERT INTO TESTTABLE10(ID,NAME,CITY) VALUES('111', ARRAY['JOHN','MIKE','BOB'], ARRAY['NYC','LA','SF']) > UPSERT INTO TESTTABLE10(ID,NAME,CITY) VALUES('112', ARRAY['CHEN','CARL','ALICE'], ARRAY['BOSTON','WASHINGTON','PALO ALTO']) > SELECT ID, UDF_ARRAY_ELEM(NAME, 2) FROM TESTTABLE10 > org.apache.phoenix.schema.ArgumentTypeMismatchException: ERROR 203 (22005): Type mismatch. expected: [INTEGER ARRAY] but was: INTEGER at UDF_ARRAY_ELEM argument 2 > at org.apache.phoenix.parse.FunctionParseNode.validate(FunctionParseNode.java:195) > at org.apache.phoenix.compile.ExpressionCompiler.visitLeave(ExpressionCompiler.java:326) > at org.apache.phoenix.compile.ProjectionCompiler$SelectClauseVisitor.visitLeave(ProjectionCompiler.java:637) > at org.apache.phoenix.compile.ProjectionCompiler$SelectClauseVisitor.visitLeave(ProjectionCompiler.java:538) > at org.apache.phoenix.parse.FunctionParseNode.accept(FunctionParseNode.java:85)Hbase> > at org.apache.phoenix.compile.ProjectionCompiler.compile(ProjectionCompiler.java:396) > at org.apache.phoenix.compile.QueryCompiler.compileSingleFlatQuery(QueryCompiler.java:537) > at org.apache.phoenix.compile.QueryCompiler.compileSingleQuery(QueryCompiler.java:488) > at org.apache.phoenix.compile.QueryCompiler.compileSelect(QueryCompiler.java:200) > at org.apache.phoenix.compile.QueryCompiler.compile(QueryCompiler.java:157) > at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:361) > at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:335) > at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:243) > at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:238) > at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53) > at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:237) > at org.apache.phoenix.jdbc.PhoenixPreparedStatement.executeQuery(PhoenixPreparedStatement.java:187) > at CustomSQL.openTerminal(CustomSQL.java:45) > at CustomSQL.main(CustomSQL.java:19) > udf function: > package com.test; > import java.util.List; > import org.apache.hadoop.hbase.io.ImmutableBytesWritable; > import org.apache.phoenix.expression.Expression; > import org.apache.phoenix.expression.function.ScalarFunction; > import org.apache.phoenix.parse.FunctionParseNode.Argument; > import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction; > import org.apache.phoenix.parse.ParseException; > import org.apache.phoenix.schema.types.PBinaryArray; > import org.apache.phoenix.schema.types.PInteger; > import org.apache.phoenix.schema.types.PArrayDataType; > import org.apache.phoenix.schema.types.PDataType; > import org.apache.phoenix.schema.types.PVarbinaryArray; > import org.apache.phoenix.schema.SortOrder; > import org.apache.phoenix.schema.tuple.Tuple; > /*@BuiltInFunction(name = ArrayIndexFunction.NAME, args = { > @Argument(allowedTypes = { PBinaryArray.class, > PVarbinaryArray.class }), > @Argument(allowedTypes = { PInteger.class }) }) > */ > public class ArrayIndexFunction extends ScalarFunction { > public static final String NAME = "UDF_ARRAY_ELEM"; > public ArrayIndexFunction() { > } > public ArrayIndexFunction(List children) { > super(children); > } > @Override > public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { > Expression indexExpr = children.get(1); > if (!indexExpr.evaluate(tuple, ptr)) { > return false; > } else if (ptr.getLength() == 0) { > return true; > } > // Use Codec to prevent Integer object allocation > int index = PInteger.INSTANCE.getCodec().decodeInt(ptr, indexExpr.getSortOrder()); > if(index < 0) { > throw new ParseException("Index cannot be negative :" + index); > } > Expression arrayExpr = children.get(0); > return PArrayDataType.positionAtArrayElement(tuple, ptr, index, arrayExpr, getDataType(), getMaxLength()); > } > @Override > public PDataType getDataType() { > return PDataType.fromTypeId(children.get(0).getDataType().getSqlType() - PDataType.ARRAY_TYPE_BASE); > } > > @Override > public Integer getMaxLength() { > return this.children.get(0).getMaxLength(); > } > @Override > public String getName() { > return NAME; > } > > @Override > public SortOrder getSortOrder() { > return this.children.get(0).getSortOrder(); > } > } -- This message was sent by Atlassian JIRA (v6.3.4#6332)