Hello everyone,
I am currently facing a situation where I am trying to implement a custom MERGE (INCREMENTAL TABLE) with DataForm. Here, I have the primary keys along with two metadata columns: LOAD_BATCH and DRIVER_ACTION_CODE.
My objective is to implement a SQLX Incremental that, given a date, creates an intermediate view that selects occurrences of the PKs for the most recent LOAD_BATCH. Following this, it should apply the MERGE, firstly where DRIVER_ACTION_CODE equals "D" to delete, and then proceed to merge where DRIVER_ACTION_CODE is either "I" or "U".
So far, I have managed to accomplish this using JS with type="operation", but I am looking to do it in a more scalable manner and take advantage of the features that DataForm offers.
Does anyone have any recommendations or tips on how to best achieve this?
Here is my current code:
includes/merge_helper.js
```JavaScript
The idea is do exactly the same steps but with a incremental sqlx or similar...
Looking forward to your responses.
Thank you in advance!
Solved! Go to Solution.
I will try to address each of your questions.
The incremental_where()
function is a Dataform-specific function that is used to filter the data that is loaded into an incremental table. It is used to ensure that only new or updated data is loaded into the table. However, it seems like you're getting an error because the function is not being recognized. This could be because you're not using it correctly. The incremental_where()
function should be used in the SQLX config block like this:
config {
type: "incremental",
...
incremental_where: {
timestamp_field: "load_batch",
comparison: "greater than or equal to"
}
}
In this example, timestamp_field
should be replaced with the name of the field in your table that contains the timestamp or date of each record, and comparison
should be replaced with the comparison operator you want to use to filter the data.
intermediate_view
is returning multiple rows for a single primary key. You might need to modify your intermediate_view
to ensure that it only returns one row for each primary key.The incremental()
macro is a Dataform-specific function that is used to create incremental tables. It works by comparing the data in the source table with the data in the target table and only loading the new or updated records into the target table. You can use it in your SQLX file like this:
${incremental("source_table", ["primary_key"])}
In this example, source_table
should be replaced with the name of your source table, and primary_key
should be replaced with the name of your primary key field.
GRANT
statement in SQL. Here's an example:post_operations {
"GRANT SELECT ON ${self()} TO group_name"
}
In this example, group_name
should be replaced with the name of the group you want to grant access to. Note that this will only work if you have the necessary permissions to grant access to other users or groups.