getShape()
The getShape() method is called by the nzl program during the nzLua UDX compile step to determine the columns and data types that will be returned by the table function.
Unlike a UDF or UDA, a UDTF can return multiple columns. Here is a simple
example:
function getShape()
local shape = {}
shape[1] = { "x", integer }
shape[2] = { "y", integer }
shape[3] = { "z", varchar(255) }
return shape
end
In this example, the UDTF is defined to return three columns of data. Based on the
getShape() method show above, the processRow() method returns
three columns of data that match the format defined by the getShape() method. For
example, the processRow() method definition could could look like
this:function processRow(a,b,c)
return { a*10, b-10, "foobar" }
end
A special case for the
getShape() method is to allow the UDTF to determine the
output shape at runtime. When the getShape method returns the value VARSHAPE the
calculateShape() method is called at runtime to determine the output columns based
on the constant arguments that are used to invoke the
UDTF.function getShape()
return VARSHAPE
end