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

Skip to content

Commit 5c894c6

Browse files
committed
Merge branch 'develop' of https://github.com/utPLSQL/utPLSQL into feature/cursor_pk_join
2 parents 5eeb7f6 + e7663b6 commit 5c894c6

6 files changed

Lines changed: 79 additions & 94 deletions

File tree

source/core/ut_utils.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ create or replace package ut_utils authid definer is
2121
*
2222
*/
2323

24-
gc_version constant varchar2(50) := 'v3.1.2.1899-develop';
24+
gc_version constant varchar2(50) := 'v3.1.2.1901-develop';
2525

2626
/* Constants: Event names */
2727
subtype t_event_name is varchar2(30);

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ create or replace package body ut_compound_data_helper is
197197
return l_pk_value;
198198
exception when no_data_found then
199199
return 'null ';
200-
end;
201-
200+
end;
201+
202202
function get_rows_diff(
203203
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
204204
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
@@ -457,6 +457,40 @@ create or replace package body ut_compound_data_helper is
457457
return l_results;
458458

459459
end;
460+
461+
function compare_type(a_join_by_xpath in varchar2,a_unordered boolean) return varchar2 is
462+
begin
463+
case
464+
when a_join_by_xpath is not null then
465+
return gc_compare_join_by;
466+
when a_unordered then
467+
return gc_compare_unordered;
468+
else
469+
return gc_compare_normal;
470+
end case;
471+
end;
472+
473+
function get_rows_diff(
474+
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
475+
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
476+
a_join_by_xpath varchar2,a_unorderdered boolean
477+
) return tt_row_diffs is
478+
l_results tt_row_diffs;
479+
l_compare_type varchar2(10):= compare_type(a_join_by_xpath,a_unorderdered);
480+
begin
481+
case
482+
when l_compare_type = gc_compare_join_by then
483+
return get_rows_diff(a_expected_dataset_guid, a_actual_dataset_guid, a_diff_id,
484+
a_max_rows, a_exclude_xpath, a_include_xpath ,a_join_by_xpath);
485+
when l_compare_type = gc_compare_unordered then
486+
return get_rows_diff_unordered(a_expected_dataset_guid, a_actual_dataset_guid, a_diff_id,
487+
a_max_rows, a_exclude_xpath, a_include_xpath);
488+
else
489+
return get_rows_diff(a_expected_dataset_guid, a_actual_dataset_guid, a_diff_id,
490+
a_max_rows, a_exclude_xpath, a_include_xpath);
491+
end case;
492+
493+
end;
460494

461495
function get_hash(a_data raw, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash is
462496
begin

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ create or replace package ut_compound_data_helper authid definer is
1616
limitations under the License.
1717
*/
1818

19+
gc_compare_join_by constant varchar2(10):='join_by';
20+
gc_compare_unordered constant varchar2(10):='unordered';
21+
gc_compare_normal constant varchar2(10):='normal';
22+
1923
type t_column_diffs is record(
2024
diff_type varchar2(1),
2125
expected_name varchar2(250),
@@ -55,22 +59,14 @@ create or replace package ut_compound_data_helper authid definer is
5559
a_expected xmltype, a_actual xmltype, a_exclude_xpath varchar2, a_include_xpath varchar2
5660
) return tt_column_diffs;
5761

58-
function get_rows_diff(
59-
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
60-
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
61-
) return tt_row_diffs;
62+
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return varchar2;
6263

63-
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return varchar2;
64-
65-
function get_rows_diff(
66-
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
67-
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
68-
a_join_by_xpath varchar2
69-
) return tt_row_diffs;
64+
function compare_type(a_join_by_xpath in varchar2,a_unordered boolean) return varchar2;
7065

71-
function get_rows_diff_unordered(
66+
function get_rows_diff(
7267
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
73-
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
68+
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
69+
a_join_by_xpath varchar2,a_unorderdered boolean
7470
) return tt_row_diffs;
7571

7672
subtype t_hash is raw(128);

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 22 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,14 @@ create or replace type body ut_compound_data_value as
7575
l_result clob;
7676
l_result_string varchar2(32767);
7777
begin
78-
if a_unordered then
79-
l_result := get_data_diff(a_other, a_exclude_xpath, a_include_xpath, a_unordered);
80-
else
81-
l_result := get_data_diff(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath);
82-
end if;
78+
l_result := get_data_diff(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath,a_unordered);
8379
l_result_string := ut_utils.to_string(l_result,null);
8480
dbms_lob.freetemporary(l_result);
8581
return l_result_string;
8682
end;
87-
88-
member function get_data_diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_unordered boolean ) return clob is
83+
84+
member function get_data_diff(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2,
85+
a_join_by_xpath varchar2, a_unordered boolean) return clob is
8986
c_max_rows constant integer := 20;
9087
l_result clob;
9188
l_results ut_utils.t_clob_tab := ut_utils.t_clob_tab();
@@ -95,51 +92,19 @@ create or replace type body ut_compound_data_value as
9592
l_actual ut_compound_data_value;
9693
l_diff_id ut_compound_data_helper.t_hash;
9794
l_row_diffs ut_compound_data_helper.tt_row_diffs;
98-
begin
99-
if not a_other is of (ut_compound_data_value) then
100-
raise value_error;
101-
end if;
102-
l_actual := treat(a_other as ut_compound_data_value);
103-
104-
dbms_lob.createtemporary(l_result,true);
105-
106-
--diff rows and row elements
107-
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_actual.data_id);
108-
-- First tell how many rows are different
109-
execute immediate 'select count(*) from ' || l_ut_owner || '.ut_compound_data_diff_tmp where diff_id = :diff_id' into l_diff_row_count using l_diff_id;
95+
l_compare_type varchar2(10);
96+
97+
function get_diff_message (a_row_diff ut_compound_data_helper.t_row_diffs,a_compare_type varchar2) return varchar2 is
98+
begin
99+
if a_compare_type = ut_compound_data_helper.gc_compare_join_by and a_row_diff.pk_value is not null then
100+
return ' '||rpad(a_row_diff.diff_type,10)||a_row_diff.diffed_row||' for key: '||a_row_diff.pk_value;
101+
elsif a_compare_type = ut_compound_data_helper.gc_compare_join_by or a_compare_type = ut_compound_data_helper.gc_compare_normal then
102+
return ' Row No. '||a_row_diff.rn||' - '||rpad(a_row_diff.diff_type,10)||a_row_diff.diffed_row;
103+
elsif a_compare_type = ut_compound_data_helper.gc_compare_unordered then
104+
return rpad(a_row_diff.diff_type,10)||a_row_diff.diffed_row;
105+
end if;
106+
end;
110107

111-
if l_diff_row_count > 0 then
112-
l_row_diffs := ut_compound_data_helper.get_rows_diff_unordered(
113-
self.data_id, l_actual.data_id, l_diff_id, c_max_rows, a_exclude_xpath, a_include_xpath
114-
);
115-
l_message := chr(10)
116-
||'Rows: [ ' || l_diff_row_count ||' differences'
117-
|| case when l_diff_row_count > c_max_rows and l_row_diffs.count > 0 then ', showing first '||c_max_rows end
118-
||' ]' || chr(10)
119-
|| case when l_row_diffs.count = 0
120-
then ' All rows are different as the columns are not matching.' end;
121-
ut_utils.append_to_clob( l_result, l_message );
122-
for i in 1 .. l_row_diffs.count loop
123-
l_results.extend;
124-
l_results(l_results.last) :=
125-
rpad(l_row_diffs(i).diff_type,10)||l_row_diffs(i).diffed_row;
126-
end loop;
127-
ut_utils.append_to_clob(l_result,l_results);
128-
end if;
129-
return l_result;
130-
end;
131-
132-
member function get_data_diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2) return clob is
133-
c_max_rows constant integer := 20;
134-
l_result clob;
135-
l_results ut_utils.t_clob_tab := ut_utils.t_clob_tab();
136-
l_message varchar2(32767);
137-
l_ut_owner varchar2(250) := ut_utils.ut_owner;
138-
l_diff_row_count integer;
139-
l_actual ut_compound_data_value;
140-
l_diff_id ut_compound_data_helper.t_hash;
141-
l_row_diffs ut_compound_data_helper.tt_row_diffs;
142-
143108
begin
144109
if not a_other is of (ut_compound_data_value) then
145110
raise value_error;
@@ -150,21 +115,16 @@ create or replace type body ut_compound_data_value as
150115

151116
--diff rows and row elements
152117
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_actual.data_id);
118+
153119
-- First tell how many rows are different
154120
execute immediate 'select count('||case when a_join_by_xpath is not null then 'distinct pk_hash' else '*' end||') from '
155121
|| l_ut_owner || '.ut_compound_data_diff_tmp
156122
where diff_id = :diff_id' into l_diff_row_count using l_diff_id;
157123

158124
if l_diff_row_count > 0 then
159-
if a_join_by_xpath is not null then
160-
l_row_diffs := ut_compound_data_helper.get_rows_diff(
161-
self.data_id, l_actual.data_id, l_diff_id, c_max_rows, a_exclude_xpath, a_include_xpath, a_join_by_xpath
162-
);
163-
else
164-
l_row_diffs := ut_compound_data_helper.get_rows_diff(
165-
self.data_id, l_actual.data_id, l_diff_id, c_max_rows, a_exclude_xpath, a_include_xpath
166-
);
167-
end if;
125+
l_compare_type := ut_compound_data_helper.compare_type(a_join_by_xpath,a_unordered);
126+
l_row_diffs := ut_compound_data_helper.get_rows_diff(
127+
self.data_id, l_actual.data_id, l_diff_id, c_max_rows, a_exclude_xpath, a_include_xpath, a_join_by_xpath, a_unordered);
168128
l_message := chr(10)
169129
||'Rows: [ ' || l_diff_row_count ||' differences'
170130
|| case when l_diff_row_count > c_max_rows and l_row_diffs.count > 0 then ', showing first '||c_max_rows end
@@ -174,17 +134,14 @@ create or replace type body ut_compound_data_value as
174134
ut_utils.append_to_clob( l_result, l_message );
175135
for i in 1 .. l_row_diffs.count loop
176136
l_results.extend;
177-
if a_join_by_xpath is not null and l_row_diffs(i).pk_value is not null then
178-
l_results(l_results.last) := ' '||rpad(l_row_diffs(i).diff_type,10)||l_row_diffs(i).diffed_row||' for key: '||l_row_diffs(i).pk_value;
179-
else
180-
l_results(l_results.last) := ' Row No. '||l_row_diffs(i).rn||' - '||rpad(l_row_diffs(i).diff_type,10)||l_row_diffs(i).diffed_row;
181-
end if;
137+
l_results(l_results.last) := get_diff_message(l_row_diffs(i),l_compare_type);
182138
end loop;
183139
ut_utils.append_to_clob(l_result,l_results);
184140
end if;
185141
return l_result;
186142
end;
187143

144+
188145
member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer is
189146
l_other ut_compound_data_value;
190147
l_ut_owner varchar2(250) := ut_utils.ut_owner;

source/expectations/data_values/ut_compound_data_value.tps

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ create or replace type ut_compound_data_value force under ut_data_value(
4343
overriding member function is_multi_line return boolean,
4444
overriding member function compare_implementation(a_other ut_data_value) return integer,
4545
overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean := false ) return varchar2,
46-
member function get_data_diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_unordered boolean ) return clob,
47-
member function get_data_diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2 ) return clob,
46+
member function get_data_diff(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean) return clob,
4847
member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer,
4948
member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean ) return integer
5049
) not final not instantiable

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,21 @@ create or replace type body ut_data_value_refcursor as
187187
ut_utils.append_to_clob(l_result, l_results);
188188
l_exclude_xpath := add_incomparable_cols_to_xpath(l_column_diffs, a_exclude_xpath);
189189
end if;
190-
191-
--diff rows and row elements
192-
if (a_join_by_xpath is not null) or not(a_unordered) then
193-
-- Check if pk filter exists
194-
l_missing_pk := ut_compound_data_helper.is_pk_exists(self.columns_info, l_actual.columns_info, a_exclude_xpath, a_include_xpath,a_join_by_xpath);
195-
if l_missing_pk.count = 0 then
196-
ut_utils.append_to_clob(l_result, self.get_data_diff(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath));
197-
else
190+
191+
--check for missing pk
192+
if (a_join_by_xpath is not null) then
193+
l_missing_pk := ut_compound_data_helper.is_pk_exists(self.columns_info, l_actual.columns_info, a_exclude_xpath, a_include_xpath,a_join_by_xpath);
194+
end if;
195+
196+
--diff rows and row elements if the pk is not missing
197+
if l_missing_pk.count = 0 then
198+
ut_utils.append_to_clob(l_result, self.get_data_diff(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath, a_unordered));
199+
else
198200
ut_utils.append_to_clob(l_result,chr(10) || 'Unable to join sets:' || chr(10));
199201
for i in 1 .. l_missing_pk.count loop
200202
l_results.extend;
201203
ut_utils.append_to_clob(l_result, get_missing_key_message(l_missing_pk(i))|| chr(10));
202204
end loop;
203-
end if;
204-
else
205-
ut_utils.append_to_clob(l_result, self.get_data_diff(a_other, l_exclude_xpath, a_include_xpath, a_unordered));
206205
end if;
207206

208207
l_result_string := ut_utils.to_string(l_result,null);

0 commit comments

Comments
 (0)