【问题标题】:PyFlink - Issue with UNNEST: query uses an unsupported SQL feature?PyFlink - UNNEST 问题:查询使用不受支持的 SQL 功能?
【发布时间】:2020-11-03 16:27:24
【问题描述】:

我正在尝试使用 Table API 中的 UNNEST 函数来展平数组。

我做错了什么还是它不是受支持的功能?这个页面虽然建议它:https://ci.apache.org/projects/flink/flink-docs-master/dev/table/sql/queries.html

谢谢!

代码

Python udf

@udf(input_types=DataTypes.STRING(), result_type=DataTypes.ARRAY(DataTypes.STRING()))
def explode(s):
    return 3*[s]

t_env.register_function("explode", explode)

处理

tab = t_env.from_path('mySource').select("id, explode(dummy) as dummy_list")
t_env.register_table("temp_table", tab)
t_env.sql_query("SELECT t.item as dummy_item FROM UNNEST(select dummy_list from temp_table) AS t(item)").insert_into("mySink")

执行

t_env.execute("dummy_unnest")

错误

TableException: Cannot generate a valid execution plan for the given query: 

LogicalProject(dummy_item=[$0])
  Uncollect
    LogicalProject(EXPR$0=[org$apache$flink$table$functions$python$PythonScalarFunction$908596b4671476ee325743dba92ed6c7($1)])
      LogicalTableScan(table=[[default_catalog, default_database, mySource]])

This exception indicates that the query uses an unsupported SQL feature.
Please check the documentation for the set of currently supported SQL features.

【问题讨论】:

    标签: apache-flink pyflink


    【解决方案1】:

    我认为您可以将查询更改为

    select id, dummy_item from temp_table CROSS JOIN UNNEST(dummy_list) AS t (dummy_item)
    

    【讨论】:

    • :) 以后如果对pyflink有疑问,也可以直接在flink用户邮件列表中提问,得到更及时的答复。
    • 谢谢,我会的。我认为这类问题可能会惠及更广泛的公众。
    猜你喜欢
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 2019-01-27
    • 2018-08-08
    • 2021-11-04
    相关资源
    最近更新 更多