BX B
06/14/2023, 2:28 PMfrom pyflink.table import EnvironmentSettings, TableEnvironment
from pyflink.table.expressions import *
def log_processing():
env_settings = <http://EnvironmentSettings.in|EnvironmentSettings.in>_streaming_mode()
t_env = TableEnvironment.create(env_settings)
##### specify connector and format jars
t_env.get_config().set("pipeline.jars", "file:///Users/karanbawejapro/Desktop/flink-sql-connector-kafka-1.17.0.jar")
t_env.get_config().set("table.exec.source.idle-timeout", "1000")
source_ddl = """
CREATE TABLE restaurant_live_pending_orders(
rest_id VARCHAR,
status VARCHAR
) WITH (
'connector' = 'kafka',
'topic' = 'live_order_status',
'properties.bootstrap.servers' = 'localhost:9092',
'properties.group.id' = 'rest_group',
'scan.startup.mode' = 'specific-offsets',
'scan.startup.specific-offsets' = 'partition:0,offset:0',
'json.fail-on-missing-field' = 'false',
'json.ignore-parse-errors' = 'true',
'format' = 'json'
)
"""
tbl = t_env.execute_sql(source_ddl)
tbl = t_env.from_path('restaurant_live_pending_orders')BX B
06/14/2023, 3:28 PMtbl = t_env.execute_sql(source_ddl)
tbl = t_env.from_path('restaurant_live_pending_orders')
result = tbl.group_by(col('rest_id')).select(col('rest_id'), col('status').sum.alias('status_count'))
result.execute().print()