简体   繁体   English

如何在 flink sql 中将多集数据类型转换为字符串?

[英]how to cast multiset datatype to string in flink sql?

when i was doing such query in flink sql:当我在 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?我如何将col4 (一种多集数据类型)转换为字符串?

i have tried cast(col4 as string) , but it didnt work.我试过cast(col4 as string) ,但没有用。 the exception is Cast function cannot convert value of type BIGINT MULTISET to type VARCHAR(2147483647)例外是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?或者如何将多集数据传递给 java udf 然后转换为字符串? how to write such udf?这样的udf怎么写?

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. UDF 可以接受所有类型。 Since the automatic reflection logic reserves the Map class for the MAP type.由于自动反射逻辑为 MAP 类型保留了Map类。 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();
  }
}

还有另一个悬而未决的问题上积极努力,这与打印的支持,但也铸造所有的结构类型为STRING做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM