I see where the confusion is coming from, and I apologize for any misunderstanding caused by my previous responses. Let’s address the issue with the correct approach given the limitations you’ve encountered.
In Dataform (Google Cloud), the js {}
block and the config {}
block indeed operate in separate scopes within .sqlx
files. This means variables defined in a js {}
block cannot be directly referenced in the config {}
block as if they were in the same scope. This separation leads to the “dependencies is not defined” error you’re encountering.
Correct Approach for Using JavaScript Variables in Config
Given the scope limitation, the correct approach to dynamically setting configurations based on JavaScript variables involves a slightly different strategy. Since direct reference isn’t possible as you’ve discovered, you would typically use the js {}
block to return the entire configuration object, including any dynamic values you wish to include. However, this pattern applies more to .js
files within Dataform projects rather than .sqlx
files.
Workaround for SQLX Files
For .sqlx
files, since the direct inclusion of JavaScript variables into the config {}
block isn’t supported, you would need to statically define your dependencies within the config {}
block or reconsider the structure of your project to utilize .js
files for dynamic configuration if your use case heavily relies on dynamic dependencies.
If your project’s structure allows for it, moving the dynamic logic to JavaScript files (*.js
) where you can programmatically define and manipulate datasets might be a more flexible approach. Here’s a conceptual example of how you might structure a .js
file:
const dependencies = ["merge_bsi_address_stage"];
const myTableName = "your_table_name";
publish(myTableName, {
type: "view",
query: `SELECT * FROM ${myTableName}`,
tags: ["adsid_tlog"],
dependencies: dependencies
});
This .js
approach allows for the dynamic inclusion of variables in both the query and the configuration, leveraging the full programmability of JavaScript.
For SQLX Files
Given the current limitations, ensure your config {}
block in .sqlx
files contains statically defined values or consider restructuring your Dataform project to utilize .js
files for parts of your pipeline that require dynamic configuration.