@@ -115,7 +115,8 @@ create or replace type body ut_data_value_refcursor as
115115 l_actual ut_data_value_refcursor;
116116 l_column_diffs ut_compound_data_helper.tt_column_diffs := ut_compound_data_helper.tt_column_diffs();
117117 l_exclude_xpath varchar2(32767) := a_exclude_xpath;
118-
118+ l_missing_pk ut_compound_data_helper.tt_missing_pk := ut_compound_data_helper.tt_missing_pk();
119+
119120 function get_col_diff_text(a_col ut_compound_data_helper.t_column_diffs) return varchar2 is
120121 begin
121122 return
@@ -130,7 +131,18 @@ create or replace type body ut_data_value_refcursor as
130131 ' Column <'||a_col.actual_name||'> is misplaced. Expected position: '||a_col.expected_pos||',' ||' actual position: '||a_col.actual_pos||'.'
131132 end;
132133 end;
133-
134+
135+ function get_missing_key_message(a_missing_keys ut_compound_data_helper.t_missing_pk) return varchar2 is
136+ begin
137+ return
138+ case a_missing_keys.diff_type
139+ when 'a' then
140+ ' Unknown key to join by in actual:'||a_missing_keys.missingxpath
141+ when 'e' then
142+ ' Unknown key to join by in expected:'||a_missing_keys.missingxpath
143+ end;
144+ end;
145+
134146 function add_incomparable_cols_to_xpath(
135147 a_column_diffs ut_compound_data_helper.tt_column_diffs, a_exclude_xpath varchar2
136148 ) return varchar2 is
@@ -151,6 +163,7 @@ create or replace type body ut_data_value_refcursor as
151163 end if;
152164 return l_result;
153165 end;
166+
154167 begin
155168 if not a_other is of (ut_data_value_refcursor) then
156169 raise value_error;
@@ -176,12 +189,20 @@ create or replace type body ut_data_value_refcursor as
176189 end if;
177190
178191 --diff rows and row elements
179- if a_join_by_xpath is not null then
180- ut_utils.append_to_clob(l_result, self.get_data_diff(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath));
181- elsif a_unordered then
182- ut_utils.append_to_clob(l_result, self.get_data_diff(a_other, l_exclude_xpath, a_include_xpath, a_unordered));
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
198+ ut_utils.append_to_clob(l_result,chr(10) || 'Unable to join sets:' || chr(10));
199+ for i in 1 .. l_missing_pk.count loop
200+ l_results.extend;
201+ ut_utils.append_to_clob(l_result, get_missing_key_message(l_missing_pk(i)));
202+ end loop;
203+ end if;
183204 else
184- ut_utils.append_to_clob(l_result, self.get_data_diff(a_other, l_exclude_xpath, a_include_xpath, a_join_by_xpath ));
205+ ut_utils.append_to_clob(l_result, self.get_data_diff(a_other, l_exclude_xpath, a_include_xpath, a_unordered ));
185206 end if;
186207
187208 l_result_string := ut_utils.to_string(l_result,null);
@@ -211,19 +232,29 @@ create or replace type body ut_data_value_refcursor as
211232 overriding 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 is
212233 l_result integer := 0;
213234 l_other ut_data_value_refcursor;
235+ l_missing_pk ut_compound_data_helper.tt_missing_pk := ut_compound_data_helper.tt_missing_pk();
214236 begin
215237 if not a_other is of (ut_data_value_refcursor) then
216238 raise value_error;
217239 end if;
218240
219241 l_other := treat(a_other as ut_data_value_refcursor);
242+
243+ l_missing_pk := ut_compound_data_helper.is_pk_exists(self.columns_info, l_other.columns_info, a_exclude_xpath, a_include_xpath,a_join_by_xpath);
244+ --if we join by key and key is missing fail and report error
245+ if a_join_by_xpath is not null and l_missing_pk.count > 0 then
246+ l_result := 1;
247+ return l_result;
248+ end if;
249+
220250 --if column names/types are not equal - build a diff of column names and types
221251 if ut_compound_data_helper.columns_hash( self, a_exclude_xpath, a_include_xpath )
222252 != ut_compound_data_helper.columns_hash( l_other, a_exclude_xpath, a_include_xpath )
223253 then
224254 l_result := 1;
225255 end if;
226- l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath, a_unordered);
256+
257+ l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath, a_unordered);
227258 return l_result;
228259 end;
229260
0 commit comments