subarray


subarray(array values, int offset [, int length]) – Slices the given array by the given offset and length parameters.

SELECT
array_slice(array(1,2,3,4,5,6),2,4),
array_slice(
array(“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”),
0, — offset
2 — length
),
array_slice(
array(“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”),
6, — offset
3 — length
),
array_slice(
array(“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”),
6, — offset
10 — length
),
array_slice(
array(“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”),
6 — offset
),
array_slice(
array(“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”),
-3 — offset
),
array_slice(
array(“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”),
-3, — offset
2 — length
);

[3,4]
[“zero”,”one”]
[“six”,”seven”,”eight”]
[“six”,”seven”,”eight”,”nine”,”ten”]
[“six”,”seven”,”eight”,”nine”,”ten”]
[“eight”,”nine”,”ten”]
[“eight”,”nine”]

Platforms: WhereOS, Spark, Hive
Class: hivemall.tools.array.ArraySliceUDF

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