@@ -186,7 +186,19 @@ create or replace package body ut_compound_data_helper is
186186
187187 return l_results;
188188 end;
189-
189+
190+ function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return varchar2 is
191+ l_pk_value varchar2(4000);
192+ begin
193+ select listagg(extractvalue(xmlelement("ROW",column_value),a_join_by_xpath),':') within group ( order by 1)
194+ into l_pk_value
195+ from table(xmlsequence(extract(a_item_data,'/*/*')));
196+
197+ return l_pk_value;
198+ exception when no_data_found then
199+ return 'null ';
200+ end;
201+
190202 function get_rows_diff(
191203 a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
192204 a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2,
@@ -195,15 +207,15 @@ create or replace package body ut_compound_data_helper is
195207 l_column_filter varchar2(32767);
196208 l_results tt_row_diffs;
197209 begin
198- l_column_filter := get_columns_filter (a_exclude_xpath,a_include_xpath);
210+ l_column_filter := get_columns_row_filter (a_exclude_xpath,a_include_xpath);
199211
200212 /**
201213 * Since its unordered search we cannot select max rows from diffs as we miss some comparision records
202214 * We will restrict output on higher level of select
203215 **/
204-
216+
205217 execute immediate q'[
206- with diff_info as (select item_hash,pk_hash,pk_value from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid)
218+ with diff_info as (select item_hash,pk_hash,pk_value, duplicate_no from ut_compound_data_diff_tmp ucdc where diff_id = :diff_guid)
207219 select rn,diff_type,diffed_row,pk_value from
208220 (
209221 select diff_type,diffed_row, dense_rank() over (order by pk_hash) rn,pk_value from
@@ -215,16 +227,17 @@ create or replace package body ut_compound_data_helper is
215227 xmlserialize(content exp.row_data no indent) exp_item,
216228 xmlserialize(content act.row_data no indent) act_item
217229 from
218- (select ucd.*, row_number() over(partition by pk_hash order by row_hash) duplicate_no
230+ (select ucd.*
219231 from
220232 (select ucd.column_value row_data,
221233 r.item_hash row_hash,
222234 r.pk_hash ,
223- r.pk_value,
235+ r.duplicate_no,
236+ ucd.column_value.getclobval() col_val,
224237 ucd.column_value.getRootElement() col_name,
225- ucd.column_value.getclobval() col_val
238+ ut_compound_data_helper.get_pk_value(:join_xpath,r.item_data) pk_value
226239 from
227- (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.pk_value
240+ (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.duplicate_no
228241 from ut_compound_data_tmp ucd,
229242 diff_info i
230243 where ucd.data_id = :self_guid
@@ -234,16 +247,17 @@ create or replace package body ut_compound_data_helper is
234247 ) ucd
235248 ) exp
236249 join (
237- select ucd.*, row_number() over(partition by pk_hash order by row_hash) duplicate_no
250+ select ucd.*
238251 from
239252 (select ucd.column_value row_data,
240253 r.item_hash row_hash,
241254 r.pk_hash ,
242- r.pk_value,
255+ r.duplicate_no,
256+ ucd.column_value.getclobval() col_val,
243257 ucd.column_value.getRootElement() col_name,
244- ucd.column_value.getclobval() col_val
258+ ut_compound_data_helper.get_pk_value(:join_xpath,r.item_data) pk_value
245259 from
246- (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.pk_value
260+ (select ]'||l_column_filter||q'[, ucd.item_no, ucd.item_hash, i.pk_hash, i.duplicate_no
247261 from ut_compound_data_tmp ucd,
248262 diff_info i
249263 where ucd.data_id = :other_guid
@@ -252,7 +266,8 @@ create or replace package body ut_compound_data_helper is
252266 table( xmlsequence( extract(r.item_data,'/*/*') ) ) ucd
253267 ) ucd
254268 ) act
255- on exp.pk_hash = act.pk_hash and exp.duplicate_no = act.duplicate_no
269+ on exp.pk_hash = act.pk_hash and exp.col_name = act.col_name
270+ and exp.duplicate_no = act.duplicate_no
256271 where dbms_lob.compare(exp.col_val, act.col_val) != 0
257272 )
258273 unpivot ( data_item for diff_type in (exp_item as 'Expected:', act_item as 'Actual:') )
@@ -261,15 +276,17 @@ create or replace package body ut_compound_data_helper is
261276 select case when exp.pk_hash is null then 'Extra:' else 'Missing:' end as diff_type,
262277 xmlserialize(content nvl(exp.item_data, act.item_data) no indent) diffed_row,
263278 coalesce(exp.pk_hash,act.pk_hash) pk_hash,
264- null pk_value
265- from (select extract(ucd.item_data,'/*/*') item_data,i.pk_hash
279+ coalesce(exp.pk_value,act.pk_value) pk_value
280+ from (select extract(ucd.item_data,'/*/*') item_data,i.pk_hash,
281+ ut_compound_data_helper.get_pk_value(:join_by,item_data) pk_value
266282 from ut_compound_data_tmp ucd,
267283 diff_info i
268284 where ucd.data_id = :self_guid
269285 and ucd.item_hash = i.item_hash
270286 ) exp
271287 full outer join (
272- select extract(ucd.item_data,'/*/*') item_data,i.pk_hash
288+ select extract(ucd.item_data,'/*/*') item_data,i.pk_hash,
289+ ut_compound_data_helper.get_pk_value(:join_by,item_data) pk_value
273290 from ut_compound_data_tmp ucd,
274291 diff_info i
275292 where ucd.data_id = :other_guid
@@ -282,10 +299,13 @@ create or replace package body ut_compound_data_helper is
282299 ]'
283300 bulk collect into l_results
284301 using a_diff_id,
302+ a_join_by_xpath,
285303 a_exclude_xpath, a_include_xpath, a_expected_dataset_guid,
304+ a_join_by_xpath,
286305 a_exclude_xpath, a_include_xpath, a_actual_dataset_guid,
287- a_expected_dataset_guid, a_actual_dataset_guid,
306+ a_join_by_xpath, a_expected_dataset_guid,a_join_by_xpath , a_actual_dataset_guid,
288307 a_max_rows;
308+
289309 return l_results;
290310 end;
291311
0 commit comments