В нашем решении Azure Data Factory v2 есть несколько шагов слияния таблиц БД. Мы объединяем таблицы в одном экземпляре БД Azure SQL Server. Исходные таблицы и таблицы назначения находятся в разных схемах БД. Источники определяются как выбор из одной таблицы или как объединение двух таблиц.
Я сомневаюсь, какой из описанных ниже сценариев лучше с точки зрения производительности.
Сценарий один (на таблицу)
Активность хранимой процедуры вызывает хранимую процедуру, которая выполняет всю работу.
Действие хранимой процедуры в конвейере вызывает эту хранимую процедуру. Добавляет в целевую таблицу все исходные данные. Пример такой хранимой процедуры:
create or alter procedure dwh.fill_lnk_cemvypdet_cemstr2c_table_with_stage_data as
merge
dwh.lnk_cemvypdet_cemstr2c as target
using
(select
t.sa_hashkey cemvypdet_hashkey,
t.sa_timestamp load_date,
t.sa_source record_source,
d.sa_hashkey cemstr2c_hashkey
from
egje.cemvypdet t
join
egje.cemstr2c d
on
t.id_mstr = d.id_mstr)
as source
on target.cemvypdet_hashkey = source.cemvypdet_hashkey
and target.cemstr2c_hashkey = source.cemstr2c_hashkey
when not matched then
insert(
cemvypdet_hashkey,
cemstr2c_hashkey,
record_source,
load_date,
last_seen_date)
values(
source.cemvypdet_hashkey,
source.cemstr2c_hashkey,
source.record_source,
source.load_date,
source.load_date)
when matched then
update set last_seen_date = source.load_date;
Сценарий два (на строку)
Действие Copy объявляет хранимую процедуру для вызова на вкладке Target, чтобы действие вызывало хранимую процедуру для каждой отдельной строки источника.
create or alter procedure dwh.fill_lnk_cemvypdet_cemstr2c_subset_table_row_with_stage_data
@lnk_cemvypdet_cemstr2c_subset dwh.lnk_cemvypdet_cemstr2c_subset_type readonly
as
merge
dwh.lnk_cemvypdet_cemstr2c_subset as target
using
@lnk_cemvypdet_cemstr2c_subset
as source
on target.cemvypdet_hashkey = source.cemvypdet_hashkey
and target.cemstr2c_hashkey = source.cemstr2c_hashkey
when not matched then
insert(
hashkey,
cemvypdet_hashkey,
cemstr2c_hashkey,
record_source,
load_date,
last_seen_date)
values(
source.hashkey,
source.cemvypdet_hashkey,
source.cemstr2c_hashkey,
source.record_source,
source.load_date,
source.load_date)
when matched then
update set last_seen_date = source.load_date;
Тип @ lnk_cemvypdet_cemstr2c_subset определяется как тип таблицы, который следует структуре целевой таблицы.