/* check if the destination already has a list of processed ids
if not we will process all loads with status 0 (==success) */
{{ "{%" }} set active_ids_exist = adapter.get_relation(
        database=this.database ,
        schema=this.schema,
        identifier="{{ processed_load_id_table_name }}" ) {{ "%}" }}

SELECT {{ c_load_id }} FROM {{ "{{" }}  source('raw_data', '{{ t_dlt_loads }}') {{ "}}" }}
WHERE {{ c_status }} = 0
/* exclude already processed load_ids */
{{ "{%" }} if active_ids_exist and not should_full_refresh() {{ "%}" }}
AND {{ c_load_id }} NOT IN (SELECT {{ c_load_id }} FROM {{ "{{" }} source('transformed_data', '{{ processed_load_id_table_name }}') {{ "}}" }})
{{ "{%" }} endif {{ "%}" }}
