Prerequisites
Triggers extend a working data load. Start from data loading, which covers topics, channels, and field calculators.What is a data-operation trigger?
A topic fetches rows from an external source; a trigger does not. Instead, a trigger runs after its ordering predecessors and works against the in-flight transaction:- it reads the rows already changed in the current transaction (the rows a topic just loaded, or the rows an unload just removed), and
- it writes derived rows into the same transaction.
How to implement a trigger
ImplementIDataOperationTrigger:
getInputTables(): the tables the trigger reads. The trigger fires whenever a requested topic feeds one of them, and runs after every topic and trigger that modified them, so it sees their complete content.getOutputTables(): the tables the trigger writes to. The transaction is opened over these tables, in addition to the topics’ target tables, so the trigger’s writes have an open transaction.execute(queryManager, transaction, context): the logic. UsequeryManagerto build the read query,transactionto query the in-flight view and to add or remove rows, andcontextfor the operationscope()andoperationType().
How to register a trigger
Register triggers onconfigurator.triggers() with a unique name. A trigger is not wired to a topic explicitly: it fires and is ordered by the tables it reads (getInputTables()), so it runs whenever a requested topic feeds one of those tables:
How to order a topic after another topic
configurator.topics().orderTopicAfterTopic(topicName, afterTopicName) schedules a topic after another topic and all of the triggers fired by that topic. Use it when one topic must load only once another topic’s rows have been loaded and its triggers have run:
How an operation with triggers runs
Configuring a trigger does not change the default load when nothing is ordered: all requested topics still load together in a single batch. Otherwise, the requested topics and the triggers they fire run in this order:- all currently-unconstrained topics load together in one batch;
- each fired trigger runs, in dependency order, reading the in-flight view and writing into the same transaction;
- any topic ordered after another topic loads once that topic and its triggers have completed.
Triggers and unloading
Triggers run on an unload too. ADlcUnloadRequest removes the rows of its topics through their unload conditions and then, in the same transaction, runs every trigger fired by a table those topics feed, just as a load does. Because a rebuild trigger re-derives its target from the current input rows, the rows it had derived from the now-removed input rows are cleaned up automatically.
This is why the rebuild pattern matters: a trigger that only adds derived rows keeps its derived table correct on load but leaves orphaned rows behind on unload. Clearing the derived rows for the scope before re-deriving keeps the table consistent for both operations. A trigger that must do something different on each can branch on context.operationType().
How to override a solution’s trigger
Trigger names must be unique. To override a pre-defined trigger, replace it under the same name withreplaceTrigger; firing follows the replacement’s own input tables:
Related pages
- Data loading: topics, channels, column renames, and field calculators.