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

Skip to content

Commit c0e1b38

Browse files
authored
Merge pull request #768 from utPLSQL/fix/fix_to_unordered
fix to unordered.
2 parents db19e30 + e5df0e2 commit c0e1b38

4 files changed

Lines changed: 56 additions & 11 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ create or replace package body ut_compound_data_helper is
373373
/**
374374
* Since its unordered search we cannot select max rows from diffs as we miss some comparision records
375375
* We will restrict output on higher level of select
376-
*/
377-
376+
*/
378377
execute immediate q'[with
379378
diff_info as (select item_hash,duplicate_no from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid)
380379
select duplicate_no,
@@ -403,6 +402,7 @@ create or replace package body ut_compound_data_helper is
403402
diff_info i
404403
where ucd.data_id = :self_guid
405404
and ucd.item_hash = i.item_hash
405+
and ucd.duplicate_no = i.duplicate_no
406406
) r,
407407
table( xmlsequence( extract(r.item_data,'/*') ) ) ucd
408408
) ucd
@@ -417,6 +417,7 @@ create or replace package body ut_compound_data_helper is
417417
diff_info i
418418
where ucd.data_id = :other_guid
419419
and ucd.item_hash = i.item_hash
420+
and ucd.duplicate_no = i.duplicate_no
420421
) r,
421422
table( xmlsequence( extract(r.item_data,'/*') ) ) ucd
422423
) ucd

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ create or replace type body ut_compound_data_value as
234234
**/
235235
execute immediate 'merge into ' || l_ut_owner || '.ut_compound_data_tmp tgt
236236
using (
237+
select ucd_out.item_hash,
238+
ucd_out.pk_hash,
239+
ucd_out.item_no,
240+
ucd_out.data_id,
241+
row_number() over (partition by ucd_out.pk_hash,ucd_out.item_hash,ucd_out.data_id order by 1,2) duplicate_no
242+
from
243+
(
237244
select '||l_ut_owner ||'.ut_compound_data_helper.get_hash(ucd.item_data.getclobval()) item_hash,
238245
pk_hash, ucd.item_no, ucd.data_id
239246
from
@@ -242,47 +249,49 @@ create or replace type body ut_compound_data_value as
242249
from ' || l_ut_owner || q'[.ut_compound_data_tmp ucd
243250
where data_id = :self_guid or data_id = :other_guid
244251
) ucd
252+
)ucd_out
245253
) src
246254
on (tgt.item_no = src.item_no and tgt.data_id = src.data_id)
247255
when matched then update
248256
set tgt.item_hash = src.item_hash,
249-
tgt.pk_hash = src.pk_hash ]'
257+
tgt.pk_hash = src.pk_hash,
258+
tgt.duplicate_no = src.duplicate_no]'
250259
using a_exclude_xpath, a_include_xpath,a_join_by_xpath,self.data_id, l_other.data_id;
251260

252261
/* Peform minus on two sets two get diffrences that will be used later on to print results */
253262
execute immediate 'insert into ' || l_ut_owner || '.ut_compound_data_diff_tmp ( diff_id,item_hash,pk_hash,duplicate_no)
254263
with source_data as
255-
( 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,
264+
( select t.data_id,t.item_hash,t.duplicate_no,
256265
pk_hash
257266
from ' || l_ut_owner || '.ut_compound_data_tmp t
258267
where data_id = :self_guid or data_id = :other_guid
259268
)
260269
select distinct :diff_id,tmp.item_hash,tmp.pk_hash,tmp.duplicate_no
261270
from(
262271
(
263-
select t.item_hash,t. duplicate_no,t.pk_hash
272+
select t.item_hash,t.duplicate_no,t.pk_hash
264273
from source_data t
265274
where t.data_id = :self_guid
266275
minus
267-
select t.item_hash,t. duplicate_no,t.pk_hash
276+
select t.item_hash,t.duplicate_no,t.pk_hash
268277
from source_data t
269278
where t.data_id = :other_guid
270279
)
271280
union all
272281
(
273-
select t.item_hash,t. duplicate_no,t.pk_hash
282+
select t.item_hash,t.duplicate_no,t.pk_hash
274283
from source_data t
275284
where t.data_id = :other_guid
276285
minus
277-
select t.item_hash,t. duplicate_no,t.pk_hash
286+
select t.item_hash,t.duplicate_no,t.pk_hash
278287
from source_data t
279288
where t.data_id = :self_guid
280289
))tmp'
281290
using self.data_id, l_other.data_id,
282291
l_diff_id,
283292
self.data_id, l_other.data_id,
284293
l_other.data_id,self.data_id;
285-
--result is OK only if both are same
294+
--result is OK only if both are same
286295
if sql%rowcount = 0 and self.elements_count = l_other.elements_count then
287296
l_result := 0;
288297
else

test/core/expectations/test_expectations_cursor.pkb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,38 @@ Diff:%
19861986
ut.expect(l_actual_message).to_be_like(l_expected_message);
19871987

19881988
end;
1989-
1989+
1990+
procedure unordered_fix_764 is
1991+
l_actual sys_refcursor;
1992+
l_expected sys_refcursor;
1993+
l_expected_message varchar2(32767);
1994+
l_actual_message varchar2(32767);
1995+
begin
1996+
open l_expected for
1997+
select 'Table' as name from dual
1998+
union all
1999+
select 'Desk' as name from dual
2000+
union all
2001+
select 'Table' as name from dual;
2002+
2003+
open l_actual for
2004+
select 'Desk' as name from dual
2005+
union all
2006+
select 'Table' as name from dual;
2007+
2008+
--Assert
2009+
ut3.ut.expect( l_actual ).to_equal( l_expected ).unordered();
2010+
2011+
--Assert
2012+
l_expected_message := q'[%Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 3 ]
2013+
%Diff:
2014+
%Rows: [ 1 differences ]
2015+
%Missing: <ROW><NAME>Table</NAME></ROW>%]';
2016+
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
2017+
--Assert
2018+
ut.expect(l_actual_message).to_be_like(l_expected_message);
2019+
2020+
end;
2021+
19902022
end;
19912023
/

test/core/expectations/test_expectations_cursor.pks

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ create or replace package test_expectations_cursor is
315315

316316
--%test(Trying to join on collection element inside record )
317317
procedure compare_rec_coll_as_join;
318-
318+
319+
--%test( Unordered fix for issues with duplicate no : #764 )
320+
procedure unordered_fix_764;
321+
319322
end;
320323
/

0 commit comments

Comments
 (0)