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

Skip to content

Commit 5b46ab0

Browse files
committed
Updated code for tests.
1 parent ee7bdf2 commit 5b46ab0

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,20 @@ create or replace package body ut_compound_data_helper is
172172
function get_rows_diff_by_sql(
173173
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
174174
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
175-
a_join_by_xpath varchar2
175+
a_join_by_xpath varchar2, a_unordered boolean
176176
) return tt_row_diffs is
177177

178178
l_act_col_filter varchar2(32767);
179179
l_exp_col_filter varchar2(32767);
180180
l_results tt_row_diffs;
181-
181+
l_sql varchar2(32767);
182182
begin
183183
l_act_col_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath,'ucd','act_item_data');
184184
l_exp_col_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath,'ucd','exp_item_data');
185185

186186
--TODO: Generate SQL based on input as unorder join should aggregate
187187

188-
execute immediate q'[with exp as (
188+
l_sql := q'[with exp as (
189189
select exp_item_data, exp_data_id, item_no rn,rownum col_no,
190190
nvl2(exp_item_data,ut3.ut_compound_data_helper.get_pk_value(i.join_by,exp_item_data),null) pk_value,
191191
s.column_value col, s.column_value.getRootElement() col_name, s.column_value.getclobval() col_val
@@ -212,15 +212,31 @@ create or replace package body ut_compound_data_helper is
212212
select rn, diff_type, diffed_row, pk_value
213213
,case when diff_type = 'Actual:' then 1 else 2 end rnk
214214
,1 final_order
215-
from (
216-
select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, pk_value pk_value
215+
from ( ]';
216+
217+
if a_unordered then
218+
l_sql := l_sql || q'[select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, pk_value pk_value
217219
from
218220
(select nvl(exp.rn, act.rn) rn, nvl(exp.pk_value, act.pk_value) pk_value, exp.col exp_item, act.col act_item
219221
from exp join act on exp.rn = act.rn and exp.col_name = act.col_name
220222
where dbms_lob.compare(exp.col_val, act.col_val) != 0)
221223
unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:')
222-
))
223-
union all
224+
))]';
225+
else
226+
l_sql := l_sql || q'[ select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, null pk_value
227+
from
228+
(select nvl(exp.rn, act.rn) rn,
229+
xmlagg(exp.col order by exp.col_no) exp_item,
230+
xmlagg(act.col order by act.col_no) act_item
231+
from exp exp join act act on exp.rn = act.rn and exp.col_name = act.col_name
232+
where dbms_lob.compare(exp.col_val, act.col_val) != 0
233+
group by exp.rn, act.rn
234+
)
235+
unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:'))
236+
)]';
237+
end if;
238+
239+
l_sql := l_sql || q'[union all
224240
select
225241
item_no as rn, case when exp_data_id is null then 'Extra:' else 'Missing:' end as diff_type,
226242
xmlserialize(content (extract((case when exp_data_id is null then act_item_data else exp_item_data end),'/*/*')) no indent) diffed_row,
@@ -233,7 +249,9 @@ create or replace package body ut_compound_data_helper is
233249
)
234250
order by final_order,
235251
case when final_order = 1 then rn else rnk end,
236-
case when final_order = 1 then rnk else rn end ]'
252+
case when final_order = 1 then rnk else rn end ]';
253+
254+
execute immediate l_sql
237255
bulk collect into l_results
238256
using a_exclude_xpath, a_include_xpath, a_join_by_xpath,
239257
a_diff_id, a_expected_dataset_guid,
@@ -322,14 +340,14 @@ create or replace package body ut_compound_data_helper is
322340
function get_rows_diff(
323341
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
324342
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
325-
a_join_by_xpath varchar2,a_refcursor boolean
343+
a_join_by_xpath varchar2,a_refcursor boolean, a_unordered boolean
326344
) return tt_row_diffs is
327345
l_result tt_row_diffs := tt_row_diffs();
328346
begin
329347
case
330348
when a_refcursor then
331349
l_result := get_rows_diff_by_sql(a_expected_dataset_guid, a_actual_dataset_guid, a_diff_id,
332-
a_max_rows, a_exclude_xpath, a_include_xpath ,a_join_by_xpath);
350+
a_max_rows, a_exclude_xpath, a_include_xpath ,a_join_by_xpath, a_unordered);
333351
else
334352
l_result := get_rows_diff(a_expected_dataset_guid, a_actual_dataset_guid, a_diff_id,
335353
a_max_rows, a_exclude_xpath, a_include_xpath);

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ create or replace package ut_compound_data_helper authid definer is
7575
function get_rows_diff(
7676
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
7777
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
78-
a_join_by_xpath varchar2,a_refcursor boolean
78+
a_join_by_xpath varchar2,a_refcursor boolean, a_unordered boolean
7979
) return tt_row_diffs;
8080

8181
subtype t_hash is raw(128);

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ create or replace type body ut_compound_data_value as
124124
if l_diff_row_count > 0 then
125125
l_row_diffs := ut_compound_data_helper.get_rows_diff(
126126
self.data_id, l_actual.data_id, l_diff_id, c_max_rows, a_exclude_xpath,
127-
a_include_xpath, a_join_by_xpath, a_other is of (ut_data_value_refcursor));
127+
a_include_xpath, a_join_by_xpath, a_other is of (ut_data_value_refcursor), a_unordered);
128128
l_message := chr(10)
129129
||'Rows: [ ' || l_diff_row_count ||' differences'
130130
|| case when l_diff_row_count > c_max_rows and l_row_diffs.count > 0 then ', showing first '||c_max_rows end

0 commit comments

Comments
 (0)