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

Skip to content

Commit e32d700

Browse files
committed
Refactoring
1 parent bf4a25a commit e32d700

10 files changed

Lines changed: 61 additions & 275 deletions

source/core/ut_metadata.pkb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,24 @@ create or replace package body ut_metadata as
341341
return l_object;
342342
end;
343343

344+
function get_anydata_compound_type(a_data_value anydata) return varchar2 is
345+
l_result varchar2(30);
346+
l_type anytype;
347+
l_type_code integer;
348+
begin
349+
if a_data_value is not null then
350+
l_type_code := a_data_value.gettype(l_type);
351+
if l_type_code in (dbms_types.typecode_table, dbms_types.typecode_varray, dbms_types.typecode_namedcollection,
352+
dbms_types.typecode_object) then
353+
if l_type_code = dbms_types.typecode_object then
354+
l_result := 'object';
355+
else
356+
l_result := 'collection';
357+
end if;
358+
end if;
359+
end if;
360+
return l_result;
361+
end;
362+
344363
end;
345364
/

source/core/ut_metadata.pks

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ create or replace package ut_metadata authid current_user as
171171
* Get object name from fully qualified name e.g ut3.test -> test
172172
*/
173173
function get_object_name(a_full_object_name in varchar2) return varchar2;
174+
175+
/**
176+
* Based on anydata decide if its a object or collection
177+
*/
178+
function get_anydata_compound_type(a_data_value anydata) return varchar2;
174179

175180
end ut_metadata;
176181
/

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,6 @@ create or replace package body ut_compound_data_helper is
6969
from act a {:join_type:} exp e on ( {:join_condition:} )
7070
where {:where_condition:}]';
7171

72-
function get_columns_filter(
73-
a_exclude_xpath varchar2, a_include_xpath varchar2,
74-
a_table_alias varchar2 := 'ucd', a_column_alias varchar2 := 'item_data'
75-
) return varchar2 is
76-
l_filter varchar2(32767);
77-
l_source_column varchar2(500) := a_table_alias||'.'||a_column_alias;
78-
begin
79-
-- this SQL statement is constructed in a way that we always get the same number and ordering of substitution variables
80-
-- That is, we always get: l_exclude_xpath, l_include_xpath
81-
-- regardless if the variables are NULL (not to be used) or NOT NULL and will be used for filtering
82-
if a_exclude_xpath is null and a_include_xpath is null then
83-
l_filter := ':l_exclude_xpath, :l_include_xpath, '||l_source_column||' as '||a_column_alias;
84-
elsif a_exclude_xpath is not null and a_include_xpath is null then
85-
l_filter := 'deletexml( '||l_source_column||', :l_exclude_xpath ) as '||a_column_alias||', :l_include_xpath';
86-
elsif a_exclude_xpath is null and a_include_xpath is not null then
87-
l_filter := ':l_exclude_xpath, extract( '||l_source_column||', :l_include_xpath ) as '||a_column_alias;
88-
elsif a_exclude_xpath is not null and a_include_xpath is not null then
89-
l_filter := 'extract( deletexml( '||l_source_column||', :l_exclude_xpath ), :l_include_xpath ) as '||a_column_alias;
90-
end if;
91-
return l_filter;
92-
end;
93-
9472
function get_columns_diff(
9573
a_expected ut_cursor_column_tab,
9674
a_actual ut_cursor_column_tab,
@@ -530,82 +508,6 @@ create or replace package body ut_compound_data_helper is
530508
return l_results;
531509
end;
532510

533-
--TODO : removal
534-
function get_rows_diff(
535-
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
536-
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
537-
) return tt_row_diffs is
538-
l_column_filter varchar2(32767);
539-
l_results tt_row_diffs;
540-
begin
541-
l_column_filter := get_columns_filter(a_exclude_xpath,a_include_xpath);
542-
execute immediate q'[
543-
with
544-
diff_info as ( select item_no
545-
from
546-
(select item_no from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid order by item_no asc)
547-
where rownum <= :max_rows)
548-
select *
549-
from (select rn, diff_type, xmlserialize(content data_item no indent) diffed_row, null pk_value
550-
from (select nvl(exp.rn, act.rn) rn,
551-
xmlagg(exp.col order by exp.col_no) exp_item,
552-
xmlagg(act.col order by act.col_no) act_item
553-
from (select r.item_no as rn, rownum col_no, s.column_value col,
554-
s.column_value.getRootElement() col_name,
555-
s.column_value.getclobval() col_val
556-
from (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_data item_data_no_filter
557-
from ut_compound_data_tmp ucd,
558-
diff_info i
559-
where ucd.data_id = :self_guid
560-
and ucd.item_no = i.item_no
561-
) r,
562-
table( xmlsequence( extract(r.item_data,'/*/*') ) ) s
563-
) exp
564-
join (
565-
select item_no as rn, rownum col_no, s.column_value col,
566-
s.column_value.getRootElement() col_name,
567-
s.column_value.getclobval() col_val
568-
from (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_data item_data_no_filter
569-
from ut_compound_data_tmp ucd,
570-
diff_info i
571-
where ucd.data_id = :other_guid
572-
and ucd.item_no = i.item_no
573-
) r,
574-
table( xmlsequence( extract(r.item_data,'/*/*') ) ) s
575-
) act
576-
on exp.rn = act.rn and exp.col_name = act.col_name
577-
where dbms_lob.compare(exp.col_val, act.col_val) != 0
578-
group by exp.rn, act.rn
579-
)
580-
unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') )
581-
)
582-
union all
583-
select nvl(exp.item_no, act.item_no) rn,
584-
case when exp.item_no is null then 'Extra:' else 'Missing:' end as diff_type,
585-
xmlserialize(content nvl(exp.item_data, act.item_data) no indent) diffed_row,
586-
null pk_value
587-
from (select ucd.item_no, extract(ucd.item_data,'/*/*') item_data
588-
from ut_compound_data_tmp ucd
589-
where ucd.data_id = :self_guid
590-
and ucd.item_no in (select i.item_no from diff_info i)
591-
) exp
592-
full outer join (
593-
select ucd.item_no, extract(ucd.item_data,'/*/*') item_data
594-
from ut_compound_data_tmp ucd
595-
where ucd.data_id = :other_guid
596-
and ucd.item_no in (select i.item_no from diff_info i)
597-
)act
598-
on exp.item_no = act.item_no
599-
where exp.item_no is null or act.item_no is null
600-
order by 1, 2]'
601-
bulk collect into l_results
602-
using a_diff_id, a_max_rows,
603-
a_exclude_xpath, a_include_xpath, a_expected_dataset_guid,
604-
a_exclude_xpath, a_include_xpath, a_actual_dataset_guid,
605-
a_expected_dataset_guid, a_actual_dataset_guid;
606-
return l_results;
607-
end;
608-
609511
function get_hash(a_data raw, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash is
610512
begin
611513
return dbms_crypto.hash(a_data, a_hash_type);

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,10 @@ create or replace package ut_compound_data_helper authid definer is
5151

5252
type t_diff_tab is table of t_diff_rec;
5353

54-
function get_columns_filter(
55-
a_exclude_xpath varchar2, a_include_xpath varchar2,
56-
a_table_alias varchar2 := 'ucd', a_column_alias varchar2 := 'item_data'
57-
) return varchar2;
58-
5954
function get_columns_diff(
6055
a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab,a_order_enforced boolean := false
6156
) return tt_column_diffs;
6257

63-
function get_rows_diff(
64-
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
65-
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
66-
) return tt_row_diffs;
67-
6858
function get_rows_diff_by_sql(
6959
a_act_cursor_info ut_cursor_column_tab,a_exp_cursor_info ut_cursor_column_tab,
7060
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ create or replace type body ut_compound_data_value as
3636
return not self.is_null();
3737
end;
3838

39-
overriding member function compare_implementation(a_other ut_data_value) return integer is
40-
begin
41-
return compare_implementation( a_other, null );
42-
end;
43-
4439
overriding member function to_string return varchar2 is
4540
l_results ut_utils.t_clob_tab;
4641
l_result clob;
@@ -68,126 +63,5 @@ create or replace type body ut_compound_data_value as
6863
return l_result_string;
6964
end;
7065

71-
overriding member function diff( a_other ut_data_value, a_match_options ut_matcher_options ) return varchar2 is
72-
l_result clob;
73-
l_result_string varchar2(32767);
74-
begin
75-
l_result := get_data_diff( a_other, a_match_options );
76-
l_result_string := ut_utils.to_string(l_result,null);
77-
dbms_lob.freetemporary(l_result);
78-
return l_result_string;
79-
end;
80-
81-
-- TODO : Rework to exclude xpath
82-
member function get_data_diff( a_other ut_data_value, a_match_options ut_matcher_options ) return clob is
83-
c_max_rows integer := ut_utils.gc_diff_max_rows;
84-
l_result clob;
85-
l_results ut_utils.t_clob_tab := ut_utils.t_clob_tab();
86-
l_message varchar2(32767);
87-
l_diff_row_count integer;
88-
l_actual ut_compound_data_value;
89-
l_diff_id ut_compound_data_helper.t_hash;
90-
l_row_diffs ut_compound_data_helper.tt_row_diffs;
91-
92-
function get_diff_message (a_row_diff ut_compound_data_helper.t_row_diffs) return varchar2 is
93-
begin
94-
return ' Row No. '||a_row_diff.rn||' - '||rpad(a_row_diff.diff_type,10)||a_row_diff.diffed_row;
95-
end;
96-
97-
begin
98-
if not a_other is of (ut_compound_data_value) then
99-
raise value_error;
100-
end if;
101-
102-
l_actual := treat(a_other as ut_compound_data_value);
103-
104-
dbms_lob.createtemporary(l_result,true);
105-
106-
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_actual.data_id);
107-
-- First tell how many rows are different
108-
l_diff_row_count := ut_compound_data_helper.get_rows_diff_count;
109-
if l_diff_row_count > 0 then
110-
l_row_diffs := ut_compound_data_helper.get_rows_diff(
111-
self.data_id, l_actual.data_id, l_diff_id, c_max_rows,
112-
a_match_options.exclude.to_xpath(),
113-
a_match_options.exclude.to_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)|| case when l_row_diffs.count = 0 then ' All rows are different as the columns are not matching.' else null end;
119-
ut_utils.append_to_clob( l_result, l_message );
120-
for i in 1 .. l_row_diffs.count loop
121-
l_results.extend;
122-
l_results(l_results.last) := get_diff_message( l_row_diffs(i) );
123-
end loop;
124-
ut_utils.append_to_clob(l_result,l_results);
125-
else
126-
l_message:= chr(10)||'Rows: [ all different ]'||chr(10)||' All rows are different as the columns are not matching.';
127-
ut_utils.append_to_clob( l_result, l_message );
128-
end if;
129-
return l_result;
130-
end;
131-
132-
133-
member function compare_implementation(a_other ut_data_value, a_match_options ut_matcher_options) return integer is
134-
l_other ut_compound_data_value;
135-
l_ut_owner varchar2(250) := ut_utils.ut_owner;
136-
l_column_filter varchar2(32767);
137-
l_diff_id ut_compound_data_helper.t_hash;
138-
l_result integer;
139-
--the XML stylesheet is applied on XML representation of data to exclude column names from comparison
140-
--column names and data-types are compared separately
141-
--user CHR(38) instead of ampersand to eliminate define request when installing through some IDEs
142-
l_xml_data_fmt constant xmltype := xmltype(
143-
q'[<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
144-
<xsl:strip-space elements="*" />
145-
<xsl:template match="/child::*">
146-
<xsl:for-each select="child::node()">
147-
<xsl:choose>
148-
<xsl:when test="*[*]"><xsl:copy-of select="node()"/></xsl:when>
149-
<xsl:when test="position()=last()"><xsl:value-of select="normalize-space(.)"/><xsl:text>'||CHR(38)||'#xD;</xsl:text></xsl:when>
150-
<xsl:otherwise><xsl:value-of select="normalize-space(.)"/>,</xsl:otherwise>
151-
</xsl:choose>
152-
</xsl:for-each>
153-
</xsl:template>
154-
</xsl:stylesheet>]');
155-
begin
156-
if not a_other is of (ut_compound_data_value) then
157-
raise value_error;
158-
end if;
159-
160-
l_other := treat(a_other as ut_compound_data_value);
161-
162-
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_other.data_id);
163-
l_column_filter := ut_compound_data_helper.get_columns_filter( a_match_options.exclude.to_xpath(), a_match_options.include.to_xpath() );
164-
-- Find differences
165-
execute immediate 'insert into ' || l_ut_owner || '.ut_compound_data_diff_tmp ( diff_id, item_no )
166-
select :diff_id, nvl(exp.item_no, act.item_no)
167-
from (select '||l_column_filter||', ucd.item_no
168-
from ' || l_ut_owner || '.ut_compound_data_tmp ucd where ucd.data_id = :self_guid) exp
169-
full outer join
170-
(select '||l_column_filter||', ucd.item_no
171-
from ' || l_ut_owner || '.ut_compound_data_tmp ucd where ucd.data_id = :l_other_guid) act
172-
on exp.item_no = act.item_no '||
173-
'where nvl( dbms_lob.compare(' ||
174-
/*the xmltransform removes column names and leaves column data to be compared only*/
175-
' coalesce( xmltransform(exp.item_data, :l_xml_data_fmt).getclobval(), empty_clob() )' ||
176-
', coalesce( xmltransform(act.item_data, :l_xml_data_fmt).getclobval(), empty_clob() )' ||
177-
')' ||
178-
',1' ||
179-
') != 0'
180-
using in l_diff_id, a_match_options.exclude.to_xpath(), a_match_options.include.to_xpath(), self.data_id,
181-
a_match_options.exclude.to_xpath(), a_match_options.include.to_xpath(), l_other.data_id, l_xml_data_fmt, l_xml_data_fmt;
182-
--result is OK only if both are same
183-
if sql%rowcount = 0 and self.elements_count = l_other.elements_count then
184-
l_result := 0;
185-
else
186-
ut_compound_data_helper.set_rows_diff(sql%rowcount);
187-
l_result := 1;
188-
end if;
189-
return l_result;
190-
end;
191-
19266
end;
19367
/

source/expectations/data_values/ut_compound_data_value.tps

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ create or replace type ut_compound_data_value force under ut_data_value(
4444
overriding member function is_null return boolean,
4545
overriding member function is_diffable return boolean,
4646
overriding member function to_string return varchar2,
47-
overriding member function is_multi_line return boolean,
48-
overriding member function compare_implementation(a_other ut_data_value) return integer,
49-
overriding member function diff( a_other ut_data_value, a_match_options ut_matcher_options ) return varchar2,
50-
member function get_data_diff( a_other ut_data_value, a_match_options ut_matcher_options ) return clob,
51-
member function compare_implementation( a_other ut_data_value, a_match_options ut_matcher_options ) return integer
47+
overriding member function is_multi_line return boolean
5248
) not final not instantiable
5349
/

0 commit comments

Comments
 (0)