Pregunta

Is it possible to pass a Python UDF a scalar argument as follows:

A = LOAD 'date_list' AS (date:chararray); --Example date: 20130131
B = FOREACH A GENERATE DATE_LIB.get_week('YYYYMMDD', date)

I'd like to be able to give a scalar argument that specifies the format of the date (for example, 'DD-MON-YY' for a date like '31-JAN-13'—I could reuse the same code for the UDF I have in DATE_LIB handling that case with control flow). How would I do this in Python? Since Python UDFs can only ever be EvalFuncs, do they have this ability?

¿Fue útil?

Solución

It is possible - if you'd look at the example scripts you'd see

@outputSchemaFunction("squareSchema")
def square(num):
  return ((num)*(num))

and the calling example

b = foreach a generate myfuncs.square(3);

in your case the udf would be something like

@outputSchemaFunction("dow:long")
def get_week(format,source_date):
    your code here
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top