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 0BEBA17867 for ; Sat, 7 Mar 2015 02:29:35 +0000 (UTC) Received: (qmail 72165 invoked by uid 500); 7 Mar 2015 02:29:35 -0000 Delivered-To: apmail-phoenix-dev-archive@phoenix.apache.org Received: (qmail 72103 invoked by uid 500); 7 Mar 2015 02:29:34 -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 72092 invoked by uid 99); 7 Mar 2015 02:29:34 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Mar 2015 02:29:34 +0000 Received: from mail-yk0-f181.google.com (mail-yk0-f181.google.com [209.85.160.181]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 5B9131A02BD for ; Sat, 7 Mar 2015 02:29:34 +0000 (UTC) Received: by ykp9 with SMTP id 9so28009649ykp.5 for ; Fri, 06 Mar 2015 18:29:33 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.236.98.65 with SMTP id u41mr15840153yhf.57.1425695373462; Fri, 06 Mar 2015 18:29:33 -0800 (PST) Received: by 10.170.170.213 with HTTP; Fri, 6 Mar 2015 18:29:33 -0800 (PST) In-Reply-To: References: Date: Fri, 6 Mar 2015 18:29:33 -0800 Message-ID: Subject: Re: Implementing ARRAY_APPEND built-in function From: James Taylor To: "dev@phoenix.apache.org" Content-Type: text/plain; charset=UTF-8 Hi Dumindu, Good questions. For future, best to post questions specific to your JIRA on the JIRA itself. All JIRA comments appear in the dev list as well. For the @BuiltInFunction annotation, you'd define your second type as PVarbinary, since the element being appended may be of any type. To get the actual type at runtime, you'd use the getChildren() method which returns a List. The children represent the arguments to your built-in function. In your case, getChildren().get(0) expression would represent the array, while the getChildren().get(1) expression would represent the element being appended. From the expression, you can call getDataType() to get the actual PDataType at runtime, and use the dataType.toBytes() method to get the bytes that represent the actual value which you can add to the array. Take a look at PArrayDataType for methods that manipulate the array. If possible, you'd want to keep the array as byte[], as converting back and forth to objects is expensive. You might need to add a new method to PArrayDataType that allows the byte[] of an element to be appended to the byte[] of the array. Note that you know the data types at compile time, so it's possible that you could create a different expression for the ArrayAppendFunction from a custom factory method. An example of this is with the RoundFunction - it has a nodeClass attribute in its annotation that delegate the creation to the indicated class. If you look at that class, you'll see that it ends up creating a RoundDateExpression, RoundTimestampExpression, or RoundDecimalExpression depending on the type of the argument. In this case, I don't think it's worth going this route, though. HTH. Thanks, James On Fri, Mar 6, 2015 at 5:16 PM, Dumindu Buddhika wrote: > Hi all, > > I am a GSOC aspirant this year from Department of Computer Science and > Engineering, University of Moratuwa, Sri Lanka. > > I would like to work on PHOENIX-1665, to create missing array built-in > functions. I am currently trying to implement ARRAY_APPEND function. I have > some questions associated with this. It would be great if someone can > answer. > PBinaryArray type would be first input of this function. Second would be a > primitive type element to be appended to the first given array. So I am > guessing it should be PDataType. > > The approach I thought was using PDataType's toObject method to construct > a PhoenixArray from given bytes(from ptr) and add the new element to it > then convert it back to bytes. > > When using this approach I have a problem how to convert the second input > argument(the element to be appended to the array) to corresponding object. > if the type of this is known of this input for sure it can be done( ex: if > its PInteger then PInteger.INSTANCE.getCodec().decodeInt can be used). But > here it can be any of the primitive types to my understanding. so how to > convert to the corresponding datatype object without exactly knowing the > type? > > It would be really great if someone can help me on this. if this approach > is wrong or if there is a better approach(directly manipulating bytes) I > would also like to know :) > > Thank you. > > Regards, > Dumindu.