Python language simple table function
This example uses the following file name: timeSplitMany.py
Code
The code in this example creates a table function that takes a variable number of string
representations of time which is separated by commas (for example "12:30:55,4:20:18”). The function
outputs one row for each time-representation. Each row displays the time, split into its component
parts. Note that you must take control of the I/O for the AE in the
def _runUdtf()
function.import nzae
class TimeSplitManyAe(nzae.Ae):
def _runUdtf(self):
for row in self:
for timeString in row[0].split(","):
self.output(timeString.split(":"))
TimeSplitManyAe.run()
Deployment
Deploy the script:
$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language python64 \
--template deploy ./timeSplitMany.py --version 3Registration
Register the table function
AE:
$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language python64 --version 3 \
--template udtf --exe timeSplitMany.py \
--sig "time_split_many(varchar(1000))" \
--return "table(hour varchar(2), minute varchar(2), second varchar(2))"Running
Run the query in
nzsql:
SELECT * FROM TABLE WITH FINAL (time_split_many('13:22:47,22:12:45,03:22:09'));
HOUR | MINUTE | SECOND
------+--------+--------
13 | 22 | 47
22 | 12 | 45
03 | 22 | 09
(3 rows)