我使用的是 Flink 1.13.0,我有以下简单的代码片段
import org.apache.flink.table.api.bridge.scala.table2RowDataSet
import org.apache.flink.table.api.{EnvironmentSettings, TableEnvironment}
object HelloFlinkBatchTable {
def main(args: Array[String]): Unit = {
val settings = EnvironmentSettings.newInstance().inBatchMode().useBlinkPlanner().build()
val tenv = TableEnvironment.create(settings)
val words = tenv.fromValues("hello", "world", "hadoop", "spark", "world").as("word")
words.collect().foreach(println)
words.printSchema()
tenv.createTemporaryView("words", words)
//collect works on TableResult
val result = tenv.executeSql("select word from words")
result.collect()
//collect doesn't work on the Table
//ERROR:Table cannot be converted into a DataSet. It is not part of a batch table environment.
words.collect()
}
}
我会问为什么 TableResult.collect
有效而 Table.collect
无效(错误是:Table cannot be converted into a DataSet. It is not part of a batch table environment.
)。我想我已经在代码中正确指定了批处理环境。
答案 0 :(得分:2)
隐式转换 table2RowDataSet
实际上已被弃用,但通常很难弃用隐式转换。
DataSet API 即将结束,将在中期完全集成到 TableEnvironment
和 StreamExecutionEnvironment
中。
TableResult.collect
是官方和稳定支持的检索结果方式。其他隐式将在 Flink 1.14 中更新,参见 FLINK-22590。