flink table api

Yuan_CSDF發表於2020-12-30

1.flink 環境各種api


  def oldFlinkBatchTable(): BatchTableEnvironment = {
    val batchEnv = ExecutionEnvironment.getExecutionEnvironment
    val oldBatchTableEnv = BatchTableEnvironment.create(batchEnv)
    oldBatchTableEnv
  }

  def oldFlinkStreamTable(): StreamTableEnvironment = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    val settings = EnvironmentSettings.newInstance()
      .useOldPlanner()
      .inStreamingMode()
      .build()
    val oldStreamTableEnv = StreamTableEnvironment.create(env, settings)
    oldStreamTableEnv

  }

  def blinkBatchTable(): TableEnvironment = {
    val blinkBatchSettings = EnvironmentSettings.newInstance()
      .useBlinkPlanner()
      .inBatchMode()
      .build()
    val blinkBatchTableEnv = TableEnvironment.create(blinkBatchSettings)
    blinkBatchTableEnv
  }

  def blinkStreamTable(): StreamTableEnvironment = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    val blinkStreamSettings = EnvironmentSettings.newInstance()
      .useBlinkPlanner()
      .inStreamingMode()
      .build()
    val blinkStreamTableEnv = StreamTableEnvironment.create(env, blinkStreamSettings)
    blinkStreamTableEnv
  }

2.如果想使用美元符號引入,需要匯入
import org.apache.flink.table.api._

    val dataTable = tableEnv.fromDataStream(dataStream, $"itemId", $"behavior", $"timestamp".rowtime as "ts")

相關文章