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

Skip to content

Commit 24c14f9

Browse files
committed
Refactoring - to be continued.
1 parent 90aca9f commit 24c14f9

8 files changed

Lines changed: 185 additions & 214 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ create or replace package body ut_compound_data_helper is
264264
l_partition_tmp clob;
265265
l_col_name varchar2(100);
266266
begin
267-
if l_cursor_info is not null then
267+
if l_cursor_info is not empty then
268268
--Parition by piece
269269
ut_utils.append_to_clob(a_partition_stmt,', row_number() over (partition by ');
270270
for i in 1..l_cursor_info.count loop
@@ -321,8 +321,11 @@ create or replace package body ut_compound_data_helper is
321321

322322

323323
function gen_compare_sql(
324-
a_inclusion_type boolean, a_is_negated boolean, a_unordered boolean,
325-
a_other ut_data_value_refcursor := null, a_join_by_list ut_varchar2_list := ut_varchar2_list()
324+
a_other ut_data_value_refcursor,
325+
a_join_by_list ut_varchar2_list,
326+
a_unordered boolean,
327+
a_inclusion_type boolean,
328+
a_is_negated boolean
326329
) return clob is
327330
l_compare_sql clob;
328331
l_temp_string varchar2(32767);
@@ -372,35 +375,35 @@ create or replace package body ut_compound_data_helper is
372375
end if;
373376

374377
if (a_join_by_list.count = 0) and a_unordered then
375-
-- If no key defined do the join on all columns
376-
ut_utils.append_to_clob(l_compare_sql,l_equal_stmt);
377-
elsif (a_join_by_list.count > 0) and a_unordered then
378-
-- If key defined do the join or these and where on diffrences
379-
ut_utils.append_to_clob(l_compare_sql,l_join_on_stmt);
380-
elsif not a_unordered then
381-
ut_utils.append_to_clob(l_compare_sql, 'a.item_no = e.item_no ' );
382-
end if;
378+
-- If no key defined do the join on all columns
379+
ut_utils.append_to_clob(l_compare_sql,l_equal_stmt);
380+
elsif (a_join_by_list.count > 0) and a_unordered then
381+
-- If key defined do the join or these and where on diffrences
382+
ut_utils.append_to_clob(l_compare_sql,l_join_on_stmt);
383+
elsif not a_unordered then
384+
ut_utils.append_to_clob(l_compare_sql, 'a.item_no = e.item_no ' );
385+
end if;
383386

384-
ut_utils.append_to_clob(l_compare_sql,' ) where ');
387+
ut_utils.append_to_clob(l_compare_sql,' ) where ');
385388

386-
if (a_join_by_list.count > 0) and (a_unordered) and (not a_is_negated) then
387-
if l_not_equal_stmt is not null then
388-
ut_utils.append_to_clob(l_compare_sql,' ( '||l_not_equal_stmt||' ) or ');
389-
end if;
390-
elsif not a_unordered and l_not_equal_stmt is not null then
391-
ut_utils.append_to_clob(l_compare_sql,' ( '||l_not_equal_stmt||' ) or ');
392-
end if;
389+
if (a_join_by_list.count > 0) and (a_unordered) and (not a_is_negated) then
390+
if l_not_equal_stmt is not null then
391+
ut_utils.append_to_clob(l_compare_sql,' ( '||l_not_equal_stmt||' ) or ');
392+
end if;
393+
elsif not a_unordered and l_not_equal_stmt is not null then
394+
ut_utils.append_to_clob(l_compare_sql,' ( '||l_not_equal_stmt||' ) or ');
395+
end if;
393396

394-
--If its inlcusion we expect a actual set to fully match and have no extra elements over expected
395-
if a_inclusion_type and not(a_is_negated) then
396-
l_temp_string := ' ( a.data_id is null ) ';
397-
elsif a_inclusion_type and a_is_negated then
398-
l_temp_string := ' 1 = 1 ';
399-
else
400-
l_temp_string := ' (a.data_id is null or e.data_id is null) ';
401-
end if;
402-
ut_utils.append_to_clob(l_compare_sql,l_temp_string);
403-
return l_compare_sql;
397+
--If its inlcusion we expect a actual set to fully match and have no extra elements over expected
398+
if a_inclusion_type and not(a_is_negated) then
399+
l_temp_string := ' ( a.data_id is null ) ';
400+
elsif a_inclusion_type and a_is_negated then
401+
l_temp_string := ' 1 = 1 ';
402+
else
403+
l_temp_string := ' (a.data_id is null or e.data_id is null) ';
404+
end if;
405+
ut_utils.append_to_clob(l_compare_sql,l_temp_string);
406+
return l_compare_sql;
404407
end;
405408

406409
function get_column_extract_path(a_cursor_info ut_cursor_column_tab) return ut_varchar2_list is
@@ -631,21 +634,6 @@ create or replace package body ut_compound_data_helper is
631634
return g_diff_count;
632635
end;
633636

634-
function getxmlchildren(a_parent_name varchar2,a_cursor_table ut_cursor_column_tab)
635-
return xmltype is
636-
l_result xmltype;
637-
begin
638-
select xmlagg(xmlelement(evalname t.column_name,t.column_type,
639-
getxmlchildren(t.column_name,a_cursor_table)))
640-
into l_result
641-
from table(a_cursor_table) t
642-
where (a_parent_name is not null and parent_name = a_parent_name and hierarchy_level > 1 and column_name is not null)
643-
or (a_parent_name is null and parent_name is null and hierarchy_level = 1 and column_name is not null)
644-
having count(*) > 0;
645-
646-
return l_result;
647-
end;
648-
649637
function is_sql_compare_allowed(a_type_name varchar2)
650638
return boolean is
651639
l_assert boolean;

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ create or replace package ut_compound_data_helper authid definer is
8181
function get_fixed_size_hash(a_string varchar2, a_base integer :=0,a_size integer :=9999999) return number;
8282

8383
function gen_compare_sql(
84-
a_inclusion_type boolean, a_is_negated boolean, a_unordered boolean,
85-
a_other ut_data_value_refcursor :=null, a_join_by_list ut_varchar2_list:=ut_varchar2_list()
84+
a_other ut_data_value_refcursor,
85+
a_join_by_list ut_varchar2_list,
86+
a_unordered boolean,
87+
a_inclusion_type boolean,
88+
a_is_negated boolean
8689
) return clob;
8790

8891
procedure insert_diffs_result(a_diff_tab t_diff_tab, a_diff_id raw);
@@ -92,8 +95,6 @@ create or replace package ut_compound_data_helper authid definer is
9295
procedure cleanup_diff;
9396

9497
function get_rows_diff_count return integer;
95-
96-
function getxmlchildren(a_parent_name varchar2,a_cursor_table ut_cursor_column_tab) return xmltype;
9798

9899
function is_sql_compare_allowed(a_type_name varchar2) return boolean;
99100

source/expectations/data_values/ut_cursor_details.tpb

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
create or replace type body ut_cursor_details as
22

3-
order member function compare(a_other ut_cursor_details) return integer is
3+
member function equals( a_other ut_cursor_details, a_match_options ut_matcher_options ) return boolean is
44
l_diffs integer;
55
begin
6-
if self.is_column_order_enforced = 1 then
7-
select count(1) into l_diffs
6+
select count(1) into l_diffs
87
from table(self.cursor_columns_info) a
98
full outer join table(a_other.cursor_columns_info) e
10-
on decode(a.parent_name,e.parent_name,1,0)= 1
11-
and a.column_name = e.column_name
12-
and replace(a.column_type,'VARCHAR2','CHAR') = replace(e.column_type,'VARCHAR2','CHAR')
13-
and a.column_position = e.column_position
14-
where a.column_name is null or e.column_name is null;
15-
else
16-
select count(1) into l_diffs
17-
from table(self.cursor_columns_info) a
18-
full outer join table(a_other.cursor_columns_info) e
19-
on decode(a.parent_name,e.parent_name,1,0)= 1
20-
and a.column_name = e.column_name
21-
and replace(a.column_type,'VARCHAR2','CHAR') = replace(e.column_type,'VARCHAR2','CHAR')
22-
where a.column_name is null or e.column_name is null;
23-
end if;
24-
return l_diffs;
9+
on decode(a.parent_name,e.parent_name,1,0)= 1
10+
and a.column_name = e.column_name
11+
and replace(a.column_type,'VARCHAR2','CHAR') = replace(e.column_type,'VARCHAR2','CHAR')
12+
and ( a.column_position = e.column_position or a_match_options.columns_are_unordered_flag = 1 )
13+
where a.column_name is null or e.column_name is null;
14+
return l_diffs = 0;
2515
end;
2616

2717
member procedure desc_compound_data(
@@ -152,7 +142,7 @@ create or replace type body ut_cursor_details as
152142
return l_collection_elements > 0;
153143
end;
154144

155-
member function get_missing_filter_columns( a_expected_columns ut_varchar2_list ) return ut_varchar2_list is
145+
member function get_missing_join_by_columns( a_expected_columns ut_varchar2_list ) return ut_varchar2_list is
156146
l_result ut_varchar2_list;
157147
begin
158148
select fl.column_value
@@ -166,10 +156,58 @@ create or replace type body ut_cursor_details as
166156
return l_result;
167157
end;
168158

169-
member procedure ordered_columns(self in out nocopy ut_cursor_details,a_ordered_columns boolean := false) is
159+
member procedure filter_columns(self in out nocopy ut_cursor_details, a_match_options ut_matcher_options) is
160+
l_result ut_cursor_details := self;
161+
c_xpath_extract_reg constant varchar2(50) := '^((/ROW/)|^(//)|^(/\*/))?(.*)';
170162
begin
171-
self.is_column_order_enforced := ut_utils.boolean_to_int(a_ordered_columns);
163+
if l_result.cursor_columns_info is not null then
164+
165+
--limit columns to those on the include items minus exclude items
166+
if a_match_options.include.items.count > 0 then
167+
-- if include - exclude = 0 then keep all columns
168+
if a_match_options.include.items != a_match_options.exclude.items then
169+
with included_columns as (
170+
select regexp_replace( column_value, c_xpath_extract_reg, '\5' ) col_names
171+
from table(a_match_options.include.items)
172+
minus
173+
select regexp_replace( column_value, c_xpath_extract_reg, '\5' ) col_names
174+
from table(a_match_options.exclude.items)
175+
)
176+
select value(x)
177+
bulk collect into l_result.cursor_columns_info
178+
from table(self.cursor_columns_info) x
179+
where exists(
180+
select 1 from included_columns f where regexp_like( x.access_path, '^'||f.col_names||'($|/.*)' )
181+
);
182+
end if;
183+
elsif a_match_options.exclude.items.count > 0 then
184+
with excluded_columns as (
185+
select regexp_replace( column_value, c_xpath_extract_reg, '\5' ) col_names
186+
from table(a_match_options.exclude.items)
187+
)
188+
select value(x)
189+
bulk collect into l_result.cursor_columns_info
190+
from table(self.cursor_columns_info) x
191+
where not exists(
192+
select 1 from excluded_columns f where regexp_like( x.access_path, '^'||f.col_names||'($|/.*)' )
193+
);
194+
end if;
195+
self := l_result;
196+
end if;
172197
end;
173198

199+
member function get_xml_children(a_parent_name varchar2 := null) return xmltype is
200+
l_result xmltype;
201+
begin
202+
select xmlagg(xmlelement(evalname t.column_name,t.column_type,
203+
self.get_xml_children(t.column_name)))
204+
into l_result
205+
from table(self.cursor_columns_info) t
206+
where (a_parent_name is not null and parent_name = a_parent_name and hierarchy_level > 1 and column_name is not null)
207+
or (a_parent_name is null and parent_name is null and hierarchy_level = 1 and column_name is not null)
208+
having count(*) > 0;
209+
210+
return l_result;
211+
end;
174212
end;
175213
/

source/expectations/data_values/ut_cursor_details.tps

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ create or replace type ut_cursor_details force authid current_user as object (
1616
limitations under the License.
1717
*/
1818
cursor_columns_info ut_cursor_column_tab,
19-
is_column_order_enforced number(1,0),
2019

2120
constructor function ut_cursor_details(self in out nocopy ut_cursor_details) return self as result,
2221
constructor function ut_cursor_details(
2322
self in out nocopy ut_cursor_details,a_cursor_number in number
2423
) return self as result,
25-
order member function compare(a_other ut_cursor_details) return integer,
24+
member function equals(a_other ut_cursor_details, a_match_options ut_matcher_options) return boolean,
2625
member procedure desc_compound_data(
2726
self in out nocopy ut_cursor_details,
2827
a_compound_data anytype,
@@ -31,7 +30,8 @@ create or replace type ut_cursor_details force authid current_user as object (
3130
a_access_path in varchar2
3231
),
3332
member function contains_collection return boolean,
34-
member function get_missing_filter_columns( a_expected_columns ut_varchar2_list ) return ut_varchar2_list,
35-
member procedure ordered_columns(self in out nocopy ut_cursor_details, a_ordered_columns boolean := false)
33+
member function get_missing_join_by_columns( a_expected_columns ut_varchar2_list ) return ut_varchar2_list,
34+
member procedure filter_columns(self in out nocopy ut_cursor_details, a_match_options ut_matcher_options),
35+
member function get_xml_children(a_parent_name varchar2 := null) return xmltype
3636
)
3737
/

0 commit comments

Comments
 (0)