I use collect() function in flink sql, and the return type is multiset. However, common functions such as cardinality, char_length, multiset[item] all cannot use for multiset. How can I get the element in multiset?
I saw the Multiset type is bridging to JVM java.util.Map<t, java.lang.Integer>, so I try to write a udf to convert Multiset to String like this,
public String eval(Map<String, Integer> map){
StringBuffer result = new StringBuffer();
for(String key: map.keySet()){
result.append(key);
result.append(";");
}
if(result.length() > 0){
result.deleteCharAt(result.length()-1);
}
return result.toString();
}
However, I got error, Map<String, Integer> could not be used Multiset.
How can I modify this udf?
The support for multisets is limited at the moment. However, you can define you own user-defined functions to deal with them. Using a @DataTypeHint("MULTISET<X>")
can be used whereever a Map<X, Integer>
can be used.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments