我创建了一个包含数据类型字段的flink表,报错类型不匹配。想知道如何在flink表中创建一个包含数组类型的临时表。
public class FlinkConnectorClickhouse {
public static void main(String[] args) throws Exception {
// create environments of both APIs
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
// create a DataStream
DataStream<Order> dataStream = env.fromCollection(Arrays.asList(
new Order(2L, "pen", 1, Arrays.asList("name01", "name02", "name03"), Arrays.asList(1, 2, 3)));
Table inputTable = tableEnv.fromDataStream(dataStreamMap, $("user").as("user_a"), $("product"), $("amount"), $("name_list"), $("id_list"));
// register the Table object as a view and query it
tableEnv.createTemporaryView("InputTable", inputTable);
tableEnv.executeSql("CREATE TABLE sink_table (\n" +
" `user_a` BIGINT,\n" +
" `product` VARCHAR,\n" +
" `amount` BIGINT,\n" +
" `name_list` ARRAY<STRING>,\n" +
" `id_list` ARRAY<INT>,\n" +
" PRIMARY KEY (user_a) NOT ENFORCED /* 如果指定 pk,进入 upsert 模式 */\n" +
") WITH (\n" +
")");
TableResult resultTable = tableEnv.executeSql("INSERT INTO sink_table SELECT user_a, product, amount,name_list,id_list FROM InputTable");
env.execute();
}
public static class Order {
private Long user;
private String product;
private Integer amount;
private List<String> name_list;
private List<Integer> id_list;
}