没有任何变化
在 2022-05-13 21:52:51,"renzhaojin" <renzhao...@100.me> 写道:
>hello,你加上设置时区试试呢
>Configuration configuration = tableEnvironment.getConfig().getConfiguration();
>
>configuration.setString("table.local-time-zone", "Asia/Shanghai");
>
>
>在 2022年5月13日 21:40,赢峰<si_ji_f...@163.com> 写道:
>
>
>DataStream 转换 Table 后事件时间怎么不对?是时区的问题吗?怎么解决? ``` DataStream<UserBehavior> 
>sourceStream = env.fromElements( new UserBehavior(1001L, 3827899L, 2920476L, 
>"pv", 1511713473000L, "2017-11-27 00:24:33"), new UserBehavior(1001L, 
>3745169L, 2891509L, "pv", 1511725471000L, "2017-11-27 03:44:31"), new 
>UserBehavior(1001L, 1531036L, 2920476L, "pv", 1511733732000L, "2017-11-27 
>06:02:12"), new UserBehavior(1001L, 2266567L, 4145813L, "pv", 1511741471000L, 
>"2017-11-27 08:11:11"), new UserBehavior(1001L, 2951368L, 1080785L, "pv", 
>1511750828000L, "2017-11-27 10:47:08"), new UserBehavior(1002L, 5002615L, 
>2520377L, "pv", 1511752985000L, "2017-11-27 11:23:05") ); // 提取时间戳并分配 
>Watermark DataStream<UserBehavior> behaviorStream = 
>sourceStream.assignTimestampsAndWatermarks( 
>WatermarkStrategy.<UserBehavior>forBoundedOutOfOrderness(Duration.ofMinutes(1))
> .withTimestampAssigner(new SerializableTimestampAssigner<UserBehavior>() { 
>@Override public long extractTimestamp(UserBehavior behavior, long 
>recordTimestamp) { return behavior.getTs(); } }) ); // 注册虚拟表 Table 
>behaviorTable = tEnv.fromDataStream(behaviorStream, $("uid"), $("ts"), 
>$("ts_row").rowtime()); tEnv.createTemporaryView("user_behavior", 
>behaviorTable); Table resultTable = tEnv.sqlQuery("SELECT uid, ts, ts_row FROM 
>user_behavior"); DataStream<Row> resultStream = 
>tEnv.toAppendStream(resultTable, Row.class); resultStream.print(); ``` 输出结果: 
>``` 3> +I[1001, 1511725471000, 2017-11-26T19:44:31] 4> +I[1001, 1511733732000, 
>2017-11-26T22:02:12] 3> +I[1002, 1511752985000, 2017-11-27T03:23:05] 2> 
>+I[1001, 1511713473000, 2017-11-26T16:24:33] 2> +I[1001, 1511750828000, 
>2017-11-27T02:47:08] 1> +I[1001, 1511741471000, 2017-11-27T00:11:11] ``` 
>1511725471000 -> 2017-11-27 03:44:31 目测是时区的问题

回复