code: def mixing_use_of_datastream_and_table():
      # use StreamTableEnvironment instead of TableEnvironment when mixing use of table & datastream
      env = StreamExecutionEnvironment.get_execution_environment()
      t_env = StreamTableEnvironment.create(
          stream_execution_environment=env
      )
  
      # define the source
      t_env.create_temporary_table(
          "source",
          TableDescriptor.for_connector("datagen")
          .schema(
              Schema.new_builder()
              .column("id", DataTypes.BIGINT())
              .column("data", DataTypes.STRING())
              .build()
          )
          .option("number-of-rows", "10")
          .build(),
      )
  
      # define the sink
      t_env.create_temporary_table(
          "sink",
          TableDescriptor.for_connector("print")
          .schema(
              Schema.new_builder()
              .column("a", DataTypes.BIGINT())
              .build()
          )
          .build(),
      )
  
      @udf(result_type=DataTypes.BIGINT())
      def length(data):
          return len(data)
  
      # perform table api operations
      table = t_env.from_path("source")
      table = table.select(col("id"), length(col("data")))
  
      # convert table to datastream and perform datastream api operations
      ds = t_env.to_data_stream(table)
      ds = ds.map(lambda i: i[0] + i[1], output_type=Types.LONG())
  
      # convert datastream to table and perform table api operations as you want
      table = t_env.from_data_stream(
          ds,
          Schema.new_builder().column("f0", DataTypes.BIGINT()).build(),
      )
  
      # execute
      table.execute_insert("sink").wait()
  
imports: import logging
  import sys
  from pyflink.common import Types
  from pyflink.datastream import StreamExecutionEnvironment
  from pyflink.table import DataTypes, TableDescriptor, Schema, StreamTableEnvironment
  from pyflink.table.expressions import col
  from pyflink.table.udf import udf
label_desc: Use image node_id 1 for calling a global function with example usage: mixing_use_of_datastream_and_table() and returns: len