Flink table的scala 代码注意写法,填坑

出现错误:

Error:(13, 34) could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[(Int, String)]
    val batch = bEnv.fromElements((133,"bbb"))

 

是因为scala写法隐式转换的问题,本地验证 stream   batch转成table代码,注意import:

1)stream转table

package com.coder.flink.core.table_sql

import org.apache.flink.streaming.api.scala._
import org.apache.flink.table.api.TableEnvironment
import org.apache.flink.table.api.scala._





//todo 注意import导包。是个坑

object Stream2Table {
  def main(args: Array[String]): Unit = {


    val env = StreamExecutionEnvironment.getExecutionEnvironment


    //todo 创建tableEnv
    val tableEnv = TableEnvironment.getTableEnvironment(env)
    val stream =  env.fromElements((192,"aa"))

    tableEnv.registerDataStream("myTable2", stream, 'myLong, 'myString)

    val tapiResult = tableEnv.scan("myTable2")
    tapiResult.printSchema()

  }
}

 

 

2)batch转table:

 

package com.coder.flink.core.table_sql

import org.apache.flink.table.api.scala._
import org.apache.flink.api.scala._
import org.apache.flink.table.api.TableEnvironment


object batch2Table {
  def main(args: Array[String]): Unit = {
    val bEnv =ExecutionEnvironment.getExecutionEnvironment
    val  batchEnv = TableEnvironment.getTableEnvironment(bEnv)
    val batch = bEnv.fromElements((133,"bbb"))
    batchEnv.registerDataSet("table1",batch)
    batchEnv.registerDataSet("table2",batch,'field1,'field2)

    val tapiResult = batchEnv.scan("table2")
    tapiResult.printSchema()
  }
}

你可能感兴趣的:(scala,Flink)