generate_series


generate_series(const int|bigint start, const int|bigint end) – Generate a series of values, from start to end. A similar function to PostgreSQL’s [generate_serics](https://www.postgresql.org/docs/current/static/functions-srf.html)

SELECT generate_series(2,4);

2
3
4

SELECT generate_series(5,1,-2);

5
3
1

SELECT generate_series(4,3);

(no return)

SELECT date_add(current_date(),value),value from (SELECT generate_series(1,3)) t;

2018-04-21 1
2018-04-22 2
2018-04-23 3

WITH input as (
SELECT 1 as c1, 10 as c2, 3 as step
UNION ALL
SELECT 10, 2, -3
)
SELECT generate_series(c1, c2, step) as series
FROM input;

1
4
7
10
10
7
4

Platforms: WhereOS, Spark, Hive
Class: hivemall.tools.GenerateSeriesUDTF

More functions can be added to WhereOS via Python or R bindings or as Java & Scala UDF (user-defined function), UDAF (user-defined aggregation function) and UDTF (user-defined table generating function) extensions. Custom libraries can be added on via Settings-page or installed from WhereOS Store.

Leave a Reply