getShape()
The getShape() method is called when the UDX is compiled to determine the column names and data types that will be returned by the table function.
Unlike a UDSF or a 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. A processRow() method in the UDTF returns three columns of data that match the format defined by the getShape() method. For example, the processRow() method definition might 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 name and type of each output column based on arguments that are specified when the UDTF is invoked.
function getShape()
return VARSHAPE
end