Thanks James. Thanks, Kathir
On Wed, May 6, 2015 at 2:37 PM, James Taylor <[email protected]> wrote: > +1 to Jaime's suggestion of providing multiple arguments. You can have > a variable number of arguments to a function by providing default > values for trailing arguments. I wouldn't rely on the Tuple argument > in the evaluate method as it might go away in the future > (PHOENIX-1887). > > Thanks, > James > > On Wed, May 6, 2015 at 6:14 AM, Kathiresan S > <[email protected]> wrote: > > Hi Jaime, > > > > In my case, the number of arguments passed to the custom function will be > > different in different scenarios. I think UDF is designed to take fixed > > number of arguments, i believe (also, I see number of arguments column in > > SYSTEM.FUNCTION table). > > > > Another question - As we have the row (tuple) at this point of the code > > (evaluate method) with all the values in it, why can't we pass the > > expression list to the evaluate method from > > PhoenixResultSet(RowProjector->columnProjectors), so we could access any > > column we want from the tuple? Am i missing something? > > > > Thanks, > > Kathir > > > > On Wed, May 6, 2015 at 8:43 AM, Jaime Solano <[email protected]> > wrote: > >> > >> Hi Kathir, > >> > >> I don't know if that's posible, but seems like the better approach is to > >> just define your function to take two arguments. > >> > >> What do you think? > >> > >> Best, > >> -Jaime > >> > >> On May 6, 2015 7:50 AM, "Kathiresan S" <[email protected]> > >> wrote: > >>> > >>> Hi, > >>> > >>> In UDF, in the implemented evaluate(tuple,ptr) method, i could access > the > >>> expression object of the columns passed to the UDF, by invoking > >>> getChildren.get(index). and then by invoking > expression.evaluate(tuple,ptr), > >>> i can get the value copied to the ptr object. But, how do i access > other > >>> elements of the tuple by passing its column name. I don't have access > to the > >>> expression object of other columns in the select query within the UDF > >>> implementation method. Please suggest what we should do to get the > value of > >>> other columns from the tuple by passing the column name. > >>> > >>> For eg. > >>> > >>> CREATE TABLE TESTTABLE (ID VARCHAR, NAME VARCHAR, PREFIX VARCHAR) > >>> > >>> CREATE FUNCTION MYFUNCTION(VARCHAR) RETURNS VARCHAR WITH 'com.test.CF' > >>> using jar '/tmp/cf.jar' > >>> > >>> SELECT ID,MYFUNCTION(NAME),PREFIX FROM TESTTABLE > >>> > >>> MYFUNCTION - is expected to concatenate PREFIX columns value and the > NAME > >>> columns value in each row. > >>> > >>> In the evaluate method, as i pass the NAME column as argument to the > >>> function, i get the expression object of it by invoking > >>> nameExpr=getChildren.get(0) and then by invoking > >>> nameExpr.evaluate(tuple,ptr) i can have the value copied to ptr. In > this > >>> case, is there a way to access the prefix columns value from the > tuple, as > >>> its also present in the SELECT clause. > >>> > >>> Thanks, > >>> Kathir > > > > >
