------------------ 原始邮件 ------------------
发件人: "奇怪的不朽琴师" <[hidden email]>; 发送时间: 2020年7月9日(星期四) 下午5:08 收件人: "godfrey he"<[hidden email]>; 主题: pyflink1.11.0window 你好: 我在使用pyflink1.11版本时,window开窗仍会报错 : org.apache.flink.table.api.ValidationException: A group window expects a time attribute for grouping in a stream environment. 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? 代码如下 谢谢 def from_kafka_to_kafka_demo(): s_env = StreamExecutionEnvironment.get_execution_environment() s_env.set_parallelism(1) # use blink table planner st_env = StreamTableEnvironment.create(s_env) # register source and sink register_rides_source(st_env) register_rides_sink(st_env) st_env.from_path("source1")\ .window(Tumble.over("1.secends").on("time1").alias("w")) \ .group_by("w") \ .select(" id, time1 , time1 ")\ .insert_into("sink1") st_env.execute("2-from_kafka_to_kafka") def register_rides_source(st_env): source_ddl = \ ''' create table source1( id int, time1 timestamp, type string ) with ( 'connector.type' = 'kafka', 'update-mode' = 'append', 'connector.topic' = 'tp1', 'connector.properties.bootstrap.servers' = 'localhost:9092' ) ''' st_env.sql_update(source_ddl) def register_rides_sink(st_env): sink_ddl = \ ''' create table sink1( id int, time1 timestamp, time2 timestamp ) with ( 'connector.type' = 'kafka', 'update-mode' = 'append', 'connector.topic' = 'tp3', 'connector.properties.bootstrap.servers' = 'localhost:9092' ) ''' st_env.sql_update(sink_ddl) if __name__ == '__main__': from_kafka_to_kafka_demo() |
琴师你好,
你的source ddl里有指定time1为 time attribute吗? create table source1( id int, time1 timestamp, type string, WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND ) with (...) 奇怪的不朽琴师 <[hidden email]> 于2020年7月10日周五 上午8:43写道: > ------------------ 原始邮件 ------------------ > 发件人: > "奇怪的不朽琴师" > < > [hidden email]>; > 发送时间: 2020年7月9日(星期四) 下午5:08 > 收件人: "godfrey he"<[hidden email]>; > > 主题: pyflink1.11.0window > > > > 你好: > 我在使用pyflink1.11版本时,window开窗仍会报错 > : org.apache.flink.table.api.ValidationException: A group window expects a > time attribute for grouping in a stream environment. > > 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > 代码如下 > 谢谢 > > > def from_kafka_to_kafka_demo(): > s_env = > StreamExecutionEnvironment.get_execution_environment() > s_env.set_parallelism(1) > > > # use blink table planner > st_env = StreamTableEnvironment.create(s_env) > > > # register source and sink > register_rides_source(st_env) > register_rides_sink(st_env) > > > st_env.from_path("source1")\ > > .window(Tumble.over("1.secends").on("time1").alias("w")) \ > .group_by("w") \ > .select(" id, time1 , time1 ")\ > .insert_into("sink1") > > st_env.execute("2-from_kafka_to_kafka") > > > > > def register_rides_source(st_env): > source_ddl = \ > ''' > create table source1( > id int, > time1 timestamp, > type string > ) with ( > 'connector.type' = 'kafka', > 'update-mode' = 'append', > 'connector.topic' = 'tp1', > 'connector.properties.bootstrap.servers' = 'localhost:9092' > ) > ''' > st_env.sql_update(source_ddl) > > > > > def register_rides_sink(st_env): > sink_ddl = \ > ''' > create table sink1( > id int, > time1 timestamp, > time2 timestamp > ) with ( > 'connector.type' = 'kafka', > 'update-mode' = 'append', > 'connector.topic' = 'tp3', > 'connector.properties.bootstrap.servers' = 'localhost:9092' > ) > ''' > st_env.sql_update(sink_ddl) > > > > > if __name__ == '__main__': > from_kafka_to_kafka_demo() > > > |
你好:
我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 Traceback (most recent call last): File "tou.py", line 71, in <module> from_kafka_to_kafka_demo() File "tou.py", line 21, in from_kafka_to_kafka_demo .select(" id, time1 , time1 ")\ File "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line 907, in select return Table(self._j_table.select(fields), self._t_env) File "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", line 1286, in __call__ answer, self.gateway_client, self.target_id, self.name) File "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line 147, in deco return f(*a, **kw) File "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", line 328, in get_return_value format(target_id, ".", name), value) py4j.protocol.Py4JJavaError: An error occurred while calling o26.select. : org.apache.flink.table.api.ValidationException: A tumble window expects a size value literal. at org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) at org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) at org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) at org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) at org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) at org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) at org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) at org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) at org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) at org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) at org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) at java.lang.Thread.run(Thread.java:748) def register_rides_source(st_env): source_ddl = \ """ create table source1( id int, time1 timestamp, type string, WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND ) with ( 'connector.type' = 'kafka', 'update-mode' = 'append', 'connector.topic' = 'tp1', 'connector.properties.bootstrap.servers' = 'localhost:9092', 'connector.properties.zookeeper.connect' = 'localhost:2181', 'format.type' = 'json', 'format.derive-schema' = 'true', 'connector.version' = 'universal' ) """ st_env.sql_update(source_ddl) s_env = StreamExecutionEnvironment.get_execution_environment() s_env.set_parallelism(1) st_env = StreamTableEnvironment.create(s_env) register_rides_source(st_env) register_rides_sink(st_env) st_env.from_path("source1")\ .window(Tumble.over("2.secends").on("time1").alias("w")) \ .group_by("w") \ .select(" id, time1 , time1 ")\ .insert_into("sink1") st_env.execute("2-from_kafka_to_kafka") 代码如上 ------------------ 原始邮件 ------------------ 发件人: "user-zh" <[hidden email]>; 发送时间: 2020年7月10日(星期五) 上午9:17 收件人: "user-zh"<[hidden email]>; 主题: Re: pyflink1.11.0window 琴师你好, 你的source ddl里有指定time1为 time attribute吗? create table source1( id int, time1 timestamp, type string, WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND ) with (...) 奇怪的不朽琴师 <[hidden email]> 于2020年7月10日周五 上午8:43写道: > ------------------&nbsp;原始邮件&nbsp;------------------ > 发件人: > "奇怪的不朽琴师" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月9日(星期四) 下午5:08 > 收件人:&nbsp;"godfrey he"<[hidden email]&gt;; > > 主题:&nbsp;pyflink1.11.0window > > > > 你好: > &nbsp; &nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > : org.apache.flink.table.api.ValidationException: A group window expects a > time attribute for grouping in a stream environment. > > 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > 代码如下 > 谢谢 > > > def from_kafka_to_kafka_demo(): > &nbsp; &nbsp; s_env = > StreamExecutionEnvironment.get_execution_environment() > &nbsp; &nbsp; s_env.set_parallelism(1) > > > &nbsp; &nbsp; # use blink table planner > &nbsp; &nbsp; st_env = StreamTableEnvironment.create(s_env) > > > &nbsp; &nbsp; # register source and sink > &nbsp; &nbsp; register_rides_source(st_env) > &nbsp; &nbsp; register_rides_sink(st_env) > > > &nbsp; &nbsp; st_env.from_path("source1")\ > &nbsp; &nbsp; &nbsp; &nbsp; > .window(Tumble.over("1.secends").on("time1").alias("w")) \ > &nbsp; &nbsp; &nbsp; &nbsp; .group_by("w") \ > &nbsp; &nbsp; &nbsp; &nbsp; .select(" id,&nbsp; time1 , time1 ")\ > &nbsp; &nbsp; &nbsp; &nbsp; .insert_into("sink1") > &nbsp; &nbsp; > &nbsp; &nbsp; st_env.execute("2-from_kafka_to_kafka") > > > > > def register_rides_source(st_env): > &nbsp; &nbsp; source_ddl = \ > &nbsp; &nbsp; ''' > &nbsp; &nbsp; create table source1( > &nbsp; &nbsp; &nbsp; &nbsp; id int, > &nbsp; &nbsp; &nbsp;time1 timestamp, > &nbsp; &nbsp; &nbsp;type string > &nbsp; &nbsp; &nbsp;) with ( > &nbsp; &nbsp; 'connector.type' = 'kafka', > &nbsp; &nbsp; 'update-mode' = 'append', > &nbsp; &nbsp; 'connector.topic' = 'tp1', > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = 'localhost:9092' > &nbsp; &nbsp; &nbsp;) > &nbsp; &nbsp; ''' > &nbsp; &nbsp; st_env.sql_update(source_ddl) > > > > > def register_rides_sink(st_env): > &nbsp; &nbsp; sink_ddl = \ > &nbsp; &nbsp; ''' > &nbsp; &nbsp; create table sink1( > &nbsp; &nbsp; &nbsp; &nbsp; id int, > &nbsp; &nbsp; &nbsp;time1 timestamp, > &nbsp; &nbsp; &nbsp;time2 timestamp > &nbsp; &nbsp; &nbsp;) with ( > &nbsp; &nbsp; 'connector.type' = 'kafka', > &nbsp; &nbsp; 'update-mode' = 'append', > &nbsp; &nbsp; 'connector.topic' = 'tp3', > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = 'localhost:9092' > &nbsp; &nbsp; &nbsp;) > &nbsp; &nbsp; ''' > &nbsp; &nbsp; st_env.sql_update(sink_ddl) > > > > > if __name__ == '__main__': > &nbsp; &nbsp; from_kafka_to_kafka_demo() > > > &nbsp; &nbsp; |
琴师你好,
异常栈信息org.apache.flink.table.api.ValidationException: A tumble window expects a size value literal. 看起来是接下tumble window定义的代码不太正确吧 Best, Shuiqiang 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 上午10:27写道: > 你好: > > 我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > Traceback (most recent call last): > File "tou.py", line 71, in <module> > from_kafka_to_kafka_demo() > File "tou.py", line 21, in from_kafka_to_kafka_demo > .select(" id, time1 , time1 ")\ > File > "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line 907, > in select > return Table(self._j_table.select(fields), self._t_env) > File "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > line 1286, in __call__ > answer, self.gateway_client, self.target_id, self.name) > File > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line > 147, in deco > return f(*a, **kw) > File "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > line 328, in get_return_value > format(target_id, ".", name), value) > py4j.protocol.Py4JJavaError: An error occurred while calling o26.select. > : org.apache.flink.table.api.ValidationException: A tumble window expects > a size value literal. > at > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > at > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > at > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > at > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > at > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > at > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > at > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at > java.lang.reflect.Method.invoke(Method.java:498) > at > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > at > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > at > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > at > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > at > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > at > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > at java.lang.Thread.run(Thread.java:748) > > > > > > > > > > > > > > > > > > > > > > > > def register_rides_source(st_env): > source_ddl = \ > """ > create table source1( > id int, > time1 timestamp, > type string, > WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND > ) with ( > 'connector.type' = 'kafka', > 'update-mode' = 'append', > 'connector.topic' = 'tp1', > 'connector.properties.bootstrap.servers' = 'localhost:9092', > 'connector.properties.zookeeper.connect' = 'localhost:2181', > 'format.type' = 'json', > 'format.derive-schema' = 'true', > 'connector.version' = 'universal' > ) > """ > st_env.sql_update(source_ddl) > > > s_env = > StreamExecutionEnvironment.get_execution_environment() > s_env.set_parallelism(1) > > > st_env = StreamTableEnvironment.create(s_env) > > > register_rides_source(st_env) > register_rides_sink(st_env) > > > st_env.from_path("source1")\ > > .window(Tumble.over("2.secends").on("time1").alias("w")) \ > .group_by("w") \ > .select(" id, time1 , time1 ")\ > .insert_into("sink1") > > st_env.execute("2-from_kafka_to_kafka") > > > 代码如上 > > > > > > > > > ------------------ 原始邮件 ------------------ > 发件人: > "user-zh" > < > [hidden email]>; > 发送时间: 2020年7月10日(星期五) 上午9:17 > 收件人: "user-zh"<[hidden email]>; > > 主题: Re: pyflink1.11.0window > > > > 琴师你好, > > 你的source ddl里有指定time1为 time attribute吗? > create table source1( > id int, > time1 timestamp, > type string, > WATERMARK FOR time1 as time1 - > INTERVAL '2' SECOND > ) with (...) > > 奇怪的不朽琴师 <[hidden email]> 于2020年7月10日周五 上午8:43写道: > > > ------------------&nbsp;原始邮件&nbsp;------------------ > > 发件人: > > > "奇怪的不朽琴师" > > > < > > [hidden email]&gt;; > > 发送时间:&nbsp;2020年7月9日(星期四) 下午5:08 > > 收件人:&nbsp;"godfrey he"<[hidden email]&gt;; > > > > 主题:&nbsp;pyflink1.11.0window > > > > > > > > 你好: > > &nbsp; &nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > > : org.apache.flink.table.api.ValidationException: A group window > expects a > > time attribute for grouping in a stream environment. > > > > 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > > 代码如下 > > 谢谢 > > > > > > def from_kafka_to_kafka_demo(): > > &nbsp; &nbsp; s_env = > > StreamExecutionEnvironment.get_execution_environment() > > &nbsp; &nbsp; s_env.set_parallelism(1) > > > > > > &nbsp; &nbsp; # use blink table planner > > &nbsp; &nbsp; st_env = StreamTableEnvironment.create(s_env) > > > > > > &nbsp; &nbsp; # register source and sink > > &nbsp; &nbsp; register_rides_source(st_env) > > &nbsp; &nbsp; register_rides_sink(st_env) > > > > > > &nbsp; &nbsp; st_env.from_path("source1")\ > > &nbsp; &nbsp; &nbsp; &nbsp; > > .window(Tumble.over("1.secends").on("time1").alias("w")) \ > > &nbsp; &nbsp; &nbsp; &nbsp; .group_by("w") \ > > &nbsp; &nbsp; &nbsp; &nbsp; .select(" id,&nbsp; > time1 , time1 ")\ > > &nbsp; &nbsp; &nbsp; &nbsp; .insert_into("sink1") > > &nbsp; &nbsp; > > &nbsp; &nbsp; st_env.execute("2-from_kafka_to_kafka") > > > > > > > > > > def register_rides_source(st_env): > > &nbsp; &nbsp; source_ddl = \ > > &nbsp; &nbsp; ''' > > &nbsp; &nbsp; create table source1( > > &nbsp; &nbsp; &nbsp; &nbsp; id int, > > &nbsp; &nbsp; &nbsp;time1 timestamp, > > &nbsp; &nbsp; &nbsp;type string > > &nbsp; &nbsp; &nbsp;) with ( > > &nbsp; &nbsp; 'connector.type' = 'kafka', > > &nbsp; &nbsp; 'update-mode' = 'append', > > &nbsp; &nbsp; 'connector.topic' = 'tp1', > > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = > 'localhost:9092' > > &nbsp; &nbsp; &nbsp;) > > &nbsp; &nbsp; ''' > > &nbsp; &nbsp; st_env.sql_update(source_ddl) > > > > > > > > > > def register_rides_sink(st_env): > > &nbsp; &nbsp; sink_ddl = \ > > &nbsp; &nbsp; ''' > > &nbsp; &nbsp; create table sink1( > > &nbsp; &nbsp; &nbsp; &nbsp; id int, > > &nbsp; &nbsp; &nbsp;time1 timestamp, > > &nbsp; &nbsp; &nbsp;time2 timestamp > > &nbsp; &nbsp; &nbsp;) with ( > > &nbsp; &nbsp; 'connector.type' = 'kafka', > > &nbsp; &nbsp; 'update-mode' = 'append', > > &nbsp; &nbsp; 'connector.topic' = 'tp3', > > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = > 'localhost:9092' > > &nbsp; &nbsp; &nbsp;) > > &nbsp; &nbsp; ''' > > &nbsp; &nbsp; st_env.sql_update(sink_ddl) > > > > > > > > > > if __name__ == '__main__': > > &nbsp; &nbsp; from_kafka_to_kafka_demo() > > > > > > &nbsp; &nbsp; |
Shuiqiang,你好:
我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? ------------------ 原始邮件 ------------------ 发件人: "user-zh" <[hidden email]>; 发送时间: 2020年7月15日(星期三) 上午10:51 收件人: "user-zh"<[hidden email]>; 主题: Re: pyflink1.11.0window 琴师你好, 异常栈信息org.apache.flink.table.api.ValidationException: A tumble window expects a size value literal. 看起来是接下tumble window定义的代码不太正确吧 Best, Shuiqiang 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 上午10:27写道: > 你好: > &nbsp; &nbsp; > &nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > Traceback (most recent call last): > &nbsp; File "tou.py", line 71, in <module&gt; > &nbsp; &nbsp; from_kafka_to_kafka_demo() > &nbsp; File "tou.py", line 21, in from_kafka_to_kafka_demo > &nbsp; &nbsp; .select(" id,&nbsp; time1 , time1 ")\ > &nbsp; File > "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line 907, > in select > &nbsp; &nbsp; return Table(self._j_table.select(fields), self._t_env) > &nbsp; File "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > line 1286, in __call__ > &nbsp; &nbsp; answer, self.gateway_client, self.target_id, self.name) > &nbsp; File > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line > 147, in deco > &nbsp; &nbsp; return f(*a, **kw) > &nbsp; File "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > line 328, in get_return_value > &nbsp; &nbsp; format(target_id, ".", name), value) > py4j.protocol.Py4JJavaError: An error occurred while calling o26.select. > : org.apache.flink.table.api.ValidationException: A tumble window expects > a size value literal. > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > &nbsp; &nbsp; &nbsp; &nbsp; at > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > &nbsp; &nbsp; &nbsp; &nbsp; at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > &nbsp; &nbsp; &nbsp; &nbsp; at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > &nbsp; &nbsp; &nbsp; &nbsp; at > java.lang.reflect.Method.invoke(Method.java:498) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > &nbsp; &nbsp; &nbsp; &nbsp; at java.lang.Thread.run(Thread.java:748) > > > > > > > > > > > > > > > > > > > > > > > > def register_rides_source(st_env): > &nbsp; &nbsp; source_ddl = \ > &nbsp; &nbsp; """ > &nbsp; &nbsp; create table source1( > &nbsp; &nbsp; &nbsp;id int, > &nbsp; &nbsp; &nbsp;time1 timestamp, > &nbsp; &nbsp; &nbsp;type string, > &nbsp; &nbsp; &nbsp;WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND > &nbsp; &nbsp; &nbsp;) with ( > &nbsp; &nbsp; 'connector.type' = 'kafka', > &nbsp; &nbsp; 'update-mode' = 'append', > &nbsp; &nbsp; 'connector.topic' = 'tp1', > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = 'localhost:9092', > &nbsp; &nbsp; 'connector.properties.zookeeper.connect' = 'localhost:2181', > &nbsp; &nbsp; 'format.type' = 'json', > &nbsp; &nbsp; 'format.derive-schema' = 'true', > &nbsp; &nbsp; 'connector.version' = 'universal' > &nbsp; &nbsp; &nbsp;) > &nbsp; &nbsp; """ > &nbsp; &nbsp; st_env.sql_update(source_ddl) > > &nbsp; &nbsp;&nbsp; > &nbsp; &nbsp; s_env = > StreamExecutionEnvironment.get_execution_environment() > &nbsp; &nbsp; s_env.set_parallelism(1) > > > &nbsp; &nbsp; st_env = StreamTableEnvironment.create(s_env) > > > &nbsp; &nbsp; register_rides_source(st_env) > &nbsp; &nbsp; register_rides_sink(st_env) > > > &nbsp; &nbsp; st_env.from_path("source1")\ > &nbsp; &nbsp; &nbsp; &nbsp; > .window(Tumble.over("2.secends").on("time1").alias("w")) \ > &nbsp; &nbsp; &nbsp; &nbsp; .group_by("w") \ > &nbsp; &nbsp; &nbsp; &nbsp; .select(" id,&nbsp; time1 , time1 ")\ > &nbsp; &nbsp; &nbsp; &nbsp; .insert_into("sink1") > &nbsp; &nbsp;&nbsp; > &nbsp; &nbsp; st_env.execute("2-from_kafka_to_kafka") > > > 代码如上 > > > > > > > > > ------------------&nbsp;原始邮件&nbsp;------------------ > 发件人: > "user-zh" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月10日(星期五) 上午9:17 > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > 主题:&nbsp;Re: pyflink1.11.0window > > > > 琴师你好, > > 你的source ddl里有指定time1为 time attribute吗? > create table source1( > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id int, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; time1 timestamp, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type string, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WATERMARK FOR time1 as time1 - > INTERVAL '2' SECOND > ) with (...) > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月10日周五 上午8:43写道: > > &gt; ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > &gt; 发件人: > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > "奇怪的不朽琴师" > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > < > &gt; [hidden email]&amp;gt;; > &gt; 发送时间:&amp;nbsp;2020年7月9日(星期四) 下午5:08 > &gt; 收件人:&amp;nbsp;"godfrey he"<[hidden email]&amp;gt;; > &gt; > &gt; 主题:&amp;nbsp;pyflink1.11.0window > &gt; > &gt; > &gt; > &gt; 你好: > &gt; &amp;nbsp; &amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > &gt; : org.apache.flink.table.api.ValidationException: A group window > expects a > &gt; time attribute for grouping in a stream environment. > &gt; > &gt; 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > &gt; 代码如下 > &gt; 谢谢 > &gt; > &gt; > &gt; def from_kafka_to_kafka_demo(): > &gt; &amp;nbsp; &amp;nbsp; s_env = > &gt; StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;nbsp; &amp;nbsp; s_env.set_parallelism(1) > &gt; > &gt; > &gt; &amp;nbsp; &amp;nbsp; # use blink table planner > &gt; &amp;nbsp; &amp;nbsp; st_env = StreamTableEnvironment.create(s_env) > &gt; > &gt; > &gt; &amp;nbsp; &amp;nbsp; # register source and sink > &gt; &amp;nbsp; &amp;nbsp; register_rides_source(st_env) > &gt; &amp;nbsp; &amp;nbsp; register_rides_sink(st_env) > &gt; > &gt; > &gt; &amp;nbsp; &amp;nbsp; st_env.from_path("source1")\ > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > &gt; .window(Tumble.over("1.secends").on("time1").alias("w")) \ > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .group_by("w") \ > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .select(" id,&amp;nbsp; > time1 , time1 ")\ > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .insert_into("sink1") > &gt; &amp;nbsp; &amp;nbsp; > &gt; &amp;nbsp; &amp;nbsp; st_env.execute("2-from_kafka_to_kafka") > &gt; > &gt; > &gt; > &gt; > &gt; def register_rides_source(st_env): > &gt; &amp;nbsp; &amp;nbsp; source_ddl = \ > &gt; &amp;nbsp; &amp;nbsp; ''' > &gt; &amp;nbsp; &amp;nbsp; create table source1( > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; id int, > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;time1 timestamp, > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;type string > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) with ( > &gt; &amp;nbsp; &amp;nbsp; 'connector.type' = 'kafka', > &gt; &amp;nbsp; &amp;nbsp; 'update-mode' = 'append', > &gt; &amp;nbsp; &amp;nbsp; 'connector.topic' = 'tp1', > &gt; &amp;nbsp; &amp;nbsp; 'connector.properties.bootstrap.servers' = > 'localhost:9092' > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) > &gt; &amp;nbsp; &amp;nbsp; ''' > &gt; &amp;nbsp; &amp;nbsp; st_env.sql_update(source_ddl) > &gt; > &gt; > &gt; > &gt; > &gt; def register_rides_sink(st_env): > &gt; &amp;nbsp; &amp;nbsp; sink_ddl = \ > &gt; &amp;nbsp; &amp;nbsp; ''' > &gt; &amp;nbsp; &amp;nbsp; create table sink1( > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; id int, > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;time1 timestamp, > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;time2 timestamp > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) with ( > &gt; &amp;nbsp; &amp;nbsp; 'connector.type' = 'kafka', > &gt; &amp;nbsp; &amp;nbsp; 'update-mode' = 'append', > &gt; &amp;nbsp; &amp;nbsp; 'connector.topic' = 'tp3', > &gt; &amp;nbsp; &amp;nbsp; 'connector.properties.bootstrap.servers' = > 'localhost:9092' > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) > &gt; &amp;nbsp; &amp;nbsp; ''' > &gt; &amp;nbsp; &amp;nbsp; st_env.sql_update(sink_ddl) > &gt; > &gt; > &gt; > &gt; > &gt; if __name__ == '__main__': > &gt; &amp;nbsp; &amp;nbsp; from_kafka_to_kafka_demo() > &gt; > &gt; > &gt; &amp;nbsp; &amp;nbsp; |
举个sql例子
select platformcodetoname(payPlatform) as platform, sum(payAmount) as pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as rowtime from payment_msg group by tumble(rt, interval '5' seconds), payPlatform 这个query 对每5s的tumble窗口做统计。 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 上午11:10写道: > Shuiqiang,你好: > 我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? > > > ------------------ 原始邮件 ------------------ > 发件人: > "user-zh" > < > [hidden email]>; > 发送时间: 2020年7月15日(星期三) 上午10:51 > 收件人: "user-zh"<[hidden email]>; > > 主题: Re: pyflink1.11.0window > > > > 琴师你好, > 异常栈信息org.apache.flink.table.api.ValidationException: A tumble window > expects a size value literal. > 看起来是接下tumble window定义的代码不太正确吧 > > Best, > Shuiqiang > > 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 上午10:27写道: > > > 你好: > > &nbsp; &nbsp; > > > &nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > > Traceback (most recent call last): > > &nbsp; File "tou.py", line 71, in <module&gt; > > &nbsp; &nbsp; from_kafka_to_kafka_demo() > > &nbsp; File "tou.py", line 21, in from_kafka_to_kafka_demo > > &nbsp; &nbsp; .select(" id,&nbsp; time1 , time1 ")\ > > &nbsp; File > > "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line > 907, > > in select > > &nbsp; &nbsp; return Table(self._j_table.select(fields), > self._t_env) > > &nbsp; File > "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > > line 1286, in __call__ > > &nbsp; &nbsp; answer, self.gateway_client, self.target_id, > self.name) > > &nbsp; File > > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", > line > > 147, in deco > > &nbsp; &nbsp; return f(*a, **kw) > > &nbsp; File > "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > > line 328, in get_return_value > > &nbsp; &nbsp; format(target_id, ".", name), value) > > py4j.protocol.Py4JJavaError: An error occurred while calling > o26.select. > > : org.apache.flink.table.api.ValidationException: A tumble window > expects > > a size value literal. > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > java.lang.reflect.Method.invoke(Method.java:498) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > > &nbsp; &nbsp; &nbsp; &nbsp; at > > > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > > &nbsp; &nbsp; &nbsp; &nbsp; at > java.lang.Thread.run(Thread.java:748) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > def register_rides_source(st_env): > > &nbsp; &nbsp; source_ddl = \ > > &nbsp; &nbsp; """ > > &nbsp; &nbsp; create table source1( > > &nbsp; &nbsp; &nbsp;id int, > > &nbsp; &nbsp; &nbsp;time1 timestamp, > > &nbsp; &nbsp; &nbsp;type string, > > &nbsp; &nbsp; &nbsp;WATERMARK FOR time1 as time1 - > INTERVAL '2' SECOND > > &nbsp; &nbsp; &nbsp;) with ( > > &nbsp; &nbsp; 'connector.type' = 'kafka', > > &nbsp; &nbsp; 'update-mode' = 'append', > > &nbsp; &nbsp; 'connector.topic' = 'tp1', > > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = > 'localhost:9092', > > &nbsp; &nbsp; 'connector.properties.zookeeper.connect' = > 'localhost:2181', > > &nbsp; &nbsp; 'format.type' = 'json', > > &nbsp; &nbsp; 'format.derive-schema' = 'true', > > &nbsp; &nbsp; 'connector.version' = 'universal' > > &nbsp; &nbsp; &nbsp;) > > &nbsp; &nbsp; """ > > &nbsp; &nbsp; st_env.sql_update(source_ddl) > > > > &nbsp; &nbsp;&nbsp; > > &nbsp; &nbsp; s_env = > > StreamExecutionEnvironment.get_execution_environment() > > &nbsp; &nbsp; s_env.set_parallelism(1) > > > > > > &nbsp; &nbsp; st_env = StreamTableEnvironment.create(s_env) > > > > > > &nbsp; &nbsp; register_rides_source(st_env) > > &nbsp; &nbsp; register_rides_sink(st_env) > > > > > > &nbsp; &nbsp; st_env.from_path("source1")\ > > &nbsp; &nbsp; &nbsp; &nbsp; > > .window(Tumble.over("2.secends").on("time1").alias("w")) \ > > &nbsp; &nbsp; &nbsp; &nbsp; .group_by("w") \ > > &nbsp; &nbsp; &nbsp; &nbsp; .select(" id,&nbsp; > time1 , time1 ")\ > > &nbsp; &nbsp; &nbsp; &nbsp; .insert_into("sink1") > > &nbsp; &nbsp;&nbsp; > > &nbsp; &nbsp; st_env.execute("2-from_kafka_to_kafka") > > > > > > 代码如上 > > > > > > > > > > > > > > > > > > ------------------&nbsp;原始邮件&nbsp;------------------ > > 发件人: > > > "user-zh" > > > < > > [hidden email]&gt;; > > 发送时间:&nbsp;2020年7月10日(星期五) 上午9:17 > > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > > > 主题:&nbsp;Re: pyflink1.11.0window > > > > > > > > 琴师你好, > > > > 你的source ddl里有指定time1为 time attribute吗? > > create table source1( > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id > int, > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > time1 timestamp, > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type > string, > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > WATERMARK FOR time1 as time1 - > > INTERVAL '2' SECOND > > ) with (...) > > > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月10日周五 上午8:43写道: > > > > &gt; > ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > > &gt; 发件人: > > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > > "奇怪的不朽琴师" > > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > > < > > &gt; [hidden email]&amp;gt;; > > &gt; 发送时间:&amp;nbsp;2020年7月9日(星期四) 下午5:08 > > &gt; 收件人:&amp;nbsp;"godfrey he"<[hidden email] > &amp;gt;; > > &gt; > > &gt; 主题:&amp;nbsp;pyflink1.11.0window > > &gt; > > &gt; > > &gt; > > &gt; 你好: > > &gt; &amp;nbsp; &amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > > &gt; : org.apache.flink.table.api.ValidationException: A group > window > > expects a > > &gt; time attribute for grouping in a stream environment. > > &gt; > > &gt; 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > > &gt; 代码如下 > > &gt; 谢谢 > > &gt; > > &gt; > > &gt; def from_kafka_to_kafka_demo(): > > &gt; &amp;nbsp; &amp;nbsp; s_env = > > &gt; StreamExecutionEnvironment.get_execution_environment() > > &gt; &amp;nbsp; &amp;nbsp; s_env.set_parallelism(1) > > &gt; > > &gt; > > &gt; &amp;nbsp; &amp;nbsp; # use blink table planner > > &gt; &amp;nbsp; &amp;nbsp; st_env = > StreamTableEnvironment.create(s_env) > > &gt; > > &gt; > > &gt; &amp;nbsp; &amp;nbsp; # register source and sink > > &gt; &amp;nbsp; &amp;nbsp; register_rides_source(st_env) > > &gt; &amp;nbsp; &amp;nbsp; register_rides_sink(st_env) > > &gt; > > &gt; > > &gt; &amp;nbsp; &amp;nbsp; st_env.from_path("source1")\ > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > > &gt; .window(Tumble.over("1.secends").on("time1").alias("w")) \ > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > .group_by("w") \ > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > .select(" id,&amp;nbsp; > > time1 , time1 ")\ > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > .insert_into("sink1") > > &gt; &amp;nbsp; &amp;nbsp; > > &gt; &amp;nbsp; &amp;nbsp; > st_env.execute("2-from_kafka_to_kafka") > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; def register_rides_source(st_env): > > &gt; &amp;nbsp; &amp;nbsp; source_ddl = \ > > &gt; &amp;nbsp; &amp;nbsp; ''' > > &gt; &amp;nbsp; &amp;nbsp; create table source1( > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > id int, > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;time1 timestamp, > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;type string > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) with ( > > &gt; &amp;nbsp; &amp;nbsp; 'connector.type' = 'kafka', > > &gt; &amp;nbsp; &amp;nbsp; 'update-mode' = 'append', > > &gt; &amp;nbsp; &amp;nbsp; 'connector.topic' = 'tp1', > > &gt; &amp;nbsp; &amp;nbsp; > 'connector.properties.bootstrap.servers' = > > 'localhost:9092' > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) > > &gt; &amp;nbsp; &amp;nbsp; ''' > > &gt; &amp;nbsp; &amp;nbsp; st_env.sql_update(source_ddl) > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; def register_rides_sink(st_env): > > &gt; &amp;nbsp; &amp;nbsp; sink_ddl = \ > > &gt; &amp;nbsp; &amp;nbsp; ''' > > &gt; &amp;nbsp; &amp;nbsp; create table sink1( > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > id int, > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;time1 timestamp, > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;time2 timestamp > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) with ( > > &gt; &amp;nbsp; &amp;nbsp; 'connector.type' = 'kafka', > > &gt; &amp;nbsp; &amp;nbsp; 'update-mode' = 'append', > > &gt; &amp;nbsp; &amp;nbsp; 'connector.topic' = 'tp3', > > &gt; &amp;nbsp; &amp;nbsp; > 'connector.properties.bootstrap.servers' = > > 'localhost:9092' > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) > > &gt; &amp;nbsp; &amp;nbsp; ''' > > &gt; &amp;nbsp; &amp;nbsp; st_env.sql_update(sink_ddl) > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; if __name__ == '__main__': > > &gt; &amp;nbsp; &amp;nbsp; from_kafka_to_kafka_demo() > > &gt; > > &gt; > > &gt; &amp;nbsp; &amp;nbsp; |
Shuiqiang,你好:
hi,能否请求您贡献一下完整的代码的案例,我是初学者,官网的2-from_kafka_to_kafka.py这个没有窗口,我现在想要一个在此基础上有窗口的demo,尝试编了很久也未能解决。我在给这个demo加上窗口功能后总是有各种各样的问题,十分痛苦,如能帮助,感激不尽。 恳请所有看到此封邮件的大佬! 谢谢! ------------------ 原始邮件 ------------------ 发件人: "user-zh" <[hidden email]>; 发送时间: 2020年7月15日(星期三) 中午11:25 收件人: "user-zh"<[hidden email]>; 主题: Re: pyflink1.11.0window 举个sql例子 select platformcodetoname(payPlatform) as platform, sum(payAmount) as pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as rowtime from payment_msg group by tumble(rt, interval '5' seconds), payPlatform 这个query 对每5s的tumble窗口做统计。 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 上午11:10写道: > Shuiqiang,你好: > &nbsp; &nbsp;我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? > > > ------------------&nbsp;原始邮件&nbsp;------------------ > 发件人: > "user-zh" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月15日(星期三) 上午10:51 > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > 主题:&nbsp;Re: pyflink1.11.0window > > > > 琴师你好, > 异常栈信息org.apache.flink.table.api.ValidationException: A tumble window > expects a size value literal. > 看起来是接下tumble window定义的代码不太正确吧 > > Best, > Shuiqiang > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月15日周三 上午10:27写道: > > &gt; 你好: > &gt; &amp;nbsp; &amp;nbsp; > &gt; > &amp;nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > &gt; Traceback (most recent call last): > &gt; &amp;nbsp; File "tou.py", line 71, in <module&amp;gt; > &gt; &amp;nbsp; &amp;nbsp; from_kafka_to_kafka_demo() > &gt; &amp;nbsp; File "tou.py", line 21, in from_kafka_to_kafka_demo > &gt; &amp;nbsp; &amp;nbsp; .select(" id,&amp;nbsp; time1 , time1 ")\ > &gt; &amp;nbsp; File > &gt; "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line > 907, > &gt; in select > &gt; &amp;nbsp; &amp;nbsp; return Table(self._j_table.select(fields), > self._t_env) > &gt; &amp;nbsp; File > "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > &gt; line 1286, in __call__ > &gt; &amp;nbsp; &amp;nbsp; answer, self.gateway_client, self.target_id, > self.name) > &gt; &amp;nbsp; File > &gt; "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", > line > &gt; 147, in deco > &gt; &amp;nbsp; &amp;nbsp; return f(*a, **kw) > &gt; &amp;nbsp; File > "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > &gt; line 328, in get_return_value > &gt; &amp;nbsp; &amp;nbsp; format(target_id, ".", name), value) > &gt; py4j.protocol.Py4JJavaError: An error occurred while calling > o26.select. > &gt; : org.apache.flink.table.api.ValidationException: A tumble window > expects > &gt; a size value literal. > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; java.lang.reflect.Method.invoke(Method.java:498) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > &gt; > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; at > java.lang.Thread.run(Thread.java:748) > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; def register_rides_source(st_env): > &gt; &amp;nbsp; &amp;nbsp; source_ddl = \ > &gt; &amp;nbsp; &amp;nbsp; """ > &gt; &amp;nbsp; &amp;nbsp; create table source1( > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;id int, > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;time1 timestamp, > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;type string, > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;WATERMARK FOR time1 as time1 - > INTERVAL '2' SECOND > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) with ( > &gt; &amp;nbsp; &amp;nbsp; 'connector.type' = 'kafka', > &gt; &amp;nbsp; &amp;nbsp; 'update-mode' = 'append', > &gt; &amp;nbsp; &amp;nbsp; 'connector.topic' = 'tp1', > &gt; &amp;nbsp; &amp;nbsp; 'connector.properties.bootstrap.servers' = > 'localhost:9092', > &gt; &amp;nbsp; &amp;nbsp; 'connector.properties.zookeeper.connect' = > 'localhost:2181', > &gt; &amp;nbsp; &amp;nbsp; 'format.type' = 'json', > &gt; &amp;nbsp; &amp;nbsp; 'format.derive-schema' = 'true', > &gt; &amp;nbsp; &amp;nbsp; 'connector.version' = 'universal' > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) > &gt; &amp;nbsp; &amp;nbsp; """ > &gt; &amp;nbsp; &amp;nbsp; st_env.sql_update(source_ddl) > &gt; > &gt; &amp;nbsp; &amp;nbsp;&amp;nbsp; > &gt; &amp;nbsp; &amp;nbsp; s_env = > &gt; StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;nbsp; &amp;nbsp; s_env.set_parallelism(1) > &gt; > &gt; > &gt; &amp;nbsp; &amp;nbsp; st_env = StreamTableEnvironment.create(s_env) > &gt; > &gt; > &gt; &amp;nbsp; &amp;nbsp; register_rides_source(st_env) > &gt; &amp;nbsp; &amp;nbsp; register_rides_sink(st_env) > &gt; > &gt; > &gt; &amp;nbsp; &amp;nbsp; st_env.from_path("source1")\ > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > &gt; .window(Tumble.over("2.secends").on("time1").alias("w")) \ > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .group_by("w") \ > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .select(" id,&amp;nbsp; > time1 , time1 ")\ > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .insert_into("sink1") > &gt; &amp;nbsp; &amp;nbsp;&amp;nbsp; > &gt; &amp;nbsp; &amp;nbsp; st_env.execute("2-from_kafka_to_kafka") > &gt; > &gt; > &gt; 代码如上 > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; > &gt; ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > &gt; 发件人: > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > "user-zh" > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > < > &gt; [hidden email]&amp;gt;; > &gt; 发送时间:&amp;nbsp;2020年7月10日(星期五) 上午9:17 > &gt; 收件人:&amp;nbsp;"user-zh"<[hidden email]&amp;gt;; > &gt; > &gt; 主题:&amp;nbsp;Re: pyflink1.11.0window > &gt; > &gt; > &gt; > &gt; 琴师你好, > &gt; > &gt; 你的source ddl里有指定time1为 time attribute吗? > &gt; create table source1( > &gt; > &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id > int, > &gt; > &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > time1 timestamp, > &gt; > &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type > string, > &gt; > &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > WATERMARK FOR time1 as time1 - > &gt; INTERVAL '2' SECOND > &gt; ) with (...) > &gt; > &gt; 奇怪的不朽琴师 <[hidden email]&amp;gt; 于2020年7月10日周五 上午8:43写道: > &gt; > &gt; &amp;gt; > ------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ > &gt; &amp;gt; 发件人: > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; "奇怪的不朽琴师" > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; < > &gt; &amp;gt; [hidden email]&amp;amp;gt;; > &gt; &amp;gt; 发送时间:&amp;amp;nbsp;2020年7月9日(星期四) 下午5:08 > &gt; &amp;gt; 收件人:&amp;amp;nbsp;"godfrey he"<[hidden email] > &amp;amp;gt;; > &gt; &amp;gt; > &gt; &amp;gt; 主题:&amp;amp;nbsp;pyflink1.11.0window > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; 你好: > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > &gt; &amp;gt; : org.apache.flink.table.api.ValidationException: A group > window > &gt; expects a > &gt; &amp;gt; time attribute for grouping in a stream environment. > &gt; &amp;gt; > &gt; &amp;gt; 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > &gt; &amp;gt; 代码如下 > &gt; &amp;gt; 谢谢 > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; def from_kafka_to_kafka_demo(): > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env = > &gt; &amp;gt; StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env.set_parallelism(1) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; # use blink table planner > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env = > StreamTableEnvironment.create(s_env) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; # register source and sink > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; register_rides_sink(st_env) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > &gt; &amp;gt; .window(Tumble.over("1.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .group_by("w") \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .select(" id,&amp;amp;nbsp; > &gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .insert_into("sink1") > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; def register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; source_ddl = \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; create table source1( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > id int, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;type string > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.properties.bootstrap.servers' = > &gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env.sql_update(source_ddl) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; def register_rides_sink(st_env): > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; sink_ddl = \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; create table sink1( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > id int, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;time2 timestamp > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.topic' = 'tp3', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.properties.bootstrap.servers' = > &gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env.sql_update(sink_ddl) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; if __name__ == '__main__': > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; from_kafka_to_kafka_demo() > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; |
下面这个例子从kafka读取json格式的数据, 然后做窗口聚合后写入es, 可以参考下代码结构, 修改相应数据字段。 这份代码你本地应该是不能运行的
from pyflink.datastream import StreamExecutionEnvironment, TimeCharacteristic from pyflink.table import StreamTableEnvironment, DataTypes, EnvironmentSettings from pyflink.table.udf import udf @udf(input_types=[DataTypes.INT()], result_type=DataTypes.STRING()) def platform_code_to_name(code): return "mobile" if code == 0 else "pc" def log_processing(): env = StreamExecutionEnvironment.get_execution_environment() env.set_stream_time_characteristic(TimeCharacteristic.EventTime) env_settings = EnvironmentSettings.Builder().use_blink_planner().build() t_env = StreamTableEnvironment.create(stream_execution_environment=env, environment_settings=env_settings) source_ddl = """ CREATE TABLE payment_msg( createTime VARCHAR, rt as TO_TIMESTAMP(createTime), orderId BIGINT, payAmount DOUBLE, payPlatform INT, paySource INT, WATERMARK FOR rt as rt - INTERVAL '2' SECOND ) WITH ( 'connector.type' = 'kafka', 'connector.version' = 'universal', 'connector.topic' = 'payment_msg_2', 'connector.properties.bootstrap.servers' = '0.0.0.0:9092', 'connector.properties.group.id' = 'test_3', 'connector.startup-mode' = 'latest-offset', 'format.type' = 'json' ) """ t_env.sql_update(source_ddl) es_sink_ddl = """ CREATE TABLE es_sink ( platform VARCHAR, pay_amount DOUBLE, rowtime TIMESTAMP(3) ) with ( 'connector.type' = 'elasticsearch', 'connector.version' = '7', 'connector.hosts' = '<a href="http://localhost:9200'">http://localhost:9200', 'connector.index' = 'platform_pay_amount_1', 'connector.document-type' = 'payment', 'update-mode' = 'upsert', 'connector.flush-on-checkpoint' = 'true', 'connector.key-delimiter' = '$', 'connector.key-null-literal' = 'n/a', 'connector.bulk-flush.max-size' = '42mb', 'connector.bulk-flush.max-actions' = '32', 'connector.bulk-flush.interval' = '1000', 'connector.bulk-flush.backoff.delay' = '1000', 'format.type' = 'json' ) """ t_env.sql_update(es_sink_ddl) t_env.register_function('platformcodetoname', platform_code_to_name) query = """ select platformcodetoname(payPlatform) as platform, sum(payAmount) as pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as rowtime from payment_msg group by tumble(rt, interval '5' seconds), payPlatform """ count_result = t_env.sql_query(query) t_env.create_temporary_view('windowed_values', count_result) query2 = """ select platform, last_value(pay_amount), rowtime from windowed_values group by platform, rowtime """ final_result = t_env.sql_query(query2) final_result.execute_insert(table_path='es_sink') if __name__ == '__main__': log_processing() 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 下午4:40写道: > Shuiqiang,你好: > > hi,能否请求您贡献一下完整的代码的案例,我是初学者,官网的2-from_kafka_to_kafka.py这个没有窗口,我现在想要一个在此基础上有窗口的demo,尝试编了很久也未能解决。我在给这个demo加上窗口功能后总是有各种各样的问题,十分痛苦,如能帮助,感激不尽。 > > > 恳请所有看到此封邮件的大佬! > > > 谢谢! > > > > > ------------------ 原始邮件 ------------------ > 发件人: > "user-zh" > < > [hidden email]>; > 发送时间: 2020年7月15日(星期三) 中午11:25 > 收件人: "user-zh"<[hidden email]>; > > 主题: Re: pyflink1.11.0window > > > > 举个sql例子 > select platformcodetoname(payPlatform) as platform, sum(payAmount) as > pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as > rowtime > from payment_msg group by tumble(rt, interval '5' seconds), payPlatform > 这个query 对每5s的tumble窗口做统计。 > > 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 上午11:10写道: > > > Shuiqiang,你好: > > &nbsp; > &nbsp;我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? > > > > > > ------------------&nbsp;原始邮件&nbsp;------------------ > > 发件人: > > > "user-zh" > > > < > > [hidden email]&gt;; > > 发送时间:&nbsp;2020年7月15日(星期三) 上午10:51 > > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > > > 主题:&nbsp;Re: pyflink1.11.0window > > > > > > > > 琴师你好, > > 异常栈信息org.apache.flink.table.api.ValidationException: A tumble window > > expects a size value literal. > > 看起来是接下tumble window定义的代码不太正确吧 > > > > Best, > > Shuiqiang > > > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月15日周三 上午10:27写道: > > > > &gt; 你好: > > &gt; &amp;nbsp; &amp;nbsp; > > &gt; > > > &amp;nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > > &gt; Traceback (most recent call last): > > &gt; &amp;nbsp; File "tou.py", line 71, in <module&amp;gt; > > &gt; &amp;nbsp; &amp;nbsp; from_kafka_to_kafka_demo() > > &gt; &amp;nbsp; File "tou.py", line 21, in > from_kafka_to_kafka_demo > > &gt; &amp;nbsp; &amp;nbsp; .select(" id,&amp;nbsp; > time1 , time1 ")\ > > &gt; &amp;nbsp; File > > &gt; > "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line > > 907, > > &gt; in select > > &gt; &amp;nbsp; &amp;nbsp; return > Table(self._j_table.select(fields), > > self._t_env) > > &gt; &amp;nbsp; File > > "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > > &gt; line 1286, in __call__ > > &gt; &amp;nbsp; &amp;nbsp; answer, self.gateway_client, > self.target_id, > > self.name) > > &gt; &amp;nbsp; File > > &gt; > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", > > line > > &gt; 147, in deco > > &gt; &amp;nbsp; &amp;nbsp; return f(*a, **kw) > > &gt; &amp;nbsp; File > > "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > > &gt; line 328, in get_return_value > > &gt; &amp;nbsp; &amp;nbsp; format(target_id, ".", name), > value) > > &gt; py4j.protocol.Py4JJavaError: An error occurred while calling > > o26.select. > > &gt; : org.apache.flink.table.api.ValidationException: A tumble > window > > expects > > &gt; a size value literal. > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; java.lang.reflect.Method.invoke(Method.java:498) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > &gt; > > > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > at > > java.lang.Thread.run(Thread.java:748) > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; def register_rides_source(st_env): > > &gt; &amp;nbsp; &amp;nbsp; source_ddl = \ > > &gt; &amp;nbsp; &amp;nbsp; """ > > &gt; &amp;nbsp; &amp;nbsp; create table source1( > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;id int, > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;time1 timestamp, > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;type string, > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;WATERMARK FOR > time1 as time1 - > > INTERVAL '2' SECOND > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) with ( > > &gt; &amp;nbsp; &amp;nbsp; 'connector.type' = 'kafka', > > &gt; &amp;nbsp; &amp;nbsp; 'update-mode' = 'append', > > &gt; &amp;nbsp; &amp;nbsp; 'connector.topic' = 'tp1', > > &gt; &amp;nbsp; &amp;nbsp; > 'connector.properties.bootstrap.servers' = > > 'localhost:9092', > > &gt; &amp;nbsp; &amp;nbsp; > 'connector.properties.zookeeper.connect' = > > 'localhost:2181', > > &gt; &amp;nbsp; &amp;nbsp; 'format.type' = 'json', > > &gt; &amp;nbsp; &amp;nbsp; 'format.derive-schema' = > 'true', > > &gt; &amp;nbsp; &amp;nbsp; 'connector.version' = > 'universal' > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;) > > &gt; &amp;nbsp; &amp;nbsp; """ > > &gt; &amp;nbsp; &amp;nbsp; st_env.sql_update(source_ddl) > > &gt; > > &gt; &amp;nbsp; &amp;nbsp;&amp;nbsp; > > &gt; &amp;nbsp; &amp;nbsp; s_env = > > &gt; StreamExecutionEnvironment.get_execution_environment() > > &gt; &amp;nbsp; &amp;nbsp; s_env.set_parallelism(1) > > &gt; > > &gt; > > &gt; &amp;nbsp; &amp;nbsp; st_env = > StreamTableEnvironment.create(s_env) > > &gt; > > &gt; > > &gt; &amp;nbsp; &amp;nbsp; register_rides_source(st_env) > > &gt; &amp;nbsp; &amp;nbsp; register_rides_sink(st_env) > > &gt; > > &gt; > > &gt; &amp;nbsp; &amp;nbsp; st_env.from_path("source1")\ > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > > &gt; .window(Tumble.over("2.secends").on("time1").alias("w")) \ > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > .group_by("w") \ > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > .select(" id,&amp;nbsp; > > time1 , time1 ")\ > > &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; > .insert_into("sink1") > > &gt; &amp;nbsp; &amp;nbsp;&amp;nbsp; > > &gt; &amp;nbsp; &amp;nbsp; > st_env.execute("2-from_kafka_to_kafka") > > &gt; > > &gt; > > &gt; 代码如上 > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > > &gt; > ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > > &gt; 发件人: > > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > > "user-zh" > > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > > < > > &gt; [hidden email]&amp;gt;; > > &gt; 发送时间:&amp;nbsp;2020年7月10日(星期五) 上午9:17 > > &gt; 收件人:&amp;nbsp;"user-zh"<[hidden email] > &amp;gt;; > > &gt; > > &gt; 主题:&amp;nbsp;Re: pyflink1.11.0window > > &gt; > > &gt; > > &gt; > > &gt; 琴师你好, > > &gt; > > &gt; 你的source ddl里有指定time1为 time attribute吗? > > &gt; create table source1( > > &gt; > > > &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > id > > int, > > &gt; > > > &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > > time1 timestamp, > > &gt; > > > &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > type > > string, > > &gt; > > > &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > > WATERMARK FOR time1 as time1 - > > &gt; INTERVAL '2' SECOND > > &gt; ) with (...) > > &gt; > > &gt; 奇怪的不朽琴师 <[hidden email]&amp;gt; 于2020年7月10日周五 > 上午8:43写道: > > &gt; > > &gt; &amp;gt; > > > ------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ > > &gt; &amp;gt; 发件人: > > &gt; > > > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > > &gt; "奇怪的不朽琴师" > > &gt; > > > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > > &gt; < > > &gt; &amp;gt; [hidden email]&amp;amp;gt;; > > &gt; &amp;gt; 发送时间:&amp;amp;nbsp;2020年7月9日(星期四) 下午5:08 > > &gt; &amp;gt; 收件人:&amp;amp;nbsp;"godfrey he"< > [hidden email] > > &amp;amp;gt;; > > &gt; &amp;gt; > > &gt; &amp;gt; 主题:&amp;amp;nbsp;pyflink1.11.0window > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; 你好: > > &gt; &amp;gt; &amp;amp;nbsp; > &amp;amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > > &gt; &amp;gt; : > org.apache.flink.table.api.ValidationException: A group > > window > > &gt; expects a > > &gt; &amp;gt; time attribute for grouping in a stream > environment. > > &gt; &amp;gt; > > &gt; &amp;gt; 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > > &gt; &amp;gt; 代码如下 > > &gt; &amp;gt; 谢谢 > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; def from_kafka_to_kafka_demo(): > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env = > > &gt; &amp;gt; > StreamExecutionEnvironment.get_execution_environment() > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > s_env.set_parallelism(1) > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; # use > blink table planner > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env = > > StreamTableEnvironment.create(s_env) > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; # > register source and sink > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > register_rides_source(st_env) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > register_rides_sink(st_env) > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > st_env.from_path("source1")\ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > &gt; &amp;gt; > .window(Tumble.over("1.secends").on("time1").alias("w")) \ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > .group_by("w") \ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > .select(" id,&amp;amp;nbsp; > > &gt; time1 , time1 ")\ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > .insert_into("sink1") > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > > st_env.execute("2-from_kafka_to_kafka") > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; def register_rides_source(st_env): > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > source_ddl = \ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; ''' > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; create > table source1( > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > id int, > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;time1 timestamp, > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;type string > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;) with ( > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.type' = 'kafka', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'update-mode' = 'append', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.topic' = 'tp1', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > > 'connector.properties.bootstrap.servers' = > > &gt; 'localhost:9092' > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; ''' > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > st_env.sql_update(source_ddl) > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; def register_rides_sink(st_env): > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; sink_ddl > = \ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; ''' > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; create > table sink1( > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > id int, > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;time1 timestamp, > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;time2 timestamp > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;) with ( > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.type' = 'kafka', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'update-mode' = 'append', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.topic' = 'tp3', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > > 'connector.properties.bootstrap.servers' = > > &gt; 'localhost:9092' > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; ''' > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > st_env.sql_update(sink_ddl) > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; if __name__ == '__main__': > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > from_kafka_to_kafka_demo() > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; |
非常感谢!
------------------ 原始邮件 ------------------ 发件人: "user-zh" <[hidden email]>; 发送时间: 2020年7月15日(星期三) 下午5:23 收件人: "user-zh"<[hidden email]>; 主题: Re: pyflink1.11.0window 下面这个例子从kafka读取json格式的数据, 然后做窗口聚合后写入es, 可以参考下代码结构, 修改相应数据字段。 这份代码你本地应该是不能运行的 from pyflink.datastream import StreamExecutionEnvironment, TimeCharacteristic from pyflink.table import StreamTableEnvironment, DataTypes, EnvironmentSettings from pyflink.table.udf import udf @udf(input_types=[DataTypes.INT()], result_type=DataTypes.STRING()) def platform_code_to_name(code): return "mobile" if code == 0 else "pc" def log_processing(): env = StreamExecutionEnvironment.get_execution_environment() env.set_stream_time_characteristic(TimeCharacteristic.EventTime) env_settings = EnvironmentSettings.Builder().use_blink_planner().build() t_env = StreamTableEnvironment.create(stream_execution_environment=env, environment_settings=env_settings) source_ddl = """ CREATE TABLE payment_msg( createTime VARCHAR, rt as TO_TIMESTAMP(createTime), orderId BIGINT, payAmount DOUBLE, payPlatform INT, paySource INT, WATERMARK FOR rt as rt - INTERVAL '2' SECOND ) WITH ( 'connector.type' = 'kafka', 'connector.version' = 'universal', 'connector.topic' = 'payment_msg_2', 'connector.properties.bootstrap.servers' = '0.0.0.0:9092', 'connector.properties.group.id' = 'test_3', 'connector.startup-mode' = 'latest-offset', 'format.type' = 'json' ) """ t_env.sql_update(source_ddl) es_sink_ddl = """ CREATE TABLE es_sink ( platform VARCHAR, pay_amount DOUBLE, rowtime TIMESTAMP(3) ) with ( 'connector.type' = 'elasticsearch', 'connector.version' = '7', 'connector.hosts' = '<a href="http://localhost:9200'">http://localhost:9200', 'connector.index' = 'platform_pay_amount_1', 'connector.document-type' = 'payment', 'update-mode' = 'upsert', 'connector.flush-on-checkpoint' = 'true', 'connector.key-delimiter' = '$', 'connector.key-null-literal' = 'n/a', 'connector.bulk-flush.max-size' = '42mb', 'connector.bulk-flush.max-actions' = '32', 'connector.bulk-flush.interval' = '1000', 'connector.bulk-flush.backoff.delay' = '1000', 'format.type' = 'json' ) """ t_env.sql_update(es_sink_ddl) t_env.register_function('platformcodetoname', platform_code_to_name) query = """ select platformcodetoname(payPlatform) as platform, sum(payAmount) as pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as rowtime from payment_msg group by tumble(rt, interval '5' seconds), payPlatform """ count_result = t_env.sql_query(query) t_env.create_temporary_view('windowed_values', count_result) query2 = """ select platform, last_value(pay_amount), rowtime from windowed_values group by platform, rowtime """ final_result = t_env.sql_query(query2) final_result.execute_insert(table_path='es_sink') if __name__ == '__main__': log_processing() 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 下午4:40写道: > &nbsp;Shuiqiang,你好: > &nbsp; &nbsp; > &nbsp;hi,能否请求您贡献一下完整的代码的案例,我是初学者,官网的2-from_kafka_to_kafka.py这个没有窗口,我现在想要一个在此基础上有窗口的demo,尝试编了很久也未能解决。我在给这个demo加上窗口功能后总是有各种各样的问题,十分痛苦,如能帮助,感激不尽。 > > > 恳请所有看到此封邮件的大佬! > > > 谢谢! > > > > > ------------------&nbsp;原始邮件&nbsp;------------------ > 发件人: > "user-zh" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月15日(星期三) 中午11:25 > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > 主题:&nbsp;Re: pyflink1.11.0window > > > > 举个sql例子 > select platformcodetoname(payPlatform) as platform, sum(payAmount) as > pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as > rowtime > from payment_msg group by tumble(rt, interval '5' seconds), payPlatform > 这个query 对每5s的tumble窗口做统计。 > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月15日周三 上午11:10写道: > > &gt; Shuiqiang,你好: > &gt; &amp;nbsp; > &amp;nbsp;我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? > &gt; > &gt; > &gt; ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > &gt; 发件人: > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > "user-zh" > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > < > &gt; [hidden email]&amp;gt;; > &gt; 发送时间:&amp;nbsp;2020年7月15日(星期三) 上午10:51 > &gt; 收件人:&amp;nbsp;"user-zh"<[hidden email]&amp;gt;; > &gt; > &gt; 主题:&amp;nbsp;Re: pyflink1.11.0window > &gt; > &gt; > &gt; > &gt; 琴师你好, > &gt; 异常栈信息org.apache.flink.table.api.ValidationException: A tumble window > &gt; expects a size value literal. > &gt; 看起来是接下tumble window定义的代码不太正确吧 > &gt; > &gt; Best, > &gt; Shuiqiang > &gt; > &gt; 奇怪的不朽琴师 <[hidden email]&amp;gt; 于2020年7月15日周三 上午10:27写道: > &gt; > &gt; &amp;gt; 你好: > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > &gt; &amp;gt; Traceback (most recent call last): > &gt; &amp;gt; &amp;amp;nbsp; File "tou.py", line 71, in <module&amp;amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;nbsp; File "tou.py", line 21, in > from_kafka_to_kafka_demo > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; .select(" id,&amp;amp;nbsp; > time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; &amp;gt; > "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line > &gt; 907, > &gt; &amp;gt; in select > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; return > Table(self._j_table.select(fields), > &gt; self._t_env) > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > &gt; &amp;gt; line 1286, in __call__ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; answer, self.gateway_client, > self.target_id, > &gt; self.name) > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; &amp;gt; > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", > &gt; line > &gt; &amp;gt; 147, in deco > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; return f(*a, **kw) > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > &gt; &amp;gt; line 328, in get_return_value > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; format(target_id, ".", name), > value) > &gt; &amp;gt; py4j.protocol.Py4JJavaError: An error occurred while calling > &gt; o26.select. > &gt; &amp;gt; : org.apache.flink.table.api.ValidationException: A tumble > window > &gt; expects > &gt; &amp;gt; a size value literal. > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; java.lang.reflect.Method.invoke(Method.java:498) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; java.lang.Thread.run(Thread.java:748) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; def register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; source_ddl = \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; create table source1( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;id int, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;type string, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;WATERMARK FOR > time1 as time1 - > &gt; INTERVAL '2' SECOND > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.properties.bootstrap.servers' = > &gt; 'localhost:9092', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.properties.zookeeper.connect' = > &gt; 'localhost:2181', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'format.type' = 'json', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'format.derive-schema' = > 'true', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.version' = > 'universal' > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env.sql_update(source_ddl) > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env = > &gt; &amp;gt; StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env.set_parallelism(1) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env = > StreamTableEnvironment.create(s_env) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; register_rides_sink(st_env) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > &gt; &amp;gt; .window(Tumble.over("2.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .group_by("w") \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .select(" id,&amp;amp;nbsp; > &gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .insert_into("sink1") > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; 代码如上 > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > ------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ > &gt; &amp;gt; 发件人: > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; "user-zh" > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; < > &gt; &amp;gt; [hidden email]&amp;amp;gt;; > &gt; &amp;gt; 发送时间:&amp;amp;nbsp;2020年7月10日(星期五) 上午9:17 > &gt; &amp;gt; 收件人:&amp;amp;nbsp;"user-zh"<[hidden email] > &amp;amp;gt;; > &gt; &amp;gt; > &gt; &amp;gt; 主题:&amp;amp;nbsp;Re: pyflink1.11.0window > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; 琴师你好, > &gt; &amp;gt; > &gt; &amp;gt; 你的source ddl里有指定time1为 time attribute吗? > &gt; &amp;gt; create table source1( > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > id > &gt; int, > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; time1 timestamp, > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > type > &gt; string, > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; WATERMARK FOR time1 as time1 - > &gt; &amp;gt; INTERVAL '2' SECOND > &gt; &amp;gt; ) with (...) > &gt; &amp;gt; > &gt; &amp;gt; 奇怪的不朽琴师 <[hidden email]&amp;amp;gt; 于2020年7月10日周五 > 上午8:43写道: > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; > ------------------&amp;amp;amp;nbsp;原始邮件&amp;amp;amp;nbsp;------------------ > &gt; &amp;gt; &amp;amp;gt; 发件人: > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; "奇怪的不朽琴师" > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; < > &gt; &amp;gt; &amp;amp;gt; [hidden email]&amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; 发送时间:&amp;amp;amp;nbsp;2020年7月9日(星期四) 下午5:08 > &gt; &amp;gt; &amp;amp;gt; 收件人:&amp;amp;amp;nbsp;"godfrey he"< > [hidden email] > &gt; &amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 主题:&amp;amp;amp;nbsp;pyflink1.11.0window > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 你好: > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > &gt; &amp;gt; &amp;amp;gt; : > org.apache.flink.table.api.ValidationException: A group > &gt; window > &gt; &amp;gt; expects a > &gt; &amp;gt; &amp;amp;gt; time attribute for grouping in a stream > environment. > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > &gt; &amp;gt; &amp;amp;gt; 代码如下 > &gt; &amp;gt; &amp;amp;gt; 谢谢 > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def from_kafka_to_kafka_demo(): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; s_env = > &gt; &amp;gt; &amp;amp;gt; > StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > s_env.set_parallelism(1) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; # use > blink table planner > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; st_env = > &gt; StreamTableEnvironment.create(s_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; # > register source and sink > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_sink(st_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; > .window(Tumble.over("1.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .group_by("w") \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .select(" id,&amp;amp;amp;nbsp; > &gt; &amp;gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .insert_into("sink1") > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > source_ddl = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; create > table source1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;type string > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.sql_update(source_ddl) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def register_rides_sink(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; sink_ddl > = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; create > table sink1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time2 timestamp > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.topic' = 'tp3', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.sql_update(sink_ddl) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; if __name__ == '__main__': > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; |
HI :
我现在有一个新的问题,我在此基础上加了一个关联,再写入kafka时报错,如下 Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line 147, in deco return f(*a, **kw) File "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", line 328, in get_return_value format(target_id, ".", name), value) py4j.protocol.Py4JJavaError: An error occurred while calling o5.sqlUpdate. : org.apache.flink.table.api.TableException: AppendStreamTableSink requires that Table has only insert changes. at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:123) at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:48) at org.apache.flink.table.planner.plan.nodes.exec.ExecNode$class.translateToPlan(ExecNode.scala:58) at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlan(StreamExecSink.scala:48) at org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:60) at org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:59) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) at scala.collection.Iterator$class.foreach(Iterator.scala:891) at scala.collection.AbstractIterator.foreach(Iterator.scala:1334) at scala.collection.IterableLike$class.foreach(IterableLike.scala:72) at scala.collection.AbstractIterable.foreach(Iterable.scala:54) at scala.collection.TraversableLike$class.map(TraversableLike.scala:234) at scala.collection.AbstractTraversable.map(Traversable.scala:104) at org.apache.flink.table.planner.delegation.StreamPlanner.translateToPlan(StreamPlanner.scala:59) at org.apache.flink.table.planner.delegation.PlannerBase.translate(PlannerBase.scala:153) at org.apache.flink.table.api.internal.TableEnvironmentImpl.translate(TableEnvironmentImpl.java:685) at org.apache.flink.table.api.internal.TableEnvironmentImpl.sqlUpdate(TableEnvironmentImpl.java:495) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) at org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) at org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) at org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) at org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) at org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) at java.lang.Thread.run(Thread.java:748) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "tou.py", line 99, in <module> from_kafka_to_kafka_demo() File "tou.py", line 33, in from_kafka_to_kafka_demo st_env.sql_update("insert into flink_result select id,type,rowtime from final_result2") File "/usr/local/lib/python3.7/site-packages/pyflink/table/table_environment.py", line 547, in sql_update self._j_tenv.sqlUpdate(stmt) File "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", line 1286, in __call__ answer, self.gateway_client, self.target_id, self.name) File "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line 154, in deco raise exception_mapping[exception](s.split(': ', 1)[1], stack_trace) pyflink.util.exceptions.TableException: 'AppendStreamTableSink requires that Table has only insert changes.' 这种应该如何实现,需求大概是一个流表(需要分组汇总)关联一个维表。 from pyflink.datastream import StreamExecutionEnvironment, TimeCharacteristic from pyflink.table import StreamTableEnvironment, DataTypes, EnvironmentSettings,DataTypes, CsvTableSource, CsvTableSink from pyflink.table.descriptors import Schema, Kafka, Json, Rowtime from pyflink.table.window import Tumble def from_kafka_to_kafka_demo(): # use blink table planner env = StreamExecutionEnvironment.get_execution_environment() env.set_stream_time_characteristic(TimeCharacteristic.EventTime) env_settings = EnvironmentSettings.Builder().use_blink_planner().build() st_env = StreamTableEnvironment.create(stream_execution_environment=env,environment_settings=env_settings) # register source and sink register_rides_source(st_env) register_rides_sink(st_env) register_mysql_source(st_env) query = """ select cast(sum(t1.id) as int) as id, max(t1.type) as type,cast(tumble_start(t1.time1, interval '4' second) as bigint) as rowtime from source1 t1 group by tumble(t1.time1, interval '4' second) """ count_result = st_env.sql_query(query) st_env.create_temporary_view('final_result', count_result) query2 = """ select t1.id,t2.type,t1.rowtime from final_result t1 left join dim_mysql t2 on t1.type=t2.id """ count_result2 = st_env.sql_query(query2) st_env.create_temporary_view('final_result2', count_result2) st_env.sql_update("insert into flink_result select id,type,rowtime from final_result2") st_env.execute("2-from_kafka_to_kafka") def register_rides_source(st_env): source_ddl = \ """ create table source1( id int, time2 varchar , time1 as TO_TIMESTAMP(time2,'yyyyMMddHHmmss'), type string, WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND ) with ( 'connector.type' = 'kafka', 'connector.topic' = 'tp1', 'connector.startup-mode' = 'latest-offset', 'connector.properties.bootstrap.servers' = 'localhost:9092', 'connector.properties.zookeeper.connect' = 'localhost:2181', 'format.type' = 'json', 'connector.version' = 'universal' ) """ st_env.sql_update(source_ddl) def register_mysql_source(st_env): source_ddl = \ """ CREATE TABLE dim_mysql ( id varchar, -- type varchar -- ) WITH ( 'connector.type' = 'jdbc', 'connector.url' = 'jdbc:mysql://localhost:3390/test', 'connector.table' = 'flink_test', 'connector.driver' = 'com.mysql.jdbc.Driver', 'connector.username' = '****', 'connector.password' = '*****', 'connector.lookup.cache.max-rows' = '5000', 'connector.lookup.cache.ttl' = '10min' ) """ st_env.sql_update(source_ddl) def register_rides_sink(st_env): sink_ddl = \ """ CREATE TABLE flink_result ( id int, type varchar, rtime bigint, primary key(id) ) WITH ( with ( 'connector.type' = 'kafka', 'connector.topic' = 'tp4', 'connector.startup-mode' = 'latest-offset', 'connector.properties.bootstrap.servers' = 'localhost:9092', 'connector.properties.zookeeper.connect' = 'localhost:2181', 'format.type' = 'json', 'connector.version' = 'universal' ) ) """ st_env.sql_update(sink_ddl) if __name__ == '__main__': from_kafka_to_kafka_demo() ------------------ 原始邮件 ------------------ 发件人: "我自己的邮箱" <[hidden email]>; 发送时间: 2020年7月15日(星期三) 下午5:30 收件人: "user-zh"<[hidden email]>; 主题: 回复: pyflink1.11.0window 非常感谢! ------------------ 原始邮件 ------------------ 发件人: "user-zh" <[hidden email]>; 发送时间: 2020年7月15日(星期三) 下午5:23 收件人: "user-zh"<[hidden email]>; 主题: Re: pyflink1.11.0window 下面这个例子从kafka读取json格式的数据, 然后做窗口聚合后写入es, 可以参考下代码结构, 修改相应数据字段。 这份代码你本地应该是不能运行的 from pyflink.datastream import StreamExecutionEnvironment, TimeCharacteristic from pyflink.table import StreamTableEnvironment, DataTypes, EnvironmentSettings from pyflink.table.udf import udf @udf(input_types=[DataTypes.INT()], result_type=DataTypes.STRING()) def platform_code_to_name(code): return "mobile" if code == 0 else "pc" def log_processing(): env = StreamExecutionEnvironment.get_execution_environment() env.set_stream_time_characteristic(TimeCharacteristic.EventTime) env_settings = EnvironmentSettings.Builder().use_blink_planner().build() t_env = StreamTableEnvironment.create(stream_execution_environment=env, environment_settings=env_settings) source_ddl = """ CREATE TABLE payment_msg( createTime VARCHAR, rt as TO_TIMESTAMP(createTime), orderId BIGINT, payAmount DOUBLE, payPlatform INT, paySource INT, WATERMARK FOR rt as rt - INTERVAL '2' SECOND ) WITH ( 'connector.type' = 'kafka', 'connector.version' = 'universal', 'connector.topic' = 'payment_msg_2', 'connector.properties.bootstrap.servers' = '0.0.0.0:9092', 'connector.properties.group.id' = 'test_3', 'connector.startup-mode' = 'latest-offset', 'format.type' = 'json' ) """ t_env.sql_update(source_ddl) es_sink_ddl = """ CREATE TABLE es_sink ( platform VARCHAR, pay_amount DOUBLE, rowtime TIMESTAMP(3) ) with ( 'connector.type' = 'elasticsearch', 'connector.version' = '7', 'connector.hosts' = '<a href="http://localhost:9200'">http://localhost:9200', 'connector.index' = 'platform_pay_amount_1', 'connector.document-type' = 'payment', 'update-mode' = 'upsert', 'connector.flush-on-checkpoint' = 'true', 'connector.key-delimiter' = '$', 'connector.key-null-literal' = 'n/a', 'connector.bulk-flush.max-size' = '42mb', 'connector.bulk-flush.max-actions' = '32', 'connector.bulk-flush.interval' = '1000', 'connector.bulk-flush.backoff.delay' = '1000', 'format.type' = 'json' ) """ t_env.sql_update(es_sink_ddl) t_env.register_function('platformcodetoname', platform_code_to_name) query = """ select platformcodetoname(payPlatform) as platform, sum(payAmount) as pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as rowtime from payment_msg group by tumble(rt, interval '5' seconds), payPlatform """ count_result = t_env.sql_query(query) t_env.create_temporary_view('windowed_values', count_result) query2 = """ select platform, last_value(pay_amount), rowtime from windowed_values group by platform, rowtime """ final_result = t_env.sql_query(query2) final_result.execute_insert(table_path='es_sink') if __name__ == '__main__': log_processing() 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 下午4:40写道: > &nbsp;Shuiqiang,你好: > &nbsp; &nbsp; > &nbsp;hi,能否请求您贡献一下完整的代码的案例,我是初学者,官网的2-from_kafka_to_kafka.py这个没有窗口,我现在想要一个在此基础上有窗口的demo,尝试编了很久也未能解决。我在给这个demo加上窗口功能后总是有各种各样的问题,十分痛苦,如能帮助,感激不尽。 > > > 恳请所有看到此封邮件的大佬! > > > 谢谢! > > > > > ------------------&nbsp;原始邮件&nbsp;------------------ > 发件人: > "user-zh" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月15日(星期三) 中午11:25 > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > 主题:&nbsp;Re: pyflink1.11.0window > > > > 举个sql例子 > select platformcodetoname(payPlatform) as platform, sum(payAmount) as > pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as > rowtime > from payment_msg group by tumble(rt, interval '5' seconds), payPlatform > 这个query 对每5s的tumble窗口做统计。 > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月15日周三 上午11:10写道: > > &gt; Shuiqiang,你好: > &gt; &amp;nbsp; > &amp;nbsp;我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? > &gt; > &gt; > &gt; ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > &gt; 发件人: > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > "user-zh" > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > < > &gt; [hidden email]&amp;gt;; > &gt; 发送时间:&amp;nbsp;2020年7月15日(星期三) 上午10:51 > &gt; 收件人:&amp;nbsp;"user-zh"<[hidden email]&amp;gt;; > &gt; > &gt; 主题:&amp;nbsp;Re: pyflink1.11.0window > &gt; > &gt; > &gt; > &gt; 琴师你好, > &gt; 异常栈信息org.apache.flink.table.api.ValidationException: A tumble window > &gt; expects a size value literal. > &gt; 看起来是接下tumble window定义的代码不太正确吧 > &gt; > &gt; Best, > &gt; Shuiqiang > &gt; > &gt; 奇怪的不朽琴师 <[hidden email]&amp;gt; 于2020年7月15日周三 上午10:27写道: > &gt; > &gt; &amp;gt; 你好: > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > &gt; &amp;gt; Traceback (most recent call last): > &gt; &amp;gt; &amp;amp;nbsp; File "tou.py", line 71, in <module&amp;amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;nbsp; File "tou.py", line 21, in > from_kafka_to_kafka_demo > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; .select(" id,&amp;amp;nbsp; > time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; &amp;gt; > "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line > &gt; 907, > &gt; &amp;gt; in select > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; return > Table(self._j_table.select(fields), > &gt; self._t_env) > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > &gt; &amp;gt; line 1286, in __call__ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; answer, self.gateway_client, > self.target_id, > &gt; self.name) > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; &amp;gt; > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", > &gt; line > &gt; &amp;gt; 147, in deco > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; return f(*a, **kw) > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > &gt; &amp;gt; line 328, in get_return_value > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; format(target_id, ".", name), > value) > &gt; &amp;gt; py4j.protocol.Py4JJavaError: An error occurred while calling > &gt; o26.select. > &gt; &amp;gt; : org.apache.flink.table.api.ValidationException: A tumble > window > &gt; expects > &gt; &amp;gt; a size value literal. > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; java.lang.reflect.Method.invoke(Method.java:498) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; java.lang.Thread.run(Thread.java:748) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; def register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; source_ddl = \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; create table source1( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;id int, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;type string, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;WATERMARK FOR > time1 as time1 - > &gt; INTERVAL '2' SECOND > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.properties.bootstrap.servers' = > &gt; 'localhost:9092', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.properties.zookeeper.connect' = > &gt; 'localhost:2181', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'format.type' = 'json', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'format.derive-schema' = > 'true', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.version' = > 'universal' > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env.sql_update(source_ddl) > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env = > &gt; &amp;gt; StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env.set_parallelism(1) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env = > StreamTableEnvironment.create(s_env) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; register_rides_sink(st_env) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > &gt; &amp;gt; .window(Tumble.over("2.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .group_by("w") \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .select(" id,&amp;amp;nbsp; > &gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .insert_into("sink1") > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; 代码如上 > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > ------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ > &gt; &amp;gt; 发件人: > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; "user-zh" > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; < > &gt; &amp;gt; [hidden email]&amp;amp;gt;; > &gt; &amp;gt; 发送时间:&amp;amp;nbsp;2020年7月10日(星期五) 上午9:17 > &gt; &amp;gt; 收件人:&amp;amp;nbsp;"user-zh"<[hidden email] > &amp;amp;gt;; > &gt; &amp;gt; > &gt; &amp;gt; 主题:&amp;amp;nbsp;Re: pyflink1.11.0window > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; 琴师你好, > &gt; &amp;gt; > &gt; &amp;gt; 你的source ddl里有指定time1为 time attribute吗? > &gt; &amp;gt; create table source1( > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > id > &gt; int, > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; time1 timestamp, > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > type > &gt; string, > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; WATERMARK FOR time1 as time1 - > &gt; &amp;gt; INTERVAL '2' SECOND > &gt; &amp;gt; ) with (...) > &gt; &amp;gt; > &gt; &amp;gt; 奇怪的不朽琴师 <[hidden email]&amp;amp;gt; 于2020年7月10日周五 > 上午8:43写道: > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; > ------------------&amp;amp;amp;nbsp;原始邮件&amp;amp;amp;nbsp;------------------ > &gt; &amp;gt; &amp;amp;gt; 发件人: > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; "奇怪的不朽琴师" > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; < > &gt; &amp;gt; &amp;amp;gt; [hidden email]&amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; 发送时间:&amp;amp;amp;nbsp;2020年7月9日(星期四) 下午5:08 > &gt; &amp;gt; &amp;amp;gt; 收件人:&amp;amp;amp;nbsp;"godfrey he"< > [hidden email] > &gt; &amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 主题:&amp;amp;amp;nbsp;pyflink1.11.0window > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 你好: > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > &gt; &amp;gt; &amp;amp;gt; : > org.apache.flink.table.api.ValidationException: A group > &gt; window > &gt; &amp;gt; expects a > &gt; &amp;gt; &amp;amp;gt; time attribute for grouping in a stream > environment. > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > &gt; &amp;gt; &amp;amp;gt; 代码如下 > &gt; &amp;gt; &amp;amp;gt; 谢谢 > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def from_kafka_to_kafka_demo(): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; s_env = > &gt; &amp;gt; &amp;amp;gt; > StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > s_env.set_parallelism(1) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; # use > blink table planner > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; st_env = > &gt; StreamTableEnvironment.create(s_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; # > register source and sink > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_sink(st_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; > .window(Tumble.over("1.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .group_by("w") \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .select(" id,&amp;amp;amp;nbsp; > &gt; &amp;gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .insert_into("sink1") > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > source_ddl = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; create > table source1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;type string > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.sql_update(source_ddl) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def register_rides_sink(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; sink_ddl > = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; create > table sink1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time2 timestamp > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.topic' = 'tp3', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.sql_update(sink_ddl) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; if __name__ == '__main__': > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; |
看看异常信息, 是不是你的insert mode没配置对。
BTW, 你粘贴的文本带有很多" ", 有点影响可读性。 Best, Shuiqiang 奇怪的不朽琴师 <[hidden email]> 于2020年7月20日周一 下午4:23写道: > HI : > 我现在有一个新的问题,我在此基础上加了一个关联,再写入kafka时报错,如下 > Traceback (most recent call last): > File > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line > 147, in deco > return f(*a, **kw) > File "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > line 328, in get_return_value > format(target_id, ".", name), value) > py4j.protocol.Py4JJavaError: An error occurred while calling o5.sqlUpdate. > : org.apache.flink.table.api.TableException: AppendStreamTableSink > requires that Table has only insert changes. > at > org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:123) > at > org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:48) > at > org.apache.flink.table.planner.plan.nodes.exec.ExecNode$class.translateToPlan(ExecNode.scala:58) > at > org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlan(StreamExecSink.scala:48) > at > org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:60) > at > org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:59) > at > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) > at > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) > at > scala.collection.Iterator$class.foreach(Iterator.scala:891) > at > scala.collection.AbstractIterator.foreach(Iterator.scala:1334) > at > scala.collection.IterableLike$class.foreach(IterableLike.scala:72) > at > scala.collection.AbstractIterable.foreach(Iterable.scala:54) > at > scala.collection.TraversableLike$class.map(TraversableLike.scala:234) > at > scala.collection.AbstractTraversable.map(Traversable.scala:104) > at > org.apache.flink.table.planner.delegation.StreamPlanner.translateToPlan(StreamPlanner.scala:59) > at > org.apache.flink.table.planner.delegation.PlannerBase.translate(PlannerBase.scala:153) > at > org.apache.flink.table.api.internal.TableEnvironmentImpl.translate(TableEnvironmentImpl.java:685) > at > org.apache.flink.table.api.internal.TableEnvironmentImpl.sqlUpdate(TableEnvironmentImpl.java:495) > at > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at > java.lang.reflect.Method.invoke(Method.java:498) > at > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > at > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > at > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > at > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > at > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > at > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > at java.lang.Thread.run(Thread.java:748) > > > > > During handling of the above exception, another exception occurred: > > > Traceback (most recent call last): > File "tou.py", line 99, in <module> > from_kafka_to_kafka_demo() > File "tou.py", line 33, in from_kafka_to_kafka_demo > st_env.sql_update("insert into flink_result select > id,type,rowtime from final_result2") > File > "/usr/local/lib/python3.7/site-packages/pyflink/table/table_environment.py", > line 547, in sql_update > self._j_tenv.sqlUpdate(stmt) > File "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > line 1286, in __call__ > answer, self.gateway_client, self.target_id, self.name) > File > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line > 154, in deco > raise exception_mapping[exception](s.split(': ', 1)[1], > stack_trace) > pyflink.util.exceptions.TableException: 'AppendStreamTableSink requires > that Table has only insert changes.' > > > > > > 这种应该如何实现,需求大概是一个流表(需要分组汇总)关联一个维表。 > > > from pyflink.datastream import StreamExecutionEnvironment, > TimeCharacteristic > from pyflink.table import StreamTableEnvironment, DataTypes, > EnvironmentSettings,DataTypes, CsvTableSource, CsvTableSink > from pyflink.table.descriptors import Schema, Kafka, Json, Rowtime > from pyflink.table.window import Tumble > > > > > def from_kafka_to_kafka_demo(): > > > # use blink table planner > env = StreamExecutionEnvironment.get_execution_environment() > > env.set_stream_time_characteristic(TimeCharacteristic.EventTime) > env_settings = > EnvironmentSettings.Builder().use_blink_planner().build() > st_env = > StreamTableEnvironment.create(stream_execution_environment=env,environment_settings=env_settings) > > > # register source and sink > register_rides_source(st_env) > register_rides_sink(st_env) > register_mysql_source(st_env) > > > query = """ > select cast(sum(t1.id) as int) as id, max(t1.type) as > type,cast(tumble_start(t1.time1, interval '4' second) as bigint) as rowtime > from source1 t1 > group by tumble(t1.time1, interval '4' second) > """ > count_result = st_env.sql_query(query) > st_env.create_temporary_view('final_result', count_result) > query2 = """ > select t1.id,t2.type,t1.rowtime from final_result t1 > left join dim_mysql t2 on t1.type=t2.id > """ > count_result2 = st_env.sql_query(query2) > st_env.create_temporary_view('final_result2', count_result2) > > > st_env.sql_update("insert into flink_result select > id,type,rowtime from final_result2") > st_env.execute("2-from_kafka_to_kafka") > > > > > > def register_rides_source(st_env): > source_ddl = \ > """ > create table source1( > id int, > time2 varchar , > time1 as TO_TIMESTAMP(time2,'yyyyMMddHHmmss'), > type string, > WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND > ) with ( > 'connector.type' = 'kafka', > 'connector.topic' = 'tp1', > 'connector.startup-mode' = 'latest-offset', > 'connector.properties.bootstrap.servers' = 'localhost:9092', > 'connector.properties.zookeeper.connect' = 'localhost:2181', > 'format.type' = 'json', > 'connector.version' = 'universal' > ) > """ > st_env.sql_update(source_ddl) > > > def register_mysql_source(st_env): > source_ddl = \ > """ > CREATE TABLE dim_mysql ( > id varchar, -- > type varchar -- > ) WITH ( > 'connector.type' = 'jdbc', > 'connector.url' = 'jdbc:mysql://localhost:3390/test', > 'connector.table' = 'flink_test', > 'connector.driver' = 'com.mysql.jdbc.Driver', > 'connector.username' = '****', > 'connector.password' = '*****', > 'connector.lookup.cache.max-rows' = '5000', > 'connector.lookup.cache.ttl' = '10min' > ) > """ > st_env.sql_update(source_ddl) > > > def register_rides_sink(st_env): > sink_ddl = \ > """ > CREATE TABLE flink_result ( > id int, > type varchar, > rtime bigint, > primary key(id) > ) WITH ( > with ( > 'connector.type' = 'kafka', > 'connector.topic' = 'tp4', > 'connector.startup-mode' = 'latest-offset', > 'connector.properties.bootstrap.servers' = 'localhost:9092', > 'connector.properties.zookeeper.connect' = 'localhost:2181', > 'format.type' = 'json', > 'connector.version' = 'universal' > ) > ) > """ > st_env.sql_update(sink_ddl) > > > > > if __name__ == '__main__': > from_kafka_to_kafka_demo() > > > > > > ------------------ 原始邮件 ------------------ > 发件人: > "我自己的邮箱" > < > [hidden email]>; > 发送时间: 2020年7月15日(星期三) 下午5:30 > 收件人: "user-zh"<[hidden email]>; > > 主题: 回复: pyflink1.11.0window > > > > 非常感谢! > > > > > ------------------ 原始邮件 ------------------ > 发件人: > "user-zh" > < > [hidden email]>; > 发送时间: 2020年7月15日(星期三) 下午5:23 > 收件人: "user-zh"<[hidden email]>; > > 主题: Re: pyflink1.11.0window > > > > 下面这个例子从kafka读取json格式的数据, 然后做窗口聚合后写入es, 可以参考下代码结构, 修改相应数据字段。 这份代码你本地应该是不能运行的 > > from pyflink.datastream import StreamExecutionEnvironment, > TimeCharacteristic > from pyflink.table import StreamTableEnvironment, DataTypes, > EnvironmentSettings > from pyflink.table.udf import udf > > > @udf(input_types=[DataTypes.INT()], result_type=DataTypes.STRING()) > def platform_code_to_name(code): > return "mobile" if code == 0 else "pc" > > > def log_processing(): > env = StreamExecutionEnvironment.get_execution_environment() > > env.set_stream_time_characteristic(TimeCharacteristic.EventTime) > env_settings = > EnvironmentSettings.Builder().use_blink_planner().build() > t_env = > StreamTableEnvironment.create(stream_execution_environment=env, > environment_settings=env_settings) > > source_ddl = """ > CREATE TABLE > payment_msg( > > createTime VARCHAR, > > rt as TO_TIMESTAMP(createTime), > > orderId BIGINT, > > payAmount DOUBLE, > > payPlatform INT, > > paySource INT, > > WATERMARK FOR rt as rt - INTERVAL '2' SECOND > ) WITH ( > > 'connector.type' = 'kafka', > > 'connector.version' = 'universal', > > 'connector.topic' = 'payment_msg_2', > > 'connector.properties.bootstrap.servers' = '0.0.0.0:9092', > ' > connector.properties.group.id' = 'test_3', > > 'connector.startup-mode' = 'latest-offset', > > 'format.type' = 'json' > ) > """ > t_env.sql_update(source_ddl) > > es_sink_ddl = """ > CREATE TABLE > es_sink ( > platform > VARCHAR, > pay_amount > DOUBLE, > rowtime > TIMESTAMP(3) > ) with ( > > 'connector.type' = 'elasticsearch', > > 'connector.version' = '7', > > 'connector.hosts' = '<a href="http://localhost:9200'">http://localhost:9200', > > 'connector.index' = 'platform_pay_amount_1', > > 'connector.document-type' = 'payment', > > 'update-mode' = 'upsert', > > 'connector.flush-on-checkpoint' = 'true', > > 'connector.key-delimiter' = '$', > > 'connector.key-null-literal' = 'n/a', > > 'connector.bulk-flush.max-size' = '42mb', > > 'connector.bulk-flush.max-actions' = '32', > > 'connector.bulk-flush.interval' = '1000', > > 'connector.bulk-flush.backoff.delay' = '1000', > > 'format.type' = 'json' > ) > """ > > t_env.sql_update(es_sink_ddl) > > t_env.register_function('platformcodetoname', > platform_code_to_name) > > query = """ > select platformcodetoname(payPlatform) as platform, > sum(payAmount) > as pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) > as rowtime > from payment_msg > group by tumble(rt, interval '5' seconds), payPlatform > """ > > count_result = t_env.sql_query(query) > > t_env.create_temporary_view('windowed_values', count_result) > > query2 = """ > select platform, last_value(pay_amount), rowtime from > windowed_values group by platform, rowtime > """ > > final_result = t_env.sql_query(query2) > > final_result.execute_insert(table_path='es_sink') > > > if __name__ == '__main__': > log_processing() > > > 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 下午4:40写道: > > > &nbsp;Shuiqiang,你好: > > &nbsp; &nbsp; > > > &nbsp;hi,能否请求您贡献一下完整的代码的案例,我是初学者,官网的2-from_kafka_to_kafka.py这个没有窗口,我现在想要一个在此基础上有窗口的demo,尝试编了很久也未能解决。我在给这个demo加上窗口功能后总是有各种各样的问题,十分痛苦,如能帮助,感激不尽。 > > > > > > 恳请所有看到此封邮件的大佬! > > > > > > 谢谢! > > > > > > > > > > ------------------&nbsp;原始邮件&nbsp;------------------ > > 发件人: > > > "user-zh" > > > < > > [hidden email]&gt;; > > 发送时间:&nbsp;2020年7月15日(星期三) 中午11:25 > > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > > > 主题:&nbsp;Re: pyflink1.11.0window > > > > > > > > 举个sql例子 > > select platformcodetoname(payPlatform) as platform, sum(payAmount) as > > pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as > > rowtime > > from payment_msg group by tumble(rt, interval '5' seconds), > payPlatform > > 这个query 对每5s的tumble窗口做统计。 > > > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月15日周三 上午11:10写道: > > > > &gt; Shuiqiang,你好: > > &gt; &amp;nbsp; > > &amp;nbsp;我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? > > &gt; > > &gt; > > &gt; > ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > > &gt; 发件人: > > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > > "user-zh" > > > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > > < > > &gt; [hidden email]&amp;gt;; > > &gt; 发送时间:&amp;nbsp;2020年7月15日(星期三) 上午10:51 > > &gt; 收件人:&amp;nbsp;"user-zh"<[hidden email] > &amp;gt;; > > &gt; > > &gt; 主题:&amp;nbsp;Re: pyflink1.11.0window > > &gt; > > &gt; > > &gt; > > &gt; 琴师你好, > > &gt; 异常栈信息org.apache.flink.table.api.ValidationException: A > tumble window > > &gt; expects a size value literal. > > &gt; 看起来是接下tumble window定义的代码不太正确吧 > > &gt; > > &gt; Best, > > &gt; Shuiqiang > > &gt; > > &gt; 奇怪的不朽琴师 <[hidden email]&amp;gt; 于2020年7月15日周三 > 上午10:27写道: > > &gt; > > &gt; &amp;gt; 你好: > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > > &gt; &amp;gt; > > &gt; > > > &amp;amp;nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > > &gt; &amp;gt; Traceback (most recent call last): > > &gt; &amp;gt; &amp;amp;nbsp; File "tou.py", line 71, in > <module&amp;amp;gt; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > from_kafka_to_kafka_demo() > > &gt; &amp;gt; &amp;amp;nbsp; File "tou.py", line 21, in > > from_kafka_to_kafka_demo > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; .select(" > id,&amp;amp;nbsp; > > time1 , time1 ")\ > > &gt; &amp;gt; &amp;amp;nbsp; File > > &gt; &amp;gt; > > "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line > > &gt; 907, > > &gt; &amp;gt; in select > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; return > > Table(self._j_table.select(fields), > > &gt; self._t_env) > > &gt; &amp;gt; &amp;amp;nbsp; File > > &gt; > "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > > &gt; &amp;gt; line 1286, in __call__ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; answer, > self.gateway_client, > > self.target_id, > > &gt; self.name) > > &gt; &amp;gt; &amp;amp;nbsp; File > > &gt; &amp;gt; > > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", > > &gt; line > > &gt; &amp;gt; 147, in deco > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; return > f(*a, **kw) > > &gt; &amp;gt; &amp;amp;nbsp; File > > &gt; "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > > &gt; &amp;gt; line 328, in get_return_value > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > format(target_id, ".", name), > > value) > > &gt; &amp;gt; py4j.protocol.Py4JJavaError: An error occurred > while calling > > &gt; o26.select. > > &gt; &amp;gt; : > org.apache.flink.table.api.ValidationException: A tumble > > window > > &gt; expects > > &gt; &amp;gt; a size value literal. > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; java.lang.reflect.Method.invoke(Method.java:498) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; &amp;gt; > > &gt; > > > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > at > > &gt; java.lang.Thread.run(Thread.java:748) > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; def register_rides_source(st_env): > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > source_ddl = \ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; """ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; create > table source1( > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;id int, > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;time1 timestamp, > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;type string, > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;WATERMARK FOR > > time1 as time1 - > > &gt; INTERVAL '2' SECOND > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;) with ( > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.type' = 'kafka', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'update-mode' = 'append', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.topic' = 'tp1', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > > 'connector.properties.bootstrap.servers' = > > &gt; 'localhost:9092', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > > 'connector.properties.zookeeper.connect' = > > &gt; 'localhost:2181', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'format.type' = 'json', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'format.derive-schema' = > > 'true', > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.version' = > > 'universal' > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp;) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; """ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > st_env.sql_update(source_ddl) > > &gt; &amp;gt; > > &gt; &amp;gt; &amp;amp;nbsp; > &amp;amp;nbsp;&amp;amp;nbsp; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env = > > &gt; &amp;gt; > StreamExecutionEnvironment.get_execution_environment() > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > s_env.set_parallelism(1) > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env = > > StreamTableEnvironment.create(s_env) > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > register_rides_source(st_env) > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > register_rides_sink(st_env) > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > st_env.from_path("source1")\ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > &gt; &amp;gt; > .window(Tumble.over("2.secends").on("time1").alias("w")) \ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > .group_by("w") \ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > .select(" id,&amp;amp;nbsp; > > &gt; time1 , time1 ")\ > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &amp;amp;nbsp; &amp;amp;nbsp; > > .insert_into("sink1") > > &gt; &amp;gt; &amp;amp;nbsp; > &amp;amp;nbsp;&amp;amp;nbsp; > > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > > st_env.execute("2-from_kafka_to_kafka") > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; 代码如上 > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > > ------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ > > &gt; &amp;gt; 发件人: > > &gt; > > > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > > &gt; "user-zh" > > &gt; > > > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > > &gt; < > > &gt; &amp;gt; [hidden email]&amp;amp;gt;; > > &gt; &amp;gt; 发送时间:&amp;amp;nbsp;2020年7月10日(星期五) 上午9:17 > > &gt; &amp;gt; 收件人:&amp;amp;nbsp;"user-zh"< > [hidden email] > > &amp;amp;gt;; > > &gt; &amp;gt; > > &gt; &amp;gt; 主题:&amp;amp;nbsp;Re: pyflink1.11.0window > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; > > &gt; &amp;gt; 琴师你好, > > &gt; &amp;gt; > > &gt; &amp;gt; 你的source ddl里有指定time1为 time attribute吗? > > &gt; &amp;gt; create table source1( > > &gt; &amp;gt; > > &gt; > > > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > > id > > &gt; int, > > &gt; &amp;gt; > > &gt; > > > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > > &gt; time1 timestamp, > > &gt; &amp;gt; > > &gt; > > > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > > type > > &gt; string, > > &gt; &amp;gt; > > &gt; > > > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > > &gt; WATERMARK FOR time1 as time1 - > > &gt; &amp;gt; INTERVAL '2' SECOND > > &gt; &amp;gt; ) with (...) > > &gt; &amp;gt; > > &gt; &amp;gt; 奇怪的不朽琴师 <[hidden email]&amp;amp;gt; > 于2020年7月10日周五 > > 上午8:43写道: > > &gt; &amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; > > > ------------------&amp;amp;amp;nbsp;原始邮件&amp;amp;amp;nbsp;------------------ > > &gt; &amp;gt; &amp;amp;gt; 发件人: > > &gt; &amp;gt; > > &gt; > > > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > > &gt; &amp;gt; "奇怪的不朽琴师" > > &gt; &amp;gt; > > &gt; > > > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > > &gt; &amp;gt; < > > &gt; &amp;gt; &amp;amp;gt; [hidden email] > &amp;amp;amp;gt;; > > &gt; &amp;gt; &amp;amp;gt; > 发送时间:&amp;amp;amp;nbsp;2020年7月9日(星期四) 下午5:08 > > &gt; &amp;gt; &amp;amp;gt; > 收件人:&amp;amp;amp;nbsp;"godfrey he"< > > [hidden email] > > &gt; &amp;amp;amp;gt;; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > 主题:&amp;amp;amp;nbsp;pyflink1.11.0window > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; 你好: > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > > &gt; &amp;gt; &amp;amp;gt; : > > org.apache.flink.table.api.ValidationException: A group > > &gt; window > > &gt; &amp;gt; expects a > > &gt; &amp;gt; &amp;amp;gt; time attribute for grouping in > a stream > > environment. > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > > &gt; &amp;gt; &amp;amp;gt; 代码如下 > > &gt; &amp;gt; &amp;amp;gt; 谢谢 > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; def from_kafka_to_kafka_demo(): > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; s_env = > > &gt; &amp;gt; &amp;amp;gt; > > StreamExecutionEnvironment.get_execution_environment() > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > s_env.set_parallelism(1) > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; # use > > blink table planner > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; st_env = > > &gt; StreamTableEnvironment.create(s_env) > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; # > > register source and sink > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > register_rides_source(st_env) > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > register_rides_sink(st_env) > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > st_env.from_path("source1")\ > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > > &gt; &amp;gt; &amp;amp;gt; > > .window(Tumble.over("1.secends").on("time1").alias("w")) \ > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > > &gt; .group_by("w") \ > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > > &gt; .select(" id,&amp;amp;amp;nbsp; > > &gt; &amp;gt; time1 , time1 ")\ > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > > &gt; .insert_into("sink1") > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &gt; st_env.execute("2-from_kafka_to_kafka") > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; def > register_rides_source(st_env): > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > source_ddl = \ > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; ''' > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; create > > table source1( > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > > &gt; id int, > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp;time1 timestamp, > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp;type string > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp;) with ( > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > 'connector.type' = 'kafka', > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > 'update-mode' = 'append', > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > 'connector.topic' = 'tp1', > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &gt; 'connector.properties.bootstrap.servers' = > > &gt; &amp;gt; 'localhost:9092' > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp;) > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; ''' > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > st_env.sql_update(source_ddl) > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; def > register_rides_sink(st_env): > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; sink_ddl > > = \ > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; ''' > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; create > > table sink1( > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > > &gt; id int, > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp;time1 timestamp, > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp;time2 timestamp > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp;) with ( > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > 'connector.type' = 'kafka', > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > 'update-mode' = 'append', > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > 'connector.topic' = 'tp3', > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &gt; 'connector.properties.bootstrap.servers' = > > &gt; &amp;gt; 'localhost:9092' > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > &amp;amp;amp;nbsp;) > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; ''' > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > st_env.sql_update(sink_ddl) > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; if __name__ == '__main__': > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; > > from_kafka_to_kafka_demo() > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; > > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; |
In reply to this post by 琴师
Hi,因为你的Sink只支持数据的insert插入,请检查insert 语句
关键报错信息是这一句: “AppendStreamTableSink requires that Table has only insert changes.” [hidden email] 发件人: 奇怪的不朽琴师 发送时间: 2020-07-20 16:23 收件人: user-zh 主题: 回复: pyflink1.11.0window HI : 我现在有一个新的问题,我在此基础上加了一个关联,再写入kafka时报错,如下 Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line 147, in deco return f(*a, **kw) File "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", line 328, in get_return_value format(target_id, ".", name), value) py4j.protocol.Py4JJavaError: An error occurred while calling o5.sqlUpdate. : org.apache.flink.table.api.TableException: AppendStreamTableSink requires that Table has only insert changes. at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:123) at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:48) at org.apache.flink.table.planner.plan.nodes.exec.ExecNode$class.translateToPlan(ExecNode.scala:58) at org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlan(StreamExecSink.scala:48) at org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:60) at org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:59) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) at scala.collection.Iterator$class.foreach(Iterator.scala:891) at scala.collection.AbstractIterator.foreach(Iterator.scala:1334) at scala.collection.IterableLike$class.foreach(IterableLike.scala:72) at scala.collection.AbstractIterable.foreach(Iterable.scala:54) at scala.collection.TraversableLike$class.map(TraversableLike.scala:234) at scala.collection.AbstractTraversable.map(Traversable.scala:104) at org.apache.flink.table.planner.delegation.StreamPlanner.translateToPlan(StreamPlanner.scala:59) at org.apache.flink.table.planner.delegation.PlannerBase.translate(PlannerBase.scala:153) at org.apache.flink.table.api.internal.TableEnvironmentImpl.translate(TableEnvironmentImpl.java:685) at org.apache.flink.table.api.internal.TableEnvironmentImpl.sqlUpdate(TableEnvironmentImpl.java:495) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) at org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) at org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) at org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) at org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) at org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) at java.lang.Thread.run(Thread.java:748) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "tou.py", line 99, in <module> from_kafka_to_kafka_demo() File "tou.py", line 33, in from_kafka_to_kafka_demo st_env.sql_update("insert into flink_result select id,type,rowtime from final_result2") File "/usr/local/lib/python3.7/site-packages/pyflink/table/table_environment.py", line 547, in sql_update self._j_tenv.sqlUpdate(stmt) File "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", line 1286, in __call__ answer, self.gateway_client, self.target_id, self.name) File "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line 154, in deco raise exception_mapping[exception](s.split(': ', 1)[1], stack_trace) pyflink.util.exceptions.TableException: 'AppendStreamTableSink requires that Table has only insert changes.' 这种应该如何实现,需求大概是一个流表(需要分组汇总)关联一个维表。 from pyflink.datastream import StreamExecutionEnvironment, TimeCharacteristic from pyflink.table import StreamTableEnvironment, DataTypes, EnvironmentSettings,DataTypes, CsvTableSource, CsvTableSink from pyflink.table.descriptors import Schema, Kafka, Json, Rowtime from pyflink.table.window import Tumble def from_kafka_to_kafka_demo(): # use blink table planner env = StreamExecutionEnvironment.get_execution_environment() env.set_stream_time_characteristic(TimeCharacteristic.EventTime) env_settings = EnvironmentSettings.Builder().use_blink_planner().build() st_env = StreamTableEnvironment.create(stream_execution_environment=env,environment_settings=env_settings) # register source and sink register_rides_source(st_env) register_rides_sink(st_env) register_mysql_source(st_env) query = """ select cast(sum(t1.id) as int) as id, max(t1.type) as type,cast(tumble_start(t1.time1, interval '4' second) as bigint) as rowtime from source1 t1 group by tumble(t1.time1, interval '4' second) """ count_result = st_env.sql_query(query) st_env.create_temporary_view('final_result', count_result) query2 = """ select t1.id,t2.type,t1.rowtime from final_result t1 left join dim_mysql t2 on t1.type=t2.id """ count_result2 = st_env.sql_query(query2) st_env.create_temporary_view('final_result2', count_result2) st_env.sql_update("insert into flink_result select id,type,rowtime from final_result2") st_env.execute("2-from_kafka_to_kafka") def register_rides_source(st_env): source_ddl = \ """ create table source1( id int, time2 varchar , time1 as TO_TIMESTAMP(time2,'yyyyMMddHHmmss'), type string, WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND ) with ( 'connector.type' = 'kafka', 'connector.topic' = 'tp1', 'connector.startup-mode' = 'latest-offset', 'connector.properties.bootstrap.servers' = 'localhost:9092', 'connector.properties.zookeeper.connect' = 'localhost:2181', 'format.type' = 'json', 'connector.version' = 'universal' ) """ st_env.sql_update(source_ddl) def register_mysql_source(st_env): source_ddl = \ """ CREATE TABLE dim_mysql ( id varchar, -- type varchar -- ) WITH ( 'connector.type' = 'jdbc', 'connector.url' = 'jdbc:mysql://localhost:3390/test', 'connector.table' = 'flink_test', 'connector.driver' = 'com.mysql.jdbc.Driver', 'connector.username' = '****', 'connector.password' = '*****', 'connector.lookup.cache.max-rows' = '5000', 'connector.lookup.cache.ttl' = '10min' ) """ st_env.sql_update(source_ddl) def register_rides_sink(st_env): sink_ddl = \ """ CREATE TABLE flink_result ( id int, type varchar, rtime bigint, primary key(id) ) WITH ( with ( 'connector.type' = 'kafka', 'connector.topic' = 'tp4', 'connector.startup-mode' = 'latest-offset', 'connector.properties.bootstrap.servers' = 'localhost:9092', 'connector.properties.zookeeper.connect' = 'localhost:2181', 'format.type' = 'json', 'connector.version' = 'universal' ) ) """ st_env.sql_update(sink_ddl) if __name__ == '__main__': from_kafka_to_kafka_demo() ------------------ 原始邮件 ------------------ 发件人: "我自己的邮箱" <[hidden email]>; 发送时间: 2020年7月15日(星期三) 下午5:30 收件人: "user-zh"<[hidden email]>; 主题: 回复: pyflink1.11.0window 非常感谢! ------------------ 原始邮件 ------------------ 发件人: "user-zh" <[hidden email]>; 发送时间: 2020年7月15日(星期三) 下午5:23 收件人: "user-zh"<[hidden email]>; 主题: Re: pyflink1.11.0window 下面这个例子从kafka读取json格式的数据, 然后做窗口聚合后写入es, 可以参考下代码结构, 修改相应数据字段。 这份代码你本地应该是不能运行的 from pyflink.datastream import StreamExecutionEnvironment, TimeCharacteristic from pyflink.table import StreamTableEnvironment, DataTypes, EnvironmentSettings from pyflink.table.udf import udf @udf(input_types=[DataTypes.INT()], result_type=DataTypes.STRING()) def platform_code_to_name(code): return "mobile" if code == 0 else "pc" def log_processing(): env = StreamExecutionEnvironment.get_execution_environment() env.set_stream_time_characteristic(TimeCharacteristic.EventTime) env_settings = EnvironmentSettings.Builder().use_blink_planner().build() t_env = StreamTableEnvironment.create(stream_execution_environment=env, environment_settings=env_settings) source_ddl = """ CREATE TABLE payment_msg( createTime VARCHAR, rt as TO_TIMESTAMP(createTime), orderId BIGINT, payAmount DOUBLE, payPlatform INT, paySource INT, WATERMARK FOR rt as rt - INTERVAL '2' SECOND ) WITH ( 'connector.type' = 'kafka', 'connector.version' = 'universal', 'connector.topic' = 'payment_msg_2', 'connector.properties.bootstrap.servers' = '0.0.0.0:9092', 'connector.properties.group.id' = 'test_3', 'connector.startup-mode' = 'latest-offset', 'format.type' = 'json' ) """ t_env.sql_update(source_ddl) es_sink_ddl = """ CREATE TABLE es_sink ( platform VARCHAR, pay_amount DOUBLE, rowtime TIMESTAMP(3) ) with ( 'connector.type' = 'elasticsearch', 'connector.version' = '7', 'connector.hosts' = '<a href="http://localhost:9200'">http://localhost:9200', 'connector.index' = 'platform_pay_amount_1', 'connector.document-type' = 'payment', 'update-mode' = 'upsert', 'connector.flush-on-checkpoint' = 'true', 'connector.key-delimiter' = '$', 'connector.key-null-literal' = 'n/a', 'connector.bulk-flush.max-size' = '42mb', 'connector.bulk-flush.max-actions' = '32', 'connector.bulk-flush.interval' = '1000', 'connector.bulk-flush.backoff.delay' = '1000', 'format.type' = 'json' ) """ t_env.sql_update(es_sink_ddl) t_env.register_function('platformcodetoname', platform_code_to_name) query = """ select platformcodetoname(payPlatform) as platform, sum(payAmount) as pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as rowtime from payment_msg group by tumble(rt, interval '5' seconds), payPlatform """ count_result = t_env.sql_query(query) t_env.create_temporary_view('windowed_values', count_result) query2 = """ select platform, last_value(pay_amount), rowtime from windowed_values group by platform, rowtime """ final_result = t_env.sql_query(query2) final_result.execute_insert(table_path='es_sink') if __name__ == '__main__': log_processing() 奇怪的不朽琴师 <[hidden email]> 于2020年7月15日周三 下午4:40写道: > &nbsp;Shuiqiang,你好: > &nbsp; &nbsp; > &nbsp;hi,能否请求您贡献一下完整的代码的案例,我是初学者,官网的2-from_kafka_to_kafka.py这个没有窗口,我现在想要一个在此基础上有窗口的demo,尝试编了很久也未能解决。我在给这个demo加上窗口功能后总是有各种各样的问题,十分痛苦,如能帮助,感激不尽。 > > > 恳请所有看到此封邮件的大佬! > > > 谢谢! > > > > > ------------------&nbsp;原始邮件&nbsp;------------------ > 发件人: > "user-zh" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月15日(星期三) 中午11:25 > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > 主题:&nbsp;Re: pyflink1.11.0window > > > > 举个sql例子 > select platformcodetoname(payPlatform) as platform, sum(payAmount) as > pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as > rowtime > from payment_msg group by tumble(rt, interval '5' seconds), payPlatform > 这个query 对每5s的tumble窗口做统计。 > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月15日周三 上午11:10写道: > > &gt; Shuiqiang,你好: > &gt; &amp;nbsp; > &amp;nbsp;我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? > &gt; > &gt; > &gt; ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > &gt; 发件人: > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > "user-zh" > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > < > &gt; [hidden email]&amp;gt;; > &gt; 发送时间:&amp;nbsp;2020年7月15日(星期三) 上午10:51 > &gt; 收件人:&amp;nbsp;"user-zh"<[hidden email]&amp;gt;; > &gt; > &gt; 主题:&amp;nbsp;Re: pyflink1.11.0window > &gt; > &gt; > &gt; > &gt; 琴师你好, > &gt; 异常栈信息org.apache.flink.table.api.ValidationException: A tumble window > &gt; expects a size value literal. > &gt; 看起来是接下tumble window定义的代码不太正确吧 > &gt; > &gt; Best, > &gt; Shuiqiang > &gt; > &gt; 奇怪的不朽琴师 <[hidden email]&amp;gt; 于2020年7月15日周三 上午10:27写道: > &gt; > &gt; &amp;gt; 你好: > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > &gt; &amp;gt; Traceback (most recent call last): > &gt; &amp;gt; &amp;amp;nbsp; File "tou.py", line 71, in <module&amp;amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;nbsp; File "tou.py", line 21, in > from_kafka_to_kafka_demo > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; .select(" id,&amp;amp;nbsp; > time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; &amp;gt; > "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line > &gt; 907, > &gt; &amp;gt; in select > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; return > Table(self._j_table.select(fields), > &gt; self._t_env) > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > &gt; &amp;gt; line 1286, in __call__ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; answer, self.gateway_client, > self.target_id, > &gt; self.name) > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; &amp;gt; > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", > &gt; line > &gt; &amp;gt; 147, in deco > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; return f(*a, **kw) > &gt; &amp;gt; &amp;amp;nbsp; File > &gt; "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > &gt; &amp;gt; line 328, in get_return_value > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; format(target_id, ".", name), > value) > &gt; &amp;gt; py4j.protocol.Py4JJavaError: An error occurred while calling > &gt; o26.select. > &gt; &amp;gt; : org.apache.flink.table.api.ValidationException: A tumble > window > &gt; expects > &gt; &amp;gt; a size value literal. > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; java.lang.reflect.Method.invoke(Method.java:498) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > at > &gt; java.lang.Thread.run(Thread.java:748) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; def register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; source_ddl = \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; create table source1( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;id int, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;type string, > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;WATERMARK FOR > time1 as time1 - > &gt; INTERVAL '2' SECOND > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.properties.bootstrap.servers' = > &gt; 'localhost:9092', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > 'connector.properties.zookeeper.connect' = > &gt; 'localhost:2181', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'format.type' = 'json', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'format.derive-schema' = > 'true', > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; 'connector.version' = > 'universal' > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env.sql_update(source_ddl) > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env = > &gt; &amp;gt; StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; s_env.set_parallelism(1) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env = > StreamTableEnvironment.create(s_env) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; register_rides_sink(st_env) > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > &gt; &amp;gt; .window(Tumble.over("2.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .group_by("w") \ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .select(" id,&amp;amp;nbsp; > &gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; > .insert_into("sink1") > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;nbsp; &amp;amp;nbsp; > st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; 代码如上 > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > ------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ > &gt; &amp;gt; 发件人: > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; "user-zh" > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; < > &gt; &amp;gt; [hidden email]&amp;amp;gt;; > &gt; &amp;gt; 发送时间:&amp;amp;nbsp;2020年7月10日(星期五) 上午9:17 > &gt; &amp;gt; 收件人:&amp;amp;nbsp;"user-zh"<[hidden email] > &amp;amp;gt;; > &gt; &amp;gt; > &gt; &amp;gt; 主题:&amp;amp;nbsp;Re: pyflink1.11.0window > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; 琴师你好, > &gt; &amp;gt; > &gt; &amp;gt; 你的source ddl里有指定time1为 time attribute吗? > &gt; &amp;gt; create table source1( > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > id > &gt; int, > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; time1 timestamp, > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > type > &gt; string, > &gt; &amp;gt; > &gt; > &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; WATERMARK FOR time1 as time1 - > &gt; &amp;gt; INTERVAL '2' SECOND > &gt; &amp;gt; ) with (...) > &gt; &amp;gt; > &gt; &amp;gt; 奇怪的不朽琴师 <[hidden email]&amp;amp;gt; 于2020年7月10日周五 > 上午8:43写道: > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; > ------------------&amp;amp;amp;nbsp;原始邮件&amp;amp;amp;nbsp;------------------ > &gt; &amp;gt; &amp;amp;gt; 发件人: > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; "奇怪的不朽琴师" > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; < > &gt; &amp;gt; &amp;amp;gt; [hidden email]&amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; 发送时间:&amp;amp;amp;nbsp;2020年7月9日(星期四) 下午5:08 > &gt; &amp;gt; &amp;amp;gt; 收件人:&amp;amp;amp;nbsp;"godfrey he"< > [hidden email] > &gt; &amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 主题:&amp;amp;amp;nbsp;pyflink1.11.0window > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 你好: > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > &gt; &amp;gt; &amp;amp;gt; : > org.apache.flink.table.api.ValidationException: A group > &gt; window > &gt; &amp;gt; expects a > &gt; &amp;gt; &amp;amp;gt; time attribute for grouping in a stream > environment. > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > &gt; &amp;gt; &amp;amp;gt; 代码如下 > &gt; &amp;gt; &amp;amp;gt; 谢谢 > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def from_kafka_to_kafka_demo(): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; s_env = > &gt; &amp;gt; &amp;amp;gt; > StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > s_env.set_parallelism(1) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; # use > blink table planner > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; st_env = > &gt; StreamTableEnvironment.create(s_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; # > register source and sink > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_sink(st_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; > .window(Tumble.over("1.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .group_by("w") \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .select(" id,&amp;amp;amp;nbsp; > &gt; &amp;gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .insert_into("sink1") > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > source_ddl = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; create > table source1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;type string > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.sql_update(source_ddl) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def register_rides_sink(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; sink_ddl > = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; create > table sink1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time2 timestamp > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.topic' = 'tp3', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.sql_update(sink_ddl) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; if __name__ == '__main__': > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; |
In reply to this post by Shuiqiang Chen
你好:
他这个会自动转译空格回车啥的符号,暂时没什么好办法,很难受,大佬这边有pyflink的多表关联的demo么,万分感谢! 发送 ------------------ 原始邮件 ------------------ 发件人: "user-zh" <[hidden email]>; 发送时间: 2020年7月20日(星期一) 晚上8:42 收件人: "user-zh"<[hidden email]>; 主题: Re: pyflink1.11.0window 看看异常信息, 是不是你的insert mode没配置对。 BTW, 你粘贴的文本带有很多"&nbsp;", 有点影响可读性。 Best, Shuiqiang 奇怪的不朽琴师 <[hidden email]> 于2020年7月20日周一 下午4:23写道: > HI : > &nbsp; &nbsp; 我现在有一个新的问题,我在此基础上加了一个关联,再写入kafka时报错,如下 > Traceback (most recent call last): > &nbsp; File > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line > 147, in deco > &nbsp; &nbsp; return f(*a, **kw) > &nbsp; File "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > line 328, in get_return_value > &nbsp; &nbsp; format(target_id, ".", name), value) > py4j.protocol.Py4JJavaError: An error occurred while calling o5.sqlUpdate. > : org.apache.flink.table.api.TableException: AppendStreamTableSink > requires that Table has only insert changes. > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:123) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:48) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.plan.nodes.exec.ExecNode$class.translateToPlan(ExecNode.scala:58) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlan(StreamExecSink.scala:48) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:60) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:59) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.Iterator$class.foreach(Iterator.scala:891) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.AbstractIterator.foreach(Iterator.scala:1334) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.IterableLike$class.foreach(IterableLike.scala:72) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.AbstractIterable.foreach(Iterable.scala:54) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.TraversableLike$class.map(TraversableLike.scala:234) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.AbstractTraversable.map(Traversable.scala:104) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.delegation.StreamPlanner.translateToPlan(StreamPlanner.scala:59) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.delegation.PlannerBase.translate(PlannerBase.scala:153) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.api.internal.TableEnvironmentImpl.translate(TableEnvironmentImpl.java:685) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.api.internal.TableEnvironmentImpl.sqlUpdate(TableEnvironmentImpl.java:495) > &nbsp; &nbsp; &nbsp; &nbsp; at > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > &nbsp; &nbsp; &nbsp; &nbsp; at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > &nbsp; &nbsp; &nbsp; &nbsp; at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > &nbsp; &nbsp; &nbsp; &nbsp; at > java.lang.reflect.Method.invoke(Method.java:498) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > &nbsp; &nbsp; &nbsp; &nbsp; at java.lang.Thread.run(Thread.java:748) > > > > > During handling of the above exception, another exception occurred: > > > Traceback (most recent call last): > &nbsp; File "tou.py", line 99, in <module&gt; > &nbsp; &nbsp; from_kafka_to_kafka_demo() > &nbsp; File "tou.py", line 33, in from_kafka_to_kafka_demo > &nbsp; &nbsp; st_env.sql_update("insert into flink_result select > id,type,rowtime from final_result2") > &nbsp; File > "/usr/local/lib/python3.7/site-packages/pyflink/table/table_environment.py", > line 547, in sql_update > &nbsp; &nbsp; self._j_tenv.sqlUpdate(stmt) > &nbsp; File "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > line 1286, in __call__ > &nbsp; &nbsp; answer, self.gateway_client, self.target_id, self.name) > &nbsp; File > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line > 154, in deco > &nbsp; &nbsp; raise exception_mapping[exception](s.split(': ', 1)[1], > stack_trace) > pyflink.util.exceptions.TableException: 'AppendStreamTableSink requires > that Table has only insert changes.' > > > > > > 这种应该如何实现,需求大概是一个流表(需要分组汇总)关联一个维表。 > > > from pyflink.datastream import StreamExecutionEnvironment, > TimeCharacteristic > from pyflink.table import StreamTableEnvironment, DataTypes, > EnvironmentSettings,DataTypes, CsvTableSource, CsvTableSink > from pyflink.table.descriptors import Schema, Kafka, Json, Rowtime > from pyflink.table.window import Tumble&nbsp; > > > > > def from_kafka_to_kafka_demo(): > > > &nbsp; &nbsp; # use blink table planner > &nbsp; &nbsp; env = StreamExecutionEnvironment.get_execution_environment() > &nbsp; &nbsp; > env.set_stream_time_characteristic(TimeCharacteristic.EventTime) > &nbsp; &nbsp; env_settings = > EnvironmentSettings.Builder().use_blink_planner().build() > &nbsp; &nbsp; st_env = > StreamTableEnvironment.create(stream_execution_environment=env,environment_settings=env_settings) > > > &nbsp; &nbsp; # register source and sink > &nbsp; &nbsp; register_rides_source(st_env) > &nbsp; &nbsp; register_rides_sink(st_env) > &nbsp; &nbsp; register_mysql_source(st_env) > > > &nbsp; &nbsp; query = """ > &nbsp; &nbsp; select&nbsp; cast(sum(t1.id) as int) as id, max(t1.type) as > type,cast(tumble_start(t1.time1, interval '4' second) as bigint) as rowtime > &nbsp; &nbsp; from source1 t1&nbsp; > &nbsp; &nbsp; group by tumble(t1.time1, interval '4' second) > &nbsp; &nbsp; """ > &nbsp; &nbsp; count_result = st_env.sql_query(query) > &nbsp; &nbsp; st_env.create_temporary_view('final_result', count_result) > &nbsp; &nbsp; query2 = """ > &nbsp; &nbsp; select&nbsp; t1.id,t2.type,t1.rowtime from final_result t1 > left join dim_mysql t2 on t1.type=t2.id > &nbsp; &nbsp; """ > &nbsp; &nbsp; count_result2 = st_env.sql_query(query2) > &nbsp; &nbsp; st_env.create_temporary_view('final_result2', count_result2) > > > &nbsp; &nbsp; st_env.sql_update("insert into flink_result select > id,type,rowtime from final_result2") > &nbsp; &nbsp; st_env.execute("2-from_kafka_to_kafka") > &nbsp; &nbsp;&nbsp; > > > > > def register_rides_source(st_env): > &nbsp; &nbsp; source_ddl = \ > &nbsp; &nbsp; """ > &nbsp; &nbsp; create table source1( > &nbsp; &nbsp; &nbsp;id int, > &nbsp; &nbsp; &nbsp;time2 varchar , > &nbsp; &nbsp; &nbsp;time1 as TO_TIMESTAMP(time2,'yyyyMMddHHmmss'), > &nbsp; &nbsp; &nbsp;type string, > &nbsp; &nbsp; &nbsp;WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND > &nbsp; &nbsp; &nbsp;) with ( > &nbsp; &nbsp; 'connector.type' = 'kafka', > &nbsp; &nbsp; 'connector.topic' = 'tp1', > &nbsp; &nbsp; 'connector.startup-mode' = 'latest-offset', > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = 'localhost:9092', > &nbsp; &nbsp; 'connector.properties.zookeeper.connect' = 'localhost:2181', > &nbsp; &nbsp; 'format.type' = 'json', > &nbsp; &nbsp; 'connector.version' = 'universal' > &nbsp; &nbsp; &nbsp;) > &nbsp; &nbsp; """ > &nbsp; &nbsp; st_env.sql_update(source_ddl) > > > def register_mysql_source(st_env): > &nbsp; &nbsp; source_ddl = \ > &nbsp; &nbsp; """ > &nbsp; &nbsp; CREATE TABLE dim_mysql ( > &nbsp; &nbsp; id varchar,&nbsp; --&nbsp; > &nbsp; &nbsp; type varchar --&nbsp; > &nbsp; &nbsp; ) WITH ( > &nbsp; &nbsp; 'connector.type' = 'jdbc', > &nbsp; &nbsp; 'connector.url' = 'jdbc:mysql://localhost:3390/test', > &nbsp; &nbsp; 'connector.table' = 'flink_test', > &nbsp; &nbsp; 'connector.driver' = 'com.mysql.jdbc.Driver', > &nbsp; &nbsp; 'connector.username' = '****', > &nbsp; &nbsp; 'connector.password' = '*****', > &nbsp; &nbsp; 'connector.lookup.cache.max-rows' = '5000', > &nbsp; &nbsp; 'connector.lookup.cache.ttl' = '10min' > &nbsp; &nbsp; ) > &nbsp; &nbsp; """&nbsp; &nbsp;&nbsp; > &nbsp; &nbsp; st_env.sql_update(source_ddl) > > > def register_rides_sink(st_env): > &nbsp; &nbsp; sink_ddl = \ > &nbsp; &nbsp; """ > &nbsp; &nbsp; CREATE TABLE flink_result ( > &nbsp; &nbsp; id int,&nbsp; &nbsp; > &nbsp; &nbsp; type varchar, > &nbsp; &nbsp; rtime bigint, > &nbsp; &nbsp; primary key(id) > &nbsp; &nbsp; ) WITH ( > &nbsp; &nbsp; with ( > &nbsp; &nbsp; 'connector.type' = 'kafka', > &nbsp; &nbsp; 'connector.topic' = 'tp4', > &nbsp; &nbsp; 'connector.startup-mode' = 'latest-offset', > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = 'localhost:9092', > &nbsp; &nbsp; 'connector.properties.zookeeper.connect' = 'localhost:2181', > &nbsp; &nbsp; 'format.type' = 'json', > &nbsp; &nbsp; 'connector.version' = 'universal' > &nbsp; &nbsp; &nbsp;) > &nbsp; &nbsp; ) > &nbsp; &nbsp; """ > &nbsp; &nbsp; st_env.sql_update(sink_ddl) > > > > > if __name__ == '__main__': > &nbsp; &nbsp; from_kafka_to_kafka_demo() > > > > > > ------------------&nbsp;原始邮件&nbsp;------------------ > 发件人: > "我自己的邮箱" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月15日(星期三) 下午5:30 > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > 主题:&nbsp;回复: pyflink1.11.0window > > > > &nbsp; &nbsp; &nbsp;非常感谢! > > > > > ------------------ 原始邮件 ------------------ > 发件人: > "user-zh" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月15日(星期三) 下午5:23 > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > 主题:&nbsp;Re: pyflink1.11.0window > > > > 下面这个例子从kafka读取json格式的数据, 然后做窗口聚合后写入es, 可以参考下代码结构, 修改相应数据字段。 这份代码你本地应该是不能运行的 > > from pyflink.datastream import StreamExecutionEnvironment, > TimeCharacteristic > from pyflink.table import StreamTableEnvironment, DataTypes, > EnvironmentSettings > from pyflink.table.udf import udf > > > @udf(input_types=[DataTypes.INT()], result_type=DataTypes.STRING()) > def platform_code_to_name(code): > &nbsp; &nbsp; return "mobile" if code == 0 else "pc" > > > def log_processing(): > &nbsp; &nbsp; env = StreamExecutionEnvironment.get_execution_environment() > &nbsp; &nbsp; > env.set_stream_time_characteristic(TimeCharacteristic.EventTime) > &nbsp; &nbsp; env_settings = > EnvironmentSettings.Builder().use_blink_planner().build() > &nbsp; &nbsp; t_env = > StreamTableEnvironment.create(stream_execution_environment=env, > environment_settings=env_settings) > > &nbsp; &nbsp; source_ddl = """ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; CREATE TABLE > payment_msg( > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; createTime VARCHAR, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; rt as TO_TIMESTAMP(createTime), > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; orderId BIGINT, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; payAmount DOUBLE, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; payPlatform INT, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; paySource INT, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; WATERMARK FOR rt as rt - INTERVAL '2' SECOND > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ) WITH ( > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.type' = 'kafka', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.version' = 'universal', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.topic' = 'payment_msg_2', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.properties.bootstrap.servers' = '0.0.0.0:9092', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ' > connector.properties.group.id' = 'test_3', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.startup-mode' = 'latest-offset', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'format.type' = 'json' > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ) > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; """ > &nbsp; &nbsp; t_env.sql_update(source_ddl) > > &nbsp; &nbsp; es_sink_ddl = """ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; CREATE TABLE > es_sink ( > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; platform > VARCHAR, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; pay_amount > DOUBLE, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; rowtime > TIMESTAMP(3) > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ) with ( > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.type' = 'elasticsearch', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.version' = '7', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.hosts' = '<a href="http://localhost:9200'">http://localhost:9200', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.index' = 'platform_pay_amount_1', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.document-type' = 'payment', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'update-mode' = 'upsert', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.flush-on-checkpoint' = 'true', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.key-delimiter' = '$', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.key-null-literal' = 'n/a', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.bulk-flush.max-size' = '42mb', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.bulk-flush.max-actions' = '32', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.bulk-flush.interval' = '1000', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.bulk-flush.backoff.delay' = '1000', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'format.type' = 'json' > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ) > &nbsp; &nbsp; """ > > &nbsp; &nbsp; t_env.sql_update(es_sink_ddl) > > &nbsp; &nbsp; t_env.register_function('platformcodetoname', > platform_code_to_name) > > &nbsp; &nbsp; query = """ > &nbsp; &nbsp; select platformcodetoname(payPlatform) as platform, > sum(payAmount) > as pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) > as rowtime > &nbsp; &nbsp; from payment_msg > &nbsp; &nbsp; group by tumble(rt, interval '5' seconds), payPlatform > &nbsp; &nbsp; """ > > &nbsp; &nbsp; count_result = t_env.sql_query(query) > > &nbsp; &nbsp; t_env.create_temporary_view('windowed_values', count_result) > > &nbsp; &nbsp; query2 = """ > &nbsp; &nbsp; select platform, last_value(pay_amount), rowtime from > windowed_values group by platform, rowtime > &nbsp; &nbsp; """ > > &nbsp; &nbsp; final_result = t_env.sql_query(query2) > > &nbsp; &nbsp; final_result.execute_insert(table_path='es_sink') > > > if __name__ == '__main__': > &nbsp; &nbsp; log_processing() > > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月15日周三 下午4:40写道: > > &gt; &amp;nbsp;Shuiqiang,你好: > &gt; &amp;nbsp; &amp;nbsp; > &gt; > &amp;nbsp;hi,能否请求您贡献一下完整的代码的案例,我是初学者,官网的2-from_kafka_to_kafka.py这个没有窗口,我现在想要一个在此基础上有窗口的demo,尝试编了很久也未能解决。我在给这个demo加上窗口功能后总是有各种各样的问题,十分痛苦,如能帮助,感激不尽。 > &gt; > &gt; > &gt; 恳请所有看到此封邮件的大佬! > &gt; > &gt; > &gt; 谢谢! > &gt; > &gt; > &gt; > &gt; > &gt; ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > &gt; 发件人: > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; "user-zh" > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; < > &gt; [hidden email]&amp;gt;; > &gt; 发送时间:&amp;nbsp;2020年7月15日(星期三) 中午11:25 > &gt; 收件人:&amp;nbsp;"user-zh"<[hidden email]&amp;gt;; > &gt; > &gt; 主题:&amp;nbsp;Re: pyflink1.11.0window > &gt; > &gt; > &gt; > &gt; 举个sql例子 > &gt; select platformcodetoname(payPlatform) as platform, sum(payAmount) as > &gt; pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as > &gt; rowtime > &gt; from payment_msg group by tumble(rt, interval '5' seconds), > payPlatform > &gt; 这个query 对每5s的tumble窗口做统计。 > &gt; > &gt; 奇怪的不朽琴师 <[hidden email]&amp;gt; 于2020年7月15日周三 上午11:10写道: > &gt; > &gt; &amp;gt; Shuiqiang,你好: > &gt; &amp;gt; &amp;amp;nbsp; > &gt; &amp;amp;nbsp;我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > ------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ > &gt; &amp;gt; 发件人: > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; "user-zh" > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; < > &gt; &amp;gt; [hidden email]&amp;amp;gt;; > &gt; &amp;gt; 发送时间:&amp;amp;nbsp;2020年7月15日(星期三) 上午10:51 > &gt; &amp;gt; 收件人:&amp;amp;nbsp;"user-zh"<[hidden email] > &amp;amp;gt;; > &gt; &amp;gt; > &gt; &amp;gt; 主题:&amp;amp;nbsp;Re: pyflink1.11.0window > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; 琴师你好, > &gt; &amp;gt; 异常栈信息org.apache.flink.table.api.ValidationException: A > tumble window > &gt; &amp;gt; expects a size value literal. > &gt; &amp;gt; 看起来是接下tumble window定义的代码不太正确吧 > &gt; &amp;gt; > &gt; &amp;gt; Best, > &gt; &amp;gt; Shuiqiang > &gt; &amp;gt; > &gt; &amp;gt; 奇怪的不朽琴师 <[hidden email]&amp;amp;gt; 于2020年7月15日周三 > 上午10:27写道: > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;gt; 你好: > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > &gt; &amp;gt; &amp;amp;gt; Traceback (most recent call last): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File "tou.py", line 71, in > <module&amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File "tou.py", line 21, in > &gt; from_kafka_to_kafka_demo > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; .select(" > id,&amp;amp;amp;nbsp; > &gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File > &gt; &amp;gt; &amp;amp;gt; > &gt; "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line > &gt; &amp;gt; 907, > &gt; &amp;gt; &amp;amp;gt; in select > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; return > &gt; Table(self._j_table.select(fields), > &gt; &amp;gt; self._t_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File > &gt; &amp;gt; > "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > &gt; &amp;gt; &amp;amp;gt; line 1286, in __call__ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; answer, > self.gateway_client, > &gt; self.target_id, > &gt; &amp;gt; self.name) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File > &gt; &amp;gt; &amp;amp;gt; > &gt; "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", > &gt; &amp;gt; line > &gt; &amp;gt; &amp;amp;gt; 147, in deco > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; return > f(*a, **kw) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File > &gt; &amp;gt; "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > &gt; &amp;gt; &amp;amp;gt; line 328, in get_return_value > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > format(target_id, ".", name), > &gt; value) > &gt; &amp;gt; &amp;amp;gt; py4j.protocol.Py4JJavaError: An error occurred > while calling > &gt; &amp;gt; o26.select. > &gt; &amp;gt; &amp;amp;gt; : > org.apache.flink.table.api.ValidationException: A tumble > &gt; window > &gt; &amp;gt; expects > &gt; &amp;gt; &amp;amp;gt; a size value literal. > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; java.lang.reflect.Method.invoke(Method.java:498) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; java.lang.Thread.run(Thread.java:748) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > source_ddl = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; create > table source1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;type string, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;WATERMARK FOR > &gt; time1 as time1 - > &gt; &amp;gt; INTERVAL '2' SECOND > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; 'localhost:9092', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.zookeeper.connect' = > &gt; &amp;gt; 'localhost:2181', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'format.type' = 'json', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'format.derive-schema' = > &gt; 'true', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.version' = > &gt; 'universal' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.sql_update(source_ddl) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; s_env = > &gt; &amp;gt; &amp;amp;gt; > StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > s_env.set_parallelism(1) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; st_env = > &gt; StreamTableEnvironment.create(s_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_sink(st_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; > .window(Tumble.over("2.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .group_by("w") \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .select(" id,&amp;amp;amp;nbsp; > &gt; &amp;gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .insert_into("sink1") > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 代码如上 > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; > ------------------&amp;amp;amp;nbsp;原始邮件&amp;amp;amp;nbsp;------------------ > &gt; &amp;gt; &amp;amp;gt; 发件人: > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; "user-zh" > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; < > &gt; &amp;gt; &amp;amp;gt; [hidden email]&amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; 发送时间:&amp;amp;amp;nbsp;2020年7月10日(星期五) 上午9:17 > &gt; &amp;gt; &amp;amp;gt; 收件人:&amp;amp;amp;nbsp;"user-zh"< > [hidden email] > &gt; &amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 主题:&amp;amp;amp;nbsp;Re: pyflink1.11.0window > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 琴师你好, > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 你的source ddl里有指定time1为 time attribute吗? > &gt; &amp;gt; &amp;amp;gt; create table source1( > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; id > &gt; &amp;gt; int, > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; type > &gt; &amp;gt; string, > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; WATERMARK FOR time1 as time1 - > &gt; &amp;gt; &amp;amp;gt; INTERVAL '2' SECOND > &gt; &amp;gt; &amp;amp;gt; ) with (...) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 奇怪的不朽琴师 <[hidden email]&amp;amp;amp;gt; > 于2020年7月10日周五 > &gt; 上午8:43写道: > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; > &gt; > ------------------&amp;amp;amp;amp;nbsp;原始邮件&amp;amp;amp;amp;nbsp;------------------ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; 发件人: > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;gt;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; "奇怪的不朽琴师" > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;gt;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; < > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; [hidden email] > &amp;amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > 发送时间:&amp;amp;amp;amp;nbsp;2020年7月9日(星期四) 下午5:08 > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > 收件人:&amp;amp;amp;amp;nbsp;"godfrey he"< > &gt; [hidden email] > &gt; &amp;gt; &amp;amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > 主题:&amp;amp;amp;amp;nbsp;pyflink1.11.0window > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; 你好: > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; : > &gt; org.apache.flink.table.api.ValidationException: A group > &gt; &amp;gt; window > &gt; &amp;gt; &amp;amp;gt; expects a > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; time attribute for grouping in > a stream > &gt; environment. > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; 代码如下 > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; 谢谢 > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; def from_kafka_to_kafka_demo(): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; s_env = > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; s_env.set_parallelism(1) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; # use > &gt; blink table planner > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; st_env = > &gt; &amp;gt; StreamTableEnvironment.create(s_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; # > &gt; register source and sink > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; register_rides_sink(st_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; .window(Tumble.over("1.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; .group_by("w") \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; .select(" id,&amp;amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; .insert_into("sink1") > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; def > register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; source_ddl = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; create > &gt; table source1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;type string > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; &amp;amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; st_env.sql_update(source_ddl) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; def > register_rides_sink(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; sink_ddl > &gt; = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; create > &gt; table sink1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;time2 timestamp > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'connector.topic' = 'tp3', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; &amp;amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; st_env.sql_update(sink_ddl) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; if __name__ == '__main__': > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; |
Hi,
你这个报错信息主要原因是kafkaTableSink是属于AppendStreamTableSink,而你的上一级数据源final_result2是由前面source1表group by得到的final_result与mysql维表join后而来,经过group by之后的StreamTable 已经变为RetractStreamTableSink,所以这里才会报错 请查阅有关AppendStreamTableSink、RetractStreamTableSink的资料。 关于文中出现 “ ” ,可以换一个邮箱编辑器。 希望能帮助到你 [hidden email] 发件人: 奇怪的不朽琴师 发送时间: 2020-07-21 10:23 收件人: user-zh 主题: 回复: pyflink1.11.0window 你好: 他这个会自动转译空格回车啥的符号,暂时没什么好办法,很难受,大佬这边有pyflink的多表关联的demo么,万分感谢! 发送 ------------------ 原始邮件 ------------------ 发件人: "user-zh" <[hidden email]>; 发送时间: 2020年7月20日(星期一) 晚上8:42 收件人: "user-zh"<[hidden email]>; 主题: Re: pyflink1.11.0window 看看异常信息, 是不是你的insert mode没配置对。 BTW, 你粘贴的文本带有很多"&nbsp;", 有点影响可读性。 Best, Shuiqiang 奇怪的不朽琴师 <[hidden email]> 于2020年7月20日周一 下午4:23写道: > HI : > &nbsp; &nbsp; 我现在有一个新的问题,我在此基础上加了一个关联,再写入kafka时报错,如下 > Traceback (most recent call last): > &nbsp; File > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line > 147, in deco > &nbsp; &nbsp; return f(*a, **kw) > &nbsp; File "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > line 328, in get_return_value > &nbsp; &nbsp; format(target_id, ".", name), value) > py4j.protocol.Py4JJavaError: An error occurred while calling o5.sqlUpdate. > : org.apache.flink.table.api.TableException: AppendStreamTableSink > requires that Table has only insert changes. > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:123) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlanInternal(StreamExecSink.scala:48) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.plan.nodes.exec.ExecNode$class.translateToPlan(ExecNode.scala:58) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecSink.translateToPlan(StreamExecSink.scala:48) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:60) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.delegation.StreamPlanner$$anonfun$translateToPlan$1.apply(StreamPlanner.scala:59) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.Iterator$class.foreach(Iterator.scala:891) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.AbstractIterator.foreach(Iterator.scala:1334) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.IterableLike$class.foreach(IterableLike.scala:72) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.AbstractIterable.foreach(Iterable.scala:54) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.TraversableLike$class.map(TraversableLike.scala:234) > &nbsp; &nbsp; &nbsp; &nbsp; at > scala.collection.AbstractTraversable.map(Traversable.scala:104) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.delegation.StreamPlanner.translateToPlan(StreamPlanner.scala:59) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.planner.delegation.PlannerBase.translate(PlannerBase.scala:153) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.api.internal.TableEnvironmentImpl.translate(TableEnvironmentImpl.java:685) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.table.api.internal.TableEnvironmentImpl.sqlUpdate(TableEnvironmentImpl.java:495) > &nbsp; &nbsp; &nbsp; &nbsp; at > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > &nbsp; &nbsp; &nbsp; &nbsp; at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > &nbsp; &nbsp; &nbsp; &nbsp; at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > &nbsp; &nbsp; &nbsp; &nbsp; at > java.lang.reflect.Method.invoke(Method.java:498) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > &nbsp; &nbsp; &nbsp; &nbsp; at > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > &nbsp; &nbsp; &nbsp; &nbsp; at java.lang.Thread.run(Thread.java:748) > > > > > During handling of the above exception, another exception occurred: > > > Traceback (most recent call last): > &nbsp; File "tou.py", line 99, in <module&gt; > &nbsp; &nbsp; from_kafka_to_kafka_demo() > &nbsp; File "tou.py", line 33, in from_kafka_to_kafka_demo > &nbsp; &nbsp; st_env.sql_update("insert into flink_result select > id,type,rowtime from final_result2") > &nbsp; File > "/usr/local/lib/python3.7/site-packages/pyflink/table/table_environment.py", > line 547, in sql_update > &nbsp; &nbsp; self._j_tenv.sqlUpdate(stmt) > &nbsp; File "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > line 1286, in __call__ > &nbsp; &nbsp; answer, self.gateway_client, self.target_id, self.name) > &nbsp; File > "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", line > 154, in deco > &nbsp; &nbsp; raise exception_mapping[exception](s.split(': ', 1)[1], > stack_trace) > pyflink.util.exceptions.TableException: 'AppendStreamTableSink requires > that Table has only insert changes.' > > > > > > 这种应该如何实现,需求大概是一个流表(需要分组汇总)关联一个维表。 > > > from pyflink.datastream import StreamExecutionEnvironment, > TimeCharacteristic > from pyflink.table import StreamTableEnvironment, DataTypes, > EnvironmentSettings,DataTypes, CsvTableSource, CsvTableSink > from pyflink.table.descriptors import Schema, Kafka, Json, Rowtime > from pyflink.table.window import Tumble&nbsp; > > > > > def from_kafka_to_kafka_demo(): > > > &nbsp; &nbsp; # use blink table planner > &nbsp; &nbsp; env = StreamExecutionEnvironment.get_execution_environment() > &nbsp; &nbsp; > env.set_stream_time_characteristic(TimeCharacteristic.EventTime) > &nbsp; &nbsp; env_settings = > EnvironmentSettings.Builder().use_blink_planner().build() > &nbsp; &nbsp; st_env = > StreamTableEnvironment.create(stream_execution_environment=env,environment_settings=env_settings) > > > &nbsp; &nbsp; # register source and sink > &nbsp; &nbsp; register_rides_source(st_env) > &nbsp; &nbsp; register_rides_sink(st_env) > &nbsp; &nbsp; register_mysql_source(st_env) > > > &nbsp; &nbsp; query = """ > &nbsp; &nbsp; select&nbsp; cast(sum(t1.id) as int) as id, max(t1.type) as > type,cast(tumble_start(t1.time1, interval '4' second) as bigint) as rowtime > &nbsp; &nbsp; from source1 t1&nbsp; > &nbsp; &nbsp; group by tumble(t1.time1, interval '4' second) > &nbsp; &nbsp; """ > &nbsp; &nbsp; count_result = st_env.sql_query(query) > &nbsp; &nbsp; st_env.create_temporary_view('final_result', count_result) > &nbsp; &nbsp; query2 = """ > &nbsp; &nbsp; select&nbsp; t1.id,t2.type,t1.rowtime from final_result t1 > left join dim_mysql t2 on t1.type=t2.id > &nbsp; &nbsp; """ > &nbsp; &nbsp; count_result2 = st_env.sql_query(query2) > &nbsp; &nbsp; st_env.create_temporary_view('final_result2', count_result2) > > > &nbsp; &nbsp; st_env.sql_update("insert into flink_result select > id,type,rowtime from final_result2") > &nbsp; &nbsp; st_env.execute("2-from_kafka_to_kafka") > &nbsp; &nbsp;&nbsp; > > > > > def register_rides_source(st_env): > &nbsp; &nbsp; source_ddl = \ > &nbsp; &nbsp; """ > &nbsp; &nbsp; create table source1( > &nbsp; &nbsp; &nbsp;id int, > &nbsp; &nbsp; &nbsp;time2 varchar , > &nbsp; &nbsp; &nbsp;time1 as TO_TIMESTAMP(time2,'yyyyMMddHHmmss'), > &nbsp; &nbsp; &nbsp;type string, > &nbsp; &nbsp; &nbsp;WATERMARK FOR time1 as time1 - INTERVAL '2' SECOND > &nbsp; &nbsp; &nbsp;) with ( > &nbsp; &nbsp; 'connector.type' = 'kafka', > &nbsp; &nbsp; 'connector.topic' = 'tp1', > &nbsp; &nbsp; 'connector.startup-mode' = 'latest-offset', > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = 'localhost:9092', > &nbsp; &nbsp; 'connector.properties.zookeeper.connect' = 'localhost:2181', > &nbsp; &nbsp; 'format.type' = 'json', > &nbsp; &nbsp; 'connector.version' = 'universal' > &nbsp; &nbsp; &nbsp;) > &nbsp; &nbsp; """ > &nbsp; &nbsp; st_env.sql_update(source_ddl) > > > def register_mysql_source(st_env): > &nbsp; &nbsp; source_ddl = \ > &nbsp; &nbsp; """ > &nbsp; &nbsp; CREATE TABLE dim_mysql ( > &nbsp; &nbsp; id varchar,&nbsp; --&nbsp; > &nbsp; &nbsp; type varchar --&nbsp; > &nbsp; &nbsp; ) WITH ( > &nbsp; &nbsp; 'connector.type' = 'jdbc', > &nbsp; &nbsp; 'connector.url' = 'jdbc:mysql://localhost:3390/test', > &nbsp; &nbsp; 'connector.table' = 'flink_test', > &nbsp; &nbsp; 'connector.driver' = 'com.mysql.jdbc.Driver', > &nbsp; &nbsp; 'connector.username' = '****', > &nbsp; &nbsp; 'connector.password' = '*****', > &nbsp; &nbsp; 'connector.lookup.cache.max-rows' = '5000', > &nbsp; &nbsp; 'connector.lookup.cache.ttl' = '10min' > &nbsp; &nbsp; ) > &nbsp; &nbsp; """&nbsp; &nbsp;&nbsp; > &nbsp; &nbsp; st_env.sql_update(source_ddl) > > > def register_rides_sink(st_env): > &nbsp; &nbsp; sink_ddl = \ > &nbsp; &nbsp; """ > &nbsp; &nbsp; CREATE TABLE flink_result ( > &nbsp; &nbsp; id int,&nbsp; &nbsp; > &nbsp; &nbsp; type varchar, > &nbsp; &nbsp; rtime bigint, > &nbsp; &nbsp; primary key(id) > &nbsp; &nbsp; ) WITH ( > &nbsp; &nbsp; with ( > &nbsp; &nbsp; 'connector.type' = 'kafka', > &nbsp; &nbsp; 'connector.topic' = 'tp4', > &nbsp; &nbsp; 'connector.startup-mode' = 'latest-offset', > &nbsp; &nbsp; 'connector.properties.bootstrap.servers' = 'localhost:9092', > &nbsp; &nbsp; 'connector.properties.zookeeper.connect' = 'localhost:2181', > &nbsp; &nbsp; 'format.type' = 'json', > &nbsp; &nbsp; 'connector.version' = 'universal' > &nbsp; &nbsp; &nbsp;) > &nbsp; &nbsp; ) > &nbsp; &nbsp; """ > &nbsp; &nbsp; st_env.sql_update(sink_ddl) > > > > > if __name__ == '__main__': > &nbsp; &nbsp; from_kafka_to_kafka_demo() > > > > > > ------------------&nbsp;原始邮件&nbsp;------------------ > 发件人: > "我自己的邮箱" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月15日(星期三) 下午5:30 > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > 主题:&nbsp;回复: pyflink1.11.0window > > > > &nbsp; &nbsp; &nbsp;非常感谢! > > > > > ------------------ 原始邮件 ------------------ > 发件人: > "user-zh" > < > [hidden email]&gt;; > 发送时间:&nbsp;2020年7月15日(星期三) 下午5:23 > 收件人:&nbsp;"user-zh"<[hidden email]&gt;; > > 主题:&nbsp;Re: pyflink1.11.0window > > > > 下面这个例子从kafka读取json格式的数据, 然后做窗口聚合后写入es, 可以参考下代码结构, 修改相应数据字段。 这份代码你本地应该是不能运行的 > > from pyflink.datastream import StreamExecutionEnvironment, > TimeCharacteristic > from pyflink.table import StreamTableEnvironment, DataTypes, > EnvironmentSettings > from pyflink.table.udf import udf > > > @udf(input_types=[DataTypes.INT()], result_type=DataTypes.STRING()) > def platform_code_to_name(code): > &nbsp; &nbsp; return "mobile" if code == 0 else "pc" > > > def log_processing(): > &nbsp; &nbsp; env = StreamExecutionEnvironment.get_execution_environment() > &nbsp; &nbsp; > env.set_stream_time_characteristic(TimeCharacteristic.EventTime) > &nbsp; &nbsp; env_settings = > EnvironmentSettings.Builder().use_blink_planner().build() > &nbsp; &nbsp; t_env = > StreamTableEnvironment.create(stream_execution_environment=env, > environment_settings=env_settings) > > &nbsp; &nbsp; source_ddl = """ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; CREATE TABLE > payment_msg( > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; createTime VARCHAR, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; rt as TO_TIMESTAMP(createTime), > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; orderId BIGINT, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; payAmount DOUBLE, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; payPlatform INT, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; paySource INT, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; WATERMARK FOR rt as rt - INTERVAL '2' SECOND > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ) WITH ( > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.type' = 'kafka', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.version' = 'universal', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.topic' = 'payment_msg_2', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.properties.bootstrap.servers' = '0.0.0.0:9092', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ' > connector.properties.group.id' = 'test_3', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'connector.startup-mode' = 'latest-offset', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; > 'format.type' = 'json' > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ) > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; """ > &nbsp; &nbsp; t_env.sql_update(source_ddl) > > &nbsp; &nbsp; es_sink_ddl = """ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; CREATE TABLE > es_sink ( > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; platform > VARCHAR, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; pay_amount > DOUBLE, > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; rowtime > TIMESTAMP(3) > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ) with ( > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.type' = 'elasticsearch', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.version' = '7', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.hosts' = '<a href="http://localhost:9200'">http://localhost:9200', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.index' = 'platform_pay_amount_1', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.document-type' = 'payment', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'update-mode' = 'upsert', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.flush-on-checkpoint' = 'true', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.key-delimiter' = '$', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.key-null-literal' = 'n/a', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.bulk-flush.max-size' = '42mb', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.bulk-flush.max-actions' = '32', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.bulk-flush.interval' = '1000', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'connector.bulk-flush.backoff.delay' = '1000', > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; 'format.type' = 'json' > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ) > &nbsp; &nbsp; """ > > &nbsp; &nbsp; t_env.sql_update(es_sink_ddl) > > &nbsp; &nbsp; t_env.register_function('platformcodetoname', > platform_code_to_name) > > &nbsp; &nbsp; query = """ > &nbsp; &nbsp; select platformcodetoname(payPlatform) as platform, > sum(payAmount) > as pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) > as rowtime > &nbsp; &nbsp; from payment_msg > &nbsp; &nbsp; group by tumble(rt, interval '5' seconds), payPlatform > &nbsp; &nbsp; """ > > &nbsp; &nbsp; count_result = t_env.sql_query(query) > > &nbsp; &nbsp; t_env.create_temporary_view('windowed_values', count_result) > > &nbsp; &nbsp; query2 = """ > &nbsp; &nbsp; select platform, last_value(pay_amount), rowtime from > windowed_values group by platform, rowtime > &nbsp; &nbsp; """ > > &nbsp; &nbsp; final_result = t_env.sql_query(query2) > > &nbsp; &nbsp; final_result.execute_insert(table_path='es_sink') > > > if __name__ == '__main__': > &nbsp; &nbsp; log_processing() > > > 奇怪的不朽琴师 <[hidden email]&gt; 于2020年7月15日周三 下午4:40写道: > > &gt; &amp;nbsp;Shuiqiang,你好: > &gt; &amp;nbsp; &amp;nbsp; > &gt; > &amp;nbsp;hi,能否请求您贡献一下完整的代码的案例,我是初学者,官网的2-from_kafka_to_kafka.py这个没有窗口,我现在想要一个在此基础上有窗口的demo,尝试编了很久也未能解决。我在给这个demo加上窗口功能后总是有各种各样的问题,十分痛苦,如能帮助,感激不尽。 > &gt; > &gt; > &gt; 恳请所有看到此封邮件的大佬! > &gt; > &gt; > &gt; 谢谢! > &gt; > &gt; > &gt; > &gt; > &gt; ------------------&amp;nbsp;原始邮件&amp;nbsp;------------------ > &gt; 发件人: > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; "user-zh" > &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > &nbsp; < > &gt; [hidden email]&amp;gt;; > &gt; 发送时间:&amp;nbsp;2020年7月15日(星期三) 中午11:25 > &gt; 收件人:&amp;nbsp;"user-zh"<[hidden email]&amp;gt;; > &gt; > &gt; 主题:&amp;nbsp;Re: pyflink1.11.0window > &gt; > &gt; > &gt; > &gt; 举个sql例子 > &gt; select platformcodetoname(payPlatform) as platform, sum(payAmount) as > &gt; pay_amount, cast(tumble_start(rt, interval '5' seconds) as BIGINT) as > &gt; rowtime > &gt; from payment_msg group by tumble(rt, interval '5' seconds), > payPlatform > &gt; 这个query 对每5s的tumble窗口做统计。 > &gt; > &gt; 奇怪的不朽琴师 <[hidden email]&amp;gt; 于2020年7月15日周三 上午11:10写道: > &gt; > &gt; &amp;gt; Shuiqiang,你好: > &gt; &amp;gt; &amp;amp;nbsp; > &gt; &amp;amp;nbsp;我的目的是每间隔一段时间做一次汇总统计,比如每两秒做一下汇总,请问这个需求我改如何定义window? > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > ------------------&amp;amp;nbsp;原始邮件&amp;amp;nbsp;------------------ > &gt; &amp;gt; 发件人: > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; "user-zh" > &gt; > &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; > &gt; < > &gt; &amp;gt; [hidden email]&amp;amp;gt;; > &gt; &amp;gt; 发送时间:&amp;amp;nbsp;2020年7月15日(星期三) 上午10:51 > &gt; &amp;gt; 收件人:&amp;amp;nbsp;"user-zh"<[hidden email] > &amp;amp;gt;; > &gt; &amp;gt; > &gt; &amp;gt; 主题:&amp;amp;nbsp;Re: pyflink1.11.0window > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; > &gt; &amp;gt; 琴师你好, > &gt; &amp;gt; 异常栈信息org.apache.flink.table.api.ValidationException: A > tumble window > &gt; &amp;gt; expects a size value literal. > &gt; &amp;gt; 看起来是接下tumble window定义的代码不太正确吧 > &gt; &amp;gt; > &gt; &amp;gt; Best, > &gt; &amp;gt; Shuiqiang > &gt; &amp;gt; > &gt; &amp;gt; 奇怪的不朽琴师 <[hidden email]&amp;amp;gt; 于2020年7月15日周三 > 上午10:27写道: > &gt; &amp;gt; > &gt; &amp;gt; &amp;amp;gt; 你好: > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;我按着你回复的建议改了source但是会报新的错误,请问这个是因为什么?我想调试一个window一直没有成功,请帮帮我,谢谢。 > &gt; &amp;gt; &amp;amp;gt; Traceback (most recent call last): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File "tou.py", line 71, in > <module&amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File "tou.py", line 21, in > &gt; from_kafka_to_kafka_demo > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; .select(" > id,&amp;amp;amp;nbsp; > &gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File > &gt; &amp;gt; &amp;amp;gt; > &gt; "/usr/local/lib/python3.7/site-packages/pyflink/table/table.py", line > &gt; &amp;gt; 907, > &gt; &amp;gt; &amp;amp;gt; in select > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; return > &gt; Table(self._j_table.select(fields), > &gt; &amp;gt; self._t_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File > &gt; &amp;gt; > "/usr/local/lib/python3.7/site-packages/py4j/java_gateway.py", > &gt; &amp;gt; &amp;amp;gt; line 1286, in __call__ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; answer, > self.gateway_client, > &gt; self.target_id, > &gt; &amp;gt; self.name) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File > &gt; &amp;gt; &amp;amp;gt; > &gt; "/usr/local/lib/python3.7/site-packages/pyflink/util/exceptions.py", > &gt; &amp;gt; line > &gt; &amp;gt; &amp;amp;gt; 147, in deco > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; return > f(*a, **kw) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; File > &gt; &amp;gt; "/usr/local/lib/python3.7/site-packages/py4j/protocol.py", > &gt; &amp;gt; &amp;amp;gt; line 328, in get_return_value > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > format(target_id, ".", name), > &gt; value) > &gt; &amp;gt; &amp;amp;gt; py4j.protocol.Py4JJavaError: An error occurred > while calling > &gt; &amp;gt; o26.select. > &gt; &amp;gt; &amp;amp;gt; : > org.apache.flink.table.api.ValidationException: A tumble > &gt; window > &gt; &amp;gt; expects > &gt; &amp;gt; &amp;amp;gt; a size value literal. > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.getAsValueLiteral(AggregateOperationFactory.java:384) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.validateAndCreateTumbleWindow(AggregateOperationFactory.java:302) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.AggregateOperationFactory.createResolvedWindow(AggregateOperationFactory.java:236) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.operations.utils.OperationTreeBuilder.windowAggregate(OperationTreeBuilder.java:250) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:794) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.table.api.internal.TableImpl$WindowGroupedTableImpl.select(TableImpl.java:781) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; java.lang.reflect.Method.invoke(Method.java:498) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; at > &gt; &amp;gt; java.lang.Thread.run(Thread.java:748) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; def register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > source_ddl = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; create > table source1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;type string, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;WATERMARK FOR > &gt; time1 as time1 - > &gt; &amp;gt; INTERVAL '2' SECOND > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; 'localhost:9092', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; 'connector.properties.zookeeper.connect' = > &gt; &amp;gt; 'localhost:2181', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'format.type' = 'json', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'format.derive-schema' = > &gt; 'true', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > 'connector.version' = > &gt; 'universal' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; """ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.sql_update(source_ddl) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; s_env = > &gt; &amp;gt; &amp;amp;gt; > StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > s_env.set_parallelism(1) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; st_env = > &gt; StreamTableEnvironment.create(s_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > register_rides_sink(st_env) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; > .window(Tumble.over("2.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .group_by("w") \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .select(" id,&amp;amp;amp;nbsp; > &gt; &amp;gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; .insert_into("sink1") > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;nbsp; &amp;amp;amp;nbsp; > &gt; st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 代码如上 > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; > ------------------&amp;amp;amp;nbsp;原始邮件&amp;amp;amp;nbsp;------------------ > &gt; &amp;gt; &amp;amp;gt; 发件人: > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; "user-zh" > &gt; &amp;gt; > &gt; > &amp;amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; > &gt; &amp;gt; < > &gt; &amp;gt; &amp;amp;gt; [hidden email]&amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; 发送时间:&amp;amp;amp;nbsp;2020年7月10日(星期五) 上午9:17 > &gt; &amp;gt; &amp;amp;gt; 收件人:&amp;amp;amp;nbsp;"user-zh"< > [hidden email] > &gt; &amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 主题:&amp;amp;amp;nbsp;Re: pyflink1.11.0window > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 琴师你好, > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 你的source ddl里有指定time1为 time attribute吗? > &gt; &amp;gt; &amp;amp;gt; create table source1( > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; id > &gt; &amp;gt; int, > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; type > &gt; &amp;gt; string, > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; WATERMARK FOR time1 as time1 - > &gt; &amp;gt; &amp;amp;gt; INTERVAL '2' SECOND > &gt; &amp;gt; &amp;amp;gt; ) with (...) > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; 奇怪的不朽琴师 <[hidden email]&amp;amp;amp;gt; > 于2020年7月10日周五 > &gt; 上午8:43写道: > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; > &gt; > ------------------&amp;amp;amp;amp;nbsp;原始邮件&amp;amp;amp;amp;nbsp;------------------ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; 发件人: > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;gt;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; "奇怪的不朽琴师" > &gt; &amp;gt; &amp;amp;gt; > &gt; &amp;gt; > &gt; > &amp;amp;amp;gt;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; < > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; [hidden email] > &amp;amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > 发送时间:&amp;amp;amp;amp;nbsp;2020年7月9日(星期四) 下午5:08 > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > 收件人:&amp;amp;amp;amp;nbsp;"godfrey he"< > &gt; [hidden email] > &gt; &amp;gt; &amp;amp;amp;amp;gt;; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > 主题:&amp;amp;amp;amp;nbsp;pyflink1.11.0window > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; 你好: > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;我在使用pyflink1.11版本时,window开窗仍会报错 > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; : > &gt; org.apache.flink.table.api.ValidationException: A group > &gt; &amp;gt; window > &gt; &amp;gt; &amp;amp;gt; expects a > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; time attribute for grouping in > a stream > &gt; environment. > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > 请问这个问题没有修复么?或者是我使用的方式不对,如果是使用不对,能提供一个正确的案例么? > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; 代码如下 > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; 谢谢 > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; def from_kafka_to_kafka_demo(): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; s_env = > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; StreamExecutionEnvironment.get_execution_environment() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; s_env.set_parallelism(1) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; # use > &gt; blink table planner > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; st_env = > &gt; &amp;gt; StreamTableEnvironment.create(s_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; # > &gt; register source and sink > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; register_rides_source(st_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; register_rides_sink(st_env) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; st_env.from_path("source1")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; .window(Tumble.over("1.secends").on("time1").alias("w")) \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; .group_by("w") \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; .select(" id,&amp;amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; time1 , time1 ")\ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; .insert_into("sink1") > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; st_env.execute("2-from_kafka_to_kafka") > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; def > register_rides_source(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; source_ddl = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; create > &gt; table source1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;type string > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'connector.topic' = 'tp1', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; &amp;amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; st_env.sql_update(source_ddl) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; def > register_rides_sink(st_env): > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; sink_ddl > &gt; = \ > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; create > &gt; table sink1( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; id int, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;time1 timestamp, > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;time2 timestamp > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;) with ( > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'connector.type' = 'kafka', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'update-mode' = 'append', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; 'connector.topic' = 'tp3', > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;gt; 'connector.properties.bootstrap.servers' = > &gt; &amp;gt; &amp;amp;gt; 'localhost:9092' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; &amp;amp;amp;amp;nbsp;) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; ''' > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; st_env.sql_update(sink_ddl) > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; if __name__ == '__main__': > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; > &gt; from_kafka_to_kafka_demo() > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; > &gt; &amp;gt; &amp;amp;gt; &amp;amp;amp;gt; &amp;amp;amp;amp;nbsp; > &amp;amp;amp;amp;nbsp; |
Free forum by Nabble | Edit this page |