Dataform中JS publish()依赖声明报错,依赖无法识别求助
问题:dependencies属性声明依赖报错,但ref()函数可正常识别依赖
源文件定义
我的源文件definitions/source/tiktok/advertiser.sqlx声明如下:
config { type: "declaration", schema: "tiktok_ads", name: "advertiser", description: "All advertising accounts from Tiktok" }
报错场景
用JavaScript定义表时,通过dependencies属性直接指定依赖字符串,触发缺失依赖的错误:
publish("tiktok2", { schema: "sample_schema", type: "table", dependencies: ["tiktok_ads.advertiser"], description: "table description" }).query(ctx => ` SELECT advertiser.name AS campaign_advertiser FROM tiktok_ads.advertiser advertiser `)
错误提示
Missing dependency detected: Action "the-brand-usa.sample_schema.tiktok" depends on "{\"name\":\"tiktok_ads.advertiser\",\"includeDependentAssertions\":false}" which does not exist
可行方案
改用ctx.ref()函数在查询中引用表后,系统可正确识别依赖,工作区编译无报错:
publish("tiktok2", { schema: "sample_schema", type: "table", description: "table description" }).query(ctx => ` SELECT advertiser.name AS campaign_advertiser FROM ${ctx.ref("tiktok_ads", "advertiser")} advertiser `)
问题解析
dependencies属性不支持直接传入schema.table格式的字符串作为依赖项,系统无法将其解析为有效的对象引用。而ctx.ref()函数会生成符合系统要求的依赖标识对象,同时自动替换为正确的表名。如果需要显式声明dependencies,应使用ref()的返回值,示例如下:
publish("tiktok2", { schema: "sample_schema", type: "table", dependencies: [ctx.ref("tiktok_ads", "advertiser")], description: "table description" }).query(ctx => ` SELECT advertiser.name AS campaign_advertiser FROM ${ctx.ref("tiktok_ads", "advertiser")} advertiser `)
内容的提问来源于stack exchange,提问作者Scott C.
相关产品推荐
相关产品推荐

