Reputation: 19
when i was doing such query in flink sql:
SELECT COLLECT(col1) OVER (
PARTITION BY col2
ORDER BY col3
ROWS BETWEEN 1 PRECEDING AND CURRENT ROW
) AS col4
FROM table
how can i cast the col4
, which is a multiset datatype, to string?
i have tried cast(col4 as string)
, but it didnt work. the exception is Cast function cannot convert value of type BIGINT MULTISET to type VARCHAR(2147483647)
OR how can i pass the multiset data to a java udf and then trasform to a string? how to write such udf?
Upvotes: 1
Views: 2106
Reputation: 1
There is also another open issue actively worked on, which has to do with supporting of printing but also casting all the structured types to STRING
Upvotes: 0
Reputation: 2664
Currently, casting of multisets is limited. The community is currently working on improving this.
Until then, I would recommend to use a scalar function. UDFs can accept all types. Since the automatic reflection logic reserves the Map
class for the MAP type. You have to add a type hint.
public class MultisetToString extends ScalarFunction {
public String eval(@DataTypeHint("MULTISET<STRING>") Map<String, Integer> multiset) {
return multiset.toString();
}
}
Upvotes: 3