https://slingdata.io logo
Hi, question about variables. i have a
# sling-help
i
Hi, question about variables. i have a table with a list of tables and parameters , for example limit and hours_back . so one table can be SELECT * FROM {stream_table} WHERE updated_at > COALESCE({incremental_value}, '1900-01-01 00:00:00') - INTERVAL {hours_back} HOUR and updated_at < '{env._sling_loaded_at}' limit {limit} i am working on incremental for 10 tables, i put this on the default of the replication. with a pre hook that bring the variables from the params_table on the target how can i load the variables and use them in the replication ? i managed to do it In a preceding pipeline but then I lose the flexibility of running only one stream (and still get its variables) If it is not possible , is there a way to load the table to environment variables before the replication and then use them in the replication ? Some other option ?
f
hey @itamar s can you share your replication/pipeline config? That will help me reproduce what you're experiencing
i
source: my_source target: my_target defaults: object: '{target.schema}.{stream_table}' mode: incremental # full-refresh | incremental | truncate | snapshot | backfill target_options: add_new_columns: false column_casing: snake # Stream SQL pulls its bounds from the pre-hook result (state.cfg.result[0].*) sql: | SELECT {fields} FROM {stream_table} WHERE updated_at >= COALESCE({incremental_value}, '1900-01-01 00:00:00') - interval '{state.cfg.result[0].hours_back}' hour AND updated_at < '{state.cfg.result[0].cutoff}' ORDER BY updated_at LIMIT {state.cfg.result[0].cycle_limit} hooks: pre: # Fetch the config row for THE_TABLE; its values feed the stream SQL above. - type: query id: cfg connection: my_target query: | SELECT table_name, cycle_limit, hours_back, cutoff FROM zstg.vw_z_refresh WHERE is_active = 1 AND table_name = 'the_table' streams: the_table: primary_key: [id] update_key: updated_at object: '{target.schema}.the_table'