@@ -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;
0 commit comments