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

Skip to content

Commit e5de7d2

Browse files
committed
Tidy up
Add include and exclude filters
1 parent 816a1c1 commit e5de7d2

2 files changed

Lines changed: 46 additions & 35 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,18 @@ create or replace package body ut_compound_data_helper is
173173
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
174174
a_join_by_xpath varchar2
175175
) return tt_row_diffs is
176-
l_column_filter varchar2(32767);
176+
177+
l_act_col_filter varchar2(32767);
178+
l_exp_col_filter varchar2(32767);
177179
l_results tt_row_diffs;
178180
begin
179-
l_column_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath);
181+
l_act_col_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath,'ucd','act_item_data');
182+
l_exp_col_filter := get_columns_row_filter(a_exclude_xpath,a_include_xpath,'ucd','exp_item_data');
180183

181184
execute immediate q'[with diff_info as
182-
( select act_data_id, exp_data_id,
183-
act_item_data act_item_data, exp_item_data exp_item_data, :join_by join_by, item_no
184-
from ut_compound_data_diff_tmp
185+
( select act_data_id, exp_data_id,]'
186+
||l_act_col_filter||','|| l_exp_col_filter||q'[, :join_by join_by, item_no
187+
from ut_compound_data_diff_tmp ucd
185188
where diff_id = :diff_id ),
186189
exp as (
187190
select exp_item_data, exp_data_id, item_no rn,rownum col_no,
@@ -206,12 +209,14 @@ create or replace package body ut_compound_data_helper is
206209
unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') )
207210
union all
208211
select item_no as rn, case when exp_data_id is null then 'Extra' else 'Missing' end as diff_type,
209-
xmlserialize(content nvl(exp_item_data, act_item_data) no indent) diffed_row,
210-
nvl2(i.join_by,ut3.ut_compound_data_helper.get_pk_value(i.join_by,coalesce(exp_item_data,act_item_data)),null) pk_value
212+
xmlserialize(content (case when exp_data_id is null then act_item_data else exp_item_data end) no indent) diffed_row,
213+
nvl2(i.join_by,ut3.ut_compound_data_helper.get_pk_value(i.join_by,case when exp_data_id is null then act_item_data else exp_item_data end),null) pk_value
211214
from diff_info i
212215
where act_data_id is null or exp_data_id is null]'
213216
bulk collect into l_results
214-
using a_join_by_xpath, a_diff_id, a_expected_dataset_guid,a_actual_dataset_guid;
217+
using a_exclude_xpath,a_include_xpath,
218+
a_exclude_xpath,a_include_xpath,
219+
a_join_by_xpath, a_diff_id, a_expected_dataset_guid,a_actual_dataset_guid;
215220

216221
return l_results;
217222
end;
@@ -761,7 +766,7 @@ create or replace package body ut_compound_data_helper is
761766
return l_sql;
762767
end;
763768

764-
function generate_xmltab_stmt (a_column_info ut_varchar2_list, a_inc_filter ut_varchar2_list, a_exc_filter ut_varchar2_list) return clob is
769+
function generate_xmltab_stmt (a_column_info ut_varchar2_list) return clob is
765770
l_sql_stmt clob;
766771
begin
767772
for i in 1..a_column_info.count loop
@@ -770,7 +775,7 @@ create or replace package body ut_compound_data_helper is
770775
return l_sql_stmt;
771776
end;
772777

773-
function generate_equal_sql (a_column_info ut_varchar2_list, a_inc_filter ut_varchar2_list, a_exc_filter ut_varchar2_list) return clob is
778+
function generate_equal_sql (a_column_info ut_varchar2_list) return clob is
774779
l_sql_stmt clob;
775780
begin
776781
for i in 1..a_column_info.count loop
@@ -812,18 +817,15 @@ create or replace package body ut_compound_data_helper is
812817

813818
function gen_compare_sql(a_column_info xmltype, a_exclude_xpath varchar2,
814819
a_include_xpath varchar2, a_join_by_xpath varchar2) return clob is
815-
l_compare_sql clob;
816-
l_column_filter varchar2(32767);
817-
l_temp_string varchar2(32767);
820+
l_compare_sql clob;
821+
l_temp_string varchar2(32767);
818822

819-
l_pk_xpath_tabs ut_varchar2_list := ut_varchar2_list();
820-
l_xpath_inc_tab ut_varchar2_list := ut_varchar2_list();
821-
l_xpath_exc_tab ut_varchar2_list := ut_varchar2_list();
822-
l_col_info_tab ut_varchar2_list := ut_varchar2_list();
823+
l_pk_xpath_tabs ut_varchar2_list := ut_varchar2_list();
824+
l_act_col_tab ut_varchar2_list := ut_varchar2_list();
823825

824-
l_ut_owner varchar2(250) := ut_utils.ut_owner;
825-
l_xmltable_stmt clob;
826-
l_where_stmt clob;
826+
l_ut_owner varchar2(250) := ut_utils.ut_owner;
827+
l_xmltable_stmt clob;
828+
l_where_stmt clob;
827829

828830
function get_columns_names (a_xpath_tab in ut_varchar2_list) return ut_varchar2_list is
829831
l_names_tab ut_varchar2_list := ut_varchar2_list();
@@ -852,12 +854,22 @@ create or replace package body ut_compound_data_helper is
852854

853855
begin
854856
dbms_lob.createtemporary(l_compare_sql, true);
855-
l_column_filter := ut_compound_data_helper.get_columns_filter(a_exclude_xpath, a_include_xpath);
856-
l_pk_xpath_tabs := get_columns_names(ut_utils.string_to_table(a_join_by_xpath,'|'));
857-
l_xpath_inc_tab := get_columns_names(ut_utils.string_to_table(a_include_xpath,'|'));
858-
l_xpath_exc_tab := get_columns_names(ut_utils.string_to_table(a_exclude_xpath,'|'));
859-
l_col_info_tab := get_columns_info(a_column_info);
860-
l_xmltable_stmt := generate_xmltab_stmt(l_col_info_tab, l_xpath_inc_tab, l_xpath_exc_tab);
857+
858+
--Check include and exclude columns and create an actual column list that have to be compared.
859+
--TODO :Reformat
860+
if a_include_xpath is null and a_exclude_xpath is null then
861+
l_act_col_tab := get_columns_info(a_column_info);
862+
elsif a_include_xpath is not null and a_exclude_xpath is null then
863+
l_act_col_tab := get_columns_names(ut_utils.string_to_table(a_include_xpath,'|'));
864+
elsif a_include_xpath is null and a_exclude_xpath is not null then
865+
l_act_col_tab := get_columns_info(a_column_info) multiset except get_columns_names(ut_utils.string_to_table(a_exclude_xpath,'|'));
866+
elsif a_include_xpath is not null and a_exclude_xpath is not null then
867+
l_act_col_tab := get_columns_names(ut_utils.string_to_table(a_include_xpath,'|')) multiset except get_columns_names(ut_utils.string_to_table(a_exclude_xpath,'|'));
868+
end if;
869+
870+
l_pk_xpath_tabs := get_columns_names(ut_utils.string_to_table(a_join_by_xpath,'|'));
871+
872+
l_xmltable_stmt := generate_xmltab_stmt(l_act_col_tab);
861873

862874
l_temp_string := q'[with exp as (select ucd.*,x.item_no,x.data_id from (select item_data,item_no,data_id from ]' || l_ut_owner || q'[.ut_compound_data_tmp where data_id = :self_guid) x,]'
863875
||q'[xmltable('/ROWSET/ROW' passing x.item_data columns ]';
@@ -872,27 +884,26 @@ create or replace package body ut_compound_data_helper is
872884

873885
if a_join_by_xpath is null then
874886
-- If no key defined do the join on all columns
875-
l_temp_string := q'[select xmlelement( name "ROW", a.item_data) act_item_data, a.data_id act_data_id, xmlelement( name "ROW", e.item_data) exp_item_data, e.data_id exp_data_id, rownum item_no ]'
887+
l_temp_string := q'[ select a.item_data as act_item_data, a.data_id act_data_id, e.item_data as exp_item_data, e.data_id exp_data_id, rownum item_no ]'
876888
|| q'[from act a full outer join exp e on ( ]';
877889
ut_utils.append_to_clob(l_compare_sql,l_temp_string);
878-
ut_utils.append_to_clob(l_compare_sql,ut_compound_data_helper.generate_equal_sql(l_col_info_tab, l_xpath_inc_tab, l_xpath_exc_tab)||q'[ ) where a.data_id is null or e.data_id is null]');
890+
ut_utils.append_to_clob(l_compare_sql,ut_compound_data_helper.generate_equal_sql(l_act_col_tab)||q'[ ) where a.data_id is null or e.data_id is null]');
879891
else
880892
-- If key defined do the join or these and where on diffrences
881-
l_temp_string := 'select a.item_data act_item_data, a.data_id act_data_id,'
882-
||' e.item_data exp_item_data, e.data_id exp_data_id, rownum item_no from act a full outer join exp e on ( ';
893+
l_temp_string := q'[ select a.item_data act_item_data, a.data_id act_data_id,]'
894+
||' e.item_data exp_item_data, e.data_id exp_data_id, rownum item_no from act a full outer join exp e on ( ';
883895
ut_utils.append_to_clob(l_compare_sql,l_temp_string);
884896

885-
ut_utils.append_to_clob(l_compare_sql,ut_compound_data_helper.generate_join_by_on_stmt (l_pk_xpath_tabs)||' ) where ');
897+
ut_utils.append_to_clob(l_compare_sql,ut_compound_data_helper.generate_join_by_on_stmt (l_pk_xpath_tabs)||' ) ');
886898

887-
l_where_stmt := ut_compound_data_helper.generate_not_equal_sql(l_col_info_tab, l_pk_xpath_tabs);
899+
l_where_stmt := ut_compound_data_helper.generate_not_equal_sql(l_act_col_tab, l_pk_xpath_tabs);
888900
case
889901
when l_where_stmt is null then
890902
null;
891903
else
892-
ut_utils.append_to_clob(l_compare_sql,'( '||l_where_stmt||' ) or ( a.data_id is null or e.data_id is null )');
904+
ut_utils.append_to_clob(l_compare_sql,' where ( '||l_where_stmt||' ) or ( a.data_id is null or e.data_id is null )');
893905
end case;
894906
end if;
895-
896907
return l_compare_sql;
897908
end;
898909

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ create or replace type body ut_compound_data_value as
296296
if (ut_utils.gc_diff_max_rows > l_sql_rowcount ) then
297297
ut_compound_data_helper.insert_diffs_result(l_diff_tab,l_diff_id);
298298
end if;
299-
299+
300300
l_sql_rowcount := l_sql_rowcount + l_diff_tab.count;
301301

302302
if (ut_utils.gc_diff_max_rows <= l_sql_rowcount and l_max_rows != ut_utils.gc_bc_fetch_limit ) then

0 commit comments

Comments
 (0)