@@ -417,73 +417,99 @@ create or replace package body ut_compound_data_helper is
417417 l_join_xpath varchar2(32767) := ut_utils.to_xpath(a_join_by_list);
418418 l_results tt_row_diffs;
419419 l_sql varchar2(32767);
420+ l_column_order varchar2(100);
420421 begin
422+ if a_enforce_column_order then
423+ l_column_order := 'col_no';
424+ else
425+ l_column_order := 'col_name';
426+ end if;
421427 l_sql := q'[
422- with exp as (
428+ with
429+ exp_rows as(
430+ select
431+ exp_data_id, extract( exp_item_data, :column_path ) exp_item_data, item_no, diff_id
432+ from ut_compound_data_diff_tmp
433+ where diff_id = :diff_id
434+ and exp_data_id = :self_guid
435+ ),
436+ act_rows as (
437+ select
438+ act_data_id, extract( act_item_data, :column_path ) act_item_data, item_no, diff_id
439+ from ut_compound_data_diff_tmp ucd
440+ where diff_id = :diff_id
441+ and ucd.act_data_id = :other_guid
442+ ),
443+ exp_cols as (
423444 select
424- exp_item_data, exp_data_id, item_no rn, rownum col_no, pk_value ,
445+ exp_item_data, exp_data_id, item_no rn, rownum col_no, diff_id ,
425446 s.column_value col, s.column_value.getRootElement() col_name,
426447 nvl(s.column_value.getclobval(),empty_clob()) col_val
427- from (
428- select
429- exp_data_id, extract( ucd.exp_item_data, :column_path ) exp_item_data, item_no,
430- replace( extract( ucd.exp_item_data, :join_by ).getclobval(), chr(10) ) pk_value
431- from ut_compound_data_diff_tmp ucd
432- where diff_id = :diff_id
433- and ucd.exp_data_id = :self_guid
434- ) i,
435- table( xmlsequence( extract(i.exp_item_data,:extract_path) ) ) s
448+ from exp_rows i,
449+ table( xmlsequence( extract( i.exp_item_data, :extract_path ) ) ) s
436450 ),
437- act as (
451+ act_cols as (
438452 select
439- act_item_data, act_data_id, item_no rn, rownum col_no, pk_value ,
453+ act_item_data, act_data_id, item_no rn, rownum col_no, diff_id ,
440454 s.column_value col, s.column_value.getRootElement() col_name,
441455 nvl(s.column_value.getclobval(),empty_clob()) col_val
456+ from act_rows i,
457+ table( xmlsequence( extract( i.act_item_data, :extract_path ) ) ) s
458+ ),
459+ data_diff as (
460+ select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, null pk_value, col_name, diff_id
442461 from (
443- select
444- act_data_id, extract( ucd.act_item_data, :column_path ) act_item_data, item_no,
445- replace( extract( ucd.act_item_data, :join_by ).getclobval(), chr(10) ) pk_value
446- from ut_compound_data_diff_tmp ucd
447- where diff_id = :diff_id
448- and ucd.act_data_id = :other_guid
449- ) i,
450- table( xmlsequence( extract(i.act_item_data,:extract_path) ) ) s
462+ select nvl(exp.rn, act.rn) rn,
463+ exp.diff_id diff_id,
464+ xmlagg(exp.col order by exp.col_no) exp_item,
465+ xmlagg(act.col order by nvl(exp.col_no, act.col_no)) act_item,
466+ max(nvl(exp.col_name,act.col_name)) col_name
467+ from exp_cols exp
468+ join act_cols act
469+ on exp.rn = act.rn and exp.col_name = act.col_name
470+ where dbms_lob.compare(exp.col_val, act.col_val) != 0
471+ group by nvl(exp.rn, act.rn), exp.diff_id
472+ )
473+ unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') )
474+ ),
475+ unordered_diff as (
476+ select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, null pk_value, col_name, diff_id
477+ from (
478+ select nvl(exp.rn, act.rn) rn,
479+ exp.diff_id diff_id,
480+ xmlagg(exp.col order by exp.col_name) exp_item,
481+ xmlagg(act.col order by act.col_name) act_item,
482+ max(nvl(exp.col_name,act.col_name)) col_name
483+ from exp_cols exp
484+ join act_cols act
485+ on exp.rn = act.rn and exp.col_name = act.col_name
486+ where dbms_lob.compare(exp.col_val, act.col_val) != 0
487+ group by nvl(exp.rn, act.rn), exp.diff_id
488+ )
489+ unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') )
451490 )
452- select rn, diff_type, diffed_row, pk_value pk_value
491+ select rn, diff_type, diffed_row, pk_value
453492 from (
454493 select rn, diff_type, diffed_row, pk_value,
455494 case when diff_type = 'Actual:' then 1 else 2 end rnk,
456495 1 final_order,
457496 col_name
458497 from ( ]'
459498 || case when a_unordered then q'[
460- select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, pk_value, col_name
461- from (
462- select nvl(exp.rn, act.rn) rn,
463- nvl(exp.pk_value, act.pk_value) pk_value,
464- exp.col exp_item,
465- act.col act_item,
466- nvl(exp.col_name,act.col_name) col_name
467- from exp
468- join act
469- on exp.rn = act.rn and exp.col_name = act.col_name
470- where dbms_lob.compare(exp.col_val, act.col_val) != 0
471- )
472- unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') ) ]'
499+ select u.rn, u.diff_type, u.diffed_row,
500+ replace(
501+ extract( case when i.exp_data_id is null then i.act_item_data else i.exp_item_data end, :join_by ).getclobval(),
502+ chr(10)
503+ ) pk_value,
504+ u.col_name
505+ from data_diff u
506+ join ut_compound_data_diff_tmp i
507+ on i.diff_id = u.diff_id
508+ and i.item_no = u.rn]'
473509 else q'[
474- select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, null pk_value, col_name
475- from (
476- select nvl(exp.rn, act.rn) rn,
477- xmlagg(exp.col order by exp.col_no) exp_item,
478- xmlagg(act.col order by act.col_no) act_item,
479- max(nvl(exp.col_name,act.col_name)) col_name
480- from exp exp
481- join act act
482- on exp.rn = act.rn and exp.col_name = act.col_name
483- where dbms_lob.compare(exp.col_val, act.col_val) != 0
484- group by (exp.rn, act.rn)
485- )
486- unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') ) ]'
510+ select rn, diff_type, diffed_row, pk_value, col_name
511+ from data_diff
512+ where :join_by is null ]'
487513 end ||q'[
488514 )
489515 union all
@@ -522,14 +548,13 @@ create or replace package body ut_compound_data_helper is
522548 case when final_order = 1 then to_char(rn) else col_name end,
523549 case when final_order = 1 then to_char(rnk) else col_name end
524550 ]'
525- else
526- null
527551 end;
528552 execute immediate l_sql
529553 bulk collect into l_results
530- using l_exp_extract_xpath, l_join_xpath, a_diff_id, a_expected_dataset_guid,a_extract_path,
531- l_act_extract_xpath, l_join_xpath, a_diff_id, a_actual_dataset_guid,a_extract_path,
532- l_join_xpath, l_join_xpath, a_diff_id;
554+ using l_exp_extract_xpath, a_diff_id, a_expected_dataset_guid,
555+ l_act_extract_xpath, a_diff_id, a_actual_dataset_guid,
556+ a_extract_path, a_extract_path,
557+ l_join_xpath, l_join_xpath, l_join_xpath, a_diff_id;
533558 return l_results;
534559 end;
535560
0 commit comments