Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38aba43

Browse files
committed
Added unique key name as part of compare results
Small fixes and optimizations
1 parent ac042d0 commit 38aba43

4 files changed

Lines changed: 47 additions & 41 deletions

File tree

source/expectations/data_values/ut_compound_data_diff_tmp.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ create global temporary table ut_compound_data_diff_tmp(
1515
diff_id raw(128),
1616
item_no integer,
1717
pk_hash raw(128),
18-
pk_value varchar2(4000),
1918
item_hash raw(128),
2019
duplicate_no integer,
2120
constraint ut_compound_data_diff_tmp_uk1 unique (diff_id,duplicate_no,item_no,item_hash, pk_hash),

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,19 @@ create or replace package body ut_compound_data_helper is
186186

187187
return l_results;
188188
end;
189-
189+
190+
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return varchar2 is
191+
l_pk_value varchar2(4000);
192+
begin
193+
select listagg(extractvalue(xmlelement("ROW",column_value),a_join_by_xpath),':') within group ( order by 1)
194+
into l_pk_value
195+
from table(xmlsequence(extract(a_item_data,'/*/*')));
196+
197+
return l_pk_value;
198+
exception when no_data_found then
199+
return 'null ';
200+
end;
201+
190202
function get_rows_diff(
191203
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
192204
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
@@ -195,15 +207,15 @@ create or replace package body ut_compound_data_helper is
195207
l_column_filter varchar2(32767);
196208
l_results tt_row_diffs;
197209
begin
198-
l_column_filter := get_columns_filter(a_exclude_xpath,a_include_xpath);
210+
l_column_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath);
199211

200212
/**
201213
* Since its unordered search we cannot select max rows from diffs as we miss some comparision records
202214
* We will restrict output on higher level of select
203215
**/
204-
216+
205217
execute immediate q'[
206-
with diff_info as (select item_hash,pk_hash,pk_value from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid)
218+
with diff_info as (select item_hash,pk_hash,pk_value, duplicate_no from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid)
207219
select rn,diff_type,diffed_row,pk_value from
208220
(
209221
select diff_type,diffed_row, dense_rank() over (order by pk_hash) rn,pk_value from
@@ -215,16 +227,17 @@ create or replace package body ut_compound_data_helper is
215227
xmlserialize(content exp.row_data no indent) exp_item,
216228
xmlserialize(content act.row_data no indent) act_item
217229
from
218-
(select ucd.*, row_number() over(partition by pk_hash order by row_hash) duplicate_no
230+
(select ucd.*
219231
from
220232
(select ucd.column_value row_data,
221233
r.item_hash row_hash,
222234
r.pk_hash ,
223-
r.pk_value,
235+
r.duplicate_no,
236+
ucd.column_value.getclobval() col_val,
224237
ucd.column_value.getRootElement() col_name,
225-
ucd.column_value.getclobval() col_val
238+
ut_compound_data_helper.get_pk_value(:join_xpath,r.item_data) pk_value
226239
from
227-
(select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.pk_value
240+
(select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.duplicate_no
228241
from ut_compound_data_tmp ucd,
229242
diff_info i
230243
where ucd.data_id = :self_guid
@@ -234,16 +247,17 @@ create or replace package body ut_compound_data_helper is
234247
) ucd
235248
) exp
236249
join (
237-
select ucd.*, row_number() over(partition by pk_hash order by row_hash) duplicate_no
250+
select ucd.*
238251
from
239252
(select ucd.column_value row_data,
240253
r.item_hash row_hash,
241254
r.pk_hash ,
242-
r.pk_value,
255+
r.duplicate_no,
256+
ucd.column_value.getclobval() col_val,
243257
ucd.column_value.getRootElement() col_name,
244-
ucd.column_value.getclobval() col_val
258+
ut_compound_data_helper.get_pk_value(:join_xpath,r.item_data) pk_value
245259
from
246-
(select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.pk_value
260+
(select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.duplicate_no
247261
from ut_compound_data_tmp ucd,
248262
diff_info i
249263
where ucd.data_id = :other_guid
@@ -252,7 +266,8 @@ create or replace package body ut_compound_data_helper is
252266
table( xmlsequence( extract(r.item_data,'/*/*') ) ) ucd
253267
) ucd
254268
) act
255-
on exp.pk_hash = act.pk_hash and exp.duplicate_no = act.duplicate_no
269+
on exp.pk_hash = act.pk_hash and exp.col_name = act.col_name
270+
and exp.duplicate_no = act.duplicate_no
256271
where dbms_lob.compare(exp.col_val, act.col_val) != 0
257272
)
258273
unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') )
@@ -261,15 +276,17 @@ create or replace package body ut_compound_data_helper is
261276
select case when exp.pk_hash is null then 'Extra:' else 'Missing:' end as diff_type,
262277
xmlserialize(content nvl(exp.item_data, act.item_data) no indent) diffed_row,
263278
coalesce(exp.pk_hash,act.pk_hash) pk_hash,
264-
null pk_value
265-
from (select extract(ucd.item_data,'/*/*') item_data,i.pk_hash
279+
coalesce(exp.pk_value,act.pk_value) pk_value
280+
from (select extract(ucd.item_data,'/*/*') item_data,i.pk_hash,
281+
ut_compound_data_helper.get_pk_value(:join_by,item_data) pk_value
266282
from ut_compound_data_tmp ucd,
267283
diff_info i
268284
where ucd.data_id = :self_guid
269285
and ucd.item_hash = i.item_hash
270286
) exp
271287
full outer join (
272-
select extract(ucd.item_data,'/*/*') item_data,i.pk_hash
288+
select extract(ucd.item_data,'/*/*') item_data,i.pk_hash,
289+
ut_compound_data_helper.get_pk_value(:join_by,item_data) pk_value
273290
from ut_compound_data_tmp ucd,
274291
diff_info i
275292
where ucd.data_id = :other_guid
@@ -282,10 +299,13 @@ create or replace package body ut_compound_data_helper is
282299
]'
283300
bulk collect into l_results
284301
using a_diff_id,
302+
a_join_by_xpath,
285303
a_exclude_xpath, a_include_xpath, a_expected_dataset_guid,
304+
a_join_by_xpath,
286305
a_exclude_xpath, a_include_xpath, a_actual_dataset_guid,
287-
a_expected_dataset_guid, a_actual_dataset_guid,
306+
a_join_by_xpath,a_expected_dataset_guid,a_join_by_xpath, a_actual_dataset_guid,
288307
a_max_rows;
308+
289309
return l_results;
290310
end;
291311

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ create or replace package ut_compound_data_helper authid definer is
6060
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
6161
) return tt_row_diffs;
6262

63+
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return varchar2;
64+
6365
function get_rows_diff(
6466
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
6567
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,6 @@ create or replace type body ut_compound_data_value as
251251
l_row_diffs ut_compound_data_helper.tt_row_diffs;
252252
c_max_rows constant integer := 20;
253253

254-
function get_pk_value(a_join_by_xpath varchar2) return varchar2 is
255-
l_column varchar2(32767);
256-
begin
257-
/* due to possibility of key being to columns we cannot use xmlextractvalue
258-
usage of xmlagg is possible however it greatly complicates code and performance is impacted.
259-
xpath to be looked at or regex
260-
*/
261-
if a_join_by_xpath is not null then
262-
l_column := ' extract(t.item_data,:join_by_xpath).GetStringVal() pk_value ';
263-
else
264-
l_column := ' :join_by_xpath pk_value';
265-
end if;
266-
return l_column;
267-
end;
268-
269254
function get_column_pk_hash(a_join_by_xpath varchar2) return varchar2 is
270255
l_column varchar2(32767);
271256
begin
@@ -313,35 +298,35 @@ create or replace type body ut_compound_data_value as
313298
using a_exclude_xpath, a_include_xpath,a_join_by_xpath,self.data_id, l_other.data_id;
314299

315300
/* Peform minus on two sets two get diffrences that will be used later on to print results */
316-
execute immediate 'insert into ' || l_ut_owner || '.ut_compound_data_diff_tmp ( diff_id,item_hash,pk_hash,duplicate_no,pk_value)
301+
execute immediate 'insert into ' || l_ut_owner || '.ut_compound_data_diff_tmp ( diff_id,item_hash,pk_hash,duplicate_no)
317302
with source_data as
318303
( select t.data_id,t.item_hash,row_number() over (partition by t.pk_hash,t.item_hash,t.data_id order by 1,2) duplicate_no,
319-
pk_hash, '||get_pk_value(a_join_by_xpath)||'
304+
pk_hash
320305
from ' || l_ut_owner || '.ut_compound_data_tmp t
321306
where data_id = :self_guid or data_id = :other_guid
322307
)
323-
select distinct :diff_id,tmp.item_hash,tmp.pk_hash,tmp.duplicate_no,pk_value
308+
select distinct :diff_id,tmp.item_hash,tmp.pk_hash,tmp.duplicate_no
324309
from(
325310
(
326-
select t.item_hash,t. duplicate_no,t.pk_hash, t.pk_value
311+
select t.item_hash,t. duplicate_no,t.pk_hash
327312
from source_data t
328313
where t.data_id = :self_guid
329314
minus
330-
select t.item_hash,t. duplicate_no,t.pk_hash, t.pk_value
315+
select t.item_hash,t. duplicate_no,t.pk_hash
331316
from source_data t
332317
where t.data_id = :other_guid
333318
)
334319
union all
335320
(
336-
select t.item_hash,t. duplicate_no,t.pk_hash, t.pk_value
321+
select t.item_hash,t. duplicate_no,t.pk_hash
337322
from source_data t
338323
where t.data_id = :other_guid
339324
minus
340-
select t.item_hash,t. duplicate_no,t.pk_hash, t.pk_value
325+
select t.item_hash,t. duplicate_no,t.pk_hash
341326
from source_data t
342327
where t.data_id = :self_guid
343328
))tmp'
344-
using a_join_by_xpath,self.data_id, l_other.data_id,
329+
using self.data_id, l_other.data_id,
345330
l_diff_id,
346331
self.data_id, l_other.data_id,
347332
l_other.data_id,self.data_id;

0 commit comments

Comments
 (0)