若要在 Python 中定义视图,请应用 @temporary_view
修饰器。 与 @table
修饰器一样,可以将 Lakeflow 声明性管道中的视图用于静态或流式处理数据集。
注释
较旧的 dlt
模块使用 @view
修饰器来定义临时视图。 Databricks 建议使用 pyspark.pipelines
模块(导入为) dp
和 @temporary_view
修饰器来定义临时视图。
下面是使用 Python 定义视图的语法:
Syntax
from pyspark import pipelines as dp
@dp.view(
name="<name>",
comment="<comment>")
@dp.expect(...)
def <function-name>():
return (<query>)
参数
参数 | 类型 | Description |
---|---|---|
函数 | function |
必填。 从用户定义的查询返回 Apache Spark 数据帧或流数据帧的函数。 |
name |
str |
表名称。 如果未提供,则默认为函数名称。 |
comment |
str |
表的说明。 |