diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index e6665bd10..c6a38e35c 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -373,8 +373,7 @@ create or replace package body ut_compound_data_helper is /** * Since its unordered search we cannot select max rows from diffs as we miss some comparision records * We will restrict output on higher level of select - */ - + */ execute immediate q'[with diff_info as (select item_hash,duplicate_no from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid) select duplicate_no, @@ -403,6 +402,7 @@ create or replace package body ut_compound_data_helper is diff_info i where ucd.data_id = :self_guid and ucd.item_hash = i.item_hash + and ucd.duplicate_no = i.duplicate_no ) r, table( xmlsequence( extract(r.item_data,'/*') ) ) ucd ) ucd @@ -417,6 +417,7 @@ create or replace package body ut_compound_data_helper is diff_info i where ucd.data_id = :other_guid and ucd.item_hash = i.item_hash + and ucd.duplicate_no = i.duplicate_no ) r, table( xmlsequence( extract(r.item_data,'/*') ) ) ucd ) ucd diff --git a/source/expectations/data_values/ut_compound_data_value.tpb b/source/expectations/data_values/ut_compound_data_value.tpb index 113c5153e..de81830dd 100644 --- a/source/expectations/data_values/ut_compound_data_value.tpb +++ b/source/expectations/data_values/ut_compound_data_value.tpb @@ -234,6 +234,13 @@ create or replace type body ut_compound_data_value as **/ execute immediate 'merge into ' || l_ut_owner || '.ut_compound_data_tmp tgt using ( + select ucd_out.item_hash, + ucd_out.pk_hash, + ucd_out.item_no, + ucd_out.data_id, + row_number() over (partition by ucd_out.pk_hash,ucd_out.item_hash,ucd_out.data_id order by 1,2) duplicate_no + from + ( select '||l_ut_owner ||'.ut_compound_data_helper.get_hash(ucd.item_data.getclobval()) item_hash, pk_hash, ucd.item_no, ucd.data_id from @@ -242,17 +249,19 @@ create or replace type body ut_compound_data_value as from ' || l_ut_owner || q'[.ut_compound_data_tmp ucd where data_id = :self_guid or data_id = :other_guid ) ucd + )ucd_out ) src on (tgt.item_no = src.item_no and tgt.data_id = src.data_id) when matched then update set tgt.item_hash = src.item_hash, - tgt.pk_hash = src.pk_hash ]' + tgt.pk_hash = src.pk_hash, + tgt.duplicate_no = src.duplicate_no]' using a_exclude_xpath, a_include_xpath,a_join_by_xpath,self.data_id, l_other.data_id; /* Peform minus on two sets two get diffrences that will be used later on to print results */ execute immediate 'insert into ' || l_ut_owner || '.ut_compound_data_diff_tmp ( diff_id,item_hash,pk_hash,duplicate_no) with source_data as - ( 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, + ( select t.data_id,t.item_hash,t.duplicate_no, pk_hash from ' || l_ut_owner || '.ut_compound_data_tmp t where data_id = :self_guid or data_id = :other_guid @@ -260,21 +269,21 @@ create or replace type body ut_compound_data_value as select distinct :diff_id,tmp.item_hash,tmp.pk_hash,tmp.duplicate_no from( ( - select t.item_hash,t. duplicate_no,t.pk_hash + select t.item_hash,t.duplicate_no,t.pk_hash from source_data t where t.data_id = :self_guid minus - select t.item_hash,t. duplicate_no,t.pk_hash + select t.item_hash,t.duplicate_no,t.pk_hash from source_data t where t.data_id = :other_guid ) union all ( - select t.item_hash,t. duplicate_no,t.pk_hash + select t.item_hash,t.duplicate_no,t.pk_hash from source_data t where t.data_id = :other_guid minus - select t.item_hash,t. duplicate_no,t.pk_hash + select t.item_hash,t.duplicate_no,t.pk_hash from source_data t where t.data_id = :self_guid ))tmp' @@ -282,7 +291,7 @@ create or replace type body ut_compound_data_value as l_diff_id, self.data_id, l_other.data_id, l_other.data_id,self.data_id; - --result is OK only if both are same + --result is OK only if both are same if sql%rowcount = 0 and self.elements_count = l_other.elements_count then l_result := 0; else diff --git a/test/core/expectations/test_expectations_cursor.pkb b/test/core/expectations/test_expectations_cursor.pkb index d18cef5fb..fb75b2da8 100644 --- a/test/core/expectations/test_expectations_cursor.pkb +++ b/test/core/expectations/test_expectations_cursor.pkb @@ -1986,6 +1986,38 @@ Diff:% ut.expect(l_actual_message).to_be_like(l_expected_message); end; - + + procedure unordered_fix_764 is + l_actual sys_refcursor; + l_expected sys_refcursor; + l_expected_message varchar2(32767); + l_actual_message varchar2(32767); + begin + open l_expected for + select 'Table' as name from dual + union all + select 'Desk' as name from dual + union all + select 'Table' as name from dual; + + open l_actual for + select 'Desk' as name from dual + union all + select 'Table' as name from dual; + + --Assert + ut3.ut.expect( l_actual ).to_equal( l_expected ).unordered(); + + --Assert + l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 3 ] +%Diff: +%Rows: [ 1 differences ] +%Missing: Table%]'; + l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message; + --Assert + ut.expect(l_actual_message).to_be_like(l_expected_message); + + end; + end; / diff --git a/test/core/expectations/test_expectations_cursor.pks b/test/core/expectations/test_expectations_cursor.pks index a1cff85d9..88d59e1a3 100644 --- a/test/core/expectations/test_expectations_cursor.pks +++ b/test/core/expectations/test_expectations_cursor.pks @@ -315,6 +315,9 @@ create or replace package test_expectations_cursor is --%test(Trying to join on collection element inside record ) procedure compare_rec_coll_as_join; - + + --%test( Unordered fix for issues with duplicate no : #764 ) + procedure unordered_fix_764; + end; /