1 package body EDW_SUMMARY_COLLECT AS
2 /*$Header: EDWSCOLB.pls 120.0 2005/05/31 18:10:44 appldev noship $*/
3
4 --MAIN ACCESS POINT
5 procedure collect_dimension_main(
6 p_conc_id number,
7 p_conc_name varchar2,
8 p_dim_name varchar2,
9 p_levels EDW_OWB_COLLECTION_UTIL.varcharTableType,
10 p_child_level_number EDW_OWB_COLLECTION_UTIL.numberTableType,
11 p_child_levels EDW_OWB_COLLECTION_UTIL.varcharTableType,
12 p_child_fk EDW_OWB_COLLECTION_UTIL.varcharTableType,
13 p_parent_pk EDW_OWB_COLLECTION_UTIL.varcharTableType,
14 p_level_snapshot_logs EDW_OWB_COLLECTION_UTIL.varcharTableType,
15 p_number_levels number,
16 p_debug boolean,
17 p_exec_flag boolean,
18 p_bis_owner varchar2,
19 p_parallel number,
20 p_collection_size number,
21 p_table_owner varchar2,
22 p_forall_size number,
23 p_update_type varchar2,
24 p_level_order EDW_OWB_COLLECTION_UTIL.varcharTableType,
25 p_skip_cols EDW_OWB_COLLECTION_UTIL.varcharTableType,
26 p_number_skip_cols number,
27 p_load_pk number,
28 p_fresh_restart boolean,
29 p_op_table_space varchar2,
30 p_rollback varchar2,
31 p_ltc_merge_use_nl boolean,
32 p_dim_inc_refresh_derv boolean,
33 p_check_fk_change boolean,
34 p_ok_switch_update number,
35 p_join_nl_percentage number,
36 p_thread_type varchar2,
37 p_max_threads number,
38 p_min_job_load_size number,
39 p_sleep_time number,
40 p_job_status_table varchar2,
41 p_hash_area_size number,
42 p_sort_area_size number,
43 p_trace boolean,
44 p_read_cfig_options boolean,
45 p_max_fk_density number,
46 p_analyze_frequency number,
47 p_parallel_drill_down boolean,
48 p_dd_status_table varchar2
49 ) is
50 Begin
51 if p_max_threads>1 then
52 --multi threaded
53 collect_dimension_multi_thread(
54 p_conc_id,
55 p_conc_name,
56 p_dim_name,
57 p_levels,
58 p_child_level_number,
59 p_child_levels,
60 p_child_fk,
61 p_parent_pk,
62 p_level_snapshot_logs,
63 p_number_levels,
64 p_debug,
65 p_exec_flag,
66 p_bis_owner,
67 p_parallel,
68 p_collection_size,
69 p_table_owner,
70 p_forall_size,
71 p_update_type,
72 p_level_order,
73 p_skip_cols,
74 p_number_skip_cols,
75 p_load_pk,
76 p_fresh_restart,
77 p_op_table_space,
78 p_rollback,
79 p_ltc_merge_use_nl,
80 p_dim_inc_refresh_derv,
81 p_check_fk_change,
82 p_ok_switch_update,
83 p_join_nl_percentage,
84 p_thread_type,
85 p_max_threads,
86 p_min_job_load_size,
87 p_sleep_time,
88 p_job_status_table,
89 p_hash_area_size,
90 p_sort_area_size,
91 p_trace,
92 p_read_cfig_options,
93 p_max_fk_density,
94 p_analyze_frequency,
95 p_parallel_drill_down,
96 p_dd_status_table
97 );
98 else
99 --single threaded
100 collect_dimension(
101 p_conc_id,
102 p_conc_name,
103 p_dim_name,
104 p_levels,
105 p_child_level_number,
106 p_child_levels,
107 p_child_fk,
108 p_parent_pk,
109 p_level_snapshot_logs,
110 p_number_levels,
111 p_debug,
112 p_exec_flag,
113 p_bis_owner,
114 p_parallel,
115 p_collection_size,
116 p_table_owner,
117 p_forall_size,
118 p_update_type,
119 p_level_order,
120 p_skip_cols,
121 p_number_skip_cols,
122 p_load_pk,
123 p_fresh_restart,
124 p_op_table_space,
125 p_rollback,
126 p_ltc_merge_use_nl,
127 p_dim_inc_refresh_derv,
128 p_check_fk_change,
129 p_ok_switch_update,
130 p_join_nl_percentage,
131 p_read_cfig_options,
132 p_max_fk_density,
133 p_analyze_frequency
134 );
135 end if;
136 Exception when others then
137 g_status_message:=sqlerrm;
138 g_status:=false;
139 write_to_log_file_n(g_status_message);
140 End;
141
142 procedure collect_dimension_multi_thread(
143 p_conc_id number,
144 p_conc_name varchar2,
145 p_dim_name varchar2,
146 p_levels EDW_OWB_COLLECTION_UTIL.varcharTableType,
147 p_child_level_number EDW_OWB_COLLECTION_UTIL.numberTableType,
148 p_child_levels EDW_OWB_COLLECTION_UTIL.varcharTableType,
149 p_child_fk EDW_OWB_COLLECTION_UTIL.varcharTableType,
150 p_parent_pk EDW_OWB_COLLECTION_UTIL.varcharTableType,
151 p_level_snapshot_logs EDW_OWB_COLLECTION_UTIL.varcharTableType,
152 p_number_levels number,
153 p_debug boolean,
154 p_exec_flag boolean,
155 p_bis_owner varchar2,
156 p_parallel number,
157 p_collection_size number,
158 p_table_owner varchar2,
159 p_forall_size number,
160 p_update_type varchar2,
161 p_level_order EDW_OWB_COLLECTION_UTIL.varcharTableType,
162 p_skip_cols EDW_OWB_COLLECTION_UTIL.varcharTableType,
163 p_number_skip_cols number,
164 p_load_pk number,
165 p_fresh_restart boolean,
166 p_op_table_space varchar2,
167 p_rollback varchar2,
168 p_ltc_merge_use_nl boolean,
169 p_dim_inc_refresh_derv boolean,
170 p_check_fk_change boolean,
171 p_ok_switch_update number,
172 p_join_nl_percentage number,
173 p_thread_type varchar2,
174 p_max_threads number,
175 p_min_job_load_size number,
176 p_sleep_time number,
177 p_job_status_table varchar2,
178 p_hash_area_size number,
179 p_sort_area_size number,
180 p_trace boolean,
181 p_read_cfig_options boolean,
182 p_max_fk_density number,
183 p_analyze_frequency number,
184 p_parallel_drill_down boolean,
185 p_dd_status_table varchar2
186 ) is
187 l_input_table varchar2(200);
188 l_ilog_table varchar2(100);
189 l_ok_low_end EDW_OWB_COLLECTION_UTIL.numberTableType;
190 l_ok_high_end EDW_OWB_COLLECTION_UTIL.numberTableType;
191 l_ok_end_count integer;
192 l_job_id EDW_OWB_COLLECTION_UTIL.numberTableType;
193 l_number_jobs number;
194 -----------------------------------------
195 l_temp_conc_name varchar2(200);
196 l_temp_conc_short_name varchar2(200);
197 l_temp_exe_name varchar2(200);
198 l_bis_short_name varchar2(200);
199 l_try_serial boolean;
200 -----------------------------------------
201 l_errbuf varchar2(2000);
202 l_retcode varchar2(200);
203 -----------------------------------------
204 Begin
205 g_dim_name:=p_dim_name;
206 g_jobid_stmt:=null;
207 g_job_id:=null;
208 g_conc_id :=p_conc_id;
209 g_conc_name:=p_conc_name;
210 g_object_type:='DIMENSION';
211 g_levels:=p_levels;
212 g_child_level_number:=p_child_level_number;
213 g_child_levels:=p_child_levels;
214 g_child_fk:=p_child_fk;
215 g_parent_pk:=p_parent_pk;
216 g_level_snapshot_logs:=p_level_snapshot_logs;
217 g_number_levels:=p_number_levels;
218 g_exec_flag:=p_exec_flag;
219 g_debug:=p_debug;
220 g_bis_owner:=p_bis_owner;
221 g_parallel:=p_parallel;
222 g_collection_size:=p_collection_size;
223 g_table_owner :=p_table_owner;
224 g_forall_size:=p_forall_size;
225 g_update_type :=p_update_type;
226 g_level_order:=p_level_order;
227 g_skip_cols:=p_skip_cols;
228 g_number_skip_cols:=p_number_skip_cols;
229 g_load_pk:=p_load_pk;
230 g_fresh_restart:=p_fresh_restart;
231 g_op_table_space:=p_op_table_space;
232 g_rollback:=p_rollback;
233 g_ltc_merge_use_nl:=p_ltc_merge_use_nl;
234 g_dim_inc_refresh_derv:=p_dim_inc_refresh_derv;
235 g_check_fk_change:=p_check_fk_change;
236 g_ok_switch_update:=p_ok_switch_update;
237 g_join_nl_percentage:=p_join_nl_percentage;
238 g_read_cfig_options:=p_read_cfig_options;
239 g_max_threads:=p_max_threads;
240 g_min_job_load_size:=p_min_job_load_size;
241 g_sleep_time:=p_sleep_time;
242 g_job_status_table:=p_job_status_table;
243 g_hash_area_size:=p_hash_area_size;
244 g_sort_area_size:=p_sort_area_size;
245 g_trace:=p_trace;
246 g_max_fk_density:=p_max_fk_density;
247 g_analyze_freq:=p_analyze_frequency;
248 g_thread_type:=p_thread_type;
249 g_parallel_drill_down:=p_parallel_drill_down;
250 g_dd_status_table:=p_dd_status_table;
251 if g_debug then
252 write_to_log_file_n('In collect_dimension_multi_thread for '||p_dim_name||get_time);
253 if g_parallel_drill_down then
254 write_to_log_file('Parallel drill down true table='||g_dd_status_table);
255 else
256 write_to_log_file('Parallel drill down false');
257 end if;
258 end if;
259 g_dim_id:=EDW_OWB_COLLECTION_UTIL.get_object_id(g_dim_name);
260 if g_debug then
261 write_to_log_file_n('g_dim_id='||g_dim_id);
262 end if;
263 if g_dim_id=-1 then
264 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
265 g_status:=false;
266 return;
267 end if;
268 l_input_table:=p_bis_owner||'.INP_TAB_'||g_dim_id;
269 g_jobid_stmt:=null;
270 g_job_id:=null;
271 g_status:=true;
272 g_job_status_table:=p_job_status_table;
273 g_all_done:=false;
274 if EDW_OWB_COLLECTION_UTIL.create_dim_load_input_table(
275 p_dim_name,
276 l_input_table,
277 p_conc_id,
278 p_conc_name,
279 p_levels,
280 p_child_level_number,
281 p_child_levels,
282 p_child_fk,
283 p_parent_pk,
284 p_level_snapshot_logs,
285 p_number_levels,
286 p_debug,
287 p_exec_flag,
288 p_bis_owner,
289 p_parallel,
290 p_collection_size,
291 p_table_owner,
292 p_forall_size,
293 p_update_type,
294 p_level_order,
295 p_skip_cols,
296 p_number_skip_cols,
297 p_load_pk,
298 p_fresh_restart,
299 p_op_table_space,
300 p_rollback,
301 p_ltc_merge_use_nl,
302 p_dim_inc_refresh_derv,
303 p_check_fk_change,
304 p_ok_switch_update,
305 p_join_nl_percentage,
306 p_max_threads,
307 p_min_job_load_size,
308 p_sleep_time,
309 p_job_status_table,
310 p_hash_area_size,
311 p_sort_area_size,
312 p_trace,
313 p_read_cfig_options,
314 p_max_fk_density
315 )=false then
316 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_status_message;
317 g_status:=false;
318 end if;
319 if g_status then
320 if initial_set_up(
321 l_input_table,
322 p_max_threads,
323 p_debug,
324 l_ilog_table)=false then
325 g_status:=false;
326 end if;
327 if g_all_done then
328 return;
329 end if;
330 if g_status then
331 if g_dim_direct_load then
332 insert_into_star;
333 else
334 if EDW_OWB_COLLECTION_UTIL.update_dim_load_input_table(
335 l_input_table,
336 l_ilog_table,
337 g_skip_ilog_update,
338 g_level_change,--to recreate from stmt etc
339 g_dim_empty_flag,
340 g_before_update_table_final,
341 g_error_rec_flag,
342 g_consider_snapshot,
343 g_levels_I,
344 g_use_ltc_ilog,
345 g_number_levels
346 )=false then
347 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_status_message;
348 g_status:=false;
349 end if;
350 if g_status then
351 --BRING IN THE CALL TO COLLECT
352 --if l_ilog_table is null, there are no records to load
353 if l_ilog_table is not null then
354 if EDW_OWB_COLLECTION_UTIL.find_ok_distribution(
355 l_ilog_table,
356 g_bis_owner,
357 p_max_threads,
358 p_min_job_load_size,
359 l_ok_low_end,
360 l_ok_high_end,
361 l_ok_end_count)=false then
362 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_status_message;
363 g_status:=false;
364 end if;
365 --l_ok_end_count decides the number of threads
366 if g_status then
367 /*
368 we will go for active polling. this main session will sleep for g_sleep_time and then
369 wake up and check the status of each of the jobs. If they are done, we can then proceed.
370 DBMS_JOB.SUBMIT(id,'test_pack_2.run_pack;')
371 */
372 l_number_jobs:=0;
373 l_temp_conc_name:='Sub-Proc Dim-'||g_dim_id;
374 l_temp_conc_short_name:='CONC_DIM_'||g_dim_id||'_CONC';
375 l_temp_exe_name:=l_temp_conc_name||'_EXE';
376 l_bis_short_name:='BIS';
377 if g_thread_type='CONC' then
378 --create the executable, conc program etc
379 if create_conc_program(l_temp_conc_name,l_temp_conc_short_name,l_temp_exe_name,
380 l_bis_short_name)=false then
381 if g_debug then
382 write_to_log_file_n('Could not create seed data for conc programs. Trying jobs');
383 end if;
384 g_thread_type:='JOB';
385 end if;
386 end if;
387 for j in 1..l_ok_end_count loop
388 l_number_jobs:=l_number_jobs+1;
389 l_job_id(l_number_jobs):=null;
390 if g_debug then
391 write_to_log_file_n('EDW_SUMMARY_COLLECT.COLLECT_DIMENSION('''||p_dim_name||''','||
392 ''''||l_input_table||''','||l_number_jobs||','||l_ok_low_end(j)||','||
393 l_ok_high_end(j)||');');
394 end if;
395 begin
396 l_try_serial:=false;
397 if g_thread_type='CONC' then
398 l_job_id(l_number_jobs):=FND_REQUEST.SUBMIT_REQUEST(
399 application=>l_bis_short_name,
400 program=>l_temp_conc_short_name,
401 argument1=>p_dim_name,
402 argument2=>l_input_table,
403 argument3=>l_number_jobs,
404 argument4=>l_ok_low_end(j),
405 argument5=>l_ok_high_end(j));
406 commit;
407 if g_debug then
408 write_to_log_file_n('Concurrent Request '||l_job_id(l_number_jobs)||' launched '||get_time);
409 end if;
410 if l_job_id(l_number_jobs)<=0 then
411 l_try_serial:=true;
412 end if;
413 else
414 DBMS_JOB.SUBMIT(l_job_id(l_number_jobs),'EDW_SUMMARY_COLLECT.COLLECT_DIMENSION('''||p_dim_name||''','||
415 ''''||l_input_table||''','||l_number_jobs||','||l_ok_low_end(j)||','||
416 l_ok_high_end(j)||');');
417 commit;--this commit is very imp
418 if g_debug then
419 write_to_log_file_n('Job '||l_job_id(l_number_jobs)||' launched '||get_time);
420 end if;
421 if l_job_id(l_number_jobs)<=0 then
422 l_try_serial:=true;
423 end if;
424 end if;
425 exception when others then
426 if g_debug then
427 write_to_log_file_n('Error launching parallel slaves '||sqlerrm);
428 end if;
429 l_try_serial:=true;
430 end;
431 if l_try_serial then
432 if g_debug then
433 write_to_log_file_n('Attempt serial load');
434 end if;
435 l_job_id(l_number_jobs):=0-l_number_jobs;
436 EDW_SUMMARY_COLLECT.COLLECT_DIMENSION(
437 l_errbuf,
438 l_retcode,
439 p_dim_name,
440 l_input_table,
441 l_number_jobs,
442 l_ok_low_end(j),
443 l_ok_high_end(j)
444 );
445 end if;
446 end loop;
447 if EDW_OWB_COLLECTION_UTIL.wait_on_jobs(
448 l_job_id,
449 l_number_jobs,
450 p_sleep_time,
451 g_thread_type)=false then
452 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_status_message;
453 g_status:=false;
454 g_status:=false;
455 end if;
456 if g_status then
457 if EDW_OWB_COLLECTION_UTIL.check_all_child_jobs(
458 p_job_status_table,
459 l_job_id,
460 l_number_jobs,
461 p_dim_name)=false then
462 g_status:=false;
463 return;
464 end if;
465 end if;
466 --dont delete the conc pgm. we may need the conc request log file
467 /*if g_thread_type='CONC' then
468 --drop the conc programs
469 if EDW_OWB_COLLECTION_UTIL.delete_conc_program(
470 l_temp_conc_short_name,
471 l_temp_exe_name,
472 l_bis_short_name,
473 'SHORT')=false then
474 null;
475 end if;
476 end if;*/
477 end if;
478 end if;
479 end if;
480 end if;
481 end if;
482 end if;
483 if g_status then
484 if drop_input_tables(l_input_table)=false then
485 null;
486 end if;
487 if EDW_OWB_COLLECTION_UTIL.drop_table(l_ilog_table)=false then
488 null;
489 end if;
490 if EDW_OWB_COLLECTION_UTIL.drop_table(p_job_status_table)=false then
491 null;
492 end if;
493 if drop_prot_table(g_insert_prot_table,g_insert_prot_table_active)=false then
494 null;
495 end if;
496 if drop_prot_table(g_bu_insert_prot_table,g_bu_insert_prot_table_active)=false then
497 null;
498 end if;
499 analyze_star_table;
500 clean_up;
501 end if;
502 Exception when others then
503 g_status_message:=sqlerrm;
504 g_status:=false;
505 write_to_log_file_n(g_status_message);
506 End;--procedure collect_dimension IS
507
508 function initial_set_up(
509 p_table_name varchar2,
510 p_max_threads number,
511 p_debug boolean,
512 p_ok_table out nocopy varchar2) return boolean is
513 Begin
514 if g_debug then
515 write_to_log_file_n('In initial_set_up p_max_threads='||p_max_threads||' '||get_time);
516 end if;
517 /*
518 the following must be updated into the inp table
519 g_skip_ilog_update
520 g_level_change --to recreate from stmt etc
521 g_dim_empty_flag
522 g_before_update_table_final
523 */
524 g_max_threads:=p_max_threads;
525 g_debug:=p_debug;
526 if EDW_OWB_COLLECTION_UTIL.create_job_status_table(g_job_status_table,g_op_table_space)=false then
527 return false;
528 end if;
529 init_all(g_job_id);
530 /*
531 see if the star is empty. if it is then load the rowid of the lowest level into the ilog
532 */
533 check_dim_star_empty; --reqd
534 if check_error = false then
535 return false;
536 end if;
537 if g_fresh_restart or g_dim_empty_flag then
538 if drop_restart_tables=false then
539 return false;
540 end if;
541 else
542 if EDW_OWB_COLLECTION_UTIL.merge_all_ilog_tables(g_ilog,g_ilog,g_ilog||'A','IL',g_op_table_space,g_bis_owner,
543 g_parallel)=false then
544 return false;
545 end if;
546 end if;
547 if get_dim_storage=false then
548 g_dim_next_extent:=16000000;--16M default
549 end if;
550 if g_debug then
551 write_to_log_file_n('Next extent ='||g_dim_next_extent);
552 end if;
553 insert_into_load_progress_d(g_load_pk,g_dim_name,'Read Metadata'||g_jobid_stmt,sysdate,null,'DIMENSION',
554 'METADAT','RM'||g_job_id,'I');
555 if get_snapshot_log = false then
556 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
557 return false;
558 end if;
559 if g_dim_empty_flag = false then
560 if check_snapshot_logs = false then
561 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog)=false then
562 null;
563 end if;
564 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
565 write_to_log_file_n('No incremental data to be considered for any level ');
566 g_all_done:=true;
567 return true;
568 end if;
569 if g_status=false then
570 return false;
571 end if;
572 end if;
573 make_level_alias;
574 if check_error = false then
575 return false;
576 end if;
577 /*
578 get the mapping details for the star
579 */
580 get_lvl_relations;
581 if check_error = false then
582 return false;
583 end if;
584 /*
585 get the dim star table pks
586 */
587 get_dim_map_ids;
588 if g_status=false then
589 return false;
590 end if;
591 if recover_from_previous_error= false then
592 return false;
593 end if;
594 --get the fks in the map
595 if EDW_OWB_COLLECTION_UTIL.get_fks_in_dim(g_dim_name,g_src_fk_table,g_src_fk,g_number_src_fk_table)=false then
596 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
597 g_status:=false;
598 return false;
599 end if;
600 if g_debug then
601 write_to_log_file_n('The FK used in the dim');
602 for i in 1..g_number_src_fk_table loop
603 write_to_log_file(g_src_fk_table(i)||'('||g_src_fk(i)||')');
604 end loop;
605 end if;
606 --make the select, from and where clause
607 make_select_from_where_stmt;
608 if check_error = false then
609 return false;
610 end if;
611 make_select_from_where_ins;
612 if check_error = false then
613 return false;
614 end if;
615 if name_op_tables(g_job_id)=false then
616 return false;
617 end if;
618 if drop_I_tables=false then
619 null;
620 end if;
621 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
622 --identify the slow changing cols
623 identify_slow_cols;
624 if check_error = false then
625 return false;
626 end if;
627 if g_dim_inc_refresh_derv then
628 if is_dim_in_derv_map= false then
629 return false;
630 end if;
631 end if;
632 if check_ll_snplog_col=-1 then --required
633 return false;
634 end if;
635 if g_dim_empty_flag then
636 if initial_insert_into_star(true)=false then
637 return false;
638 end if;
639 else
640 insert_into_load_progress_d(g_load_pk,g_dim_name,'Load ILOG'||g_jobid_stmt,sysdate,null,'DIMENSION',
641 'INSERT','IL2010'||g_job_id,'I');
642 insert_into_ilog(true);--multi threading true
643 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'IL2010'||g_job_id,'U');
644 if g_status=false then
645 return false;
646 end if;
647 end if;
648 insert_into_load_progress_d(g_load_pk,g_dim_name,'Create Protection Table'||g_jobid_stmt,sysdate,null,'DIMENSION',
649 'INSERT','CPTBL'||g_job_id,'I');
650 if g_dim_inc_refresh_derv then
651 if create_prot_table(g_bu_insert_prot_table,g_bu_insert_prot_table_active)=false then
652 g_status:=false;
653 return false;
654 end if;
655 if get_before_update_table_name=false then
656 g_status:=false;
657 return false;
658 end if;
659 end if;
660 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CPTBL'||g_job_id,'U');
661 if edw_owb_collection_util.is_column_in_table(g_ilog,'row_num',g_bis_owner)=false then
662 if put_rownum_in_ok_table=false then
663 g_status:=false;
664 return false;
665 end if;
666 end if;
667 p_ok_table:=g_ilog;
668 return true;
669 Exception when others then
670 g_status_message:=sqlerrm;
671 write_to_log_file_n('Error in initial_set_up '||g_status_message);
672 return false;
673 End;
674
675 /*
676 main entry point for each of the child concurrent request
677 */
678 procedure COLLECT_DIMENSION(
679 errbuf out nocopy varchar2,
680 retcode out nocopy varchar2,
681 p_dim_name varchar2,
682 p_table_name varchar2,--input table
683 p_job_id number,
684 p_ok_low_end number,
685 p_ok_high_end number
686 ) is
687 Begin
688 retcode:='0';
689 COLLECT_DIMENSION(
690 p_dim_name,
691 p_table_name,
692 p_job_id,
693 p_ok_low_end,
694 p_ok_high_end
695 );
696 if g_status=false then
697 retcode:='2';
698 errbuf:=g_status_message;
699 end if;
700 Exception when others then
701 errbuf:=sqlerrm;
702 retcode:='2';
703 write_to_log_file_n('Exception in COLLECT_DIMENSION '||sqlerrm||get_time);
704 End;
705
706 /*
707 main entry point for each of the child jobs
708 */
709 procedure COLLECT_DIMENSION(
710 p_dim_name varchar2,
711 p_table_name varchar2,--input table
712 p_job_id number,
713 p_ok_low_end number,
714 p_ok_high_end number
715 ) is
716 Begin
717 g_job_id:=p_job_id;
718 g_jobid_stmt:=' Job '||g_job_id||' ';
719 g_status:=true;
720 g_dim_name:=p_dim_name;
721 EDW_OWB_COLLECTION_UTIL.init_all(g_dim_name||'_'||g_job_id,null,'bis.edw.loader');
722 write_to_log_file_n('In COLLECT_DIMENSION. p_dim_name='||p_dim_name||', p_table_name='||p_table_name||
723 ', p_job_id='||p_job_id||', p_ok_low_end='||p_ok_low_end||', p_ok_high_end='||p_ok_high_end||get_time);
724 --g_job_id is not the dbms_job job_id. its just an identifier. goes from 1..n
725 /*need to open log file
726 this wont be conc manager log file
727 */
728 if COLLECT_DIMENSION(p_table_name,p_ok_low_end,p_ok_high_end)=false then
729 if EDW_OWB_COLLECTION_UTIL.log_into_job_status_table(
730 g_job_status_table,
731 g_dim_name,
732 g_job_id,
733 'ERROR',
734 g_status_message)=false then
735 null;
736 end if;
737 else
738 if EDW_OWB_COLLECTION_UTIL.log_into_job_status_table(
739 g_job_status_table,
740 g_dim_name,
741 g_job_id,
742 'SUCCESS',
743 g_status_message)=false then
744 null;
745 end if;
746 end if;
747 Exception when others then
748 g_status_message:=sqlerrm;
749 write_to_log_file_n('Error in COLLECT '||g_status_message);
750 g_status:=false;
751 End;
752
753 function COLLECT_DIMENSION(
754 p_table_name varchar2,--input table
755 p_ok_low_end number,
756 p_ok_high_end number
757 ) return boolean is
758 Begin
759 if read_options_table(p_table_name)=false then
760 return false;
761 end if;
762 --g_conc_program_id is read from p_table_name
763 EDW_OWB_COLLECTION_UTIL.set_conc_program_id(g_conc_id);
764 EDW_OWB_COLLECTION_UTIL.set_debug(g_debug);
765 EDW_OWB_COLLECTION_UTIL.set_parallel(g_parallel);
766 EDW_OWB_COLLECTION_UTIL.set_g_read_cfig_options(g_read_cfig_options);
767 if set_session_parameters=false then
768 g_status:=false;
769 return false;
770 end if; --alter session etc
771 g_dim_id:=EDW_OWB_COLLECTION_UTIL.get_object_id(g_dim_name);
772 if g_dim_id=-1 then
773 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
774 return false;
775 end if;
776 Init_all(g_job_id);--all tables will get job_id appended to them
777 /*
778 becasue init_all resets many of the global variables that we updated into the inp table,
779 will have to read again
780 */
781 if read_options_table(p_table_name)=false then
782 return false;
783 end if;
784 EDW_OWB_COLLECTION_UTIL.set_up(g_dim_name);
785 --if set_level_I_flag=false then
786 --return false;
787 --end if;
788 if get_dim_storage=false then
789 g_dim_next_extent:=16000000;--16M default
790 end if;
791 if g_debug then
792 write_to_log_file_n('Next extent ='||g_dim_next_extent);
793 end if;
794 insert_into_load_progress_d(g_load_pk,g_dim_name,'Read Metadata'||g_jobid_stmt,sysdate,null,'DIMENSION',
795 'METADAT','RM'||g_job_id,'I');
796 make_level_alias;
797 if g_status=false then
798 return false;
799 end if;
800 get_lvl_relations;
801 if g_status=false then
802 return false;
803 end if;
804 get_dim_map_ids;
805 if g_status=false then
806 return false;
807 end if;
808 if EDW_OWB_COLLECTION_UTIL.get_fks_in_dim(g_dim_name,g_src_fk_table,g_src_fk,g_number_src_fk_table)=false then
809 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
810 g_status:=false;
811 return false;
812 end if;
813 if g_debug then
814 write_to_log_file_n('The FK used in the dim');
815 for i in 1..g_number_src_fk_table loop
816 write_to_log_file(g_src_fk_table(i)||'('||g_src_fk(i)||')');
817 end loop;
818 end if;
819 if name_op_tables(g_job_id)=false then
820 return false;
821 end if;
822 make_select_from_where_stmt;
823 if g_status=false then
824 return false;
825 end if;
826 make_select_from_where_ins;
827 if g_status=false then
828 return false;
829 end if;
830 identify_slow_cols;
831 if g_status=false then
832 return false;
833 end if;
834 if g_dim_inc_refresh_derv then
835 if is_dim_in_derv_map= false then
836 return false;
837 end if;
838 end if;
839 if g_level_change then --g_level_change comes from inp table
840 if recreate_from_stmt=false then
841 return false;
842 end if;
843 end if;
844 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
845 if p_ok_low_end is null then
846 g_ilog:=g_ilog_main_name;
847 else
848 if make_ok_from_main_ok(
849 g_ilog_main_name,
850 p_ok_low_end,
851 p_ok_high_end)=false then
852 return false;
853 end if;
854 end if;
855 if g_status then
856 if g_dim_empty_flag then
857 insert_into_star;
858 else
859 collect_dim_via_temp;
860 end if;
861 end if;
862 if g_status then
863 clean_up_job;
864 else
865 return false;
866 end if;
867 return true;
868 Exception when others then
869 g_status_message:=sqlerrm;
870 write_to_log_file_n('Error in COLLECT '||g_status_message);
871 g_status:=false;
872 return false;
873 End;
874
875 --for single thread
876 procedure collect_dimension(
877 p_conc_id number,
878 p_conc_name varchar2,
879 p_dim_name varchar2,
880 p_levels EDW_OWB_COLLECTION_UTIL.varcharTableType,
881 p_child_level_number EDW_OWB_COLLECTION_UTIL.numberTableType,
882 p_child_levels EDW_OWB_COLLECTION_UTIL.varcharTableType,
883 p_child_fk EDW_OWB_COLLECTION_UTIL.varcharTableType,
884 p_parent_pk EDW_OWB_COLLECTION_UTIL.varcharTableType,
885 p_level_snapshot_logs EDW_OWB_COLLECTION_UTIL.varcharTableType,
886 p_number_levels number,
887 p_debug boolean,
888 p_exec_flag boolean,
889 p_bis_owner varchar2,
890 p_parallel number,
891 p_collection_size number,
892 p_table_owner varchar2,
893 p_forall_size number,
894 p_update_type varchar2,
895 p_level_order EDW_OWB_COLLECTION_UTIL.varcharTableType,
896 p_skip_cols EDW_OWB_COLLECTION_UTIL.varcharTableType,
897 p_number_skip_cols number,
898 p_load_pk number,
899 p_fresh_restart boolean,
900 p_op_table_space varchar2,
901 p_rollback varchar2,
902 p_ltc_merge_use_nl boolean,
903 p_dim_inc_refresh_derv boolean,
904 p_check_fk_change boolean,
905 p_ok_switch_update number,
906 p_join_nl_percentage number,
907 p_read_cfig_options boolean,
908 p_max_fk_density number,
909 p_analyze_frequency number
910 ) is
911 --get the mapping details for dim
912 --also used to see if slowly changing dim is implemented
913 begin
914 g_dim_name:=p_dim_name;
915 g_jobid_stmt:=null;
916 g_job_id:=null;
917 g_conc_id :=p_conc_id;
918 g_conc_name:=p_conc_name;
919 g_object_type:='DIMENSION';
920 g_levels:=p_levels;
921 g_child_level_number:=p_child_level_number;
922 g_child_levels:=p_child_levels;
923 g_child_fk:=p_child_fk;
924 g_parent_pk:=p_parent_pk;
925 g_level_snapshot_logs:=p_level_snapshot_logs;
926 g_number_levels:=p_number_levels;
927 g_exec_flag:=p_exec_flag;
928 g_debug:=p_debug;
929 g_bis_owner:=p_bis_owner;
930 g_parallel:=p_parallel;
931 g_collection_size:=p_collection_size;
932 g_table_owner :=p_table_owner;
933 g_forall_size:=p_forall_size;
934 g_update_type :=p_update_type;
935 g_level_order:=p_level_order;
936 g_skip_cols:=p_skip_cols;
937 g_number_skip_cols:=p_number_skip_cols;
938 g_load_pk:=p_load_pk;
939 g_fresh_restart:=p_fresh_restart;
940 g_op_table_space:=p_op_table_space;
941 g_rollback:=p_rollback;
942 g_ltc_merge_use_nl:=p_ltc_merge_use_nl;
943 g_dim_inc_refresh_derv:=p_dim_inc_refresh_derv;
944 g_check_fk_change:=p_check_fk_change;
945 g_ok_switch_update:=p_ok_switch_update;
946 g_join_nl_percentage:=p_join_nl_percentage;
947 g_read_cfig_options:=p_read_cfig_options;
948 g_max_fk_density:=p_max_fk_density;
949 g_analyze_freq:=p_analyze_frequency;
950 if g_debug then
951 write_to_log_file_n('In Summary Collect');
952 write_to_log_file('Input parameters');
953 write_to_log_file('g_dim_name='||g_dim_name);
954 write_to_log_file('g_bis_owner='||g_bis_owner);
955 write_to_log_file('g_parallel='||g_parallel);
956 write_to_log_file('g_collection_size='||g_collection_size);
957 write_to_log_file('g_table_owner='||g_table_owner);
958 write_to_log_file('g_forall_size='||g_forall_size);
959 write_to_log_file('g_number_levels='||g_number_levels);
960 write_to_log_file('g_load_pk='||g_load_pk);
961 write_to_log_file('g_op_table_space='||g_op_table_space);
962 write_to_log_file('g_rollback='||g_rollback);
963 if g_exec_flag then
964 write_to_log_file('Execute flag turned ON');
965 else
966 write_to_log_file('Execute flag turned OFF');
967 end if;
968 write_to_log_file('Level tables(snapshot log)');
969 for i in 1..g_number_levels loop
970 write_to_log_file(g_levels(i)||'('||g_level_snapshot_logs(i)||')');
971 end loop;
972 write_to_log_file('Ordered levels');
973 for i in 1..g_number_levels loop
974 write_to_log_file(g_level_order(i));
975 end loop;
976 write_to_log_file('The Skipped Columns');
977 for i in 1..g_number_skip_cols loop
978 write_to_log_file(g_skip_cols(i));
979 end loop;
980 if g_fresh_restart then
981 write_to_log_file('g_fresh_restart TRUE');
982 else
983 write_to_log_file('g_fresh_restart FALSE');
984 end if;
985 if g_ltc_merge_use_nl then
986 write_to_log_file('g_ltc_merge_use_nl TRUE');
987 else
988 write_to_log_file('g_ltc_merge_use_nl FALSE');
989 end if;
990 if g_dim_inc_refresh_derv then
991 write_to_log_file('g_dim_inc_refresh_derv TRUE');
992 else
993 write_to_log_file('g_dim_inc_refresh_derv FALSE');
994 end if;
995 if g_check_fk_change then
996 write_to_log_file('g_check_fk_change TRUE');
997 else
998 write_to_log_file('g_check_fk_change FALSE');
999 end if;
1000 write_to_log_file('g_ok_switch_update='||g_ok_switch_update);
1001 write_to_log_file('g_join_nl_percentage='||g_join_nl_percentage);
1002 if g_read_cfig_options then
1003 write_to_log_file('g_read_cfig_options TRUE');
1004 else
1005 write_to_log_file('g_read_cfig_options FALSE');
1006 end if;
1007 write_to_log_file('g_max_fk_density='||g_max_fk_density);
1008 write_to_log_file('g_analyze_freq='||g_analyze_freq);
1009 end if;
1010 g_dim_id:=EDW_OWB_COLLECTION_UTIL.get_object_id(g_dim_name);
1011 if g_dim_id=-1 then
1012 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
1013 return;
1014 end if;
1015 init_all(g_job_id);
1016 /*
1017 see if the star is empty. if it is then load the rowid of the lowest level into the ilog
1018 */
1019 check_dim_star_empty;
1020 if check_error = false then
1021 return;
1022 end if;
1023 if g_fresh_restart or g_dim_empty_flag then
1024 if drop_restart_tables=false then
1025 return;
1026 end if;
1027 else
1028 if EDW_OWB_COLLECTION_UTIL.merge_all_ilog_tables(g_ilog,g_ilog,g_ilog||'A','IL',g_op_table_space,g_bis_owner,
1029 g_parallel)=false then
1030 g_status:=false;
1031 return;
1032 end if;
1033 end if;
1034 if get_dim_storage=false then
1035 g_dim_next_extent:=16000000;--16M default
1036 end if;
1037 if g_debug then
1038 write_to_log_file_n('Next extent ='||g_dim_next_extent);
1039 end if;
1040 insert_into_load_progress_d(g_load_pk,g_dim_name,'Read Metadata'||g_jobid_stmt,sysdate,null,'DIMENSION',
1041 'METADAT','RM'||g_job_id,'I');
1042 if get_snapshot_log = false then
1043 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1044 return;
1045 end if;
1046 if g_dim_empty_flag = false then
1047 if check_snapshot_logs = false then
1048 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog)=false then
1049 null;
1050 end if;
1051 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1052 write_to_log_file_n('No incremental data to be considered for any level ');
1053 return;
1054 end if;
1055 if g_status=false then
1056 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1057 return;
1058 end if;
1059 end if;
1060 make_level_alias;
1061 if check_error = false then
1062 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1063 return;
1064 end if;
1065 /*
1066 get the mapping details for the star
1067 */
1068 get_lvl_relations;
1069 if check_error = false then
1070 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1071 return;
1072 end if;
1073 /*
1074 get the dim star table pks
1075 */
1076 get_dim_map_ids;
1077 if g_status=false then
1078 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1079 return;
1080 end if;
1081 if recover_from_previous_error= false then
1082 return;
1083 end if;
1084 --get the fks in the map
1085 if EDW_OWB_COLLECTION_UTIL.get_fks_in_dim(g_dim_name,g_src_fk_table,g_src_fk,g_number_src_fk_table)=false then
1086 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
1087 g_status:=false;
1088 return;
1089 end if;
1090 if g_debug then
1091 write_to_log_file_n('The FK used in the dim');
1092 for i in 1..g_number_src_fk_table loop
1093 write_to_log_file(g_src_fk_table(i)||'('||g_src_fk(i)||')');
1094 end loop;
1095 end if;
1096 --make the select, from and where clause
1097 make_select_from_where_stmt;
1098 if check_error = false then
1099 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1100 return;
1101 end if;
1102 make_select_from_where_ins;
1103 if check_error = false then
1104 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1105 return;
1106 end if;
1107 if name_op_tables(g_job_id)=false then
1108 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1109 return;
1110 end if;
1111 if drop_I_tables=false then
1112 null;
1113 end if;
1114 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'RM'||g_job_id,'U');
1115 --identify the slow changing cols
1116 identify_slow_cols;
1117 if check_error = false then
1118 return;
1119 end if;
1120 if g_dim_inc_refresh_derv then
1121 if is_dim_in_derv_map= false then
1122 return;
1123 end if;
1124 end if;
1125 insert_into_load_progress_d(g_load_pk,g_dim_name,'Create Protection Table'||g_jobid_stmt,sysdate,null,'DIMENSION',
1126 'INSERT','CPTBL'||g_job_id,'I');
1127 /*
1128 if g_slow_implemented then
1129 if create_prot_table(g_insert_prot_table,g_insert_prot_table_active)=false then
1130 g_status:=false;
1131 return ;
1132 end if;
1133 end if;*/
1134 if g_dim_inc_refresh_derv then
1135 if create_prot_table(g_bu_insert_prot_table,g_bu_insert_prot_table_active)=false then
1136 g_status:=false;
1137 return ;
1138 end if;
1139 if get_before_update_table_name=false then
1140 g_status:=false;
1141 return ;
1142 end if;
1143 end if;
1144 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CPTBL'||g_job_id,'U');
1145 collect_dimension;
1146 if check_error = false then
1147 return;
1148 end if;
1149 /*
1150 drop the temp, ilog tables etc
1151 */
1152 if drop_prot_table(g_insert_prot_table,g_insert_prot_table_active)=false then
1153 null;
1154 end if;
1155 if drop_prot_table(g_bu_insert_prot_table,g_bu_insert_prot_table_active)=false then
1156 null;
1157 end if;
1158 analyze_star_table;
1159 clean_up;
1160 Exception when others then
1161 g_status_message:=sqlerrm;
1162 g_status:=false;
1163 write_to_log_file_n(g_status_message);
1164 End;--procedure collect_dimension IS
1165
1166 /*
1167 the actual movement of data from the ltc to star
1168 here only in case of single thread
1169 */
1170 procedure collect_dimension is
1171 l_count number;
1172 Begin
1173 --now for performance optimization, see if the star table is empty.
1174 --if it is, then simple insert
1175 --check if the star had crashed previously. if yes, what is the number of processed records
1176 --from previous run?
1177 if g_debug then
1178 write_to_log_file_n('In Internal collect_dimension');
1179 end if;
1180 if check_ll_snplog_col=-1 then
1181 return;
1182 end if;
1183 if g_dim_empty_flag then
1184 if initial_insert_into_star(false)=false then
1185 return;
1186 end if;
1187 insert_into_star;
1188 else
1189 --INCREMENTAL DATA
1190 insert_into_load_progress_d(g_load_pk,g_dim_name,'Load ILOG'||g_jobid_stmt,sysdate,null,'DIMENSION',
1191 'INSERT','IL2010'||g_job_id,'I');
1192 insert_into_ilog(false);
1193 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'IL2010'||g_job_id,'U');
1194 if g_status=false then
1195 return;
1196 end if;
1197 collect_dim_via_temp;
1198 end if;--if g_dim_empty_flag then
1199 return;
1200 Exception when others then
1201 g_status_message:=sqlerrm;
1202 g_status:=false;
1203 write_to_log_file_n(g_status_message);
1204 End;--procedure collect_dimension IS
1205
1206 procedure collect_dim_via_temp is
1207 l_count number:=0;
1208 l_status number;
1209 Begin
1210 if g_debug then
1211 write_to_log_file_n('In collect_dim_via_temp');
1212 end if;
1213 make_temp_insert_sql;--to insert into the temp int table
1214 if check_error = false then
1215 return;
1216 end if;
1217 if g_debug then
1218 write_to_log_file_n('g_temp_insert_stmt is ');
1219 write_to_log_file(g_temp_insert_stmt);
1220 end if;
1221 --make_update_stmt_temp;
1222 make_temp_int_to_tm_stmt;
1223 if check_error = false then
1224 return;
1225 end if;
1226 make_hold_insert_stmt;
1227 if check_error = false then
1228 return;
1229 end if;
1230 if g_debug then
1231 write_to_log_file_n('The hold table insert stmt is '||g_hold_insert_stmt);
1232 end if;
1233 make_insert_update_stmt_star;
1234 if check_error = false then
1235 return;
1236 end if;
1237 if g_debug then
1238 write_to_log_file_n('The insert stmt into star is '||g_insert_stmt_star);
1239 end if;
1240 if g_debug then
1241 write_to_log_file_n('The update stmt into star is '||g_update_stmt_star);
1242 end if;
1243 if create_temp_table = false then
1244 write_to_log_file_n('create_temp_table returned with error ');
1245 return;
1246 end if;
1247 if create_temp_table_int = false then
1248 write_to_log_file_n('create_temp_table_int returned with error ');
1249 return;
1250 end if;
1251 if set_g_type_ilog_generation=false then
1252 g_type_ilog_generation:='CTAS';
1253 end if;
1254 loop
1255 l_count:=l_count+1;
1256 --if reset_profiles=false then
1257 --g_status:=false;
1258 --return;
1259 --end if;
1260 if g_error_rec_flag=false then --no error recovery
1261 if g_skip_ilog_update=false then
1262 l_status:=set_gilog_status;
1263 else
1264 g_skip_ilog_update:=false;
1265 l_status:=2;
1266 end if;
1267 else
1268 if EDW_OWB_COLLECTION_UTIL.does_table_have_data(g_ilog,' status=1 ')=2 then
1269 l_status:=2;
1270 else
1271 l_status:=set_gilog_status;
1272 end if;
1273 g_error_rec_flag:=false;
1274 g_skip_ilog_update:=false;
1275 end if;
1276 if l_status=0 then --error
1277 write_to_log_file_n('ERROR set_gilog_status returned with status 0');
1278 g_status:=false;
1279 return;
1280 elsif l_status=1 then
1281 --no more records to move to star
1282 write_to_log_file_n('All incremental data moved into the star');
1283 write_to_log_file('Moved a total of '||g_number_rows_inserted||' records into the star table');
1284 exit;
1285 else
1286 --process still going on
1287 insert_into_load_progress_d(g_load_pk,g_dim_name,'Determine Incremental Data'||g_jobid_stmt,
1288 sysdate,null,'DIMENSION','CREATE-TABLE','CDVT2000'||l_count||' '||g_job_id,'I');
1289 if g_level_change then
1290 if create_L_from_ilog=false then
1291 g_status:=false;
1292 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2000'||l_count||' '||
1293 g_job_id,'U');
1294 return;
1295 end if;
1296 if drill_up_net_change('SNP')=false then--create L tables for upper levels
1297 g_status:=false;
1298 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2000'||l_count||' '||
1299 g_job_id,'U');
1300 return;
1301 end if;
1302 if drop_ltc_copies=false then
1303 g_status:=false;
1304 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2000'||l_count||' '||g_job_id,'U');
1305 return;
1306 end if;
1307 if create_ltc_copies('SNP')=false then
1308 g_status:=false;
1309 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2000'||l_count||' '||g_job_id,'U');
1310 return;
1311 end if;
1312 --create_ltc_copies drops all the L tables
1313 end if;
1314 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2000'||l_count||' '||g_job_id,'U');
1315 insert_into_load_progress_d(g_load_pk,g_dim_name,'Pre proccess Dimension Data'||g_jobid_stmt,
1316 sysdate,null,'DIMENSION','INSERT','CDVT2010'||l_count||' '||g_job_id,'I');
1317 execute_temp_insert_sql;--move the data into int temp table
1318 if check_error = false then
1319 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2010'||l_count||' '||g_job_id,'U');
1320 return;
1321 end if;
1322 if g_slow_implemented then
1323 --make the key lookup table
1324 if create_kl_table = false then --contains the user pk and max(rowid)
1325 write_to_log_file_n('create_kl_table returned with error');
1326 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2010'||l_count||' '||g_job_id,'U');
1327 return ;
1328 end if;
1329 end if;
1330 if create_g_dim_name_with_slow=false then
1331 g_status:=false;
1332 return;
1333 end if;
1334 execute_temp_int_to_tm_stmt;
1335 if check_error = false then
1336 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2010'||l_count||' '||g_job_id,'U');
1337 return;
1338 end if;
1339 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2010'||l_count||' '||g_job_id,'U');
1340 --if there is insert, we need to create ltc copies for all those levels that have g_level_consider=false
1341 --insert needs to join all levels. update needs to join only the needed levels
1342 if g_level_change then
1343 if g_insert_star_flag then
1344 insert_into_load_progress_d(g_load_pk,g_dim_name,'Drill Up for all levels'||g_jobid_stmt,
1345 sysdate,null,'DIMENSION','CREATE-TABLE','DUPALL000'||l_count||' '||g_job_id,'I');
1346 if g_debug then
1347 write_to_log_file_n('Drill up for non considered levels');
1348 end if;
1349 if g_called_ltc_ilog_create=false then
1350 if create_ltc_ilog_table('NON-SNP')=false then
1351 g_status:=false;
1352 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'DUPALL000'||l_count||' '||g_job_id,'U');
1353 return;
1354 end if;
1355 else
1356 g_called_ltc_ilog_create:=true;
1357 end if;
1358 if drill_up_net_change('NON-SNP')=false then
1359 g_status:=false;
1360 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'DUPALL000'||l_count||' '||g_job_id,'U');
1361 return;
1362 end if;
1363 if create_ltc_copies('NON-SNP')=false then
1364 g_status:=false;
1365 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'DUPALL000'||l_count||' '||g_job_id,'U');
1366 return;
1367 end if;
1368 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'DUPALL000'||l_count||' '||g_job_id,'U');
1369 end if;
1370 if drop_L_tables=false then
1371 g_status:=false;
1372 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'DUPALL000'||l_count||' '||g_job_id,'U');
1373 return;
1374 end if;
1375 end if;
1376 --if there are rows for update, move the data into hold table
1377 if g_update_star_flag then
1378 insert_into_load_progress_d(g_load_pk,g_dim_name,'Move Update Data into Hold Table'||g_jobid_stmt,
1379 sysdate,null,'DIMENSION','CREATE-TABLE','CDVT2020'||l_count||' '||g_job_id,'I');
1380 execute_hold_insert_stmt;
1381 if check_error = false then
1382 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2020'||l_count||' '||g_job_id,'U');
1383 return;
1384 end if;
1385 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2020'||l_count||' '||g_job_id,'U');
1386 end if;
1387 execute_insert_update_star(l_count);
1388 g_number_rows_processed:=g_number_rows_processed+g_number_rows_inserted;
1389 if g_debug then
1390 write_to_log_file_n('Moved '||g_number_rows_inserted||' into star table');
1391 write_to_log_file('Total moved so far '||g_number_rows_processed);
1392 end if;
1393 if check_error = false then
1394 return;
1395 end if;
1396 if g_type_ilog_generation='UPDATE' then
1397 if delete_gilog_status = false then --delete where status=1
1398 return;
1399 end if;
1400 end if;
1401 if EDW_OWB_COLLECTION_UTIL.record_coll_progress(g_dim_name, g_object_type,
1402 g_number_rows_processed,'PROCESSING','UPDATE')=false then
1403 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
1404 write_to_log_file_n(g_status_message);
1405 g_status:=false;
1406 return;
1407 end if;
1408 commit;
1409 if g_debug then
1410 write_to_log_file_n('commit');
1411 end if;
1412 if EDW_OWB_COLLECTION_UTIL.truncate_table(g_dim_name_temp_int) = false then
1413 return;
1414 end if;
1415 if EDW_OWB_COLLECTION_UTIL.truncate_table(g_dim_name_temp) = false then
1416 return;
1417 end if;
1418 if g_update_star_flag then
1419 if EDW_OWB_COLLECTION_UTIL.truncate_table(g_dim_name_hold) = false then
1420 return;
1421 end if;
1422 end if;
1423 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_with_slow)=false then
1424 null;
1425 end if;
1426 end if; --if there are still records in the ilog to consider
1427 end loop;
1428 Exception when others then
1429 g_status_message:=sqlerrm;
1430 g_status:=false;
1431 write_to_log_file_n(g_status_message);
1432 End;
1433
1434 PROCEDURE check_dim_star_empty IS
1435 l_stmt varchar2(1000);
1436 v_res number:=null;
1437 TYPE CurTyp IS REF CURSOR;
1438 cv CurTyp;
1439 Begin
1440 if g_debug then
1441 write_to_log_file_n('In check_dim_star_empty'||get_time);
1442 end if;
1443 v_res:=0;
1444 l_stmt:='select 1 from '||g_dim_name||' where rownum=1';
1445 open cv for l_stmt;
1446 fetch cv into v_res;
1447 if v_res =1 then
1448 g_dim_empty_flag:=false;
1449 if g_debug then
1450 write_to_log_file_n('Star not empty');
1451 end if;
1452 else
1453 if g_debug then
1454 write_to_log_file_n('Star empty');
1455 end if;
1456 g_dim_empty_flag:=true;
1457 end if;
1458 close cv;
1459
1460 Exception when others then
1461 begin
1462 close cv;
1463 exception when others then
1464 null;
1465 end;
1466 g_status_message:=sqlerrm;
1467 write_to_log_file_n(g_status_message);
1468 write_to_log_file('Problem statement :'||l_stmt);
1469 g_status:=false;
1470 End;--PROCEDURE check_dim_star_empty IS
1471
1472 --the procedure insert_into_star is for first time insert only.
1473 --this is for performance
1474
1475 function initial_insert_into_star(p_multi_thread boolean) return boolean is
1476 Begin
1477 if g_debug then
1478 write_to_log_file_n('In initial_insert_into_star');
1479 end if;
1480 g_dim_direct_load:=false;
1481 if g_number_levels=1 or g_collection_size=0 then
1482 g_level_change:=false;
1483 g_ltc_merge_use_nl:=false;
1484 end if;
1485 if g_level_change=false and g_collection_size=0 then
1486 g_dim_direct_load:=true;
1487 end if;
1488 if g_dim_direct_load=false then
1489 insert_into_load_progress_d(g_load_pk,g_dim_name,'Load ILOG'||g_jobid_stmt,sysdate,null,'DIMENSION',
1490 'INSERT','IL2010'||g_job_id,'I');
1491 insert_into_ilog(p_multi_thread);
1492 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'IL2010'||g_job_id,'U');
1493 if g_status=false then
1494 return false;
1495 end if;
1496 else
1497 if create_dummy_ilog=false then
1498 return false;
1499 end if;
1500 truncate_ltc_snapshot_logs;
1501 end if;
1502 if g_dim_direct_load=false and g_level_change then
1503 insert_into_load_progress_d(g_load_pk,g_dim_name,'Create Level Key Tables'||g_jobid_stmt,sysdate,null,'DIMENSION',
1504 'CREATE-TABLE','IS2020'||g_job_id,'I');
1505 if drop_L_tables=false then
1506 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'IS2020'||g_job_id,'U');
1507 g_status:=false;
1508 return false;
1509 end if;
1510 if create_ltc_ilog_table('SNP')=false then
1511 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'IS2020'||g_job_id,'U');
1512 g_status:=false;
1513 return false;
1514 end if;
1515 if recreate_from_stmt=false then
1516 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'IS2020'||g_job_id,'U');
1517 g_status:=false;
1518 return false;
1519 end if;
1520 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'IS2020'||g_job_id,'U');
1521 end if;
1522 return true;
1523 Exception when others then
1524 g_status_message:=sqlerrm;
1525 write_to_log_file_n('Error in initial_insert_into_star '||g_status_message);
1526 g_status:=false;
1527 End;
1528
1529 PROCEDURE insert_into_star IS
1530 l_stmt varchar2(32000);
1531 l_stmt_row varchar2(32000);
1532 l_count number:=0; --counts the records as they make in
1533 l_status number;
1534 l_table varchar2(200);
1535 TYPE CurTyp IS REF CURSOR;
1536 cv CurTyp;
1537 l_stmt1 varchar2(4000);
1538 l_rowid rowid;
1539 l_ins_count number;
1540 l_insert_type varchar2(200);
1541 Begin
1542 if g_debug then
1543 write_to_log_file_n('In insert_into_star'||get_time);
1544 end if;
1545 l_insert_type:='MASS';
1546 --assume that there are proper levels here
1547 if g_parallel is null then
1548 l_stmt:='insert into '||g_dim_name||' ( ';
1549 else
1550 l_stmt:='insert /*+ PARALLEL ('||g_dim_name||','||g_parallel||') */ into '||g_dim_name||' ( ';
1551 end if;
1552 l_stmt_row:='insert into '||g_dim_name||' ( ';
1553 for i in 1..g_number_mapping loop
1554 if g_skip_item(i)=false then
1555 l_stmt:=l_stmt||' '||g_dim_col(i)||',';
1556 l_stmt_row:=l_stmt_row||' '||g_dim_col(i)||',';
1557 end if;
1558 end loop;
1559 l_stmt:=l_stmt||' CREATION_DATE, LAST_UPDATE_DATE ) ';
1560 l_stmt_row:=l_stmt_row||' CREATION_DATE, LAST_UPDATE_DATE ) ';
1561 if g_dim_direct_load then
1562 if g_where_stmt is not null then
1563 l_stmt:=l_stmt||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' '||g_where_stmt;
1564 l_stmt_row:=l_stmt_row||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' '||g_where_stmt||' and '||
1565 g_lowest_level_alias||'.rowid=:a';
1566 else
1567 l_stmt:=l_stmt||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt;
1568 l_stmt_row:=l_stmt_row||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' where '||
1569 g_lowest_level_alias||'.rowid=:a';
1570 end if;
1571 else
1572 if g_level_change=false then
1573 if g_where_stmt is not null then
1574 l_stmt:=l_stmt||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||','||g_ilog_small||' '||g_where_stmt||
1575 ' And '||g_ilog_small||'.row_id='||g_lowest_level_alias||'.rowid';
1576 l_stmt_row:=l_stmt_row||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' '||g_where_stmt||' and '||
1577 g_lowest_level_alias||'.rowid=:a';
1578 else
1579 l_stmt:=l_stmt||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||','||g_ilog_small||' where '||
1580 g_ilog_small||'.row_id='||g_lowest_level_alias||'.rowid';
1581 l_stmt_row:=l_stmt_row||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' where '||
1582 g_lowest_level_alias||'.rowid=:a';
1583 end if;
1584 else
1585 if g_where_stmt is not null then
1586 --remember, ltc copies are only holding commit size data!
1587 if g_ltc_merge_use_nl then
1588 l_stmt:=l_stmt||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' '||g_where_stmt||
1589 ' and '||g_lowest_level_alias||'.rowid=:a';
1590 l_stmt_row:=l_stmt_row||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' '||g_where_stmt||
1591 ' and '||g_lowest_level_alias||'.rowid=:a';
1592 else
1593 l_stmt:=l_stmt||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' '||g_where_stmt;
1594 l_stmt_row:=l_stmt_row||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' '||g_where_stmt||
1595 ' and '||g_lowest_level_alias||'.rowid=:a';
1596 end if;
1597 else
1598 if g_ltc_merge_use_nl then
1599 l_stmt:=l_stmt||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' where '||
1600 g_lowest_level_alias||'.rowid=:a';
1601 l_stmt_row:=l_stmt_row||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' where '||
1602 g_lowest_level_alias||'.rowid=:a';
1603 else
1604 l_stmt:=l_stmt||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt;
1605 l_stmt_row:=l_stmt_row||g_select_stmt||',SYSDATE,SYSDATE '||g_from_stmt||' and '||
1606 g_lowest_level_alias||'.rowid=:a';
1607 end if;
1608 end if;
1609 end if;
1610 end if;
1611 if g_debug then
1612 write_to_log_file_n('The denormalization stmt is '||l_stmt);
1613 write_to_log_file_n('The denormalization stmt ROW-BY-ROW is '||l_stmt_row);
1614 end if;
1615 loop
1616 --if reset_profiles=false then
1617 --g_status:=false;
1618 --return;
1619 --end if;
1620 if g_skip_ilog_update=false then
1621 l_status:=set_gilog_status;
1622 else
1623 g_skip_ilog_update:=false;
1624 l_status:=2;
1625 end if;
1626 if l_status=0 then --error
1627 g_status:=false;
1628 return;
1629 elsif l_status=1 then
1630 --no more records to move to star
1631 write_to_log_file_n('Moved a total of '||g_number_rows_processed||' records into the star table');
1632 exit;
1633 else
1634 --process still going on
1635 --g_collection_size
1636 insert_into_load_progress_d(g_load_pk,g_dim_name,'Insert into Star'||g_jobid_stmt,sysdate,null,'DIMENSION',
1637 'INSERT','LIS2020'||l_count||' '||g_job_id,'I');
1638 if g_level_change then
1639 if create_L_from_ilog=false then
1640 g_status:=false;
1641 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LIS2020'||l_count||' '||g_job_id,'U');
1642 return;
1643 end if;
1644 if drill_up_net_change('SNP')=false then--create L tables
1645 g_status:=false;
1646 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LIS2020'||l_count||' '||g_job_id,'U');
1647 return;
1648 end if;
1649 if drop_ltc_copies=false then
1650 g_status:=false;
1651 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LIS2020'||l_count||' '||g_job_id,'U');
1652 return;
1653 end if;
1654 if create_ltc_copies('SNP')=false then
1655 g_status:=false;
1656 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LIS2020'||l_count||' '||g_job_id,'U');
1657 return;
1658 end if;
1659 if drop_L_tables=false then
1660 g_status:=false;
1661 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LIS2020'||l_count||' '||g_job_id,'U');
1662 return;
1663 end if;
1664 else
1665 if g_collection_size>0 then
1666 if create_gilog_small=false then
1667 return;
1668 end if;
1669 end if;
1670 end if;
1671 begin
1672 if g_debug then
1673 write_to_log_file_n('Going to execute insert into star');
1674 end if;
1675 <<start_direct_insert>>
1676 if g_ltc_merge_use_nl or l_insert_type='ROW-BY-ROW' then
1677 if g_debug then
1678 write_to_log_file_n('nested loop option');
1679 end if;
1680 g_number_rows_inserted:=0;
1681 l_ins_count:=0;
1682 l_table:=g_dim_name_hold||'R';
1683 l_stmt1:='create table '||l_table||' tablespace '||g_op_table_space;
1684 if g_parallel is not null then
1685 l_stmt1:=l_stmt1||' parallel (degree '||g_parallel||') ';
1686 end if;
1687 l_stmt1:=l_stmt1||' as select rowid row_id from '||g_lowest_level;
1688 if g_debug then
1689 write_to_log_file_n('Going to execute '||l_stmt1||get_time);
1690 end if;
1691 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table)=false then
1692 null;
1693 end if;
1694 execute immediate l_stmt1;
1695 if g_debug then
1696 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
1697 end if;
1698 EDW_OWB_COLLECTION_UTIL.alter_session('NO-PARALLEL');
1699 l_stmt1:='select row_id from '||l_table;
1700 open cv for l_stmt1;
1701 loop
1702 fetch cv into l_rowid;
1703 exit when cv%notfound;
1704 execute immediate l_stmt_row using l_rowid;
1705 l_ins_count:=l_ins_count+1;
1706 g_number_rows_inserted:=g_number_rows_inserted+1;
1707 if l_ins_count=5000 then
1708 commit;
1709 l_ins_count:=0;
1710 end if;
1711 end loop;
1712 commit;
1713 close cv;
1714 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table)=false then
1715 null;
1716 end if;
1717 if g_parallel is not null then
1718 EDW_OWB_COLLECTION_UTIL.alter_session('PARALLEL');
1719 end if;
1720 else
1721 begin
1722 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
1723 execute immediate l_stmt;
1724 exception when others then
1725 if sqlcode=-4030 then
1726 if g_debug then
1727 write_to_log_file_n('Out of memory error in mass insert. (Try row-by-row) '||sqlerrm);
1728 end if;
1729 l_insert_type:='ROW-BY-ROW';
1730 goto start_direct_insert;
1731 elsif sqlcode=-00060 then
1732 if g_debug then
1733 write_to_log_file_n('Deadlock detected. Try again after sleep');
1734 end if;
1735 DBMS_LOCK.SLEEP(g_sleep_time);
1736 goto start_direct_insert;
1737 end if;
1738 g_status_message:=sqlerrm;
1739 write_to_log_file_n(g_status_message);
1740 g_status:=false;
1741 return;
1742 end;
1743 g_number_rows_inserted:=sql%rowcount;
1744 end if;
1745 g_number_rows_processed:=g_number_rows_processed+g_number_rows_inserted;
1746 if g_debug then
1747 write_to_log_file_n('Moved '||g_number_rows_inserted||' into the star table '||get_time);
1748 write_to_log_file('Total moved so far '||g_number_rows_processed);
1749 end if;
1750 exception when others then
1751 g_status_message:=sqlerrm;
1752 g_status:=false;
1753 write_to_log_file_n(g_status_message);
1754 write_to_log_file('Problem stmt '||l_stmt);
1755 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LIS2020'||l_count||' '||g_job_id,'U');
1756 return;
1757 end;
1758 if g_type_ilog_generation='UPDATE' then
1759 if delete_gilog_status=false then --delete where status=1
1760 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LIS2020'||l_count||' '||g_job_id,'U');
1761 return;
1762 end if;
1763 end if;
1764 --update the row in progress log table. EDWACOLB does the insert
1765 if EDW_OWB_COLLECTION_UTIL.record_coll_progress(g_dim_name, g_object_type,
1766 g_number_rows_processed,'PROCESSING','UPDATE')= false then
1767 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
1768 g_status:=false;
1769 write_to_log_file_n(g_status_message);
1770 end if;
1771 commit;
1772 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LIS2020'||l_count||' '||g_job_id,'U');
1773 l_count:=l_count+1;
1774 end if;
1775 end loop;
1776 Exception when others then
1777 g_status_message:=sqlerrm;
1778 write_to_log_file_n(g_status_message);
1779 g_status:=false;
1780 End;--PROCEDURE insert_into_star IS
1781
1782
1783 /*
1784 this function sets the status of the ilog from 0 to 1 and also deletes those that are 1 first
1785 returns:
1786 0: error
1787 1: no more records to change from 0 to 1
1788 2: success
1789 */
1790 function set_gilog_status return number is
1791 l_stmt varchar2(10000);
1792 l_count number;
1793 L_ILOG_PREV varchar2(400);
1794 Begin
1795 --update
1796 if g_debug then
1797 write_to_log_file_n('In set_gilog_status type='||g_type_ilog_generation);
1798 end if;
1799 --no need to explictly say parallel for g_ilog because its created with parallel option
1800 --(if the g_parallel option is not null of course
1801 if g_type_ilog_generation='UPDATE' then
1802 if g_collection_size =0 then
1803 l_stmt:='update '||g_ilog||' set status=1 ';
1804 else
1805 l_stmt:='update '||g_ilog||' set status=1 where rownum <='||g_collection_size;
1806 end if;
1807 if g_debug then
1808 write_to_log_file_n('Going to execute '||l_stmt);
1809 end if;
1810 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
1811 execute immediate l_stmt;
1812 l_count:=sql%rowcount;
1813 commit;
1814 if g_debug then
1815 write_to_log_file_n('commit');
1816 end if;
1817 if g_debug then
1818 write_to_log_file_n('Updated '||l_count||' rows in '||g_ilog||get_time);
1819 end if;
1820 elsif g_type_ilog_generation='CTAS' then
1821 if g_ilog_prev is null then
1822 g_ilog_prev:=g_ilog;
1823 if substr(g_ilog,length(g_ilog),1)='A' then
1824 g_ilog:=substr(g_ilog,1,length(g_ilog)-1);
1825 else
1826 g_ilog:=g_ilog||'A';
1827 end if;
1828 else
1829 l_ilog_prev:=g_ilog_prev;
1830 g_ilog_prev:=g_ilog;
1831 g_ilog:=l_ilog_prev;
1832 end if;
1833 l_stmt:='create table '||g_ilog||' tablespace '||g_op_table_space;
1834 l_stmt:=l_stmt||' storage (initial 4M next 4M pctincrease 0) ';
1835 if g_parallel is not null then
1836 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
1837 end if;
1838 if g_collection_size > 0 then
1839 if g_ll_snplog_has_pk then
1840 l_stmt:=l_stmt||' as select row_id,'||g_ltc_pk||',decode(status,1,2,2,2,decode(sign(rownum-'||
1841 g_collection_size||'),1,0,1)) status from (select row_id,'||g_ltc_pk||',status from '||g_ilog_prev||
1842 ' order by status) abc ';
1843 else
1844 l_stmt:=l_stmt||' as select row_id,decode(status,1,2,2,2,decode(sign(rownum-'||
1845 g_collection_size||'),1,0,1)) status from (select row_id,status from '||g_ilog_prev||
1846 ' order by status) abc ';
1847 end if;
1848 else
1849 if g_ll_snplog_has_pk then
1850 l_stmt:=l_stmt||' as select row_id,'||g_ltc_pk||',decode(status,1,2,0,1,2) status from '||
1851 g_ilog_prev;
1852 else
1853 l_stmt:=l_stmt||' as select row_id,decode(status,1,2,0,1,2) status from '||
1854 g_ilog_prev;
1855 end if;
1856 end if;
1857 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog)=false then
1858 null;
1859 end if;
1860 if g_debug then
1861 write_to_log_file_n('Going to execute '||l_stmt||get_time);
1862 end if;
1863 execute immediate l_stmt;
1864 if g_debug then
1865 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
1866 end if;
1867 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog_prev)=false then
1868 null;
1869 end if;
1870 if EDW_OWB_COLLECTION_UTIL.does_table_have_data(g_ilog,' status=1 ')<2 then
1871 l_count:=0;
1872 else
1873 l_count:=1;
1874 end if;
1875 if g_debug then
1876 write_to_log_file_n('Time'||get_time);
1877 end if;
1878 end if;
1879 if l_count=0 then
1880 return 1;
1881 else
1882 return 2;
1883 end if;
1884 Exception when others then
1885 g_status_message:=sqlerrm;
1886 write_to_log_file_n(g_status_message);
1887 g_status:=false;
1888 return 0;
1889 End;
1890
1891 function delete_gilog_status return boolean is
1892 l_stmt varchar2(4000);
1893 Begin
1894 if g_debug then
1895 write_to_log_file_n('In delete_gilog_status');
1896 end if;
1897 l_stmt:='delete '||g_ilog||' where status=1';
1898 if g_debug then
1899 write_to_log_file_n('Going to execute '||l_stmt);
1900 end if;
1901 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
1902 execute immediate l_stmt;
1903 --commit;
1904 if g_debug then
1905 write_to_log_file_n('Deleted '||sql%rowcount||' rows from '||g_ilog||get_time);
1906 end if;
1907 return true;
1908 Exception when others then
1909 g_status_message:=sqlerrm;
1910 g_status:=false;
1911 write_to_log_file_n(g_status_message);
1912 write_to_log_file('Problem stmt '||l_stmt);
1913 return false;
1914 End;
1915
1916 /*
1917 for slowly changing dims, create the key lookup table that contains user pk and rowid (max)
1918 */
1919 function create_kl_table return boolean is
1920 l_stmt varchar2(10000);
1921 l_dim_name_temp_int varchar2(400);
1922 Begin
1923 --g_dim_kl_table
1924 if g_debug then
1925 write_to_log_file_n('In create_kl_table');
1926 end if;
1927 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_kl_table_temp) = false then
1928 null;
1929 end if;
1930 l_dim_name_temp_int:=g_dim_name_temp_int||'T';--just a temp table
1931 if EDW_OWB_COLLECTION_UTIL.drop_table(l_dim_name_temp_int) = false then
1932 null;
1933 end if;
1934 l_stmt:='create table '||l_dim_name_temp_int||' tablespace '||g_op_table_space;
1935 if g_parallel is not null then
1936 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
1937 end if;
1938 l_stmt:=l_stmt||' as select '||g_dim_user_pk||' from '||g_dim_name_temp_int;
1939 if g_debug then
1940 write_to_log_file_n('Going to execute '||l_stmt||get_time);
1941 end if;
1942 execute immediate l_stmt;
1943 if g_debug then
1944 write_to_log_file_n('Created '||l_dim_name_temp_int||' with '||sql%rowcount||' records '||get_time);
1945 end if;
1946 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(l_dim_name_temp_int,instr(l_dim_name_temp_int,'.')+1,
1947 length(l_dim_name_temp_int)),substr(l_dim_name_temp_int,1,instr(l_dim_name_temp_int,'.')-1));
1948 l_stmt:='create table '||g_dim_kl_table_temp||' tablespace '||g_op_table_space;
1949 if g_parallel is not null then
1950 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
1951 end if;
1952 l_stmt:=l_stmt||' as select /*+ORDERED USE_NL('||g_dim_name||')*/ ';
1953 if g_parallel is not null then
1954 l_stmt:=l_stmt||' /*+PARALLEL ('||g_dim_name||','||g_parallel||')*/ ';
1955 end if;
1956 l_stmt:=l_stmt||g_dim_name||'.'||g_dim_user_pk||' '||g_dim_user_pk||', max('||g_dim_name||'.'||g_dim_pk||') '||
1957 g_dim_pk||' from '||l_dim_name_temp_int||','||g_dim_name||' where '||g_dim_name||'.'||g_dim_user_pk||'='||
1958 l_dim_name_temp_int||'.'||g_dim_user_pk||' group by '||g_dim_name||'.'||g_dim_user_pk;
1959 begin
1960 if g_debug then
1961 write_to_log_file_n('Going to execute '||l_stmt||get_time);
1962 end if;
1963 execute immediate l_stmt;
1964 if g_debug then
1965 write_to_log_file_n('Created '||g_dim_kl_table_temp||' with '||sql%rowcount||' records '||get_time);
1966 end if;
1967 exception when others then
1968 g_status_message:=sqlerrm;
1969 g_status:=false;
1970 write_to_log_file_n(g_status_message);
1971 write_to_log_file('Problem stmt '||l_stmt);
1972 return false;
1973 end;
1974 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_dim_kl_table_temp,instr(g_dim_kl_table_temp,'.')+1,
1975 length(g_dim_kl_table_temp)),substr(g_dim_kl_table_temp,1,instr(g_dim_kl_table_temp,'.')-1));
1976 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_kl_table) = false then
1977 null;
1978 end if;
1979 if EDW_OWB_COLLECTION_UTIL.drop_table(l_dim_name_temp_int) = false then
1980 null;
1981 end if;
1982 l_stmt:='create table '||g_dim_kl_table||' tablespace '||g_op_table_space;
1983 if g_parallel is not null then
1984 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
1985 end if;
1986 l_stmt:=l_stmt||' as select /*+ORDERED*/ ';
1987 l_stmt:=l_stmt||g_dim_kl_table_temp||'.'||g_dim_user_pk||' '||g_dim_user_pk||','||
1988 g_dim_kl_table_temp||'.'||g_dim_pk||' '||g_dim_pk;
1989 if g_number_slow_cols > 0 then
1990 for i in 1..g_number_slow_cols loop
1991 l_stmt:=l_stmt||','||g_dim_name_temp_int||'.'||g_slow_cols(i)||' '||g_slow_cols(i);
1992 end loop;
1993 end if;
1994 l_stmt:=l_stmt||' from '||g_dim_name_temp_int||','||g_dim_kl_table_temp||' where '||
1995 g_dim_name_temp_int||'.'||g_dim_user_pk||'='||g_dim_kl_table_temp||'.'||g_dim_user_pk;
1996 begin
1997 if g_debug then
1998 write_to_log_file_n('Going to execute '||l_stmt||get_time);
1999 end if;
2000 execute immediate l_stmt;
2001 if g_debug then
2002 write_to_log_file_n('Created '||g_dim_kl_table||' with '||sql%rowcount||' records '||get_time);
2003 end if;
2004 exception when others then
2005 g_status_message:=sqlerrm;
2006 g_status:=false;
2007 write_to_log_file_n(g_status_message);
2008 write_to_log_file('Problem stmt '||l_stmt);
2009 return false;
2010 end;
2011 --analyze the table
2012 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_dim_kl_table,instr(g_dim_kl_table,'.')+1,
2013 length(g_dim_kl_table)),substr(g_dim_kl_table,1,instr(g_dim_kl_table,'.')-1));
2014 if g_debug then
2015 write_to_log_file_n('Table '||g_dim_kl_table||' analyzed ');
2016 end if;
2017 commit;
2018 if g_debug then
2019 write_to_log_file_n('commit');
2020 end if;
2021 return true;
2022 Exception when others then
2023 g_status_message:=sqlerrm;
2024 g_status:=false;
2025 write_to_log_file_n(g_status_message);
2026 return false;
2027 End;
2028
2029
2030 function create_temp_table return boolean is
2031 l_stmt varchar2(30000);
2032 TYPE CurTyp IS REF CURSOR;
2033 cv CurTyp;
2034 l_table_found boolean :=false;
2035 l_divide number:=2;
2036 l_next_extent number;
2037 Begin
2038 if g_debug then
2039 write_to_log_file_n('In create_temp_table');
2040 end if;
2041 --is the table there? then drop it.
2042 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_temp) = false then
2043 write_to_log_file_n('Table '||g_dim_name_temp||' not found for dropping');
2044 end if;
2045 if g_parallel is null then
2046 l_divide:=2;
2047 else
2048 l_divide:=g_parallel;
2049 end if;
2050 l_next_extent:=g_dim_next_extent/l_divide;
2051 if l_next_extent>16777216 then --16M
2052 l_next_extent:=16777216;
2053 end if;
2054 if l_next_extent is null or l_next_extent=0 then
2055 l_next_extent:=8388608;
2056 end if;
2057 l_stmt:='create table '||g_dim_name_temp||' tablespace '||g_op_table_space||
2058 ' storage (initial '||l_next_extent||' next '||l_next_extent||' pctincrease 0 MAXEXTENTS 2147483645) ';
2059 if g_parallel is not null then
2060 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
2061 end if;
2062 l_stmt:=l_stmt||' as select '||g_dim_user_pk||','||g_dim_pk;
2063 if g_update_type='DELETE-INSERT' then
2064 l_stmt:=l_stmt||',CREATION_DATE ';
2065 end if;
2066 --we need the user pk because the surr key in dim and ltc are different because of slowly changing dim
2067 -- we need pk because we need to update it for slow change
2068 l_stmt:=l_stmt||' from '||g_dim_name||' where 1=2 ';
2069 if g_debug then
2070 write_to_log_file_n('Going to execute '||l_stmt);
2071 end if;
2072 execute immediate l_stmt;
2073 if g_debug then
2074 write_to_log_file_n('Created table '||g_dim_name_temp);
2075 end if;
2076 --add the 4 extra columns
2077 l_stmt:=' alter table '||g_dim_name_temp||' add (operation_code1 number, '||
2078 ' row_id1 rowid, row_id2 rowid, row_id3 rowid, slow_flag number) ';
2079 if g_debug then
2080 write_to_log_file_n('Going to execute '||l_stmt);
2081 end if;
2082 execute immediate l_stmt;
2083 return true;
2084 Exception when others then
2085 g_status_message:=sqlerrm;
2086 g_status:=false;
2087 write_to_log_file_n(g_status_message);
2088 write_to_log_file('Problem stmt '||l_stmt);
2089 return false;
2090 End;
2091
2092 function create_index_temp return boolean is
2093 l_stmt varchar2(4000);
2094 Begin
2095 return true;
2096 Exception when others then
2097 g_status_message:=sqlerrm;
2098 g_status:=false;
2099 write_to_log_file_n(g_status_message);
2100 return false;
2101 End;
2102
2103 function drop_index_temp return boolean is
2104 l_stmt varchar2(2000);
2105 Begin
2106 if g_debug then
2107 write_to_log_file_n('In drop_index_temp');
2108 end if;
2109 l_stmt:='drop index '||g_dim_name_temp||'n1';
2110 if g_debug then
2111 write_to_log_file_n('Going to execute '||l_stmt);
2112 end if;
2113 execute immediate l_stmt;
2114 l_stmt:='drop index '||g_dim_name_temp||'u1';
2115 if g_debug then
2116 write_to_log_file_n('Going to execute '||l_stmt);
2117 end if;
2118 execute immediate l_stmt;
2119 return true;
2120 Exception when others then
2121 g_status_message:=sqlerrm;
2122 g_status:=false;
2123 write_to_log_file_n(g_status_message);
2124 return false;
2125 End;
2126
2127
2128 function create_temp_table_int return boolean is
2129 l_stmt varchar2(30000);
2130 TYPE CurTyp IS REF CURSOR;
2131 cv CurTyp;
2132 l_table_found boolean :=false;
2133 Begin
2134 if g_debug then
2135 write_to_log_file_n('In create_temp_table_int');
2136 end if;
2137 --is the table there? then drop it.
2138 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_temp_int) = false then
2139 write_to_log_file_n('Table '||g_dim_name_temp_int||' not found for dropping');
2140 end if;
2141 l_stmt:='create table '||g_dim_name_temp_int||' tablespace '||g_op_table_space;
2142 if g_parallel is not null then
2143 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
2144 end if;
2145 l_stmt:=l_stmt||' as select '||g_dim_user_pk||','||g_dim_pk;
2146 if g_number_slow_cols > 0 then
2147 for i in 1..g_number_slow_cols loop
2148 l_stmt:=l_stmt||','||g_slow_cols(i);
2149 end loop;
2150 end if;
2151 l_stmt:=l_stmt||' from '||g_dim_name||' where 1=2 ';
2152 if g_debug then
2153 write_to_log_file_n('Going to execute '||l_stmt);
2154 end if;
2155 execute immediate l_stmt;
2156 if g_debug then
2157 write_to_log_file_n('Created table '||g_dim_name_temp_int);
2158 end if;
2159 --add the 4 extra columns
2160 l_stmt:=' alter table '||g_dim_name_temp_int||' add (operation_code1 number, '||
2161 ' row_id1 rowid, row_id2 rowid, row_id3 rowid) ';
2162 if g_debug then
2163 write_to_log_file_n('Going to execute '||l_stmt);
2164 end if;
2165 execute immediate l_stmt;
2166 return true;
2167 Exception when others then
2168 g_status_message:=sqlerrm;
2169 g_status:=false;
2170 write_to_log_file_n(g_status_message);
2171 write_to_log_file('Problem stmt '||l_stmt);
2172 return false;
2173 End;
2174
2175 function drop_index_temp_int return boolean is
2176 l_stmt varchar2(2000);
2177 Begin
2178 l_stmt:='drop index '||g_dim_name_temp_int||'u1';
2179 if g_debug then
2180 write_to_log_file_n('Going to execute '||l_stmt);
2181 end if;
2182 execute immediate l_stmt;
2183 return true;
2184 Exception when others then
2185 g_status_message:=sqlerrm;
2186 g_status:=false;
2187 write_to_log_file_n(g_status_message);
2188 write_to_log_file('Problem stmt '||l_stmt);
2189 return false;
2190 End;
2191
2192 function create_index_temp_int return boolean is
2193 l_stmt varchar2(2000);
2194 Begin
2195 return true;
2196 Exception when others then
2197 g_status_message:=sqlerrm;
2198 g_status:=false;
2199 write_to_log_file_n(g_status_message);
2200 write_to_log_file('Problem stmt '||l_stmt);
2201 return false;
2202 End;
2203
2204 procedure make_temp_int_to_tm_stmt is
2205 Begin
2206 if g_debug then
2207 write_to_log_file_n('In make_temp_int_to_tm_stmt');
2208 end if;
2209 g_temp_int_tm_stmt:='insert into '||g_dim_name_temp||'( ';
2210 if g_update_type='DELETE-INSERT' then
2211 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||g_dim_user_pk||','||g_dim_pk||
2212 ', row_id1, row_id3, operation_code1,CREATION_DATE,slow_flag) ';
2213 else
2214 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||g_dim_user_pk||','||g_dim_pk||
2215 ', row_id1, row_id3, operation_code1,slow_flag) ';
2216 end if;
2217 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||' select /*+ORDERED*/ ';
2218 if g_slow_implemented then
2219 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||g_dim_name_temp_int||'.'||g_dim_user_pk||','||
2220 ' decode ('||g_dim_kl_table||'.rowid,null,'||g_dim_name_temp_int||'.'||g_dim_pk||','||
2221 ' decode ('||g_dim_name_with_slow||'.row_id,null,'||g_seq_name||'.nextval,'||
2222 g_dim_kl_table||'.'||g_dim_pk||')), '||g_dim_name_with_slow||'.row_id, '||
2223 g_dim_name_temp_int||'.row_id3, decode('||g_dim_kl_table||'.rowid,null,0,decode('||
2224 g_dim_name_with_slow||'.row_id,null,0,1)) ';
2225 if g_update_type='DELETE-INSERT' then
2226 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||','||g_dim_name_with_slow||'.CREATION_DATE ';
2227 end if;
2228 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||',decode('||g_dim_kl_table||'.rowid,null,0,decode('||
2229 g_dim_name_with_slow||'.row_id,null,1,0)) ';
2230 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||' from '||g_dim_name_temp_int||','||g_dim_kl_table||','||
2231 g_dim_name_with_slow||' where '||g_dim_kl_table||'.'||g_dim_user_pk||'(+)='||
2232 g_dim_name_temp_int||'.'||g_dim_user_pk||
2233 ' and '||g_dim_name_with_slow||'.'||g_dim_pk||'(+)='||g_dim_kl_table||'.'||g_dim_pk;
2234 for i in 1..g_number_slow_cols loop
2235 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||' and nvl('||g_dim_name_with_slow||'.'||g_slow_cols(i)
2236 ||'(+),''^^'')= nvl('||g_dim_kl_table||'.'||g_slow_cols(i)||',''^^'')';
2237 end loop;
2238 else
2239 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||g_dim_name_temp_int||'.'||g_dim_user_pk||','||
2240 g_dim_name_temp_int||'.'||g_dim_pk||','||g_dim_name_with_slow||'.row_id,'||g_dim_name_temp_int||'.row_id3,'||
2241 'decode('||g_dim_name_with_slow||'.row_id,null,0,1) ';
2242 if g_update_type='DELETE-INSERT' then
2243 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||','||g_dim_name_with_slow||'.CREATION_DATE ';
2244 end if;
2245 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||',0 ';
2246 g_temp_int_tm_stmt:=g_temp_int_tm_stmt||' from '||g_dim_name_temp_int||','||g_dim_name_with_slow||
2247 ' where '||g_dim_name_with_slow||'.'||g_dim_pk||'(+)='||g_dim_name_temp_int||'.'||g_dim_pk;
2248 end if;
2249 if g_debug then
2250 write_to_log_file_n('g_temp_int_tm_stmt is '||g_temp_int_tm_stmt);
2251 end if;
2252 Exception when others then
2253 g_status_message:=sqlerrm;
2254 write_to_log_file_n(g_status_message);
2255 g_status:=false;
2256 End;
2257
2258 procedure make_hold_insert_stmt is
2259 l_divide number:=2;
2260 l_extent number;
2261 Begin
2262 if g_debug then
2263 write_to_log_file_n('In make_hold_insert_stmt');
2264 end if;
2265 if g_parallel is null then
2266 l_divide:=2;
2267 else
2268 l_divide:=g_parallel;
2269 end if;
2270 l_extent:=g_dim_next_extent/l_divide;
2271 if l_extent>16777216 then --16M
2272 l_extent:=16777216;
2273 end if;
2274 if l_extent is null or l_extent=0 then
2275 l_extent:=8388608;
2276 end if;
2277 g_hold_insert_stmt:='create table '||g_dim_name_hold||' tablespace '||g_op_table_space;
2278 if g_dim_next_extent is not null then
2279 g_hold_insert_stmt:=g_hold_insert_stmt||' storage (initial '||l_extent||' next '||
2280 l_extent||' pctincrease 0 MAXEXTENTS 2147483645) ';
2281 end if;
2282 if g_parallel is not null then
2283 g_hold_insert_stmt:=g_hold_insert_stmt||' parallel (degree '||g_parallel||') ';
2284 end if;
2285 g_hold_insert_stmt:=g_hold_insert_stmt||' as ';
2286 g_hold_insert_stmt:=g_hold_insert_stmt||g_select_stmt_nopk;
2287 g_hold_insert_stmt:=g_hold_insert_stmt||',TM.'||g_dim_pk||',TM.'||g_dim_user_pk||',TM.ROW_ID1 row_id';
2288 if g_update_type='DELETE-INSERT' then
2289 g_hold_insert_stmt:=g_hold_insert_stmt||',TM.CREATION_DATE ';
2290 end if;
2291 g_hold_insert_stmt:=g_hold_insert_stmt||' '||g_from_stmt;
2292 g_hold_insert_stmt:=g_hold_insert_stmt||','||g_dim_name_temp||' TM ';
2293 if g_where_stmt is not null then
2294 g_hold_insert_stmt:=g_hold_insert_stmt||g_where_stmt||' And ';
2295 else
2296 g_hold_insert_stmt:=g_hold_insert_stmt||' where ';
2297 end if;
2298 g_hold_insert_stmt:=g_hold_insert_stmt||' TM.row_id3='||g_lowest_level_alias||'.ROWID';
2299 g_hold_insert_stmt:=g_hold_insert_stmt||' And TM.operation_code1=1 ';
2300 g_hold_insert_stmt_row:='insert into '||g_dim_name_hold||'(';
2301 g_hold_insert_stmt_row:=g_hold_insert_stmt_row||g_insert_stmt_nopk;
2302 g_hold_insert_stmt_row:=g_hold_insert_stmt_row||','||g_dim_pk||','||g_dim_user_pk||',row_id) ';
2303 g_hold_insert_stmt_row:=g_hold_insert_stmt_row||g_select_stmt_nopk;
2304 g_hold_insert_stmt_row:=g_hold_insert_stmt_row||','||g_dim_pk||','||g_dim_user_pk||',ROW_ID1';
2305 g_hold_insert_stmt_row:=g_hold_insert_stmt_row||' '||g_from_stmt_hd_row;
2306 if g_where_stmt is not null then
2307 g_hold_insert_stmt_row:=g_hold_insert_stmt_row||g_where_stmt||' and ';
2308 else
2309 g_hold_insert_stmt_row:=g_hold_insert_stmt_row||' where ';
2310 end if;
2311 g_hold_insert_stmt_row:=g_hold_insert_stmt_row||g_lowest_level_alias||'.rowid=:a';
2312 if g_debug then
2313 write_to_log_file_n('g_hold_insert_stmt_row is '||g_hold_insert_stmt_row);
2314 end if;
2315 Exception when others then
2316 g_status_message:=sqlerrm;
2317 write_to_log_file_n(g_status_message);
2318 g_status:=false;
2319 End;
2320
2321 /*
2322 to speed up creation of the TM table...
2323 */
2324 function create_g_dim_name_with_slow return boolean is
2325 l_stmt varchar2(20000);
2326 l_kl_table varchar2(80);
2327 l_kl_table_count number;
2328 l_use_nl boolean;
2329 Begin
2330 if g_debug then
2331 write_to_log_file_n('In create_g_dim_name_with_slow');
2332 end if;
2333 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_with_slow)=false then
2334 null;
2335 end if;
2336 if g_dim_count is null then
2337 g_dim_count:=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_dim_name,g_table_owner);
2338 end if;
2339 if g_slow_implemented then
2340 l_kl_table:=g_dim_kl_table;
2341 else
2342 l_kl_table:=g_dim_name_temp_int;
2343 end if;
2344 l_kl_table_count:=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(l_kl_table,g_bis_owner);
2345 if g_debug then
2346 write_to_log_file_n('Dim count = '||g_dim_count||', kl table count='||l_kl_table_count);
2347 end if;
2348 l_use_nl:=true;
2349 if g_dim_count>0 then
2350 l_use_nl:=EDW_OWB_COLLECTION_UTIL.get_join_nl(l_kl_table_count,g_dim_count,g_join_nl_percentage);
2351 end if;
2352 l_stmt:='create table '||g_dim_name_with_slow||' tablespace '||g_op_table_space;
2353 if g_parallel is not null then
2354 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
2355 end if;
2356 l_stmt:=l_stmt||' as select ';
2357 l_stmt:=l_stmt||'/*+ordered ';
2358 if l_use_nl then
2359 l_stmt:=l_stmt||'use_nl('||g_dim_name||')';
2360 end if;
2361 l_stmt:=l_stmt||'*/ ';
2362 if g_parallel is not null then
2363 l_stmt:=l_stmt||'/*+PARALLEL('||g_dim_name||','||g_parallel||')*/ ';
2364 end if;
2365 l_stmt:=l_stmt||g_dim_name||'.'||g_dim_pk||','||g_dim_name||'.rowid row_id ';
2366 if g_slow_implemented then
2367 for i in 1..g_number_slow_cols loop
2368 l_stmt:=l_stmt||','||g_dim_name||'.'||g_slow_cols(i);
2369 end loop;
2370 end if;
2371 if g_update_type='DELETE-INSERT' then
2372 l_stmt:=l_stmt||','||g_dim_name||'.CREATION_DATE';
2373 end if;
2374 l_stmt:=l_stmt||' from '||l_kl_table||','||g_dim_name||' where '||
2375 l_kl_table||'.'||g_dim_pk||'='||g_dim_name||'.'||g_dim_pk;
2376 if g_debug then
2377 write_to_log_file_n('Going to execute '||l_stmt||get_time);
2378 end if;
2379 execute immediate l_stmt;
2380 if g_debug then
2381 write_to_log_file_n('Created '||g_dim_name_with_slow||' with '||sql%rowcount||' rows '||get_time);
2382 end if;
2383 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_dim_name_with_slow,instr(g_dim_name_with_slow,'.')+1,
2384 length(g_dim_name_with_slow)),substr(g_dim_name_with_slow,1,instr(g_dim_name_with_slow,'.')-1));
2385 return true;
2386 Exception when others then
2387 g_status_message:=sqlerrm;
2388 write_to_log_file_n(g_status_message);
2389 g_status:=false;
2390 return false;
2391 End;
2392
2393 --move the data from int temp to temp
2394 procedure execute_temp_int_to_tm_stmt is
2395 Begin
2396 if g_debug then
2397 write_to_log_file_n('In execute_temp_int_to_tm_stmt');
2398 end if;
2399 if g_debug then
2400 write_to_log_file_n('Going to execute g_temp_int_tm_stmt '||get_time);
2401 end if;
2402 execute immediate g_temp_int_tm_stmt;
2403 if g_debug then
2404 write_to_log_file_n('Inserted '||sql%rowcount||' rows into '||g_dim_name_temp||get_time);
2405 end if;
2406 commit;
2407 if g_debug then
2408 write_to_log_file_n('commit');
2409 end if;
2410 --analyze the table
2411 if sql%rowcount > 0 then
2412 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_dim_name_temp,instr(g_dim_name_temp,'.')+1,
2413 length(g_dim_name_temp)),substr(g_dim_name_temp,1,instr(g_dim_name_temp,'.')-1));
2414 end if;
2415 commit;
2416 if g_debug then
2417 write_to_log_file_n('commit');
2418 end if;
2419 --if there is slow change and there are pk key for slow change, log it into g_insert_prot_table
2420 --if g_slow_implemented then
2421 --if log_pk_into_insert_prot=false then
2422 --g_status:=false;
2423 --return;
2424 --end if;
2425 --end if;
2426 /*
2427 we can boost performance by testing to see if there is updates or not
2428 if there is no update then dont even bother to execute it
2429 */
2430 if check_temp_table_for_status('UPDATE')=true then
2431 g_update_star_flag:=true;
2432 if g_debug then
2433 write_to_log_file_n('Star Update Needed');
2434 end if;
2435 else
2436 g_update_star_flag:=false;
2437 if g_debug then
2438 write_to_log_file_n('Star Update NOT Needed');
2439 end if;
2440 end if;
2441 if check_temp_table_for_status('INSERT')=true then
2442 g_insert_star_flag:=true;
2443 if g_debug then
2444 write_to_log_file_n('Star Insert Needed');
2445 end if;
2446 else
2447 g_insert_star_flag:=false;
2448 if g_debug then
2449 write_to_log_file_n('Star Insert NOT Needed');
2450 end if;
2451 end if;
2452 if g_debug then
2453 count_temp_table_records; --this prints out NOCOPY how many insert update etc
2454 end if;
2455
2456 Exception when others then
2457 g_status_message:=sqlerrm;
2458 g_status:=false;
2459 write_to_log_file_n(g_status_message);
2460 write_to_log_file('Problem stmt '||g_temp_int_tm_stmt);
2461 End ;
2462
2463 /*
2464 see if in the temp table there are any records with opeartion_code1 of update or insert
2465 */
2466 function check_temp_table_for_status(p_status varchar2) return boolean is
2467 l_stmt varchar2(2000);
2468 TYPE CurTyp IS REF CURSOR;
2469 cv CurTyp;
2470 l_res number:=null;
2471 l_status number;
2472 Begin
2473 if g_debug then
2474 write_to_log_file_n('In check_temp_table_for_status for status '||p_status);
2475 end if;
2476 if p_status='INSERT' then
2477 l_status:=0;
2478 elsif p_status='UPDATE' then
2479 l_status:=1;
2480 else
2481 l_status:=2;
2482 end if;
2483 l_stmt:='select 1 from '||g_dim_name_temp||' where operation_code1=:a and rownum=1';
2484 open cv for l_stmt using l_status;
2485 fetch cv into l_res;
2486 close cv;
2487 if l_res is null then
2488 return false;
2489 else
2490 return true;
2491 end if;
2492 Exception when others then
2493 g_status_message:=sqlerrm;
2494 g_status:=false;
2495 write_to_log_file_n(g_status_message);
2496 return false;
2497 End ;
2498
2499 procedure count_temp_table_records is
2500 l_stmt varchar2(2000);
2501 TYPE CurTyp IS REF CURSOR;
2502 cv CurTyp;
2503 l_operation_code1 EDW_OWB_COLLECTION_UTIL.varcharTableType;
2504 l_operation_code2 EDW_OWB_COLLECTION_UTIL.varcharTableType;
2505 l_count EDW_OWB_COLLECTION_UTIL.numberTableType;
2506 l_rowid EDW_OWB_COLLECTION_UTIL.rowidTableType;
2507 l_number number;
2508 begin
2509 if g_debug then
2510 write_to_log_file_n('In count_temp_table_records');
2511 end if;
2512 l_stmt:='select count(*), operation_code1 from '||g_dim_name_temp||' '||
2513 ' group by operation_code1 ';
2514 l_number:=1;
2515 open cv for l_stmt;
2516 loop
2517 fetch cv into l_count(l_number),
2518 l_operation_code1(l_number);
2519 exit when cv%notfound;
2520 l_number:=l_number+1;
2521 end loop;
2522 l_number:=l_number-1;
2523 close cv;
2524 write_to_log_file_n('The count(*),operation_code1 of the temp table '||
2525 g_dim_name_temp);
2526 for i in 1..l_number loop
2527 write_to_log_file(' '||l_count(i)||' '||l_operation_code1(i));
2528 end loop;
2529 Exception when others then
2530 g_status_message:=sqlerrm;
2531 g_status:=false;
2532 write_to_log_file_n('Error in count_temp_table_records, not critical '||sqlerrm||get_time);
2533 End ;
2534
2535
2536 PROCEDURE identify_slow_cols IS
2537 l_table EDW_OWB_COLLECTION_UTIL.varcharTableType;
2538 l_table_count number:=1;
2539 cursor c4(p_dim_id number) is
2540 select relation.sequence_name
2541 from edw_pvt_sequences_md_v relation,
2542 edw_pvt_map_properties_md_v map,
2543 edw_pvt_map_properties_md_v map2,
2544 edw_pvt_map_sources_md_v ru
2545 where
2546 map.primary_target=p_dim_id
2547 and map2.primary_target=map.primary_source
2548 and ru.mapping_id=map2.mapping_id
2549 and ru.source_id=relation.sequence_id;
2550 Begin
2551 if g_debug then
2552 write_to_log_file_n('In identify_slow_cols '||get_time);
2553 end if;
2554 if EDW_OWB_COLLECTION_UTIL.is_slow_change_implemented(g_dim_name,g_slow_is_name)= true then
2555 g_slow_implemented:=true;
2556 if g_debug then
2557 write_to_log_file_n('Slowly changing implemented');
2558 end if;
2559 else
2560 g_slow_implemented:=false;
2561 if g_debug then
2562 write_to_log_file_n('Slowly changing NOT implemented');
2563 end if;
2564 return;
2565 end if;
2566 l_table_count:=0;
2567 if g_slow_implemented then
2568 --g_dim_map_id_slow look here...get the cols (dim cols)
2569 if g_read_cfig_options then
2570 if g_debug then
2571 write_to_log_file_n('Reading from Config Options');
2572 end if;
2573 if edw_option.get_option_columns(null,g_dim_id,'SLOWDIM',l_table,l_table_count)=false then
2574 g_status_message:=edw_option.g_status_message;
2575 g_status:=false;
2576 return;
2577 end if;
2578 else
2579 if EDW_OWB_COLLECTION_UTIL.get_item_set_cols(l_table,l_table_count,g_dim_name,g_slow_is_name)=false then
2580 g_status:=false;
2581 return;
2582 end if;
2583 end if;
2584 end if;
2585 if g_debug then
2586 write_to_log_file_n('The dimension columns being tracked');
2587 for i in 1..l_table_count loop
2588 write_to_log_file(l_table(i));
2589 end loop;
2590 end if;
2591 g_number_slow_cols:=0;
2592 --for the level names, get the star table col names
2593 for i in 1..l_table_count loop
2594 for j in 1..g_number_mapping loop
2595 if g_skip_item(j)=false and g_consider_col(j) then
2596 if l_table(i)=g_dim_col(j) then
2597 g_number_slow_cols:=g_number_slow_cols+1;
2598 g_slow_cols(g_number_slow_cols):=g_dim_col(j);
2599 g_slow_level(g_number_slow_cols):=g_level_name(j);
2600 g_slow_level_alias(g_number_slow_cols):=get_level_alias(g_level_name(j));
2601 g_slow_level_col(g_number_slow_cols):=g_level_col(j);
2602 exit;
2603 end if;
2604 end if;
2605 end loop;
2606 end loop;
2607 if g_debug then
2608 write_to_log_file_n('Dim slow col Level Table Alias Level Table col');
2609 for i in 1..g_number_slow_cols loop
2610 write_to_log_file(g_slow_cols(i)||' '||g_slow_level(i)||' '||g_slow_level_alias(i)||
2611 ' '||g_slow_level_col(i));
2612 end loop;
2613 end if;
2614 if g_number_slow_cols=0 then
2615 g_slow_implemented:=false;
2616 if g_debug then
2617 write_to_log_file_n('No columns found for tracking. Turning off slowly changing');
2618 end if;
2619 return;
2620 end if;
2621 --also get the seq name
2622 open c4(g_dim_id);
2623 fetch c4 into g_seq_name;
2624 close c4;
2625 if g_debug then
2626 write_to_log_file_n('The sequence name for slow change dims is '||g_seq_name);
2627 end if;
2628 Exception when others then
2629 g_status_message:=sqlerrm;
2630 write_to_log_file_n(g_status_message);
2631 g_status:=false;
2632 return;
2633 End;
2634
2635 PROCEDURE make_insert_update_stmt_star IS
2636 l_iv varchar2(400);
2637 Begin
2638 if g_debug then
2639 write_to_log_file_n('In make_insert_update_stmt_star '||get_time);
2640 end if;
2641 l_iv:=g_dim_name||'_IV';
2642
2643 if g_parallel is null then
2644 g_insert_stmt_star:='insert into '||g_dim_name||'( ';
2645 else
2646 g_insert_stmt_star:='insert /*+ PARALLEL ('||g_dim_name||','||g_parallel||') */ into '||g_dim_name||'( ';
2647 end if;
2648 g_insert_stmt_star_row:='insert into '||g_dim_name||'( ';
2649 /*for i in 1..g_number_mapping loop
2650 if i = 1 then
2651 g_insert_stmt_star:=g_insert_stmt_star||' '||g_dim_col(i);
2652 else
2653 g_insert_stmt_star:=g_insert_stmt_star||','||g_dim_col(i);
2654 end if;
2655 end loop;*/
2656 g_insert_stmt_star:=g_insert_stmt_star||g_insert_stmt_nopk_ins;
2657 g_insert_stmt_star:=g_insert_stmt_star||','||g_dim_pk||','||g_dim_user_pk;
2658 g_insert_stmt_star:=g_insert_stmt_star||',CREATION_DATE,LAST_UPDATE_DATE) ';
2659 g_insert_stmt_star:=g_insert_stmt_star||g_select_stmt_nopk_ins;
2660 g_insert_stmt_star:=g_insert_stmt_star||',TM.'||g_dim_pk||',TM.'||g_dim_user_pk;
2661 g_insert_stmt_star:=g_insert_stmt_star||',SYSDATE,SYSDATE ';
2662 g_insert_stmt_star:=g_insert_stmt_star||' '||g_from_stmt_ins;
2663 g_insert_stmt_star:=g_insert_stmt_star||','||g_dim_name_temp||' TM ';
2664 if g_where_stmt_ins is not null then
2665 g_insert_stmt_star:=g_insert_stmt_star||g_where_stmt_ins||' And ';
2666 else
2667 g_insert_stmt_star:=g_insert_stmt_star||' where ';
2668 end if;
2669 g_insert_stmt_star:=g_insert_stmt_star||' TM.row_id3='||g_lowest_level_alias||'.ROWID';
2670 g_insert_stmt_star:=g_insert_stmt_star||' And TM.operation_code1=0 ';
2671 --row by row stmt
2672 g_insert_stmt_star_row:=g_insert_stmt_star_row||g_insert_stmt_nopk_ins;
2673 g_insert_stmt_star_row:=g_insert_stmt_star_row||','||g_dim_pk||','||g_dim_user_pk;
2674 g_insert_stmt_star_row:=g_insert_stmt_star_row||',CREATION_DATE,LAST_UPDATE_DATE) ';
2675 g_insert_stmt_star_row:=g_insert_stmt_star_row||g_select_stmt_nopk_ins;
2676 g_insert_stmt_star_row:=g_insert_stmt_star_row||','||g_dim_pk||','||g_dim_user_pk;
2677 g_insert_stmt_star_row:=g_insert_stmt_star_row||',SYSDATE,SYSDATE ';
2678 g_insert_stmt_star_row:=g_insert_stmt_star_row||' '||g_from_stmt_ins_row;
2679 if g_where_stmt_ins is not null then
2680 g_insert_stmt_star_row:=g_insert_stmt_star_row||g_where_stmt_ins||' And ';
2681 else
2682 g_insert_stmt_star_row:=g_insert_stmt_star_row||' where ';
2683 end if;
2684 g_insert_stmt_star_row:=g_insert_stmt_star_row||g_lowest_level_alias||'.rowid=:a';
2685 --make the update stmt
2686 if g_update_type='DELETE-INSERT' then
2687 g_update_stmt_star:='insert into '||g_dim_name||' ( ';
2688 g_update_stmt_star:=g_update_stmt_star||g_insert_stmt_nopk_ins;
2689 g_update_stmt_star:=g_update_stmt_star||','||g_dim_pk||','||g_dim_user_pk;
2690 g_update_stmt_star:=g_update_stmt_star||',CREATION_DATE,LAST_UPDATE_DATE';
2691 g_update_stmt_star:=g_update_stmt_star||') select ';
2692 g_update_stmt_star:=g_update_stmt_star||g_insert_stmt_nopk_ins;
2693 g_update_stmt_star:=g_update_stmt_star||','||g_dim_pk||','||g_dim_user_pk;
2694 g_update_stmt_star:=g_update_stmt_star||',CREATION_DATE,SYSDATE';
2695 g_update_stmt_star:=g_update_stmt_star||' from '||g_dim_name_hold;
2696 else
2697 if g_update_type='ROW-BY-ROW' then
2698 g_update_stmt_star:='update '||g_dim_name||' set ( ';
2699 elsif g_update_type='MASS' then
2700 if g_parallel is null then
2701 g_update_stmt_star:='update /*+ ORDERED USE_NL('||g_dim_name||')*/ '||g_dim_name||' set ( ';
2702 else
2703 g_update_stmt_star:='update /*+ ORDERED USE_NL('||g_dim_name||')*/ /*+PARALLEL ('||g_dim_name||','||
2704 g_parallel||')*/ '||g_dim_name||' set ( ';
2705 end if;
2706 end if;
2707 g_update_stmt_star:=g_update_stmt_star||g_insert_stmt_nopk;
2708 g_update_stmt_star:=g_update_stmt_star||','||g_dim_pk||','||g_dim_user_pk;
2709 g_update_stmt_star:=g_update_stmt_star||',LAST_UPDATE_DATE) = ( select ';
2710 g_update_stmt_star:=g_update_stmt_star||g_insert_stmt_nopk;
2711 g_update_stmt_star:=g_update_stmt_star||','||g_dim_pk||','||g_dim_user_pk;
2712 g_update_stmt_star:=g_update_stmt_star||',SYSDATE ';
2713 g_update_stmt_star:=g_update_stmt_star||' from '||g_dim_name_hold||' where ';
2714 if g_update_type='ROW-BY-ROW' then
2715 g_update_stmt_star:=g_update_stmt_star||g_dim_name_hold||'.row_id=:a) where '||g_dim_name||'.rowid=:b ';
2716 elsif g_update_type='MASS' then
2717 g_update_stmt_star:=g_update_stmt_star||g_dim_name_hold||'.row_id='||g_dim_name||'.rowid) where '||
2718 g_dim_name||'.rowid in (select row_id from '||g_dim_name_hold||')';
2719 end if;
2720 end if;
2721 g_update_stmt_star_row:='update '||g_dim_name||' set ( '||
2722 g_insert_stmt_nopk||','||g_dim_pk||','||g_dim_user_pk||',LAST_UPDATE_DATE) = ( select '||
2723 g_insert_stmt_nopk||','||g_dim_pk||','||g_dim_user_pk||',SYSDATE '||' from '||g_dim_name_hold||' where '||
2724 g_dim_name_hold||'.row_id=:a) where '||g_dim_name||'.rowid=:b ';
2725 Exception when others then
2726 g_status_message:=sqlerrm;
2727 write_to_log_file_n(g_status_message);
2728 g_status:=false;
2729 End;
2730
2731 function create_hold_index return boolean is
2732 l_stmt varchar2(4000);
2733 l_next_extent number;
2734 Begin
2735 if g_debug then
2736 write_to_log_file_n('In create_hold_index');
2737 end if;
2738 l_next_extent:=g_dim_next_extent/4;
2739 if l_next_extent>8388608 then --8M
2740 l_next_extent:=8388608;
2741 end if;
2742 if l_next_extent is null or l_next_extent=0 then
2743 l_next_extent:=4194304;
2744 end if;
2745 l_stmt:='create unique index '||g_dim_name_hold||'u on '||
2746 g_dim_name_hold||'(row_id) tablespace '||g_op_table_space;
2747 --' storage (initial '||l_next_extent||' next '||l_next_extent||' pctincrease 0 MAXEXTENTS 2147483645)';
2748 if g_parallel is not null then
2749 l_stmt:=l_stmt||' parallel '||g_parallel;
2750 end if;
2751 if g_debug then
2752 write_to_log_file_n('Going to execute '||l_stmt);
2753 end if;
2754 execute immediate l_stmt;
2755 return true;
2756 Exception when others then
2757 write_to_log_file_n('Error in create_hold_index '||sqlerrm);
2758 return false;
2759 End;
2760
2761
2762 procedure execute_hold_insert_stmt is
2763 l_stmt varchar2(5000);
2764 TYPE CurTyp IS REF CURSOR;
2765 cv CurTyp;
2766 l_rowid rowid;
2767 l_count number;
2768 l_total_count number;
2769 l_table varchar2(200);
2770 l_create_type varchar2(200);
2771 Begin
2772 if g_debug then
2773 write_to_log_file_n('In execute_hold_insert_stmt'||get_time);
2774 end if;
2775 l_create_type:='MASS';
2776 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_hold)=false then
2777 null;
2778 end if;
2779 <<start_hd_create>>
2780 if g_ltc_merge_use_nl=true or l_create_type='ROW-BY-ROW' then
2781 if g_debug then
2782 write_to_log_file_n('Nested loop option');
2783 end if;
2784 if create_hold_table=false then
2785 return;
2786 end if;
2787 if create_ltc_copy_low_hd_ins('UPDATE')=false then
2788 return;
2789 end if;
2790 l_table:=g_dim_name_hold||'R';
2791 l_stmt:='create table '||l_table||' tablespace '||g_op_table_space;
2792 if g_parallel is not null then
2793 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
2794 end if;
2795 if g_ltc_merge_use_nl then
2796 l_stmt:=l_stmt||' as select rowid row_id from '||g_levels_copy_low_hd_ins;
2797 else
2798 l_stmt:=l_stmt||' as select row_id3 row_id from '||g_dim_name_temp||
2799 ' where operation_code1=1';
2800 end if;
2801 if g_debug then
2802 write_to_log_file_n('Going to execute '||l_stmt||get_time);
2803 end if;
2804 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table)=false then
2805 null;
2806 end if;
2807 execute immediate l_stmt;
2808 if g_debug then
2809 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
2810 end if;
2811 l_count:=0;
2812 l_total_count:=0;
2813 --disable parallel dml
2814 EDW_OWB_COLLECTION_UTIL.alter_session('NO-PARALLEL');
2815 l_stmt:='select row_id from '||l_table;
2816 if g_debug then
2817 write_to_log_file_n('Going to execute '||l_stmt||get_time);
2818 end if;
2819 open cv for l_stmt;
2820 loop
2821 fetch cv into l_rowid;
2822 exit when cv%notfound;
2823 execute immediate g_hold_insert_stmt_row using l_rowid;
2824 l_count:=l_count+1;
2825 l_total_count:=l_total_count+1;
2826 if l_count=5000 then
2827 commit;
2828 l_count:=0;
2829 end if;
2830 end loop;
2831 close cv;
2832 commit;
2833 if g_debug then
2834 write_to_log_file_n('Inserted '||l_total_count||' rows into '||g_dim_name_hold||get_time);
2835 end if;
2836 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table)=false then
2837 null;
2838 end if;
2839 if g_parallel is not null then
2840 EDW_OWB_COLLECTION_UTIL.alter_session('PARALLEL');
2841 end if;
2842 else
2843 begin
2844 execute immediate g_hold_insert_stmt;
2845 exception when others then
2846 if sqlcode=-4030 then
2847 if g_debug then
2848 write_to_log_file_n('Out of memory error '||sqlerrm||' Try row-by-row');
2849 end if;
2850 l_create_type:='ROW-BY-ROW';
2851 goto start_hd_create;
2852 end if;
2853 g_status_message:=sqlerrm;
2854 write_to_log_file_n(g_status_message);
2855 g_status:=false;
2856 return;
2857 end;
2858 g_count_dim_name_hold:=sql%rowcount;
2859 if g_debug then
2860 write_to_log_file_n('Inserted '||g_count_dim_name_hold||' rows into '||g_dim_name_hold||get_time);
2861 end if;
2862 end if;
2863 if create_hold_index=false then
2864 null;
2865 end if;
2866 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_dim_name_hold,instr(g_dim_name_hold,'.')+1,
2867 length(g_dim_name_hold)),substr(g_dim_name_hold,1,instr(g_dim_name_hold,'.')-1));
2868 Exception when others then
2869 g_status_message:=sqlerrm;
2870 write_to_log_file_n(g_status_message);
2871 g_status:=false;
2872 End;
2873
2874 function create_dim_name_rowid_hold return boolean is
2875 l_stmt varchar2(2000);
2876 Begin
2877 if g_debug then
2878 write_to_log_file_n('In create_dim_name_rowid_hold');
2879 end if;
2880 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_rowid_hold)=false then
2881 null;
2882 end if;
2883 l_stmt:='create table '||g_dim_name_rowid_hold||' tablespace '||g_op_table_space;
2884 if g_parallel is not null then
2885 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
2886 end if;
2887 l_stmt:=l_stmt||'as select row_id from '||g_dim_name_hold;
2888 if g_debug then
2889 write_to_log_file_n('Going to execute '||l_stmt||get_time);
2890 end if;
2891 execute immediate l_stmt;
2892 if g_debug then
2893 write_to_log_file_n('Created '||g_dim_name_rowid_hold||' with '||sql%rowcount||' rows '||get_time);
2894 end if;
2895 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_dim_name_rowid_hold,instr(g_dim_name_rowid_hold,'.')+1,
2896 length(g_dim_name_rowid_hold)),substr(g_dim_name_rowid_hold,1,instr(g_dim_name_rowid_hold,'.')-1));
2897 return true;
2898 Exception when others then
2899 g_status_message:=sqlerrm;
2900 write_to_log_file_n(g_status_message);
2901 g_status:=false;
2902 return false;
2903 End;
2904
2905
2906 function execute_update_stmt return number is
2907 l_stmt varchar2(5000);
2908 TYPE CurTyp IS REF CURSOR;
2909 cv CurTyp;
2910 l_rowid EDW_OWB_COLLECTION_UTIL.rowidTableType;
2911 l_count number;
2912 l_total_count number:=0;
2913 l_update_type varchar2(400);
2914 Begin
2915 if g_debug then
2916 write_to_log_file_n('In execute_update_stmt');
2917 end if;
2918 l_update_type:=g_update_type;
2919
2920 <<start_update>>
2921
2922 if l_update_type='MASS' or l_update_type='DELETE-INSERT' then
2923 --if create_dim_name_rowid_hold=false then
2924 --return false;
2925 --end if;
2926 /*
2927 having the rowid table seemed to slow down the update!
2928 */
2929 null;
2930 end if;
2931 if l_update_type='ROW-BY-ROW' then
2932 l_stmt:='select row_id from '||g_dim_name_hold;
2933 if g_debug then
2934 write_to_log_file_n('Going to execute '||l_stmt);
2935 end if;
2936 l_count:=1;
2937 open cv for l_stmt;
2938 loop
2939 fetch cv into l_rowid(l_count);
2940 exit when cv%notfound;
2941 if l_count>=g_forall_size then
2942 for i in 1..l_count loop
2943 execute immediate g_update_stmt_star_row using l_rowid(i),l_rowid(i);
2944 end loop;
2945 l_total_count:=l_total_count+l_count;
2946 l_count:=1;
2947 commit;
2948 else
2949 l_count:=l_count+1;
2950 end if;
2951 end loop;
2952 close cv;
2953 l_count:=l_count-1;
2954 if l_count>0 then
2955 for i in 1..l_count loop
2956 execute immediate g_update_stmt_star_row using l_rowid(i),l_rowid(i);
2957 end loop;
2958 l_total_count:=l_total_count+l_count;
2959 end if;
2960 elsif l_update_type='MASS' then
2961 begin
2962 if g_debug then
2963 write_to_log_file_n('Going to execute g_update_stmt_star '||get_time);
2964 end if;
2965 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
2966 execute immediate g_update_stmt_star;
2967 l_total_count:=sql%rowcount;
2968 exception when others then
2969 if sqlcode=-4030 then
2970 commit;
2971 write_to_log_file_n('Memory issue with Mass Update. Retrying using ROW_BY_ROW');
2972 l_update_type:='ROW-BY-ROW';
2973 goto start_update;
2974 elsif sqlcode=-00060 then
2975 if g_debug then
2976 write_to_log_file_n('Deadlock detected. Try again after sleep');
2977 end if;
2978 DBMS_LOCK.SLEEP(g_sleep_time);
2979 goto start_update;
2980 end if;
2981 g_status:=false;
2982 g_status_message:=sqlerrm;
2983 write_to_log_file_n(g_status_message);
2984 write_to_log_file('Problem stmt '||g_update_stmt_star);
2985 return null;
2986 end ;
2987 elsif l_update_type='DELETE-INSERT' then
2988 --first delete
2989 l_stmt:='delete '||g_dim_name||' where exists (select 1 from '||g_dim_name_hold||' where '||
2990 g_dim_name_hold||'.row_id='||g_dim_name||'.rowid)';
2991 --l_stmt:='delete '||g_dim_name||' where exists (select 1 from '||g_dim_name_hold||' where '||
2992 --g_dim_name_rowid_hold||'.row_id='||g_dim_name||'.rowid)';
2993 begin
2994 if g_debug then
2995 write_to_log_file_n('Going to execute '||l_stmt||get_time);
2996 end if;
2997 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
2998 execute immediate l_stmt;
2999 if g_debug then
3000 write_to_log_file('Deleted '||sql%rowcount||' rows');
3001 end if;
3002 exception when others then
3003 g_status:=false;
3004 g_status_message:=sqlerrm;
3005 write_to_log_file_n(g_status_message);
3006 write_to_log_file('Problem stmt '||l_stmt);
3007 return null;
3008 end ;
3009 begin
3010 if g_debug then
3011 write_to_log_file_n('Going to execute g_update_stmt_star');
3012 end if;
3013 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
3014 execute immediate g_update_stmt_star;
3015 if g_debug then
3016 write_to_log_file('Inserted '||sql%rowcount||' rows');
3017 end if;
3018 l_total_count:=sql%rowcount;
3019 exception when others then
3020 g_status:=false;
3021 g_status_message:=sqlerrm;
3022 write_to_log_file_n(g_status_message);
3023 write_to_log_file('Problem stmt '||g_update_stmt_star);
3024 return null;
3025 end ;
3026 end if;
3027 if g_debug then
3028 write_to_log_file_n('Updated '||l_total_count||' records In Star Table '||get_time);
3029 end if;
3030 --if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_rowid_hold)=false then
3031 --null;
3032 --end if;
3033 return l_total_count;
3034 EXCEPTION when others then
3035 g_status:=false;
3036 g_status_message:=sqlerrm;
3037 write_to_log_file_n(g_status_message);
3038 return null;
3039 End;
3040
3041 PROCEDURE execute_insert_update_star(p_count number) IS
3042 l_update_count number:=0;
3043 Begin
3044 if g_debug then
3045 write_to_log_file_n('In execute_insert_update_star '||get_time);
3046 end if;
3047 if g_insert_star_flag then
3048 Begin
3049 insert_into_load_progress_d(g_load_pk,g_dim_name,'Insert Into Star Table'||g_jobid_stmt,sysdate,null,
3050 'DIMENSION','INSERT','CDVT2030'||p_count||' '||g_job_id,'I');
3051 if execute_insert_stmt=false then
3052 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2030'||p_count||' '||g_job_id,'U');
3053 return;
3054 end if;
3055 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2030'||p_count||' '||g_job_id,'U');
3056 Exception when others then
3057 g_status_message:=sqlerrm;
3058 write_to_log_file_n(g_status_message);
3059 g_status:=false;
3060 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2030'||p_count||' '||g_job_id,'U');
3061 return;
3062 End;
3063 end if;--if g_insert_star_flag then
3064 --execute update
3065 if g_update_star_flag then
3066 --if the dim is a part of any derv/summary fact, log all needed cols before update
3067 if g_derv_snp_change_flag then
3068 insert_into_load_progress_d(g_load_pk,g_dim_name,'Log Before Update Data'||g_jobid_stmt,sysdate,null,
3069 'DIMENSION','INSERT','LBUCDVT2040'||p_count||' '||g_job_id,'I');
3070 if log_before_update_data=false then
3071 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LBUCDVT2040'||p_count||' '||g_job_id,'U');
3072 return;
3073 end if;
3074 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'LBUCDVT2040'||p_count||' '||g_job_id,'U');
3075 end if;
3076 insert_into_load_progress_d(g_load_pk,g_dim_name,'Update Star Table'||g_jobid_stmt,sysdate,null,
3077 'DIMENSION','INSERT','CDVT2040'||p_count||' '||g_job_id,'I');
3078 l_update_count:=execute_update_stmt;--creates update prot table inside
3079 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'CDVT2040'||p_count||' '||g_job_id,'U');
3080 if l_update_count is null then
3081 g_status:=false;
3082 return;
3083 end if;
3084 end if;
3085 g_number_rows_inserted:=g_number_rows_inserted+l_update_count;
3086 if g_debug then
3087 write_to_log_file_n('Finished execute_insert_update_star '||get_time);
3088 end if;
3089 Exception when others then
3090 g_status_message:=sqlerrm;
3091 write_to_log_file_n(g_status_message);
3092 g_status:=false;
3093 End;
3094
3095 function execute_insert_stmt return boolean is
3096 l_stmt varchar2(4000);
3097 TYPE CurTyp IS REF CURSOR;
3098 cv CurTyp;
3099 l_rowid rowid;
3100 l_table varchar2(200);
3101 l_insert_type varchar2(200);
3102 l_unique_violation boolean;
3103 Begin
3104 if g_debug then
3105 write_to_log_file_n('In execute_insert_stmt '||get_time);
3106 end if;
3107 l_insert_type:='MASS';
3108 <<start_insert>>
3109 if g_ltc_merge_use_nl or l_insert_type='ROW-BY-ROW' then
3110 l_unique_violation:=false;
3111 if g_debug then
3112 write_to_log_file_n('ROW-BY-ROW INSERTS');
3113 end if;
3114 g_number_rows_inserted:=0;
3115 if create_ltc_copy_low_hd_ins('INSERT')=false then
3116 g_status:=false;
3117 return false;
3118 end if;
3119 l_table:=g_dim_name_hold||'R';
3120 l_stmt:='create table '||l_table||' tablespace '||g_op_table_space;
3121 if g_parallel is not null then
3122 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
3123 end if;
3124 if g_ltc_merge_use_nl then
3125 l_stmt:=l_stmt||' as select rowid row_id from '||g_levels_copy_low_hd_ins;
3126 else
3127 l_stmt:=l_stmt||' as select row_id3 row_id from '||g_dim_name_temp||
3128 ' where operation_code1=0';
3129 end if;
3130 if g_debug then
3131 write_to_log_file_n('Going to execute '||l_stmt||get_time);
3132 end if;
3133 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table)=false then
3134 null;
3135 end if;
3136 execute immediate l_stmt;
3137 if g_debug then
3138 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
3139 end if;
3140 EDW_OWB_COLLECTION_UTIL.alter_session('NO-PARALLEL');
3141 l_stmt:='select row_id from '||l_table;
3142 if g_debug then
3143 write_to_log_file_n('Going to execute '||l_stmt||get_time);
3144 end if;
3145 open cv for l_stmt;
3146 loop
3147 fetch cv into l_rowid;
3148 exit when cv%notfound;
3149 begin
3150 execute immediate g_insert_stmt_star_row using l_rowid;
3151 commit;
3152 g_number_rows_inserted:=g_number_rows_inserted+1;
3153 exception when others then
3154 rollback;
3155 if sqlcode=-00001 then
3156 l_unique_violation:=true;
3157 else
3158 g_status_message:=sqlerrm;
3159 write_to_log_file_n(g_status_message);
3160 g_status:=false;
3161 return false;
3162 end if;
3163 end;
3164 end loop;
3165 close cv;
3166 commit;
3167 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table)=false then
3168 null;
3169 end if;
3170 if g_parallel is not null then
3171 EDW_OWB_COLLECTION_UTIL.alter_session('PARALLEL');
3172 end if;
3173 if l_unique_violation then
3174 if reset_temp_opcode=false then
3175 return false;
3176 end if;
3177 end if;
3178 else
3179 if g_debug then
3180 write_to_log_file_n('going to execute g_insert_stmt_star ');
3181 end if;
3182 begin
3183 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
3184 execute immediate g_insert_stmt_star;
3185 g_number_rows_inserted:=sql%rowcount;
3186 exception when others then
3187 rollback;
3188 if sqlcode=-4030 then
3189 if g_debug then
3190 write_to_log_file_n('Out of memory error in mass insert. (Try row-by-row) '||sqlerrm||get_time);
3191 end if;
3192 l_insert_type:='ROW-BY-ROW';
3193 goto start_insert;
3194 elsif sqlcode=-00001 then
3195 if g_debug then
3196 write_to_log_file_n('Unique constraint violated '||sqlerrm||get_time);
3197 end if;
3198 if reset_temp_opcode=false then
3199 return false;
3200 end if;
3201 goto start_insert;
3202 elsif sqlcode=-00060 then
3203 if g_debug then
3204 write_to_log_file_n('Deadlock detected. Try again after sleep');
3205 end if;
3206 DBMS_LOCK.SLEEP(g_sleep_time);
3207 goto start_insert;
3208 else
3209 g_status_message:=sqlerrm;
3210 write_to_log_file_n(g_status_message);
3211 g_status:=false;
3212 return false;
3213 end if;
3214 end;
3215 end if;
3216 if g_debug then
3217 write_to_log_file_n('Inserted '||g_number_rows_inserted||' rows'||get_time);
3218 end if;
3219 commit;
3220 return true;
3221 Exception when others then
3222 g_status_message:=sqlerrm;
3223 write_to_log_file_n(g_status_message);
3224 g_status:=false;
3225 return false;
3226 End;
3227
3228 function check_error return boolean is
3229 begin
3230 if g_status=false then
3231 --log the error message
3232 return false;
3233 end if;
3234 return true;
3235 End ;--function check_error return boolean
3236
3237 Function get_status_message return varchar2 is
3238 begin
3239 return g_status_message;
3240 End;--Function get_status_message return varchar2 is
3241
3242 procedure get_dim_map_ids IS
3243 cursor c3(p_dim_name varchar2) is
3244 select upper(item.column_name),
3245 replace(upper(item.column_name),'_KEY'), --for now assume this...
3246 dim.dim_id
3247 from edw_unique_keys_md_v pk,
3248 edw_pvt_key_columns_md_v isu,
3249 edw_pvt_columns_md_v item,
3250 edw_dimensions_md_v dim
3251 where pk.entity_id=dim.dim_id
3252 and isu.key_id=pk.key_id
3253 and isu.column_id=item.column_id
3254 and pk.primarykey=1
3255 and dim.dim_name=p_dim_name;
3256 begin
3257 --get the PK of the dim table
3258 g_dim_pk:=null;
3259 open c3(g_dim_name);
3260 fetch c3 into g_dim_pk,g_dim_user_pk,g_dim_id;
3261 close c3;
3262 if g_dim_pk is null then
3263 --user did not define a PK constraint on dim start table
3264 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_message('EDW_NO_PRIMARY_KEY_FOUND');
3265 write_to_log_file_n(g_status_message);
3266 g_status:=false;
3267 return;
3268 end if;
3269 --get the corresponding ltc values
3270 --assume star structure
3271 for i in 1..g_number_mapping loop
3272 if g_dim_col(i)=g_dim_pk then
3273 g_ltc_pk:=g_level_col(i);
3274 exit;
3275 end if;
3276 end loop;
3277 for i in 1..g_number_mapping loop
3278 if g_dim_col(i)=g_dim_user_pk then
3279 g_ltc_user_pk:=g_level_col(i);
3280 exit;
3281 end if;
3282 end loop;
3283 if g_debug then
3284 write_to_log_file_n('The star PK, Ltc Pk, Star User PK and Ltc User Pk');
3285 write_to_log_file(g_dim_pk||' '||g_ltc_pk||' '||g_dim_user_pk||' '||g_ltc_user_pk);
3286 end if;
3287 if g_ltc_pk is null or g_ltc_user_pk is null then
3288 write_to_log_file_n('No Ltc Pk or User Pk found for the star pks');
3289 g_status:=false;
3290 return;
3291 end if;
3292 Exception when others then
3293 g_status_message:=sqlerrm;
3294 write_to_log_file_n(g_status_message);
3295 g_status:=false;
3296 return;
3297 End;--procedure get_dim_map_ids
3298
3299 procedure make_level_alias is
3300 Begin
3301 if g_debug then
3302 write_to_log_file_n('In make_level_alias');
3303 end if;
3304 for i in 1..g_number_levels loop
3305 g_levels_alias(i):='A_'||i;
3306 end loop;
3307 Exception when others then
3308 g_status_message:=sqlerrm;
3309 write_to_log_file_n(g_status_message);
3310 g_status:=false;
3311 return;
3312 End;
3313
3314 function get_level_alias(p_level varchar2) return varchar2 is
3315 Begin
3316 if g_debug then
3317 write_to_log_file_n('In get_level_alias, level is '||p_level);
3318 end if;
3319 for i in 1..g_number_levels loop
3320 if g_levels(i)=p_level then
3321 return g_levels_alias(i);
3322 end if;
3323 end loop;
3324 return null;
3325 Exception when others then
3326 g_status_message:=sqlerrm;
3327 write_to_log_file_n(g_status_message);
3328 g_status:=false;
3329 return null;
3330 End;
3331
3332
3333 /*
3334 get_lvl_relations gets the mapping details for the star mapping
3335 */
3336 Procedure get_lvl_relations IS
3337 Begin
3338 if g_debug then
3339 write_to_log_file_n('In get_lvl_relations'||get_time);
3340 end if;
3341 EDW_OWB_COLLECTION_UTIL.Get_lvl_dim_mapping(
3342 g_dim_col,
3343 g_level_name,
3344 g_level_col,
3345 g_number_mapping,
3346 1); --dont find the rowid
3347 if g_number_mapping=0 then
3348 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_message('EDW_NO_LVL_DIM_MAPPING_FOUND');
3349 write_to_log_file_n(g_status_message);
3350 g_status:=false;
3351 return;
3352 end if;
3353 --get the lowest level and its relation id
3354 EDW_OWB_COLLECTION_UTIL.get_lowest_level(g_lowest_level, g_lowest_level_id);
3355 if g_lowest_level is null then
3356 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_message('EDW_NO_LOWEST_LEVEL_FOUND');
3357 write_to_log_file_n(g_status_message);
3358 g_status:=false;
3359 return;
3360 end if;
3361 g_lowest_level_global:=g_lowest_level;
3362 --determine the lowest level alias
3363 for i in 1..g_number_levels loop
3364 if g_levels(i)=g_lowest_level then
3365 g_lowest_level_alias:='A_'||i;
3366 g_lowest_level_index:=i;
3367 end if;
3368 end loop;
3369 if g_lowest_level_alias is null then
3370 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_message('EDW_NO_LOWEST_LEVEL_FOUND');
3371 write_to_log_file_n(g_status_message);
3372 g_status:=false;
3373 return;
3374 end if;
3375 if g_debug then
3376 write_to_log_file_n('The lowest level and its relation id and the alias');
3377 write_to_log_file(g_lowest_level||' '||g_lowest_level_id||' '||g_lowest_level_alias);
3378 write_to_log_file_n('The mapping between level tables and star table');
3379 for i in 1..g_number_mapping loop
3380 write_to_log_file(g_dim_col(i)||' '||g_level_name(i)||' '||g_level_col(i));
3381 end loop;
3382 end if;
3383 --mark the columns to be skipped
3384 for i in 1..g_number_mapping loop
3385 g_skip_item(i):=false;
3386 end loop;
3387 if g_number_skip_cols >0 then
3388 for i in 1..g_number_mapping loop
3389 for j in 1..g_number_skip_cols loop
3390 if g_dim_col(i)=g_skip_cols(j) then
3391 g_skip_item(i):=true;
3392 exit;
3393 end if;
3394 end loop;
3395 end loop;
3396 end if;
3397 Exception when others then
3398 g_status_message:=sqlerrm;
3399 write_to_log_file_n(g_status_message);
3400 g_status:=false;
3401 End;--Procedure get_lvl_relations IS
3402
3403 procedure make_select_from_where_stmt is
3404 l_run integer:=0;
3405 l_all_count integer:=0;
3406 first_time boolean;
3407 l_alias EDW_OWB_COLLECTION_UTIL.varcharTableType;
3408 child_alias varchar2(100);
3409 l_look_at EDW_OWB_COLLECTION_UTIL.booleanTableType;
3410 l_looked_at EDW_OWB_COLLECTION_UTIL.booleanTableType;
3411 l_start number;
3412 l_done_flag boolean;
3413 l_consider_level EDW_OWB_COLLECTION_UTIL.varcharTableType;
3414 l_number_consider_level number:=0;
3415 l_level_index number;
3416 l_child_index number;
3417 l_affected_levels EDW_OWB_COLLECTION_UTIL.varcharTableType;
3418 l_number_affected_levels number;
3419 Begin
3420 --make the alias
3421 if g_debug then
3422 write_to_log_file_n('In make_select_from_where_stmt');
3423 end if;
3424 if g_dim_empty_flag=false and g_error_rec_flag=false and g_check_fk_change then
3425 for i in 1..g_number_levels loop
3426 l_looked_at(i):=false;
3427 g_consider_level(i):=false;
3428 if g_consider_snapshot(i) then
3429 l_look_at(i):=true;
3430 else
3431 l_look_at(i):=false;
3432 end if;
3433 end loop;
3434 l_start:=1;
3435 l_done_flag:=false;
3436 l_run:=0;
3437 loop
3438 if l_look_at(l_start) and l_looked_at(l_start)=false then
3439 l_number_consider_level:=l_number_consider_level+1;
3440 l_consider_level(l_number_consider_level):=g_levels(l_start);
3441 g_consider_level(l_start):=true;
3442 l_level_index:=0;
3443 for j in 1..g_child_level_number(l_start) loop
3444 l_run:=l_run+1;
3445 l_level_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,g_child_levels(l_run));
3446 if EDW_OWB_COLLECTION_UTIL.value_in_table(l_consider_level,l_number_consider_level,
3447 g_child_levels(l_run)) then
3448 l_looked_at(l_start):=true;
3449 exit;
3450 elsif l_look_at(l_level_index) then
3451 l_looked_at(l_start):=true;
3452 l_start:=0;
3453 l_run:=0;
3454 exit;
3455 elsif g_child_levels(l_run)=g_lowest_level_global then
3456 l_looked_at(l_start):=true;
3457 l_look_at(l_level_index):=true;
3458 l_start:=0;
3459 l_run:=0;
3460 exit;
3461 end if;
3462 end loop;
3463 if l_level_index=0 and l_start<>0 then
3464 --lowest level
3465 l_looked_at(l_start):=true;
3466 elsif l_start<>0 then
3467 if l_looked_at(l_start)=false then
3468 --add the child to the list
3469 l_look_at(l_level_index):=true;
3470 l_start:=0;
3471 l_run:=0;
3472 l_looked_at(l_start):=true;
3473 end if;
3474 end if;
3475 else
3476 for j in 1..g_child_level_number(l_start) loop
3477 l_run:=l_run+1;
3478 end loop;
3479 end if;
3480 l_start:=l_start+1;
3481 if l_start>g_number_levels then
3482 l_done_flag:=true;
3483 exit;
3484 end if;
3485 end loop;
3486 --if a child fk has changed, the parent and its parents need to be considered
3487 if find_all_affected_levels(g_job_id,l_affected_levels,l_number_affected_levels)=false then
3488 for i in 1..g_number_levels loop
3489 g_consider_level(i):=true;
3490 end loop;
3491 else
3492 for i in 1..l_number_affected_levels loop
3493 g_consider_level(EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,
3494 l_affected_levels(i))):=true;
3495 end loop;
3496 end if;
3497 else
3498 --consider all levels
3499 for i in 1..g_number_levels loop
3500 g_consider_level(i):=true;
3501 end loop;
3502 end if;
3503 l_level_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,g_lowest_level_global);
3504 if g_consider_level(l_level_index)=false then
3505 if g_debug then
3506 write_to_log_file_n('Lowest level not in. something fishy');
3507 end if;
3508 g_consider_level(l_level_index):=true;
3509 end if;
3510 if g_debug then
3511 write_to_log_file_n('The considered levels');
3512 for i in 1..g_number_levels loop
3513 if g_consider_level(i) then
3514 write_to_log_file(g_levels(i));
3515 end if;
3516 end loop;
3517 end if;
3518 for i in 1..g_number_mapping loop
3519 g_consider_col(i):=false;
3520 end loop;
3521 for i in 1..g_number_levels loop
3522 if g_consider_level(i) then
3523 for j in 1..g_number_mapping loop
3524 if g_level_name(j)=g_levels(i) then
3525 g_consider_col(j):=true;
3526 end if;
3527 end loop;
3528 end if;
3529 end loop;
3530 if g_debug then
3531 write_to_log_file_n('The mappings to be considered');
3532 for i in 1..g_number_mapping loop
3533 if g_consider_col(i) then
3534 write_to_log_file(g_level_name(i)||'('||g_level_col(i)||') to '||g_dim_col(i));
3535 end if;
3536 end loop;
3537 end if;
3538 --make the insert stmt without the pk and user pk
3539 g_insert_stmt_nopk:=null;
3540 for i in 1..g_number_mapping loop
3541 if g_skip_item(i)=false then
3542 if g_dim_col(i) <> g_dim_pk and g_dim_col(i) <> g_dim_user_pk then
3543 if g_consider_col(i) then
3544 g_insert_stmt_nopk:=g_insert_stmt_nopk||g_dim_col(i)||',';
3545 end if;
3546 end if;
3547 end if;
3548 end loop;
3549 if g_insert_stmt_nopk is not null then
3550 g_insert_stmt_nopk:=substr(g_insert_stmt_nopk,1,length(g_insert_stmt_nopk)-1);
3551 end if;
3552 if g_debug then
3553 write_to_log_file_n('Insert stmt NOPK is '||g_insert_stmt_nopk);
3554 end if;
3555 for i in 1..g_number_mapping loop
3556 l_alias(i):=null;
3557 for j in 1..g_number_levels loop
3558 if g_level_name(i)=g_levels(j) then
3559 l_alias(i):='A_'||j;
3560 exit;
3561 end if;
3562 end loop;
3563 end loop;
3564 --identify the top level
3565 for i in 1..g_number_levels loop
3566 if g_levels(i)=g_all_level then
3567 g_all_level_index:=i;
3568 exit;
3569 end if;
3570 end loop;
3571 g_select_stmt:=' select ';
3572 g_select_stmt_nopk:=' select ';
3573 --make the select stmt
3574 for i in 1..g_number_mapping loop
3575 if g_skip_item(i)=false then
3576 if g_consider_col(i) then
3577 g_select_stmt:=g_select_stmt||l_alias(i)||'.'||g_level_col(i)||' '||g_dim_col(i)||',';
3578 if g_dim_col(i) <> g_dim_pk and g_dim_col(i) <> g_dim_user_pk then
3579 g_select_stmt_nopk:=g_select_stmt_nopk||l_alias(i)||'.'||g_level_col(i)||' '||g_dim_col(i)||',';
3580 end if;
3581 end if;
3582 end if;
3583 end loop;
3584 g_select_stmt:=substr(g_select_stmt,1,length(g_select_stmt)-1);
3585 g_select_stmt_nopk:=substr(g_select_stmt_nopk,1,length(g_select_stmt_nopk)-1);
3586 if g_debug then
3587 write_to_log_file_n('select stmt is '||g_select_stmt);
3588 write_to_log_file_n('select stmt NOPK is '||g_select_stmt_nopk);
3589 end if;
3590 --make the from
3591 g_from_stmt:=' from ';
3592 for i in 1..g_number_levels loop
3593 if g_consider_level(i) then
3594 g_from_stmt:=g_from_stmt||g_levels(i)||' A_'||i||',';
3595 end if;
3596 end loop;
3597 g_from_stmt:=substr(g_from_stmt,1,length(g_from_stmt)-1);
3598 if g_debug then
3599 write_to_log_file_n('from stmt is '||g_from_stmt);
3600 end if;
3601 --make the where clause
3602 g_fk_pk_number:=0;
3603 l_run:=0;
3604 l_all_count:=0;--in the star schema, there is need only to join to the all level for one hierarchy
3605 g_where_stmt:=' where ';
3606 for i in 1..g_number_levels loop
3607 for j in 1..g_child_level_number(i) loop
3608 l_run:=l_run+1;
3609 child_alias:=null;
3610 for k in 1..g_number_levels loop
3611 if g_child_levels(l_run)=g_levels(k) then
3612 child_alias:='A_'||k;
3613 l_child_index:=k;
3614 exit;
3615 end if;
3616 end loop;
3617 if l_child_index=0 then
3618 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_message('EDW_NO_LEVEL_FOUND');
3619 write_to_log_file_n(g_status_message);
3620 g_status:=false;
3621 return;
3622 end if;
3623 ------------------------------------------------------------
3624 -- the child and parent info are stored for drill down, drill up etc. improve inc perf
3625 g_fk_pk_number:=g_fk_pk_number+1;
3626 g_fk_pk_parent_level(g_fk_pk_number):=g_levels(i);
3627 g_fk_pk_parent_alias(g_fk_pk_number):=' A_'||i;
3628 g_fk_pk_parent_pk(g_fk_pk_number):=g_parent_pk(l_run);
3629 g_fk_pk_child_level(g_fk_pk_number):=g_child_levels(l_run);
3630 g_fk_pk_child_alias(g_fk_pk_number):=child_alias;
3631 g_fk_pk_child_fk(g_fk_pk_number):=g_child_fk(l_run);
3632 ------------------------------------------------------------
3633 if g_consider_level(i) and g_consider_level(l_child_index) then
3634 if g_all_level_index=i then
3635 if l_all_count=0 then
3636 g_where_stmt:=g_where_stmt||child_alias||'.'||g_child_fk(l_run)||'='||
3637 ' A_'||i||'.'||g_parent_pk(l_run)||' and ';
3638 l_all_count:=l_all_count+1;
3639 end if;
3640 else
3641 g_where_stmt:=g_where_stmt||child_alias||'.'||g_child_fk(l_run)||'='||
3642 ' A_'||i||'.'||g_parent_pk(l_run)||' and ';
3643 end if;
3644 end if;
3645 end loop;
3646 end loop;
3647 if g_where_stmt=' where ' then
3648 g_where_stmt:=null;
3649 else
3650 g_where_stmt:=substr(g_where_stmt,1,length(g_where_stmt)-4);
3651 end if;
3652 if g_debug then
3653 write_to_log_file_n('where stmt is '||g_where_stmt);
3654 end if;
3655 if g_debug then
3656 write_to_log_file_n('The fk-pk arrays');
3657 write_to_log_file('Child level, alias, fk, parent level, alias, pk');
3658 for i in 1..g_fk_pk_number loop
3659 write_to_log_file(g_fk_pk_child_level(i)||' '||g_fk_pk_child_alias(i)||' '||g_fk_pk_child_fk(i)||' '||
3660 g_fk_pk_parent_level(i)||' '||g_fk_pk_parent_alias(i)||' '||g_fk_pk_parent_pk(i));
3661 end loop;
3662 end if;
3663 first_time:=true;
3664 g_where_snplog_stmt:=null;
3665 /*
3666 g_where_snplog_stmt will not contain the join to the snapshot log for the lowest level
3667 */
3668 for i in 1..g_number_levels loop
3669 if g_consider_snapshot.exists(i) then
3670 if g_consider_snapshot(i) = true and g_levels(i) <> g_lowest_level then
3671 if first_time then
3672 g_where_snplog_stmt:=g_where_snplog_stmt||' And ( ';
3673 g_where_snplog_stmt:=g_where_snplog_stmt||' '||'A_'||i||'.ROWID IN (select M_ROW$$ from '
3674 ||g_level_snapshot_logs(i)||') ';
3675 first_time:=false;
3676 else
3677 g_where_snplog_stmt:=g_where_snplog_stmt||' Or '||'A_'||i||'.ROWID IN (select M_ROW$$ from '
3678 ||g_level_snapshot_logs(i)||') ';
3679 end if;
3680 end if;
3681 end if;
3682 end loop;
3683 if first_time = false then
3684 g_where_snplog_stmt:=g_where_snplog_stmt||' ) ';
3685 end if;
3686 if g_debug then
3687 write_to_log_file_n('Snapshot where stmt is '||g_where_snplog_stmt);
3688 end if;
3689 Exception when others then
3690 g_status_message:=sqlerrm;
3691 write_to_log_file_n(g_status_message);
3692 g_status:=false;
3693 End;
3694
3695 procedure make_select_from_where_ins is
3696 l_run integer:=0;
3697 l_all_count integer:=0;
3698 first_time boolean;
3699 l_alias EDW_OWB_COLLECTION_UTIL.varcharTableType;
3700 child_alias varchar2(100);
3701 l_child_index number;
3702 Begin
3703 --make the alias
3704 if g_debug then
3705 write_to_log_file_n('In make_select_from_where_ins');
3706 end if;
3707 --make the insert stmt without the pk and user pk
3708 g_insert_stmt_nopk_ins:=null;
3709 for i in 1..g_number_mapping loop
3710 if g_skip_item(i)=false then
3711 if g_dim_col(i) <> g_dim_pk and g_dim_col(i) <> g_dim_user_pk then
3712 g_insert_stmt_nopk_ins:=g_insert_stmt_nopk_ins||g_dim_col(i)||',';
3713 end if;
3714 end if;
3715 end loop;
3716 if g_insert_stmt_nopk_ins is not null then
3717 g_insert_stmt_nopk_ins:=substr(g_insert_stmt_nopk_ins,1,length(g_insert_stmt_nopk_ins)-1);
3718 end if;
3719 if g_debug then
3720 write_to_log_file_n('Insert stmt NOPK is '||g_insert_stmt_nopk_ins);
3721 end if;
3722 for i in 1..g_number_mapping loop
3723 l_alias(i):=null;
3724 for j in 1..g_number_levels loop
3725 if g_level_name(i)=g_levels(j) then
3726 l_alias(i):='A_'||j;
3727 exit;
3728 end if;
3729 end loop;
3730 end loop;
3731 --identify the top level
3732 for i in 1..g_number_levels loop
3733 if g_levels(i)=g_all_level then
3734 g_all_level_index:=i;
3735 exit;
3736 end if;
3737 end loop;
3738 g_select_stmt_ins:=' select ';
3739 g_select_stmt_nopk_ins:=' select ';
3740 --make the select stmt
3741 for i in 1..g_number_mapping loop
3742 if g_skip_item(i)=false then
3743 g_select_stmt_ins:=g_select_stmt_ins||l_alias(i)||'.'||g_level_col(i)||' '||g_dim_col(i)||',';
3744 if g_dim_col(i) <> g_dim_pk and g_dim_col(i) <> g_dim_user_pk then
3745 g_select_stmt_nopk_ins:=g_select_stmt_nopk_ins||l_alias(i)||'.'||g_level_col(i)||' '||g_dim_col(i)||',';
3746 end if;
3747 end if;
3748 end loop;
3749 g_select_stmt_ins:=substr(g_select_stmt_ins,1,length(g_select_stmt_ins)-1);
3750 g_select_stmt_nopk_ins:=substr(g_select_stmt_nopk_ins,1,length(g_select_stmt_nopk_ins)-1);
3751 if g_debug then
3752 write_to_log_file_n('select stmt is '||g_select_stmt_ins);
3753 write_to_log_file_n('select stmt NOPK is '||g_select_stmt_nopk_ins);
3754 end if;
3755 --make the from
3756 g_from_stmt_ins:=' from ';
3757 for i in 1..g_number_levels loop
3758 g_from_stmt_ins:=g_from_stmt_ins||g_levels(i)||' A_'||i||',';
3759 end loop;
3760 g_from_stmt_ins:=substr(g_from_stmt_ins,1,length(g_from_stmt_ins)-1);
3761 if g_debug then
3762 write_to_log_file_n('from stmt is '||g_from_stmt_ins);
3763 end if;
3764 --make the where clause
3765 l_run:=0;
3766 l_all_count:=0;--in the star schema, there is need only to join to the all level for one hierarchy
3767 g_where_stmt_ins:=' where ';
3768 for i in 1..g_number_levels loop
3769 for j in 1..g_child_level_number(i) loop
3770 l_run:=l_run+1;
3771 child_alias:=null;
3772 l_child_index:=0;
3773 for k in 1..g_number_levels loop
3774 if g_child_levels(l_run)=g_levels(k) then
3775 child_alias:='A_'||k;
3776 l_child_index:=k;
3777 exit;
3778 end if;
3779 end loop;
3780 if l_child_index=0 then
3781 g_status_message:=EDW_OWB_COLLECTION_UTIL.get_message('EDW_NO_LEVEL_FOUND');
3782 write_to_log_file_n(g_status_message);
3783 g_status:=false;
3784 return;
3785 end if;
3786 if g_all_level_index=i then
3787 if l_all_count=0 then
3788 g_where_stmt_ins:=g_where_stmt_ins||child_alias||'.'||g_child_fk(l_run)||'='||
3789 ' A_'||i||'.'||g_parent_pk(l_run)||' and ';
3790 l_all_count:=l_all_count+1;
3791 end if;
3792 else
3793 g_where_stmt_ins:=g_where_stmt_ins||child_alias||'.'||g_child_fk(l_run)||'='||
3794 ' A_'||i||'.'||g_parent_pk(l_run)||' and ';
3795 end if;
3796 end loop;
3797 end loop;
3798 if g_where_stmt_ins=' where ' then
3799 g_where_stmt_ins:=null;
3800 else
3801 g_where_stmt_ins:=substr(g_where_stmt_ins,1,length(g_where_stmt_ins)-4);
3802 end if;
3803 if g_debug then
3804 write_to_log_file_n('where stmt is '||g_where_stmt_ins);
3805 end if;
3806 Exception when others then
3807 g_status_message:=sqlerrm;
3808 write_to_log_file_n(g_status_message);
3809 g_status:=false;
3810 End;
3811
3812 function create_ilog_table return boolean is
3813 l_stmt varchar2(10000);
3814 Begin
3815 if g_debug then
3816 write_to_log_file_n('In create_ilog_table');
3817 end if;
3818 l_stmt:='create table '||g_ilog||' tablespace '||g_op_table_space||
3819 ' storage(initial 4M next 4M pctincrease 0 MAXEXTENTS 2147483645)';
3820 if g_parallel is not null then
3821 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
3822 end if;
3823 l_stmt:=l_stmt||' as select rowid row_id,';
3824 if g_ll_snplog_has_pk then
3825 l_stmt:=l_stmt||g_ltc_pk||',';
3826 end if;
3827 l_stmt:=l_stmt||' 0 status from '||g_lowest_level_global||' where 1=2';
3828 --l_stmt:='create table '||g_ilog||' (row_id rowid, status number) '||' tablespace '||g_op_table_space||
3829 --' storage(initial 8M next 8M pctincrease 0 MAXEXTENTS 2147483645)';
3830 --if g_parallel is not null then
3831 --l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
3832 --end if;
3833 if g_debug then
3834 write_to_log_file_n('Going to execute '||l_stmt);
3835 end if;
3836 execute immediate l_stmt;
3837 return true;
3838 Exception when others then
3839 g_status_message:=sqlerrm;
3840 write_to_log_file_n(g_status_message);
3841 g_status:=false;
3842 return false;
3843 End;
3844
3845 /*
3846 a temp function here only because m_row$$ is varchar2 while row_id is rowid, see MINUS
3847 */
3848 function create_gilog_T(p_snp_log varchar2,p_ilog_temp varchar2) return boolean is
3849 l_stmt varchar2(4000);
3850 Begin
3851 if g_debug then
3852 write_to_log_file_n('In create_gilog_T');
3853 end if;
3854 if EDW_OWB_COLLECTION_UTIL.drop_table(p_ilog_temp)=false then
3855 null;
3856 end if;
3857 l_stmt:='create table '||p_ilog_temp||'(row_id rowid) '||' tablespace '||g_op_table_space;
3858 if g_parallel is not null then
3859 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
3860 end if;
3861 if g_debug then
3862 write_to_log_file_n('Going to execute '||l_stmt);
3863 end if;
3864 begin
3865 execute immediate l_stmt;
3866 exception when others then
3867 g_status:=false;
3868 g_status_message:=sqlerrm;
3869 write_to_log_file_n(g_status_message);
3870 return false;
3871 end;
3872 l_stmt:='insert into '||p_ilog_temp||' (row_id) select ';
3873 if g_parallel is not null then
3874 l_stmt:=l_stmt||' /*+PARALLEL ('||p_snp_log||','||g_parallel||')*/ ';
3875 end if;
3876 l_stmt:=l_stmt||' M_ROW$$ from '||p_snp_log;
3877 if g_debug then
3878 write_to_log_file_n('Going to execute '||l_stmt);
3879 end if;
3880 begin
3881 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
3882 execute immediate l_stmt;
3883 if g_debug then
3884 write_to_log_file_n('Moved '||sql%rowcount||' rows into '||p_ilog_temp);
3885 end if;
3886 commit;
3887 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(p_ilog_temp,instr(p_ilog_temp,'.')+1,
3888 length(p_ilog_temp)),substr(p_ilog_temp,1,instr(p_ilog_temp,'.')-1));
3889 exception when others then
3890 g_status:=false;
3891 g_status_message:=sqlerrm;
3892 write_to_log_file_n(g_status_message);
3893 return false;
3894 end;
3895 return true;
3896 Exception when others then
3897 g_status_message:=sqlerrm;
3898 write_to_log_file_n(g_status_message);
3899 g_status:=false;
3900 return false;
3901 End;
3902
3903 /*
3904 create the level Ilog table for all levels
3905 */
3906 function create_ltc_ilog_table(p_mode varchar2) return boolean is
3907 l_stmt varchar2(10000);
3908 l_pk varchar2(400);
3909 l_fk EDW_OWB_COLLECTION_UTIL.varcharTableType;
3910 l_number_fk number;
3911 l_found boolean:=false;
3912 l_consider boolean;
3913 l_create_ilog_index boolean;
3914 l_total_count number;
3915 l_ltc_count number;
3916 l_storage number;
3917 Begin
3918 if g_debug then
3919 write_to_log_file_n('In create_ltc_ilog_table mode='||p_mode);
3920 end if;
3921 if p_mode='SNP' then
3922 for i in 1..g_number_levels loop
3923 if g_consider_level(i) and g_levels(i)<>g_lowest_level_global then
3924 l_found:=true;
3925 end if;
3926 end loop;
3927 if l_found=false then
3928 if g_debug then
3929 write_to_log_file_n('Only lowest level changed. No need to create ltc ilog');
3930 end if;
3931 return true;
3932 end if;
3933 end if;
3934 for i in 1..g_number_levels loop
3935 l_consider:=false;
3936 if g_use_ltc_ilog(i) then
3937 if p_mode='SNP' then
3938 if g_consider_level(i) then
3939 l_consider:=true;
3940 end if;
3941 elsif p_mode='NON-SNP' then
3942 if EDW_OWB_COLLECTION_UTIL.check_table(g_levels_I(i))=false then
3943 l_consider:=true;
3944 end if;
3945 end if;
3946 if g_debug then
3947 if l_consider then
3948 write_to_log_file_n('Creating ltc ilog for '||g_levels(i));
3949 else
3950 write_to_log_file_n('NOT Creating ltc ilog for '||g_levels(i));
3951 end if;
3952 end if;
3953 if l_consider then
3954 --get the pk
3955 l_pk:=null;
3956 l_number_fk:=0;
3957 for j in 1..g_fk_pk_number loop
3958 if g_fk_pk_parent_level(j)=g_levels(i) then
3959 l_pk:=g_fk_pk_parent_pk(j);
3960 exit;
3961 end if;
3962 end loop;
3963 if g_levels(i)=g_lowest_level_global then
3964 l_pk:=g_ltc_pk;
3965 end if;
3966 if g_debug then
3967 write_to_log_file_n('Considering level '||g_levels(i)||' and pk='||l_pk);
3968 end if;
3969 --get the fks
3970 for j in 1..g_fk_pk_number loop
3971 if g_fk_pk_child_level(j)=g_levels(i) then
3972 l_number_fk:=l_number_fk+1;
3973 l_fk(l_number_fk):=g_fk_pk_child_fk(j);
3974 end if;
3975 end loop;
3976 if g_debug then
3977 write_to_log_file('FKs are ');
3978 for j in 1..l_number_fk loop
3979 write_to_log_file(l_fk(j));
3980 end loop;
3981 end if;
3982 if EDW_OWB_COLLECTION_UTIL.drop_table(g_levels_I(i))=false then
3983 null;
3984 end if;
3985 l_ltc_count:=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_levels(i),g_table_owner);
3986 if g_debug then
3987 write_to_log_file_n('LTC count='||l_ltc_count);
3988 end if;
3989 l_storage:=4;
3990 if l_ltc_count is not null and l_ltc_count>g_big_table then
3991 l_storage:=8;
3992 end if;
3993 l_stmt:='create table '||g_levels_I(i)||' tablespace '||g_op_table_space;
3994 l_stmt:=l_stmt||' storage (initial '||l_storage||'M next '||l_storage||'M pctincrease 0) ';
3995 if g_parallel is not null then
3996 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
3997 end if;
3998 l_stmt:=l_stmt||' as select ';
3999 if g_parallel is not null then
4000 if l_ltc_count is not null and l_ltc_count>g_big_table then
4001 l_stmt:=l_stmt||'/*+PARALLEL('||g_levels(i)||','||g_parallel||')*/ ';
4002 else
4003 l_stmt:=l_stmt||'/*+PARALLEL('||g_levels(i)||','||g_parallel||')*/ ';
4004 end if;
4005 end if;
4006 if l_pk is not null then
4007 l_stmt:=l_stmt||l_pk||' '||l_pk||',';
4008 end if;
4009 for j in 1..l_number_fk loop
4010 l_stmt:=l_stmt||l_fk(j)||' '||l_fk(j)||',';
4011 end loop;
4012 l_stmt:=l_stmt||'rowid row_id from '||g_levels(i);
4013 if g_debug then
4014 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4015 end if;
4016 l_create_ilog_index:=true;
4017 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
4018 begin
4019 execute immediate l_stmt;
4020 l_total_count:=sql%rowcount;
4021 if g_debug then
4022 write_to_log_file_n('Created '||g_levels_I(i)||' with '||l_total_count||' rows '||get_time);
4023 end if;
4024 exception when others then
4025 if sqlcode=-00955 then
4026 --only here in case of multi threading
4027 if g_debug then
4028 write_to_log_file_n('Error creating '||g_levels_I(i)||' '||sqlerrm||get_time);
4029 write_to_log_file('This table '||g_levels_I(i)||' already exists! Some other thread created it!');
4030 end if;
4031 l_create_ilog_index:=false;
4032 else
4033 g_status_message:=sqlerrm;
4034 write_to_log_file_n(g_status_message);
4035 g_status:=false;
4036 return false;
4037 end if;
4038 end;
4039 if l_create_ilog_index then
4040 l_create_ilog_index:=EDW_OWB_COLLECTION_UTIL.get_join_nl(g_collection_size,l_total_count,
4041 g_join_nl_percentage);
4042 if l_create_ilog_index then
4043 if l_pk is not null then
4044 l_stmt:='create unique index '||g_levels_I(i)||'u1 on '||g_levels_I(i)||'('||l_pk||')';
4045 l_stmt:=l_stmt||' tablespace '||g_op_table_space;
4046 if g_parallel is not null then
4047 l_stmt:=l_stmt||' parallel '||g_parallel;
4048 end if;
4049 if g_debug then
4050 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4051 end if;
4052 execute immediate l_stmt;
4053 end if;
4054 l_stmt:='create unique index '||g_levels_I(i)||'u2 on '||g_levels_I(i)||'(row_id)';
4055 l_stmt:=l_stmt||' tablespace '||g_op_table_space;
4056 if g_parallel is not null then
4057 l_stmt:=l_stmt||' parallel '||g_parallel;
4058 end if;
4059 if g_debug then
4060 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4061 end if;
4062 execute immediate l_stmt;
4063 end if;
4064 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_levels_I(i),instr(g_levels_I(i),'.')+1,
4065 length(g_levels_I(i))),substr(g_levels_I(i),1,instr(g_levels_I(i),'.')-1));
4066 end if;
4067 end if;--if l_consider then
4068 else
4069 g_levels_I(i):=g_levels(i);
4070 end if;--if g_use_ltc_ilog(i) then
4071 end loop;
4072 return true;
4073 Exception when others then
4074 g_status_message:=sqlerrm;
4075 write_to_log_file_n(g_status_message);
4076 g_status:=false;
4077 return false;
4078 End;
4079
4080 --copy of the snapshot logs
4081 function create_snp_L_tables return boolean is
4082 l_stmt varchar2(10000);
4083 l_table varchar2(200);
4084 l_count number;
4085 l_ltc_i_found boolean;
4086 l_use_nl boolean;
4087 l_use_ordered_hint boolean;
4088 Begin
4089 if g_debug then
4090 write_to_log_file_n('In create_snp_L_tables');
4091 end if;
4092 l_use_ordered_hint:=true;
4093 for i in 1..g_number_levels loop
4094 l_table:=g_snplogs_L(i)||'TMP';
4095 l_stmt:='create table '||l_table||' tablespace '||g_op_table_space;
4096 l_stmt:=l_stmt||' storage (initial 4M next 4M pctincrease 0) ';
4097 if g_parallel is not null then
4098 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4099 end if;
4100 l_stmt:=l_stmt||' as select ';
4101 if g_parallel is not null then
4102 l_stmt:=l_stmt||'/*+PARALLEL('||g_level_snapshot_logs(i)||','||g_parallel||')*/ ';
4103 end if;
4104 if g_levels(i)=g_lowest_level_global and g_ll_snplog_has_pk then
4105 l_stmt:=l_stmt||' distinct '||g_ltc_pk||' from '||g_level_snapshot_logs(i);
4106 else
4107 l_stmt:=l_stmt||' distinct m_row$$ row_id from '||g_level_snapshot_logs(i);
4108 end if;
4109 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table)=false then
4110 null;
4111 end if;
4112 if g_debug then
4113 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4114 end if;
4115 execute immediate l_stmt;
4116 l_count:=sql%rowcount;
4117 if g_debug then
4118 write_to_log_file_n('Created with '||l_count||' rows '||get_time);
4119 end if;
4120 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(l_table,instr(l_table,'.')+1,
4121 length(l_table)),substr(l_table,1,instr(l_table,'.')-1));
4122 if l_count>0 then
4123 l_ltc_i_found:=false;
4124 if not(g_levels(i)=g_lowest_level_global and g_ll_snplog_has_pk) then
4125 --if g_levels_I(i)<>g_levels(i) then
4126 if g_use_ltc_ilog(i) then
4127 if EDW_OWB_COLLECTION_UTIL.check_table(g_levels_I(i)) then
4128 l_ltc_i_found:=true;
4129 end if;
4130 end if;
4131 end if;
4132 end if;
4133 <<start_data_into_L>>
4134 if EDW_OWB_COLLECTION_UTIL.drop_table(g_snplogs_L(i))=false then
4135 null;
4136 end if;
4137 /*l_stmt:='create table '||g_snplogs_L(i)||' tablespace '||g_op_table_space;
4138 l_stmt:=l_stmt||' storage (initial 4M next 4M pctincrease 0) ';
4139 if g_parallel is not null then
4140 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4141 end if;
4142 l_stmt:=l_stmt||' as select rowid row_id ';
4143 if g_levels(i)=g_lowest_level_global and g_ll_snplog_has_pk then
4144 l_stmt:=l_stmt||','||g_ltc_pk;
4145 end if;
4146 l_stmt:=l_stmt||' from '||g_levels(i)||' where 1=2';
4147 if g_debug then
4148 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4149 end if;
4150 execute immediate l_stmt;
4151 if g_debug then
4152 write_to_log_file_n('Created '||g_snplogs_L(i)||get_time);
4153 end if; */
4154 if l_count>0 then
4155 /*if g_levels(i)=g_lowest_level_global and g_ll_snplog_has_pk then
4156 l_stmt:='insert into '||g_snplogs_L(i)||'(row_id,'||g_ltc_pk||')';
4157 else
4158 l_stmt:='insert into '||g_snplogs_L(i)||'(row_id)';
4159 end if;
4160 */
4161 l_stmt:='create table '||g_snplogs_L(i)||' tablespace '||g_op_table_space;
4162 l_stmt:=l_stmt||' storage (initial 4M next 4M pctincrease 0) ';
4163 if g_parallel is not null then
4164 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4165 end if;
4166 if g_level_count(i) is null then
4167 g_level_count(i):=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_levels(i),g_table_owner);
4168 end if;
4169 l_use_nl:=EDW_OWB_COLLECTION_UTIL.get_join_nl(l_count,g_level_count(i),g_join_nl_percentage);
4170 if g_levels(i)=g_lowest_level_global and g_ll_snplog_has_pk then
4171 l_stmt:=l_stmt||' as select ';
4172 if l_use_ordered_hint then
4173 l_stmt:=l_stmt||'/*+ordered ';
4174 if l_use_nl then
4175 l_stmt:=l_stmt||'use_nl(A)';
4176 end if;
4177 l_stmt:=l_stmt||'*/ ';
4178 end if;
4179 if g_parallel is not null then
4180 l_stmt:=l_stmt||' /*+PARALLEL(A,'||g_parallel||')*/ ';
4181 end if;
4182 l_stmt:=l_stmt||'A.rowid row_id,A.'||g_ltc_pk||' from '||l_table||' B,'||g_levels(i)||' A '||
4183 ' where B.'||g_ltc_pk||'=A.'||g_ltc_pk;
4184 else
4185 l_stmt:=l_stmt||' as select ';
4186 if l_ltc_i_found=false then
4187 if l_use_ordered_hint then
4188 l_stmt:=l_stmt||'/*+ordered ';
4189 if l_use_nl then
4190 l_stmt:=l_stmt||'use_nl(A)';
4191 end if;
4192 l_stmt:=l_stmt||'*/ ';
4193 end if;
4194 if g_parallel is not null then
4195 l_stmt:=l_stmt||'/*+PARALLEL(A,'||g_parallel||')*/ ';
4196 end if;
4197 l_stmt:=l_stmt||'A.rowid row_id from '||l_table||' B,'||g_levels(i)||' A '||
4198 ' where B.row_id=A.rowid';
4199 else
4200 if l_use_ordered_hint then
4201 l_stmt:=l_stmt||'/*+ordered*/ ';
4202 end if;
4203 l_stmt:=l_stmt||'A.row_id from '||l_table||' B,'||g_levels_I(i)||' A '||
4204 ' where B.row_id=A.row_id';
4205 end if;
4206 end if;
4207 if g_debug then
4208 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4209 end if;
4210 begin
4211 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
4212 execute immediate l_stmt;
4213 if g_debug then
4214 write_to_log_file_n('Inserted into '||g_snplogs_L(i)||' '||sql%rowcount||' rows '||get_time);
4215 end if;
4216 commit;
4217 exception when others then
4218 write_to_log_file_n('Error '||sqlerrm||get_time);
4219 if sqlcode=-01410 then --invalid rowid error
4220 if l_use_ordered_hint then
4221 l_use_ordered_hint:=false;
4222 goto start_data_into_L;
4223 else
4224 write_to_log_file_n('Unrecoverable invalid rowid error');
4225 raise;
4226 end if;
4227 end if;
4228 end;
4229 else
4230 --create the empty g_snplogs_L(i) table
4231 l_stmt:='create table '||g_snplogs_L(i)||' tablespace '||g_op_table_space;
4232 l_stmt:=l_stmt||' storage (initial 4M next 4M pctincrease 0) ';
4233 if g_parallel is not null then
4234 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4235 end if;
4236 l_stmt:=l_stmt||' as select rowid row_id ';
4237 if g_levels(i)=g_lowest_level_global and g_ll_snplog_has_pk then
4238 l_stmt:=l_stmt||','||g_ltc_pk;
4239 end if;
4240 l_stmt:=l_stmt||' from '||g_levels(i)||' where 1=2';
4241 if g_debug then
4242 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4243 end if;
4244 execute immediate l_stmt;
4245 if g_debug then
4246 write_to_log_file_n('Created '||g_snplogs_L(i)||get_time);
4247 end if;
4248 end if;
4249 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_snplogs_L(i),instr(g_snplogs_L(i),'.')+1,
4250 length(g_snplogs_L(i))),substr(g_snplogs_L(i),1,instr(g_snplogs_L(i),'.')-1));
4251 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table)=false then
4252 null;
4253 end if;
4254 end loop;
4255 return true;
4256 Exception when others then
4257 g_status_message:=sqlerrm;
4258 write_to_log_file_n(g_status_message);
4259 g_status:=false;
4260 return false;
4261 End;
4262
4263 /*
4264 insert the rowids of the child level into the LT table for the child for all the changed records of the parent
4265 p_mode=DOWN means we are drilling down. for changes to parent, we are finding change to child
4266 p_mode=UP means we are drilling up. for changes to child, we are finding changes to parent
4267 */
4268 function insert_into_LT(p_child_level varchar2, p_parent_level varchar2,p_mode varchar2) return boolean is
4269 l_stmt varchar2(10000);
4270 l_child_index number:=null;
4271 l_index number;
4272 l_parent_index number:=null;
4273 l_fk_pk_index number:=null;
4274 l_a1_key varchar2(400);
4275 l_a2_key varchar2(400);
4276 l_fk_table varchar2(400);
4277 l_fk_table_count number:=null;--number of rows in fk table
4278 l_L_table_found boolean:=true;
4279 l_snplogs_L varchar2(400);
4280 l_rowid_child varchar2(20);
4281 l_rowid_parent varchar2(20);
4282 l_use_nl_child boolean;
4283 l_use_nl_parent boolean;
4284 l_L_count number;
4285 Begin
4286 if g_debug then
4287 write_to_log_file_n('In insert_into_LT');
4288 write_to_log_file('p_parent_level='||p_parent_level);
4289 write_to_log_file('p_child_level='||p_child_level);
4290 write_to_log_file('p_mode='||p_mode);
4291 end if;
4292 for i in 1..g_number_levels loop
4293 if g_levels(i)=p_child_level then
4294 l_child_index:=i;
4295 exit;
4296 end if;
4297 end loop;
4298 for i in 1..g_number_levels loop
4299 if g_levels(i)=p_parent_level then
4300 l_parent_index:=i;
4301 exit;
4302 end if;
4303 end loop;
4304 l_use_nl_child:=false;
4305 l_use_nl_parent:=false;
4306 if g_levels_I(l_parent_index)=g_levels(l_parent_index) then
4307 l_rowid_parent:='rowid';
4308 else
4309 l_rowid_parent:='row_id';
4310 end if;
4311 if g_levels_I(l_child_index)=g_levels(l_child_index) then
4312 l_rowid_child:='rowid';
4313 else
4314 l_rowid_child:='row_id';
4315 end if;
4316 if g_debug then
4317 write_to_log_file_n('parent level and rowid='||g_levels_I(l_parent_index)||'('||l_rowid_parent||')');
4318 write_to_log_file('child level and rowid='||g_levels_I(l_child_index)||'('||l_rowid_child||')');
4319 end if;
4320 for i in 1..g_fk_pk_number loop
4321 if g_fk_pk_child_level(i)=p_child_level and g_fk_pk_parent_level(i)=p_parent_level then
4322 l_fk_pk_index:=i;
4323 exit;
4324 end if;
4325 end loop;
4326 if p_mode='DOWN' then
4327 l_L_table_found:=EDW_OWB_COLLECTION_UTIL.check_table(g_snplogs_L(l_child_index));
4328 if g_debug then
4329 if l_L_table_found then
4330 write_to_log_file_n('The L table '||g_snplogs_L(l_child_index)||' found');
4331 else
4332 write_to_log_file_n('The L table '||g_snplogs_L(l_child_index)||' NOT found');
4333 end if;
4334 end if;
4335 l_a1_key:=g_fk_pk_child_fk(l_fk_pk_index);
4336 l_a2_key:=g_fk_pk_parent_pk(l_fk_pk_index);
4337 l_L_count:=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_snplogs_L(l_parent_index),g_bis_owner);
4338 if g_levels_I(l_child_index)=g_levels(l_child_index) then
4339 if g_level_count(l_child_index) is null then
4340 g_level_count(l_child_index):=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_levels(l_child_index),
4341 g_table_owner);
4342 end if;
4343 --check index on l_a1_key
4344 if EDW_OWB_COLLECTION_UTIL.check_index_on_column(g_levels(l_child_index),g_table_owner,l_a1_key) then
4345 l_use_nl_child:=EDW_OWB_COLLECTION_UTIL.get_join_nl(l_L_count,g_level_count(l_child_index),
4346 g_join_nl_percentage);
4347 end if;
4348 end if;
4349 if g_levels_I(l_parent_index)=g_levels(l_parent_index) then
4350 if g_level_count(l_parent_index) is null then
4351 g_level_count(l_parent_index):=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_levels(l_parent_index),
4352 g_table_owner);
4353 end if;
4354 l_use_nl_parent:=EDW_OWB_COLLECTION_UTIL.get_join_nl(l_L_count,g_level_count(l_parent_index),
4355 g_join_nl_percentage);
4356 end if;
4357 if l_L_table_found then
4358 l_stmt:='create table '||g_snplogs_LT(l_child_index)||' tablespace '||g_op_table_space;
4359 else
4360 l_stmt:='create table '||g_snplogs_L(l_child_index)||' tablespace '||g_op_table_space;
4361 end if;
4362 if g_parallel is not null then
4363 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4364 end if;
4365 l_stmt:=l_stmt||' as select /*+ORDERED ';
4366 if l_use_nl_parent then
4367 l_stmt:=l_stmt||' use_nl(A2)';
4368 end if;
4369 if l_use_nl_child then
4370 l_stmt:=l_stmt||' use_nl(A1)';
4371 end if;
4372 l_stmt:=l_stmt||'*/ ';
4373 if g_parallel is not null then
4374 l_stmt:=l_stmt||'/*+parallel(A1,'||g_parallel||') parallel(A2,'||g_parallel||')*/ ';
4375 end if;
4376 l_stmt:=l_stmt||' A1.'||l_rowid_child||' row_id ';
4377 if g_levels(l_child_index)=g_lowest_level_global and g_ll_snplog_has_pk then
4378 l_stmt:=l_stmt||',A1.'||g_ltc_pk;
4379 end if;
4380 l_stmt:=l_stmt||' from '||g_snplogs_L(l_parent_index)||' Y,'||g_levels_I(l_parent_index)||' A2,'||
4381 g_levels_I(l_child_index)||' A1 where A2.'||l_rowid_parent||'=Y.row_id and A1.'||l_a1_key||'=A2.'||l_a2_key;
4382 else
4383 l_L_table_found:=EDW_OWB_COLLECTION_UTIL.check_table(g_snplogs_L(l_parent_index));
4384 if g_debug then
4385 if l_L_table_found then
4386 write_to_log_file_n('The L table '||g_snplogs_L(l_parent_index)||' found');
4387 else
4388 write_to_log_file_n('The L table '||g_snplogs_L(l_parent_index)||' NOT found');
4389 end if;
4390 end if;
4391 l_a1_key:=g_fk_pk_child_fk(l_fk_pk_index);
4392 l_a2_key:=g_fk_pk_parent_pk(l_fk_pk_index);
4393 l_L_count:=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_snplogs_L(l_child_index),g_bis_owner);
4394 if g_levels_I(l_child_index)=g_levels(l_child_index) then
4395 if g_level_count(l_child_index) is null then
4396 g_level_count(l_child_index):=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_levels(l_child_index),
4397 g_table_owner);
4398 end if;
4399 l_use_nl_child:=EDW_OWB_COLLECTION_UTIL.get_join_nl(l_L_count,g_level_count(l_child_index),
4400 g_join_nl_percentage);
4401 end if;
4402 --first create a fk table
4403 l_fk_table:=g_snplogs_L(l_parent_index)||'F';
4404 l_stmt:='create table '||l_fk_table||' tablespace '||g_op_table_space;
4405 if g_parallel is not null then
4406 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4407 end if;
4408 l_stmt:=l_stmt||' as select /*+ORDERED ';
4409 if l_use_nl_child then
4410 l_stmt:=l_stmt||' use_nl(A1)';
4411 end if;
4412 l_stmt:=l_stmt||'*/ ';
4413 if g_parallel is not null then
4414 l_stmt:=l_stmt||'/*+parallel(A1,'||g_parallel||')*/ ';
4415 end if;
4416 l_stmt:=l_stmt||' distinct A1.'||l_a1_key||' from '||g_snplogs_L(l_child_index)||' Y,'||
4417 g_levels_I(l_child_index)||' A1 where A1.'||l_rowid_child||'=Y.row_id';
4418 if EDW_OWB_COLLECTION_UTIL.drop_table(l_fk_table)=false then
4419 null;
4420 end if;
4421 if g_debug then
4422 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4423 end if;
4424 execute immediate l_stmt;
4425 l_fk_table_count:=sql%rowcount;
4426 if g_debug then
4427 write_to_log_file_n('Created '||l_fk_table||' with '||sql%rowcount||' rows '||get_time);
4428 end if;
4429 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(l_fk_table,instr(l_fk_table,'.')+1,
4430 length(l_fk_table)),substr(l_fk_table,1,instr(l_fk_table,'.')-1));
4431 if g_levels_I(l_parent_index)=g_levels(l_parent_index) then
4432 if g_level_count(l_parent_index) is null then
4433 g_level_count(l_parent_index):=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_levels(l_parent_index),
4434 g_table_owner);
4435 end if;
4436 if EDW_OWB_COLLECTION_UTIL.check_index_on_column(g_levels(l_parent_index),g_table_owner,l_a2_key) then
4437 l_use_nl_parent:=EDW_OWB_COLLECTION_UTIL.get_join_nl(l_fk_table_count,g_level_count(l_parent_index),
4438 g_join_nl_percentage);
4439 end if;
4440 end if;
4441 if l_L_table_found then
4442 l_stmt:='create table '||g_snplogs_LT(l_parent_index)||' tablespace '||g_op_table_space;
4443 else
4444 l_stmt:='create table '||g_snplogs_L(l_parent_index)||' tablespace '||g_op_table_space;
4445 end if;
4446 if g_parallel is not null then
4447 /*
4448 encounetered a wierd bug in the database. this sql
4449 create table BIS.EDW_TRD_PARTNER_A_LTCLF parallel (degree 3) as select distinct
4450 A1.PARENT_TPARTNER_FK_KEY from BIS.EDW_TPRT_P4_TPARTNER_LTCI A1,
4451 BIS.EDW_TPRT_P4_TPARTNER_LTCL Y where A1.row_id=Y.row_id oo01/29/2001 16:47:30
4452 was stuck forever. all the tables have only 1 row! if we remove the parallel (degree 3)
4453 statement, its very fast!! is this a database bug?
4454 */
4455 if l_fk_table_count >= 100 then
4456 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4457 end if;
4458 end if;
4459 l_stmt:=l_stmt||' as select /*+ORDERED ';
4460 if l_use_nl_parent then
4461 l_stmt:=l_stmt||' use_nl(A1)';
4462 end if;
4463 l_stmt:=l_stmt||'*/ ';
4464 if g_parallel is not null then
4465 l_stmt:=l_stmt||'/*+parallel(A1,'||g_parallel||')*/ ';
4466 end if;
4467 l_stmt:=l_stmt||' A1.'||l_rowid_parent||' row_id from '||l_fk_table||' Y,'||
4468 g_levels_I(l_parent_index)||' A1 where A1.'||l_a2_key||'=Y.'||l_a1_key;
4469 l_index:=l_parent_index;
4470 l_parent_index:=l_child_index;
4471 l_child_index:=l_index;
4472 end if;
4473 if g_debug then
4474 write_to_log_file_n('l_parent_index='||l_parent_index);
4475 write_to_log_file('parent level '||g_levels(l_parent_index));
4476 write_to_log_file('l_child_index='||l_child_index);
4477 write_to_log_file('child level '||g_levels(l_child_index));
4478 write_to_log_file('l_a1_key='||l_a1_key);
4479 write_to_log_file('l_a2_key='||l_a2_key);
4480 end if;
4481 if EDW_OWB_COLLECTION_UTIL.drop_table(g_snplogs_LT(l_child_index))=false then
4482 null;
4483 end if;
4484 if g_debug then
4485 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4486 end if;
4487 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
4488 execute immediate l_stmt;
4489 if g_debug then
4490 if l_L_table_found then
4491 write_to_log_file_n('Created '||g_snplogs_LT(l_child_index)||' with '||sql%rowcount||' rows '||get_time);
4492 else
4493 write_to_log_file_n('Created '||g_snplogs_L(l_child_index)||' with '||sql%rowcount||' rows '||get_time);
4494 end if;
4495 end if;
4496 commit;
4497 if l_L_table_found then
4498 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_snplogs_LT(l_child_index),
4499 instr(g_snplogs_LT(l_child_index),'.')+1,length(g_snplogs_LT(l_child_index))),
4500 substr(g_snplogs_LT(l_child_index),1,instr(g_snplogs_LT(l_child_index),'.')-1));
4501 end if;
4502 --now insert into the L table
4503 if l_L_table_found then
4504 l_snplogs_L:=g_snplogs_L(l_child_index)||'Z';
4505 l_stmt:='create table '||l_snplogs_L||' tablespace '||g_op_table_space;
4506 if g_parallel is not null then
4507 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4508 end if;
4509 l_stmt:=l_stmt||' as select row_id from '||g_snplogs_LT(l_child_index)||
4510 ' MINUS select row_id from '||g_snplogs_L(l_child_index);
4511 if EDW_OWB_COLLECTION_UTIL.drop_table(l_snplogs_L)=false then
4512 null;
4513 end if;
4514 if g_debug then
4515 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4516 end if;
4517 execute immediate l_stmt;
4518 if g_debug then
4519 write_to_log_file_n('Created '||l_snplogs_L||' with '||sql%rowcount||' rows '||get_time);
4520 end if;
4521 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(l_snplogs_L,instr(l_snplogs_L,'.')+1,
4522 length(l_snplogs_L)),substr(l_snplogs_L,1,instr(l_snplogs_L,'.')-1));
4523 if g_levels(l_child_index)=g_lowest_level_global and g_ll_snplog_has_pk then
4524 l_stmt:='insert into '||g_snplogs_L(l_child_index)||'(row_id,'||g_ltc_pk||') select A.row_id,A.'||g_ltc_pk||
4525 ' from '||l_snplogs_L||' B,'||g_snplogs_LT(l_child_index)||' A where A.row_id=B.row_id';
4526 else
4527 l_stmt:='insert into '||g_snplogs_L(l_child_index)||'(row_id) select row_id from '||l_snplogs_L;
4528 end if;
4529 if g_debug then
4530 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4531 end if;
4532 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
4533 execute immediate l_stmt;
4534 if g_debug then
4535 write_to_log_file_n('Inserted '||sql%rowcount||' rows into '||g_snplogs_L(l_child_index)||get_time);
4536 end if;
4537 commit;
4538 if EDW_OWB_COLLECTION_UTIL.drop_table(l_snplogs_L)=false then
4539 null;
4540 end if;
4541 end if;
4542 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_snplogs_L(l_child_index),
4543 instr(g_snplogs_L(l_child_index),'.')+1,length(g_snplogs_L(l_child_index))),
4544 substr(g_snplogs_L(l_child_index),1,instr(g_snplogs_L(l_child_index),'.')-1));
4545 if l_fk_table is not null then
4546 if EDW_OWB_COLLECTION_UTIL.drop_table(l_fk_table)=false then
4547 null;
4548 end if;
4549 end if;
4550 if EDW_OWB_COLLECTION_UTIL.drop_table(g_snplogs_LT(l_child_index))=false then
4551 null;
4552 end if;
4553 return true;
4554 Exception when others then
4555 g_status_message:=sqlerrm;
4556 write_to_log_file_n(g_status_message);
4557 g_status:=false;
4558 return false;
4559 End;
4560
4561 /*
4562 given a level, see what are the rowids that have changed because of change to the parent
4563 */
4564 function find_rowid_parent_change(p_level varchar2) return boolean is
4565 l_parent_index number;
4566 l_parent varchar2(400);
4567 l_index number;
4568 Begin
4569 if g_debug then
4570 write_to_log_file_n('In find_rowid_parent_change');
4571 write_to_log_file('p_level='||p_level);
4572 end if;
4573 for i in 1..g_fk_pk_number loop
4574 if g_fk_pk_child_level(i)=p_level then
4575 l_parent:=g_fk_pk_parent_level(i);
4576 l_parent_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,l_parent);
4577 l_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,p_level);
4578 if g_consider_level(l_index) and g_consider_level(l_parent_index) then
4579 --if the parent L table has data then
4580 --if the parent level has been already considered, do not consider it again
4581 if EDW_OWB_COLLECTION_UTIL.value_in_table(g_considered_parent,g_number_considered_parent,
4582 g_levels(l_parent_index))=false then
4583 if EDW_OWB_COLLECTION_UTIL.does_table_have_data(g_snplogs_L(l_parent_index))= 2 then
4584 if insert_into_LT(p_level,g_levels(l_parent_index),'DOWN')=false then
4585 return false;
4586 end if;
4587 g_number_considered_parent:=g_number_considered_parent+1;
4588 g_considered_parent(g_number_considered_parent):=g_levels(l_parent_index);
4589 end if;
4590 else
4591 if g_debug then
4592 write_to_log_file_n('Level '||g_levels(l_parent_index)||' already considered');
4593 end if;
4594 end if;
4595 else
4596 if g_debug then
4597 write_to_log_file_n('Both levels '||p_level||' and '||l_parent||' together have no change');
4598 end if;
4599 end if;
4600 end if;
4601 end loop;
4602 return true;
4603 Exception when others then
4604 g_status_message:=sqlerrm;
4605 write_to_log_file_n(g_status_message);
4606 g_status:=false;
4607 return false;
4608 End;
4609
4610 /*
4611 given a level, see what are the parent rowids that have changed because of the child
4612 */
4613 function find_rowid_child_change(p_level varchar2,p_mode varchar2) return boolean is
4614 l_parent_index number;
4615 l_child_index number;
4616 l_parent varchar2(400);
4617 Begin
4618 if g_debug then
4619 write_to_log_file_n('In find_rowid_child_change mode='||p_mode||',level='||p_level);
4620 end if;
4621 for i in 1..g_fk_pk_number loop
4622 if g_fk_pk_child_level(i)=p_level then
4623 l_parent:=g_fk_pk_parent_level(i);
4624 l_parent_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,l_parent);
4625 l_child_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,p_level);
4626 if (p_mode='SNP' and g_consider_level(l_child_index) and g_consider_level(l_parent_index))
4627 OR p_mode='NON-SNP' then
4628 if g_debug then
4629 write_to_log_file_n('Drill '||g_levels(l_child_index)||' to '||g_levels(l_parent_index));
4630 end if;
4631 --if the parent level has been already considered, do not consider it again
4632 if EDW_OWB_COLLECTION_UTIL.value_in_table(g_considered_parent,g_number_considered_parent,
4633 g_levels(l_parent_index))=false then
4634 if EDW_OWB_COLLECTION_UTIL.does_table_have_data(g_snplogs_L(l_child_index))= 2 then
4635 if insert_into_LT(p_level,g_levels(l_parent_index),'UP')=false then
4636 return false;
4637 end if;
4638 g_number_considered_parent:=g_number_considered_parent+1;
4639 g_considered_parent(g_number_considered_parent):=g_levels(l_parent_index);
4640 end if;
4641 else
4642 if g_debug then
4643 write_to_log_file_n('Level '||g_levels(l_parent_index)||' already considered');
4644 end if;
4645 end if;
4646 else
4647 if g_debug then
4648 write_to_log_file_n('Both levels '||p_level||' and '||l_parent||' together have no change');
4649 end if;
4650 end if;
4651 end if;
4652 end loop;
4653 return true;
4654 Exception when others then
4655 g_status_message:=sqlerrm;
4656 write_to_log_file_n(g_status_message);
4657 g_status:=false;
4658 return false;
4659 End;
4660
4661 /*
4662 after inserting into the L table, insert these rows into the ILOG table
4663 we cannot drop and recreate ilog so we can support error recovery
4664 */
4665 function insert_into_ilog_from_L(p_multi_thread boolean) return boolean is
4666 l_stmt varchar2(10000);
4667 l_index number;
4668 l_ilog varchar2(400);
4669 l_ilog_el varchar2(400);
4670 Begin
4671 if g_debug then
4672 write_to_log_file_n('In insert_into_ilog_from_L');
4673 end if;
4674 l_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,g_lowest_level_global);
4675 if EDW_OWB_COLLECTION_UTIL.check_table(g_ilog)=false then
4676 --if create_ilog_table= false then
4677 --return false;
4678 --end if;
4679 l_stmt:='create table '||g_ilog||' tablespace '||g_op_table_space;
4680 if g_parallel is not null then
4681 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4682 end if;
4683 l_stmt:=l_stmt||' as select ';
4684 if p_multi_thread=false or g_collection_size=0 then
4685 g_skip_ilog_update:=true;
4686 else
4687 g_skip_ilog_update:=false;
4688 end if;
4689 if g_collection_size>0 then
4690 if g_ll_snplog_has_pk then
4691 if p_multi_thread then
4692 l_stmt:=l_stmt||' row_id,'||g_ltc_pk||',0 status,rownum row_num from '||g_snplogs_L(l_index);
4693 else
4694 l_stmt:=l_stmt||' row_id,'||g_ltc_pk||
4695 ',decode(sign(rownum-'||g_collection_size||'),1,0,1) status from '||g_snplogs_L(l_index);
4696 end if;
4697 else
4698 if p_multi_thread then
4699 l_stmt:=l_stmt||' row_id,0 status,rownum row_num from '||g_snplogs_L(l_index);
4700 else
4701 l_stmt:=l_stmt||' row_id,decode(sign(rownum-'||g_collection_size||'),1,0,1) status from '||
4702 g_snplogs_L(l_index);
4703 end if;
4704 end if;
4705 else
4706 if g_ll_snplog_has_pk then
4707 l_stmt:=l_stmt||' row_id,'||g_ltc_pk||',1 status,rownum row_num from '||g_snplogs_L(l_index);
4708 else
4709 l_stmt:=l_stmt||' row_id,1 status,rownum row_num from '||g_snplogs_L(l_index);
4710 end if;
4711 end if;
4712 if g_debug then
4713 write_to_log_file_n(l_stmt||get_time);
4714 end if;
4715 execute immediate l_stmt;
4716 if g_debug then
4717 write_to_log_file_n('created with '||sql%rowcount||' rows '||get_time);
4718 end if;
4719 if p_multi_thread then
4720 edw_owb_collection_util.create_rownum_index_ilog(g_ilog,g_op_table_space,g_parallel);
4721 end if;
4722 else
4723 --must have pk_key in ilog for error recovery. there can be row migration with partitions
4724 --only effective if the lowest level snp log has pk_key
4725 if substr(g_ilog,length(g_ilog),1)='A' then
4726 l_ilog_el:=substr(g_ilog,1,length(g_ilog)-1);
4727 else
4728 l_ilog_el:=g_ilog||'A';
4729 end if;
4730 if g_ll_snplog_has_pk then
4731 l_stmt:='create table '||l_ilog_el||' tablespace '||g_op_table_space;
4732 l_stmt:=l_stmt||' storage (initial 4M next 4M pctincrease 0) ';
4733 if g_parallel is not null then
4734 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4735 end if;
4736 l_stmt:=l_stmt||' as select /*+ORDERED*/ A.'||g_ltc_pk||',A.rowid row_id,B.status from '||
4737 g_ilog||' B,'||g_lowest_level_global||' A where A.'||g_ltc_pk||'=B.'||g_ltc_pk;
4738 else
4739 l_stmt:='create table '||l_ilog_el||' tablespace '||g_op_table_space;
4740 l_stmt:=l_stmt||' storage (initial 4M next 4M pctincrease 0) ';
4741 if g_parallel is not null then
4742 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4743 end if;
4744 l_stmt:=l_stmt||' as select /*+ORDERED*/ B.row_id,B.status from '||
4745 g_ilog||' B,'||g_lowest_level_global||' A where A.rowid=B.row_id';
4746 end if;
4747 if EDW_OWB_COLLECTION_UTIL.drop_table(l_ilog_el)=false then
4748 null;
4749 end if;
4750 if g_debug then
4751 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4752 end if;
4753 execute immediate l_stmt;
4754 if g_debug then
4755 write_to_log_file_n('created '||l_ilog_el||' with '||sql%rowcount||' rows '||get_time);
4756 end if;
4757 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(l_ilog_el,instr(l_ilog_el,'.')+1,length(l_ilog_el)),
4758 substr(l_ilog_el,1,instr(l_ilog_el,'.')-1));
4759 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog)=false then
4760 null;
4761 end if;
4762 g_ilog:=l_ilog_el;
4763 l_ilog:=g_ilog||'T';
4764 l_stmt:='create table '||l_ilog||' tablespace '||g_op_table_space;
4765 if g_parallel is not null then
4766 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4767 end if;
4768 if g_ll_snplog_has_pk then
4769 l_stmt:=l_stmt||' as select row_id,'||g_ltc_pk||',0 status from '||g_snplogs_L(l_index)||
4770 ' MINUS select row_id,'||g_ltc_pk||',0 status from '||g_ilog;
4771 else
4772 l_stmt:=l_stmt||' as select row_id,0 status from '||g_snplogs_L(l_index)||
4773 ' MINUS select row_id,0 status from '||g_ilog;
4774 end if;
4775 if EDW_OWB_COLLECTION_UTIL.drop_table(l_ilog)=false then
4776 null;
4777 end if;
4778 if g_debug then
4779 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4780 end if;
4781 execute immediate l_stmt;
4782 if g_debug then
4783 write_to_log_file_n('created '||l_ilog||' with '||sql%rowcount||' rows '||get_time);
4784 end if;
4785 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(l_ilog,instr(l_ilog,'.')+1,length(l_ilog)),
4786 substr(l_ilog,1,instr(l_ilog,'.')-1));
4787 if g_ll_snplog_has_pk then
4788 l_stmt:='insert into '||g_ilog||'(row_id,'||g_ltc_pk||',status) select row_id,'||g_ltc_pk||
4789 ',status from '||l_ilog;
4790 else
4791 l_stmt:='insert into '||g_ilog||'(row_id, status) select row_id,status from '||l_ilog;
4792 end if;
4793 if g_debug then
4794 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4795 end if;
4796 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
4797 execute immediate l_stmt;
4798 if g_debug then
4799 write_to_log_file_n('Inserted '||sql%rowcount||' rows into '||g_ilog||get_time);
4800 end if;
4801 commit;
4802 if l_ilog is not null then
4803 if EDW_OWB_COLLECTION_UTIL.drop_table(l_ilog)=false then
4804 null;
4805 end if;
4806 end if;
4807 end if;
4808 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_ilog,instr(g_ilog,'.')+1,length(g_ilog)),
4809 substr(g_ilog,1,instr(g_ilog,'.')-1));
4810 return true;
4811 Exception when others then
4812 g_status_message:=sqlerrm;
4813 write_to_log_file_n(g_status_message);
4814 g_status:=false;
4815 return false;
4816 End;
4817
4818 /*
4819 create L table for the lowest level with row_id from gilog
4820 */
4821 function create_L_from_ilog return boolean is
4822 l_stmt varchar2(10000);
4823 l_index number;
4824 Begin
4825 if g_debug then
4826 write_to_log_file_n('In create_L_from_ilog');
4827 end if;
4828 if EDW_OWB_COLLECTION_UTIL.drop_table(g_snplogs_L(g_lowest_level_index))=false then
4829 null;
4830 end if;
4831 l_stmt:='create table '||g_snplogs_L(g_lowest_level_index)||' tablespace '||g_op_table_space;
4832 if g_parallel is not null then
4833 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4834 end if;
4835 l_stmt:=l_stmt||' as select row_id from '||g_ilog||' where status=1';
4836 if g_debug then
4837 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4838 end if;
4839 execute immediate l_stmt;
4840 if g_debug then
4841 write_to_log_file_n('Created '||g_snplogs_L(g_lowest_level_index)||'with '||sql%rowcount||
4842 ' rows '||get_time);
4843 end if;
4844 commit;
4845 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_snplogs_L(g_lowest_level_index),
4846 instr(g_snplogs_L(g_lowest_level_index),'.')+1,length(g_snplogs_L(g_lowest_level_index))),
4847 substr(g_snplogs_L(g_lowest_level_index),1,instr(g_snplogs_L(g_lowest_level_index),'.')-1));
4848 return true;
4849 Exception when others then
4850 g_status_message:=sqlerrm;
4851 write_to_log_file_n(g_status_message);
4852 g_status:=false;
4853 return false;
4854 End;
4855
4856 /*
4857 give all these temp tables names
4858 */
4859 function name_op_tables(p_job_id number) return boolean is
4860 l_prefix varchar2(40);
4861 l_name varchar2(40);
4862 l_name_org varchar2(40);
4863 Begin
4864 if g_debug then
4865 write_to_log_file_n('In name_op_tables');
4866 end if;
4867 for i in 1..g_number_levels loop
4868 l_prefix:=EDW_OWB_COLLECTION_UTIL.get_level_prefix(substr(g_levels(i),1,instr(g_levels(i),'_LTC')-1));
4869 l_name_org:='TAB_'||g_dim_id||'_'||l_prefix||'_';
4870 if p_job_id is null then
4871 l_name:='TAB_'||g_dim_id||'_'||l_prefix||'_';
4872 else
4873 l_name:='TAB_'||g_dim_id||'_'||l_prefix||'_'||p_job_id||'_';
4874 end if;
4875 g_snplogs_L(i):=g_bis_owner||'.'||l_name||'L';
4876 if p_job_id is null then
4877 g_levels_I(i):=g_bis_owner||'.'||l_name_org||'I';--this name is shared across threads
4878 --when p_job_id is not null, g_levels_I is read from the input table
4879 end if;
4880 g_levels_copy(i):=g_bis_owner||'.'||l_name||'C';
4881 g_snplogs_LT(i):=g_bis_owner||'.'||l_name||'LT';
4882 end loop;
4883 g_levels_copy_low_hd_ins:=g_bis_owner||'.'||l_name||'LL_CL';
4884 return true;
4885 Exception when others then
4886 g_status_message:=sqlerrm;
4887 write_to_log_file_n(g_status_message);
4888 g_status:=false;
4889 return false;
4890 End;
4891
4892 function create_ltc_copies(p_mode varchar2) return boolean is
4893 l_stmt varchar2(10000);
4894 l_pk varchar2(400);
4895 l_consider boolean;
4896 l_cols EDW_OWB_COLLECTION_UTIL.varcharTableType;
4897 l_number_cols number;
4898 l_L_count number;
4899 l_nl_flag boolean;
4900 Begin
4901 if g_debug then
4902 write_to_log_file_n('In create_ltc_copies mode='||p_mode);
4903 end if;
4904 for i in 1..g_number_levels loop
4905 l_consider:=false;
4906 if p_mode='SNP' then
4907 if EDW_OWB_COLLECTION_UTIL.drop_table(g_levels_copy(i))=false then
4908 null;
4909 end if;
4910 if g_consider_level(i) then
4911 l_consider:=true;
4912 end if;
4913 elsif p_mode='NON-SNP' and g_consider_level(i)=false then
4914 if EDW_OWB_COLLECTION_UTIL.drop_table(g_levels_copy(i))=false then
4915 null;
4916 end if;
4917 l_consider:=true;
4918 end if;
4919 if l_consider then
4920 if EDW_OWB_COLLECTION_UTIL.check_table(g_snplogs_L(i))=false then
4921 l_stmt:='create table '||g_snplogs_L(i)||' tablespace '||g_op_table_space;
4922 l_stmt:=l_stmt||' as select rowid row_id from '||g_levels(i)||' where 1=2';
4923 if g_debug then
4924 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4925 end if;
4926 execute immediate l_stmt;
4927 if g_debug then
4928 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
4929 end if;
4930 end if;
4931 if g_level_count(i) is null then
4932 g_level_count(i):=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_levels(i),g_table_owner);
4933 end if;
4934 l_L_count:=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(g_snplogs_L(i),g_bis_owner);
4935 l_nl_flag:=EDW_OWB_COLLECTION_UTIL.get_join_nl(l_L_count,g_level_count(i),g_join_nl_percentage);
4936 l_stmt:='create table '||g_levels_copy(i)||' tablespace '||g_op_table_space;
4937 if g_parallel is not null then
4938 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
4939 end if;
4940 if l_nl_flag then
4941 l_stmt:=l_stmt||' as select /*+ORDERED USE_NL('||g_levels(i)||')*/ ';
4942 else
4943 l_stmt:=l_stmt||' as select /*+ORDERED*/ ';
4944 end if;
4945 if g_parallel is not null then
4946 l_stmt:=l_stmt||'/*+PARALLEL('||g_levels(i)||','||g_parallel||')*/ ';
4947 end if;
4948 --find the columns to include
4949 l_number_cols:=0;
4950 for j in 1..g_number_mapping loop
4951 if g_level_name(j)=g_levels(i) then
4952 if g_skip_item(j)=false then
4953 l_number_cols:=l_number_cols+1;
4954 l_cols(l_number_cols):=g_level_col(j);
4955 end if;
4956 end if;
4957 end loop;
4958 if g_number_src_fk_table>0 then
4959 for j in 1..g_number_src_fk_table loop
4960 if g_src_fk_table(j)=g_levels(i) then
4961 if EDW_OWB_COLLECTION_UTIL.value_in_table(l_cols,l_number_cols,g_src_fk(j))=false then
4962 l_number_cols:=l_number_cols+1;
4963 l_cols(l_number_cols):=g_src_fk(j);
4964 end if;
4965 end if;
4966 end loop;
4967 end if;
4968 --bug
4969 --we need to include the PK_KEY columns even if they are not mapped, especially for
4970 --higher levels
4971 if g_levels(i)<>g_lowest_level_global then
4972 for j in 1..g_fk_pk_number loop
4973 if g_fk_pk_parent_level(j)=g_levels(i) then
4974 if EDW_OWB_COLLECTION_UTIL.value_in_table(l_cols,l_number_cols,g_fk_pk_parent_pk(j))=false then
4975 l_number_cols:=l_number_cols+1;
4976 l_cols(l_number_cols):=g_fk_pk_parent_pk(j);
4977 end if;
4978 end if;
4979 end loop;
4980 end if;
4981 --for the lowest level, we need row_id because we need g_ilog to join to it
4982 if g_levels(i)=g_lowest_level_global then
4983 for j in 1..l_number_cols loop
4984 l_stmt:=l_stmt||g_levels(i)||'.'||l_cols(j)||',';
4985 end loop;
4986 l_stmt:=l_stmt||g_levels(i)||'.rowid row_id from '||g_snplogs_L(i)||','||
4987 g_levels(i)||' where '||g_levels(i)||'.rowid='||g_snplogs_L(i)||'.row_id';
4988 else
4989 for j in 1..l_number_cols loop
4990 l_stmt:=l_stmt||g_levels(i)||'.'||l_cols(j)||',';
4991 end loop;
4992 l_stmt:=substr(l_stmt,1,length(l_stmt)-1);
4993 l_stmt:=l_stmt||' from '||g_snplogs_L(i)||','||g_levels(i)||' where '||
4994 g_levels(i)||'.rowid='||g_snplogs_L(i)||'.row_id';
4995 end if;
4996 if g_debug then
4997 write_to_log_file_n('Going to execute '||l_stmt||get_time);
4998 end if;
4999 execute immediate l_stmt;
5000 if g_debug then
5001 write_to_log_file_n('Created '||g_levels_copy(i)||' with '||sql%rowcount||' rows '||get_time);
5002 end if;
5003 commit;
5004 if g_levels(i)=g_lowest_level_global then
5005 null;
5006 else
5007 --create a unique index on the pk
5008 --we will need to create a unique index on all pks of the ltc table
5009 l_pk:=null;
5010 for j in 1..g_fk_pk_number loop
5011 if g_fk_pk_parent_level(j)=g_levels(i) then
5012 --we must not create a diff index on the same pk
5013 if l_pk is null or l_pk<>g_fk_pk_parent_pk(j) then
5014 l_stmt:='create unique index '||g_levels_copy(i)||'u'||j||' on '||
5015 g_levels_copy(i)||'('||g_fk_pk_parent_pk(j)||') tablespace '||g_op_table_space;
5016 if g_parallel is not null then
5017 l_stmt:=l_stmt||' parallel '||g_parallel;
5018 end if;
5019 if g_debug then
5020 write_to_log_file_n('Going to execute '||l_stmt||get_time);
5021 end if;
5022 execute immediate l_stmt;
5023 commit;
5024 l_pk:=g_fk_pk_parent_pk(j);
5025 if g_debug then
5026 write_to_log_file_n('Created unique index '||g_levels_copy(i)||'u'||j||' '||get_time);
5027 end if;
5028 end if;
5029 end if;
5030 end loop;
5031 end if;
5032 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_levels_copy(i),instr(g_levels_copy(i),'.')+1,
5033 length(g_levels_copy(i))),substr(g_levels_copy(i),1,instr(g_levels_copy(i),'.')-1));
5034 end if;
5035 end loop;
5036 return true;
5037 Exception when others then
5038 g_status_message:=sqlerrm;
5039 write_to_log_file_n(g_status_message);
5040 g_status:=false;
5041 return false;
5042 End;
5043
5044 --drop all the L tables
5045 function drop_L_tables return boolean is
5046 Begin
5047 if g_debug then
5048 write_to_log_file_n('In drop_L_tables');
5049 end if;
5050 for i in 1..g_number_levels loop
5051 if EDW_OWB_COLLECTION_UTIL.drop_table(g_snplogs_L(i))=false then
5052 null;
5053 end if;
5054 end loop;
5055 return true;
5056 Exception when others then
5057 g_status_message:=sqlerrm;
5058 write_to_log_file_n(g_status_message);
5059 g_status:=false;
5060 return false;
5061 End;
5062
5063 function drop_I_tables return boolean is
5064 Begin
5065 if g_debug then
5066 write_to_log_file_n('In drop_I_tables');
5067 end if;
5068 for i in 1..g_number_levels loop
5069 if g_levels_I(i)<>g_levels(i) then
5070 if EDW_OWB_COLLECTION_UTIL.drop_table(g_levels_I(i))=false then
5071 null;
5072 end if;
5073 end if;
5074 end loop;
5075 return true;
5076 Exception when others then
5077 g_status_message:=sqlerrm;
5078 write_to_log_file_n(g_status_message);
5079 g_status:=false;
5080 return false;
5081 End;
5082
5083 --called from clean_up
5084 function drop_ltc_copies return boolean is
5085 Begin
5086 if g_debug then
5087 write_to_log_file_n('In drop_ltc_copies');
5088 end if;
5089 for i in 1..g_number_levels loop
5090 if EDW_OWB_COLLECTION_UTIL.drop_table(g_levels_copy(i))=false then
5091 null;
5092 end if;
5093 end loop;
5094 if EDW_OWB_COLLECTION_UTIL.drop_table(g_levels_copy_low_hd_ins)=false then
5095 null;
5096 end if;
5097 return true;
5098 Exception when others then
5099 g_status_message:=sqlerrm;
5100 write_to_log_file_n(g_status_message);
5101 g_status:=false;
5102 return false;
5103 End;
5104
5105 /*
5106 starting from the top, identify all the changes to the lowest level
5107 */
5108 function drill_down_net_change(p_multi_thread boolean) return boolean is
5109 l_index number;
5110 Begin
5111 if g_debug then
5112 write_to_log_file_n('In drill_down_net_change');
5113 end if;
5114 --case 1: there is only one level
5115 --case 2: there is change to only the lowest level
5116 --case 3: there is change to any levels
5117 g_number_considered_parent:=0;
5118 if g_where_snplog_stmt is not null and g_number_levels>1 then
5119 for i in 1..g_number_levels loop
5120 l_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,g_level_order(i));
5121 if g_consider_level(l_index) then
5122 if g_debug then
5123 write_to_log_file_n('Level '||g_level_order(i)||' has changed. Drill down net change');
5124 end if;
5125 if find_rowid_parent_change(g_level_order(i))=false then
5126 return false;
5127 end if;
5128 else
5129 if g_debug then
5130 write_to_log_file_n('Level '||g_level_order(i)||' has not changed. no need to drill down');
5131 end if;
5132 end if;
5133 end loop;
5134 end if;
5135 if insert_into_ilog_from_L(p_multi_thread)=false then
5136 return false;
5137 end if;
5138 if drop_L_tables=false then
5139 return false;
5140 end if;
5141 return true;
5142 Exception when others then
5143 g_status_message:=sqlerrm;
5144 write_to_log_file_n(g_status_message);
5145 g_status:=false;
5146 return false;
5147 End;
5148
5149 /*
5150 starting from the bottom, identify all the changes to the upper levels
5151 */
5152 function drill_up_net_change(p_mode varchar2) return boolean is
5153 l_index number;
5154 Begin
5155 if g_debug then
5156 write_to_log_file_n('In drill_up_net_change mode='||p_mode);
5157 end if;
5158 if p_mode='SNP' then
5159 g_number_considered_parent:=0;
5160 else
5161 if g_debug then
5162 write_to_log_file_n('Considered parents');
5163 for i in 1..g_number_considered_parent loop
5164 write_to_log_file(g_considered_parent(i));
5165 end loop;
5166 end if;
5167 end if;
5168 if g_number_levels>1 then
5169 for i in 1..g_number_levels loop
5170 l_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,
5171 g_level_order(g_number_levels+1-i));
5172 if p_mode='SNP' and g_consider_level(l_index) then
5173 if find_rowid_child_change(g_level_order(g_number_levels+1-i),p_mode)=false then
5174 return false;
5175 end if;
5176 elsif p_mode='NON-SNP' then
5177 if find_rowid_child_change(g_level_order(g_number_levels+1-i),p_mode)=false then
5178 return false;
5179 end if;
5180 else
5181 if g_debug then
5182 write_to_log_file_n('Level '||g_level_order(g_number_levels+1-i)||
5183 ' has no inc data to drill up');
5184 end if;
5185 end if;
5186 end loop;
5187 end if;
5188 return true;
5189 Exception when others then
5190 g_status_message:=sqlerrm;
5191 write_to_log_file_n(g_status_message);
5192 g_status:=false;
5193 return false;
5194 End;
5195
5196 /*recreate the from stmt and change the g_lowest_level and insert the new row_id into g_ilog*/
5197 function recreate_from_stmt return boolean is
5198 l_index number;
5199 l_lowest_level varchar2(400);
5200 Begin
5201 if g_debug then
5202 write_to_log_file_n('In recreate_from_stmt');
5203 end if;
5204 g_from_stmt_global:=g_from_stmt;
5205 g_from_stmt:=' from ';
5206 g_from_stmt_ins:=' from ';
5207 g_from_stmt_hd_row:=' from ';
5208 g_from_stmt_ins_row:=' from ';
5209 for i in 1..g_number_levels loop
5210 if g_consider_level(i) then
5211 g_from_stmt:=g_from_stmt||g_levels_copy(i)||' A_'||i||',';
5212 end if;
5213 end loop;
5214 g_from_stmt:=substr(g_from_stmt,1,length(g_from_stmt)-1);
5215 for i in 1..g_number_levels loop
5216 g_from_stmt_ins:=g_from_stmt_ins||g_levels_copy(i)||' A_'||i||',';
5217 end loop;
5218 g_from_stmt_ins:=substr(g_from_stmt_ins,1,length(g_from_stmt_ins)-1);--for insert stmt
5219 for i in 1..g_number_levels loop
5220 if g_levels(i)<>g_lowest_level then
5221 g_from_stmt_ins_row:=g_from_stmt_ins_row||g_levels_copy(i)||' A_'||i||',';
5222 else
5223 g_from_stmt_ins_row:=g_from_stmt_ins_row||g_levels_copy_low_hd_ins||' A_'||i||',';
5224 end if;
5225 end loop;
5226 g_from_stmt_ins_row:=substr(g_from_stmt_ins_row,1,length(g_from_stmt_ins_row)-1);--for insert stmt row by row
5227 for i in 1..g_number_levels loop
5228 if g_consider_level(i) then
5229 if g_levels(i)<>g_lowest_level then
5230 g_from_stmt_hd_row:=g_from_stmt_hd_row||g_levels_copy(i)||' A_'||i||',';
5231 else
5232 g_from_stmt_hd_row:=g_from_stmt_hd_row||g_levels_copy_low_hd_ins||' A_'||i||',';
5233 end if;
5234 end if;
5235 end loop;
5236 g_from_stmt_hd_row:=substr(g_from_stmt_hd_row,1,length(g_from_stmt_hd_row)-1);--for hold nested loop
5237 /*
5238 never must g_levels be changed!!
5239 */
5240 l_index:=EDW_OWB_COLLECTION_UTIL.index_in_table(g_levels,g_number_levels,g_lowest_level);
5241 if l_index>0 then
5242 g_lowest_level:=g_levels_copy(l_index);
5243 end if;
5244 if g_debug then
5245 write_to_log_file_n('The new g_from_stmt is ');
5246 write_to_log_file(g_from_stmt);
5247 write_to_log_file_n('The new g_from_stmt_ins is ');
5248 write_to_log_file(g_from_stmt_ins);
5249 write_to_log_file_n('The new g_from_stmt_hd_row is ');
5250 write_to_log_file(g_from_stmt_hd_row);
5251 write_to_log_file_n('The new g_lowest_level is '||g_lowest_level);
5252 end if;
5253 return true;
5254 Exception when others then
5255 g_status_message:=sqlerrm;
5256 write_to_log_file_n('Error in recreate_from_stmt '||g_status_message);
5257 g_status:=false;
5258 return false;
5259 End;
5260
5261 procedure insert_into_ilog(p_multi_thread boolean) is
5262 l_stmt varchar2(30000);
5263 errbuf varchar2(2000);
5264 retcode varchar2(400);
5265 l_ilog_found boolean;
5266 l_ilog_has_data boolean;
5267 l_ilog_temp varchar2(400);
5268 --
5269 l_drill_down boolean;
5270 --
5271 Begin
5272 if g_debug then
5273 write_to_log_file_n('In insert_into_ilog');
5274 end if;
5275 if g_dim_empty_flag then
5276 --create the ilog
5277 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog) = false then
5278 write_to_log_file_n(g_ilog||' table not found for dropping');
5279 end if;
5280 --if create_ilog_table= false then
5281 --write_to_log_file_n('create_ilog_table returned with false');
5282 --return;
5283 --end if;
5284 begin
5285 /*
5286 if multi threading is true, we cannot make g_skip_ilog_update=true unless g_collection_size=0
5287 */
5288 if p_multi_thread=false or g_collection_size=0 then
5289 g_skip_ilog_update:=true;
5290 else
5291 g_skip_ilog_update:=false;
5292 end if;
5293 if g_parallel is not null then
5294 l_stmt:='create table '||g_ilog||' tablespace '||g_op_table_space||' parallel (degree '||g_parallel||') '||
5295 'as select /*+PARALLEL('||g_lowest_level||','||g_parallel||')*/ ';
5296 if g_collection_size>0 then
5297 if g_ll_snplog_has_pk then
5298 if p_multi_thread then
5299 l_stmt:=l_stmt||' rowid row_id,'||g_ltc_pk||',0 status, rownum row_num from '||
5300 g_lowest_level;
5301 else
5302 l_stmt:=l_stmt||' rowid row_id,'||g_ltc_pk||',decode(sign(rownum-'||g_collection_size||'),1,0,1) status from '||
5303 g_lowest_level;
5304 end if;
5305 else
5306 if p_multi_thread then
5307 l_stmt:=l_stmt||' rowid row_id,0 status, rownum row_num from '||g_lowest_level;
5308 else
5309 l_stmt:=l_stmt||' rowid row_id,decode(sign(rownum-'||g_collection_size||'),1,0,1) status from '||
5310 g_lowest_level;
5311 end if;
5312 end if;
5313 else
5314 if g_ll_snplog_has_pk then
5315 l_stmt:=l_stmt||' rowid row_id,'||g_ltc_pk||',1 status, rownum row_num from '||g_lowest_level;
5316 else
5317 l_stmt:=l_stmt||' rowid row_id,1 status,rownum row_num from '||g_lowest_level;
5318 end if;
5319 end if;
5320 else
5321 --l_stmt:='insert into '||g_ilog||'(row_id,status) select rowid,0 from '||g_lowest_level;
5322 l_stmt:='create table '||g_ilog||' tablespace '||g_op_table_space||' '||
5323 'as select ';
5324 if g_collection_size>0 then
5325 if g_ll_snplog_has_pk then
5326 if p_multi_thread then
5327 l_stmt:=l_stmt||' rowid row_id,'||g_ltc_pk||',0 status,rownum row_num from '||g_lowest_level;
5328 else
5329 l_stmt:=l_stmt||' rowid row_id,'||g_ltc_pk||
5330 ',decode(sign(rownum-'||g_collection_size||'),1,0,1) status from '||g_lowest_level;
5331 end if;
5332 else
5333 if p_multi_thread then
5334 l_stmt:=l_stmt||' rowid row_id,0 status, rownum row_num from '||g_lowest_level;
5335 else
5336 l_stmt:=l_stmt||' rowid row_id,decode(sign(rownum-'||
5337 g_collection_size||'),1,0,1) status from '||g_lowest_level;
5338 end if;
5339 end if;
5340 else
5341 if g_ll_snplog_has_pk then
5342 l_stmt:=l_stmt||' rowid row_id,'||g_ltc_pk||
5343 ',1 status, rownum row_num from '||g_lowest_level;
5344 else
5345 l_stmt:=l_stmt||' rowid row_id,1 status, rownum row_num from '||g_lowest_level;
5346 end if;
5347 end if;
5348 end if;
5349 if g_debug then
5350 write_to_log_file_n('Going to execute '||l_stmt);
5351 end if;
5352 --EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
5353 execute immediate l_stmt;
5354 if g_debug then
5355 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
5356 end if;
5357 commit;
5358 if p_multi_thread then
5359 edw_owb_collection_util.create_rownum_index_ilog(g_ilog,g_op_table_space,g_parallel);
5360 end if;
5361 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_ilog,instr(g_ilog,'.')+1,length(g_ilog)),
5362 substr(g_ilog,1,instr(g_ilog,'.')-1));
5363 exception when others then
5364 g_status_message:=sqlerrm;
5365 write_to_log_file_n(g_status_message);
5366 write_to_log_file('problem stmt '||l_stmt);
5367 g_status:=false;
5368 return;
5369 end;
5370 --at the end of this, we need to truncate the snapshot logs
5371 truncate_ltc_snapshot_logs;
5372 if set_level_I_flag=false then
5373 return;
5374 end if;
5375 return;
5376 end if;
5377 --here is when dim is not empty, ie incremental
5378 /*populate the ilog table and L tables. drill down net change will drop L tables*/
5379 if set_level_I_flag=false then
5380 return;
5381 end if;
5382 if create_ltc_ilog_table('SNP')=false then
5383 g_status:=false;
5384 return;
5385 end if;
5386 l_drill_down:=true;
5387 if g_parallel_drill_down then
5388 l_drill_down:=false;
5389 if g_debug then
5390 write_to_log_file_n('Parallel drill down TRUE');
5391 end if;
5392 if insert_L_ilog_parallel_dd(p_multi_thread)=false then
5393 l_drill_down:=true;
5394 end if;
5395 end if;
5396 if l_drill_down then
5397 if g_debug then
5398 write_to_log_file_n('Drilling down net change');
5399 end if;
5400 if drop_L_tables=false then
5401 g_status:=false;
5402 return;
5403 end if;
5404 if create_snp_L_tables=false then
5405 g_status:=false;
5406 return ;
5407 end if;
5408 if drill_down_net_change(p_multi_thread)=false then--populate gilog and drop L tables
5409 g_status:=false;
5410 return;
5411 end if;
5412 end if;
5413 if g_level_change then
5414 if recreate_from_stmt=false then
5415 g_status:=false;
5416 return;
5417 end if;
5418 end if;
5419 --at the end of this, we need to truncate the snapshot logs
5420 truncate_ltc_snapshot_logs;
5421 Exception when others then
5422 g_status_message:=sqlerrm;
5423 write_to_log_file_n(g_status_message);
5424 g_status:=false;
5425 End;
5426
5427 Procedure make_temp_insert_sql IS
5428 Begin
5429 if g_debug then
5430 write_to_log_file_n('In make_temp_insert_sql'||get_time);
5431 end if;
5432 --assume that there are proper levels here
5433 g_temp_insert_stmt:='insert into '||g_dim_name_temp_int||' ( ';
5434 g_temp_insert_stmt:=g_temp_insert_stmt||g_dim_pk||','||g_dim_user_pk||', row_id3 ';
5435 if g_number_slow_cols > 0 then
5436 for i in 1..g_number_slow_cols loop
5437 g_temp_insert_stmt:=g_temp_insert_stmt||','||g_slow_cols(i);
5438 end loop;
5439 end if;
5440 if g_level_change then--we dont need reference to g_ilog
5441 g_temp_insert_stmt:=g_temp_insert_stmt||') select '||g_lowest_level_alias||'.'||g_ltc_pk||','
5442 ||g_lowest_level_alias||'.'||g_ltc_user_pk||','||g_lowest_level_alias||'.ROWID ';
5443 if g_number_slow_cols > 0 then
5444 for i in 1..g_number_slow_cols loop
5445 g_temp_insert_stmt:=g_temp_insert_stmt||','||g_slow_level_alias(i)||'.'||g_slow_level_col(i);
5446 end loop;
5447 end if;
5448 if g_number_slow_cols > 0 then
5449 if g_where_stmt is not null then
5450 g_temp_insert_stmt:=g_temp_insert_stmt||g_from_stmt||' '||g_where_stmt;
5451 else
5452 g_temp_insert_stmt:=g_temp_insert_stmt||g_from_stmt;
5453 end if;
5454 else
5455 --make it even faster
5456 g_temp_insert_stmt:=g_temp_insert_stmt||' from '||g_lowest_level||' '||g_lowest_level_alias;
5457 end if;
5458 else
5459 g_temp_insert_stmt:=g_temp_insert_stmt||') select '||g_lowest_level_alias||'.'||g_ltc_pk||','
5460 ||g_lowest_level_alias||'.'||g_ltc_user_pk||','||g_lowest_level_alias||'.ROWID ';
5461 if g_number_slow_cols > 0 then
5462 for i in 1..g_number_slow_cols loop
5463 g_temp_insert_stmt:=g_temp_insert_stmt||','||g_slow_level_alias(i)||'.'||g_slow_level_col(i);
5464 end loop;
5465 end if;
5466 if g_number_slow_cols > 0 then
5467 if g_where_stmt is not null then
5468 g_temp_insert_stmt:=g_temp_insert_stmt||g_from_stmt||','||g_ilog||' '||g_where_stmt||' And ';
5469 else
5470 g_temp_insert_stmt:=g_temp_insert_stmt||g_from_stmt||','||g_ilog||' where ';
5471 end if;
5472 g_temp_insert_stmt:=g_temp_insert_stmt||g_ilog||'.row_id='||
5473 g_lowest_level_alias||'.rowid and '||g_ilog||'.status=1';
5474 else
5475 --make it even faster
5476 g_temp_insert_stmt:=g_temp_insert_stmt||' from '||g_lowest_level||' '||g_lowest_level_alias||','||g_ilog;
5477 g_temp_insert_stmt:=g_temp_insert_stmt||' where '||g_lowest_level_alias||'.rowid='||
5478 g_ilog||'.row_id and '||g_ilog||'.status=1';
5479 end if;
5480 end if;
5481
5482 Exception when others then
5483 g_status:=false;
5484 g_status_message:=sqlerrm;
5485 write_to_log_file_n(g_status_message);
5486 End;--Procedure make_temp_insert_sql
5487
5488 procedure analyze_snplogs is
5489 Begin
5490 for i in 1..g_number_levels loop
5491 if g_consider_snapshot(i) then
5492 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(g_level_snapshot_logs(i),g_table_owner);
5493 end if;
5494 end loop;
5495 Exception when others then
5496 g_status:=false;
5497 g_status_message:=sqlerrm;
5498 write_to_log_file_n(g_status_message);
5499 End;
5500
5501 function get_snapshot_log return boolean is
5502 Begin
5503 if g_debug then
5504 write_to_log_file_n('In get_snapshot_log');
5505 end if;
5506 for i in 1..g_number_levels loop
5507 --g_level_snapshot_logs(i):=EDW_OWB_COLLECTION_UTIL.get_table_snapshot_log(g_levels(i));
5508 g_consider_snapshot(i):=false;
5509 end loop;
5510 return true;
5511 Exception when others then
5512 g_status:=false;
5513 g_status_message:=sqlerrm;
5514 write_to_log_file_n(g_status_message);
5515 return false;
5516 End;
5517
5518 function check_snapshot_logs return boolean is
5519 v_res number:=null;
5520 l_consider boolean; --are all snapshot logs being considered?
5521 begin
5522 if g_debug then
5523 write_to_log_file_n('In check_snapshot_logs'||get_time);
5524 end if;
5525 if EDW_OWB_COLLECTION_UTIL.check_table(g_ilog) then
5526 g_error_rec_flag:=true;
5527 elsif EDW_OWB_COLLECTION_UTIL.check_table(g_ilog||'A')=true then
5528 g_ilog:=g_ilog||'A';
5529 g_error_rec_flag:=true;
5530 end if;
5531 if g_fresh_restart then
5532 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog)=false then
5533 null;
5534 end if;
5535 g_error_rec_flag:=false;
5536 end if;
5537 l_consider:=false;
5538 for i in 1..g_number_levels loop
5539 v_res:=EDW_OWB_COLLECTION_UTIL.does_table_have_data(g_level_snapshot_logs(i));
5540 if v_res=0 then
5541 if g_debug then
5542 write_to_log_file('Snapshot NOT FOUND!');
5543 end if;
5544 g_consider_snapshot(i):=false;
5545 elsif v_res=1 then
5546 if g_debug then
5547 write_to_log_file('Snapshot NOT considered');
5548 end if;
5549 g_consider_snapshot(i):=false;
5550 else
5551 if g_debug then
5552 write_to_log_file('Snapshot considered');
5553 end if;
5554 l_consider:=true;
5555 g_consider_snapshot(i):=true;
5556 end if;
5557 end loop;
5558 if l_consider=false then
5559 --check ilog also
5560 v_res:=EDW_OWB_COLLECTION_UTIL.does_table_have_data(g_ilog);
5561 if v_res=2 then
5562 l_consider:=true;
5563 end if;
5564 end if;
5565 return l_consider;
5566 Exception when others then
5567 g_status_message:=sqlerrm;
5568 write_to_log_file_n(g_status_message);
5569 g_status:=false;
5570 return false;
5571 End;--Procedure check_snapshot_logs is
5572
5573 --insert into the int temp table g_dim_name_temp_int
5574 Procedure execute_temp_insert_sql IS
5575 l_count number;
5576 Begin
5577 if g_debug then
5578 write_to_log_file_n('In execute_temp_insert_sql');
5579 end if;
5580 if g_exec_flag = true then
5581 if g_debug then
5582 write_to_log_file_n('Going to execute g_temp_insert_sql, inserting into table '||g_dim_name_temp_int);
5583 end if;
5584 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
5585 execute immediate g_temp_insert_stmt;
5586 l_count:=sql%rowcount;
5587 commit;
5588 if g_debug then
5589 write_to_log_file_n('Inserted '||l_count||' records into '||g_dim_name_temp_int||get_time);
5590 end if;
5591 commit;
5592 if g_debug then
5593 write_to_log_file_n('commit');
5594 end if;
5595 --analyze the table
5596 if sql%rowcount > 0 then
5597 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_dim_name_temp_int,instr(g_dim_name_temp_int,'.')+1,
5598 length(g_dim_name_temp_int)),substr(g_dim_name_temp_int,1,instr(g_dim_name_temp_int,'.')-1));
5599 end if;
5600 commit;
5601 if g_debug then
5602 write_to_log_file_n('commit');
5603 end if;
5604 else
5605 write_to_log_file_n('In execute_temp_insert_sql exec flag found false');
5606 end if;
5607 Exception when others then
5608 g_status_message:=sqlerrm;
5609 write_to_log_file_n(g_status_message);
5610 write_to_log_file_n('Problem statement '||g_temp_insert_stmt);
5611 g_status:=false;
5612 End;--Procedure execute_temp_insert_sql
5613
5614 PROCEDURE truncate_ltc_snapshot_logs IS
5615 l_owner varchar2(400);
5616 l_stmt varchar2(20000);
5617 Begin
5618 if g_debug then
5619 write_to_log_file_n('In truncate_ltc_snapshot_logs'||get_time);
5620 end if;
5621
5622 for i in 1..g_number_levels loop
5623 if EDW_OWB_COLLECTION_UTIL.truncate_table(g_level_snapshot_logs(i),g_table_owner)=false then
5624 if g_debug then
5625 write_to_log_file_n(g_table_owner||' is not the owner for '||g_level_snapshot_logs(i));
5626 end if;
5627 l_owner:=null;
5628 l_owner:=EDW_OWB_COLLECTION_UTIL.get_table_owner(g_level_snapshot_logs(i));
5629 if g_debug then
5630 write_to_log_file_n('Owner is '||l_owner);
5631 end if;
5632 if l_owner is not null then
5633 if EDW_OWB_COLLECTION_UTIL.truncate_table(g_level_snapshot_logs(i),l_owner)=false then
5634 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
5635 write_to_log_file_n(g_status_message);
5636 g_status:=false;
5637 return;
5638 end if;
5639 else
5640 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
5641 write_to_log_file_n(g_status_message);
5642 g_status:=false;
5643 return;
5644 end if;
5645 end if;
5646 end loop;
5647 Exception when others then
5648 g_status_message:=sqlerrm;
5649 write_to_log_file_n(g_status_message);
5650 g_status:=false;
5651 return;
5652 End;--PROCEDURE truncate_ltc_snapshot_logs IS
5653
5654 procedure clean_up is
5655 Begin
5656 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_temp)=false then
5657 null;
5658 end if;
5659 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_temp_int)=false then
5660 null;
5661 end if;
5662 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog)=false then
5663 null;
5664 end if;
5665 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog_small)=false then
5666 null;
5667 end if;
5668 if g_ilog_prev is not null then
5669 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog_prev)=false then
5670 null;
5671 end if;
5672 end if;
5673 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_hold)=false then
5674 null;
5675 end if;
5676 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_kl_table)=false then
5677 null;
5678 end if;
5679 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_with_slow)=false then
5680 null;
5681 end if;
5682 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_kl_table_temp)=false then
5683 null;
5684 end if;
5685 if drop_ltc_copies=false then
5686 null;
5687 end if;
5688 if drop_I_tables=false then
5689 null;
5690 end if;
5691 for i in 1..g_number_objects_to_drop loop
5692 if EDW_OWB_COLLECTION_UTIL.drop_table(g_objects_to_drop(i))=false then
5693 null;
5694 end if;
5695 end loop;
5696 Exception when others then
5697 g_status_message:=sqlerrm;
5698 g_status:=false;
5699 write_to_log_file_n(g_status_message);
5700 End;
5701
5702 /*
5703 called by the jobs. global tables are not dropped
5704 */
5705 procedure clean_up_job is
5706 Begin
5707 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_temp)=false then
5708 null;
5709 end if;
5710 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_temp_int)=false then
5711 null;
5712 end if;
5713 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog)=false then
5714 null;
5715 end if;
5716 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog_small)=false then
5717 null;
5718 end if;
5719 if g_ilog_prev is not null then
5720 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog_prev)=false then
5721 null;
5722 end if;
5723 end if;
5724 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_name_hold)=false then
5725 null;
5726 end if;
5727 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_kl_table)=false then
5728 null;
5729 end if;
5730 if EDW_OWB_COLLECTION_UTIL.drop_table(g_dim_kl_table_temp)=false then
5731 null;
5732 end if;
5733 if drop_ltc_copies=false then
5734 null;
5735 end if;
5736 for i in 1..g_number_objects_to_drop loop
5737 if EDW_OWB_COLLECTION_UTIL.drop_table(g_objects_to_drop(i))=false then
5738 null;
5739 end if;
5740 end loop;
5741 Exception when others then
5742 g_status_message:=sqlerrm;
5743 g_status:=false;
5744 write_to_log_file_n(g_status_message);
5745 End;
5746
5747 function recover_from_previous_error return boolean is
5748 l_stmt varchar2(4000);
5749 TYPE CurTyp IS REF CURSOR;
5750 cv CurTyp;
5751 l_res number:=null;
5752 Begin
5753 if g_debug then
5754 write_to_log_file_n('In recover_from_previous_error');
5755 end if;
5756 l_stmt:='select nvl(sum(number_processed),0) from edw_coll_progress_log where object_name=:a and object_type=:b '||
5757 ' and status=:c';
5758 open cv for l_stmt using g_dim_name,g_object_type,'PROCESSING';
5759 fetch cv into l_res;
5760 close cv;
5761 if g_debug then
5762 write_to_log_file_n('The number of records collected from last run is '||l_res);
5763 end if;
5764 if l_res is not null then
5765 g_number_rows_processed:=g_number_rows_processed+l_res;
5766 end if;
5767 return true;
5768 Exception when others then
5769 g_status_message:=sqlerrm;
5770 g_status:=false;
5771 write_to_log_file_n(g_status_message);
5772 return false;
5773 End;
5774
5775 procedure init_all(p_job_id number) IS
5776 l_dim_name varchar2(80);
5777 l_dim_name_org varchar2(80);
5778 begin
5779 if p_job_id is null then
5780 l_dim_name:='TAB_'||g_dim_id||'_';
5781 else
5782 l_dim_name:='TAB_'||g_dim_id||'_'||p_job_id||'_';
5783 end if;
5784 l_dim_name_org:='TAB_'||g_dim_id||'_';
5785 g_slow_implemented:=false;--slowly changing dim not implemented by default
5786 g_dim_empty_flag:=false;--assume that the star table is not empty
5787 g_dim_name_temp:=g_bis_owner||'.'||l_dim_name||'TM';
5788 g_dim_name_temp_int:=g_bis_owner||'.'||l_dim_name||'TI';--intermediate temp
5789 g_dim_name_hold :=g_bis_owner||'.'||l_dim_name||'HD';
5790 g_dim_name_rowid_hold:=g_bis_owner||'.'||l_dim_name||'HR';
5791 g_all_level:=substr(g_dim_name,1,instr(g_dim_name,'_M',-1)-1)||'_A_LTC';
5792 g_ilog:=g_bis_owner||'.'||l_dim_name||'IL';
5793 g_ilog_small:=g_ilog||'S';
5794 g_dim_kl_table:=g_bis_owner||'.'||l_dim_name||'KL';
5795 g_dim_kl_table_temp:=g_bis_owner||'.'||l_dim_name||'KT';
5796 g_insert_prot_table:=g_bis_owner||'.'||l_dim_name_org||'IP';--global only with slow change
5797 g_insert_prot_table_active:=g_bis_owner||'.'||l_dim_name_org||'IPA';--used in this session
5798 g_before_update_table_name:=g_bis_owner||'.'||l_dim_name_org||'BU';
5799 g_number_before_update_table:=1;
5800 g_bu_insert_prot_table:=g_bis_owner||'.'||l_dim_name_org||'BP';--global. used for derv fact sync
5801 g_bu_insert_prot_table_active:=g_bis_owner||'.'||l_dim_name_org||'BPA';--global. used for derv fact sync
5802 g_all_level_index:=-1;
5803 g_status_message:=' ';
5804 g_status:=true;
5805 g_slow_is_name:='DIMENSION_HISTORY';
5806 g_dim_name_with_slow:=g_bis_owner||'.'||l_dim_name||'SN';
5807 g_insert_stmt_star:=null;
5808 g_update_stmt_star:=null;
5809 g_number_slow_cols:=0;
5810 g_number_rows_inserted :=0;
5811 g_number_rows_updated :=0;
5812 g_number_rows_processed :=0;
5813 g_level_change:=true;--if ltc copies are created, this is set to true (for inc collection)
5814 g_dim_count:=0;
5815 g_number_dim_derv_map_id:=0;
5816 g_error_rec_flag:=false;
5817 g_before_update_load_pk:=0;
5818 g_type_ilog_generation:='CTAS';
5819 g_skip_ilog_update:=false;
5820 g_number_derv_fact_full_id:=0;
5821 g_ll_snplog_has_pk:=false;
5822 g_called_ltc_ilog_create:=false;
5823 g_derv_snp_change_flag:=false;
5824 if p_job_id is null then
5825 for i in 1..g_number_levels loop
5826 g_use_ltc_ilog(i):=true;
5827 end loop;
5828 end if;
5829 for i in 1..g_number_levels loop
5830 g_level_count(i):=null;
5831 end loop;
5832 g_big_table:=400000;--row count > g_big_table is a big table
5833 g_number_objects_to_drop:=0;
5834 g_dim_direct_load:=false;
5835 End;--procedure init_all
5836
5837 function get_number_rows_inserted return number is
5838 begin
5839 return g_number_rows_inserted;
5840 End;--function get_number_rows_inserted return number is
5841
5842 function get_number_rows_updated return number is
5843 begin
5844 return g_number_rows_updated;
5845 End;--function get_number_rows_updated return number is
5846
5847
5848 function get_time return varchar2 is
5849 begin
5850 return ' '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS');
5851 Exception when others then
5852 write_to_log_file_n('Exception in get_time '||sqlerrm);
5853 return null;
5854 End;
5855
5856 procedure write_to_log_file(p_message varchar2) is
5857 begin
5858 EDW_OWB_COLLECTION_UTIL.write_to_log_file(p_message);
5859 Exception when others then
5860 null;
5861 End;
5862
5863 procedure write_to_log_file_n(p_message varchar2) is
5864 begin
5865 write_to_log_file(' ');
5866 write_to_log_file(p_message);
5867 Exception when others then
5868 null;
5869 End;
5870
5871
5872 function get_number_rows_processed return number is
5873 begin
5874 --g_number_rows_processed:=g_number_rows_inserted;
5875 return g_number_rows_processed;
5876 Exception when others then
5877 write_to_log_file_n('Exception in get_number_rows_processed '||sqlerrm||' '||get_time);
5878 return null;
5879 End;
5880
5881 function reset_profiles return boolean is
5882 Begin
5883 if g_debug then
5884 write_to_log_file_n('In reset_profiles');
5885 end if;
5886 EDW_ALL_COLLECT.reset_profiles;
5887 g_collection_size:=EDW_ALL_COLLECT.g_collection_size;
5888 return true;
5889 Exception when others then
5890 g_status_message:=sqlerrm;
5891 write_to_log_file_n(g_status_message);
5892 g_status:=false;
5893 return false;
5894 End;
5895
5896 procedure insert_into_load_progress(p_load_fk number,p_object_name varchar2,p_load_progress varchar2,
5897 p_start_date date,p_end_date date,p_category varchar2, p_operation varchar2,p_seq_id varchar2,p_flag varchar2) is
5898 Begin
5899 EDW_OWB_COLLECTION_UTIL.insert_into_load_progress(p_load_fk,p_object_name,g_dim_id,p_load_progress,p_start_date,
5900 p_end_date,p_category,p_operation,p_seq_id,p_flag,1000);
5901 commit;
5902 Exception when others then
5903 g_status_message:=sqlerrm;
5904 write_to_log_file_n(g_status_message);
5905 End;
5906
5907 --if g_debug is on...
5908 procedure insert_into_load_progress_d(p_load_fk number,p_object_name varchar2,p_load_progress varchar2,
5909 p_start_date date,p_end_date date,p_category varchar2, p_operation varchar2,p_seq_id varchar2,p_flag varchar2) is
5910 Begin
5911 if g_debug then
5912 EDW_OWB_COLLECTION_UTIL.insert_into_load_progress(p_load_fk,p_object_name,g_dim_id,p_load_progress,p_start_date,
5913 p_end_date,p_category,p_operation,p_seq_id,p_flag,1000);
5914 commit;
5915 end if;
5916 Exception when others then
5917 g_status_message:=sqlerrm;
5918 write_to_log_file_n(g_status_message);
5919 End;
5920
5921 procedure analyze_star_table is
5922 l_date date;
5923 l_analyze boolean:=false;
5924 l_diff number;
5925 Begin
5926 if g_before_update_table_final is not null then
5927 if EDW_OWB_COLLECTION_UTIL.check_table(g_before_update_table_final) then
5928 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_before_update_table_final,
5929 instr(g_before_update_table_final,'.')+1,length(g_before_update_table_final)),
5930 substr(g_before_update_table_final,1,instr(g_before_update_table_final,'.')-1),1);
5931 end if;
5932 end if;
5933 l_date:=EDW_OWB_COLLECTION_UTIL.last_analyzed_date(g_dim_name,g_table_owner);
5934 if g_debug then
5935 write_to_log_file_n('Last analyzed date for '||g_dim_name||' '||
5936 to_char(l_date,'MM-DD-YYYY HH24:MI:SS'));
5937 end if;
5938 if l_date is null or (sysdate-l_date)>=g_analyze_freq then
5939 insert_into_load_progress_d(g_load_pk,g_dim_name,'Analyze Star Table'||g_jobid_stmt,sysdate,null,'DIMENSION',
5940 'ANALYZE','AN2200'||g_job_id,'I');
5941 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(g_dim_name,g_table_owner,1);
5942 if g_debug then
5943 write_to_log_file_n('Table '||g_dim_name||' analyzed');
5944 end if;
5945 commit;
5946 insert_into_load_progress_d(g_load_pk,null,null,null,sysdate,null,null,'AN2200'||g_job_id,'U');
5947 end if;
5948 Exception when others then
5949 g_status_message:=sqlerrm;
5950 write_to_log_file_n(g_status_message);
5951 End;
5952
5953 function get_dim_storage return boolean is
5954 Begin
5955 if EDW_OWB_COLLECTION_UTIL.get_table_next_extent(g_dim_name,g_table_owner,g_dim_next_extent)=false then
5956 return false;
5957 end if;
5958 if g_dim_next_extent is null or g_dim_next_extent=0 then
5959 g_dim_next_extent:=16777216;
5960 end if;
5961 return true;
5962 Exception when others then
5963 write_to_log_file_n('Error in get_dim_storage '||sqlerrm||get_time);
5964 return false;
5965 End;
5966
5967 function is_dim_in_derv_map return boolean is
5968 l_dim_fk EDW_OWB_COLLECTION_UTIL.varcharTableType;
5969 l_number_dim_fk number;
5970 Begin
5971 g_derv_snp_change_flag:=false;
5972 if EDW_OWB_COLLECTION_UTIL.get_mapid_dim_in_derv_map(g_dim_name,g_dim_derv_map_id,
5973 g_derv_fact_id,g_src_fact_id,g_number_dim_derv_map_id,'INC')=false then
5974 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
5975 return false;
5976 end if;
5977 for i in 1..g_number_dim_derv_map_id loop
5978 g_dim_derv_map_refresh(i):=true;--by default assume that all maps need to be refreshed
5979 g_dim_derv_map_full_refresh(i):=true;--by default, full refresh of the derv fact from this src fact
5980 end loop;
5981 if g_debug then
5982 write_to_log_file_n('Derv/Summary map ids where '||g_dim_name||' is a sec source');
5983 for i in 1..g_number_dim_derv_map_id loop
5984 write_to_log_file(g_dim_derv_map_id(i));
5985 end loop;
5986 end if;
5987 if g_number_dim_derv_map_id=0 then
5988 return true;
5989 end if;
5990 g_number_dim_derv_col:=0;
5991 g_number_dim_derv_pk_key:=0;
5992 g_num_dim_derv_col_map_all:=0;
5993 for i in 1..g_number_dim_derv_map_id loop
5994 l_number_dim_fk:=0;
5995 if EDW_OWB_COLLECTION_UTIL.get_dim_fk_summary_fact(g_derv_fact_id(i),g_dim_id,l_dim_fk,l_number_dim_fk)=false then
5996 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
5997 return false;
5998 end if;
5999 for j in 1..l_number_dim_fk loop
6000 if EDW_OWB_COLLECTION_UTIL.value_in_table(g_dim_derv_pk_key,g_number_dim_derv_pk_key,l_dim_fk(j))=false then
6001 g_number_dim_derv_pk_key:=g_number_dim_derv_pk_key+1;
6002 g_dim_derv_pk_key(g_number_dim_derv_pk_key):=l_dim_fk(j);
6003 end if;
6004 end loop;
6005 end loop;
6006 if g_debug then
6007 write_to_log_file_n('The higher level PK_KEY of the dimension involved in derv maps');
6008 for i in 1..g_number_dim_derv_pk_key loop
6009 write_to_log_file(g_dim_derv_pk_key(i));
6010 end loop;
6011 end if;
6012 for i in 1..g_number_dim_derv_map_id loop
6013 if get_derv_fact_map_details(g_dim_derv_map_id(i)) = false then
6014 return false;
6015 end if;
6016 end loop;
6017 if g_debug then
6018 write_to_log_file_n('The columns of the dimension involved in derv maps and ltc tables');
6019 for i in 1..g_number_dim_derv_col loop
6020 write_to_log_file(g_dim_derv_col(i)||' '||g_dim_derv_col_ltc(i));
6021 end loop;
6022 end if;
6023 for i in 1..g_number_dim_derv_col loop
6024 if g_dim_derv_col_ltc(i) is null then
6025 g_derv_snp_change_flag:=true;
6026 exit;
6027 end if;
6028 for j in 1..g_number_levels loop
6029 if g_dim_derv_col_ltc(i)=g_levels(j) then
6030 if g_consider_snapshot(j) then
6031 g_derv_snp_change_flag:=true;
6032 exit;
6033 end if;
6034 end if;
6035 end loop;
6036 if g_derv_snp_change_flag then
6037 exit;
6038 end if;
6039 end loop;
6040 if g_debug then
6041 if g_derv_snp_change_flag then
6042 write_to_log_file_n('There is snapshot change to consider for derived fact');
6043 else
6044 write_to_log_file_n('There is NO snapshot change to consider for derived fact');
6045 end if;
6046 end if;
6047 if g_derv_snp_change_flag then
6048 for i in 1..g_number_dim_derv_map_id loop
6049 if EDW_OWB_COLLECTION_UTIL.value_in_table(g_dim_derv_col_map_all,g_num_dim_derv_col_map_all,
6050 g_dim_derv_map_id(i))=false then
6051 g_dim_derv_map_refresh(i):=false;
6052 end if;
6053 end loop;
6054 end if;
6055 --for each of the maps, check the src fact fk density
6056 for i in 1..g_number_dim_derv_map_id loop
6057 if g_dim_derv_map_refresh(i) then
6058 if get_max_fk_density(g_dim_id,g_src_fact_id(i),g_dim_derv_map_id(i))<=g_max_fk_density then
6059 g_dim_derv_map_full_refresh(i):=false;
6060 end if;
6061 end if;
6062 end loop;
6063 write_to_log_file_n('The Derv/Summary maps that need to be refreshed');
6064 if g_debug then
6065 for i in 1..g_number_dim_derv_map_id loop
6066 if g_dim_derv_map_refresh(i) then
6067 if g_dim_derv_map_full_refresh(i) then
6068 write_to_log_file(g_dim_derv_map_id(i)||'(Full Refresh with the src fact)');
6069 else
6070 write_to_log_file(g_dim_derv_map_id(i)||'(INC Refresh with the src fact)');
6071 end if;
6072 else
6073 write_to_log_file(g_dim_derv_map_id(i)||' NO Refresh Needed');
6074 end if;
6075 end loop;
6076 end if;
6077 return true;
6078 Exception when others then
6079 g_status_message:=sqlerrm;
6080 write_to_log_file_n(g_status_message);
6081 g_status:=false;
6082 return false;
6083 End;
6084
6085 function get_derv_fact_map_details(p_mapping_id number) return boolean is
6086 l_hold_func EDW_OWB_COLLECTION_UTIL.varcharTableType;
6087 l_hold_func_category EDW_OWB_COLLECTION_UTIL.varcharTableType;
6088 l_hold_item EDW_OWB_COLLECTION_UTIL.varcharTableType;
6089 l_hold_item_id EDW_OWB_COLLECTION_UTIL.numberTableType;
6090 l_hold_item_usage EDW_OWB_COLLECTION_UTIL.numberTableType;
6091 l_hold_aggregatefunction EDW_OWB_COLLECTION_UTIL.varcharTableType;
6092 l_hold_is_distinct EDW_OWB_COLLECTION_UTIL.numberTableType;
6093 l_hold_relation EDW_OWB_COLLECTION_UTIL.numberTableType;
6094 l_hold_relation_name EDW_OWB_COLLECTION_UTIL.varcharTableType;
6095 l_hold_relation_usage EDW_OWB_COLLECTION_UTIL.numberTableType;
6096 l_hold_relation_type EDW_OWB_COLLECTION_UTIL.varcharTableType;
6097 l_hold_func_usage EDW_OWB_COLLECTION_UTIL.numberTableType;
6098 l_hold_func_position EDW_OWB_COLLECTION_UTIL.numberTableType;
6099 l_hold_func_dvalue EDW_OWB_COLLECTION_UTIL.varcharTableType;
6100 l_hold_number number;
6101 l_stmt varchar2(2000);
6102 l_filter_stmt varchar2(20000);
6103 l_sec_source EDW_OWB_COLLECTION_UTIL.varcharTableType;
6104 l_sec_source_id EDW_OWB_COLLECTION_UTIL.numberTableType;
6105 l_sec_source_child EDW_OWB_COLLECTION_UTIL.varcharTableType;
6106 l_sec_source_child_id EDW_OWB_COLLECTION_UTIL.numberTableType;
6107 l_pk EDW_OWB_COLLECTION_UTIL.varcharTableType;
6108 l_fk EDW_OWB_COLLECTION_UTIL.varcharTableType;
6109 l_sec_source_usage EDW_OWB_COLLECTION_UTIL.numberTableType;
6110 l_sec_source_usage_name EDW_OWB_COLLECTION_UTIL.varcharTableType;
6111 l_sec_source_child_usage EDW_OWB_COLLECTION_UTIL.numberTableType;
6112 l_sec_source_number number;
6113 l_sec_sources_child_alias EDW_OWB_COLLECTION_UTIL.varcharTableType;
6114 l_sec_source_name_index EDW_OWB_COLLECTION_UTIL.varcharTableType;
6115 l_sec_source_index EDW_OWB_COLLECTION_UTIL.numberTableType;
6116 l_sec_source_index_number number;
6117 l_start number;
6118 l_end number;
6119 l_len number;
6120 l_col varchar2(400);
6121 TYPE CurTyp IS REF CURSOR;
6122 cv CurTyp;
6123 l_metadata_version varchar2(80);
6124 Begin
6125 l_metadata_version:=EDW_OWB_COLLECTION_UTIL.get_metadata_version;
6126 if EDW_OWB_COLLECTION_UTIL.get_mapping_details(
6127 p_mapping_id
6128 ,l_hold_func
6129 ,l_hold_func_category
6130 ,l_hold_item
6131 ,l_hold_item_id
6132 ,l_hold_item_usage
6133 ,l_hold_aggregatefunction
6134 ,l_hold_is_distinct
6135 ,l_hold_relation
6136 ,l_hold_relation_name
6137 ,l_hold_relation_usage
6138 ,l_hold_relation_type
6139 ,l_hold_func_usage
6140 ,l_hold_func_position
6141 ,l_hold_func_dvalue
6142 ,l_hold_number
6143 ,l_metadata_version)=false then
6144 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
6145 return false;
6146 end if;
6147 for i in 1..l_hold_number loop
6148 if l_hold_relation_name(i)=g_dim_name then
6149 g_num_dim_derv_col_map_all:=g_num_dim_derv_col_map_all+1;
6150 g_dim_derv_col_map_all(g_num_dim_derv_col_map_all):=p_mapping_id;
6151 if EDW_OWB_COLLECTION_UTIL.value_in_table(g_dim_derv_col,g_number_dim_derv_col,l_hold_item(i))=false then
6152 g_number_dim_derv_col:=g_number_dim_derv_col+1;
6153 g_dim_derv_col(g_number_dim_derv_col):=l_hold_item(i);
6154 g_dim_derv_col_map(g_number_dim_derv_col):=p_mapping_id;
6155 end if;
6156 end if;
6157 end loop;
6158 if EDW_OWB_COLLECTION_UTIL.get_sec_source_info(
6159 p_mapping_id,
6160 l_sec_source,
6161 l_sec_source_id ,
6162 l_sec_source_child ,
6163 l_sec_source_child_id,
6164 l_pk,
6165 l_fk,
6166 l_sec_source_usage,
6167 l_sec_source_usage_name,
6168 l_sec_source_child_usage,
6169 l_sec_source_number) = false then
6170 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
6171 return false;
6172 end if;
6173 --also look at the filter clause
6174 --not checked
6175 l_stmt:='select text from edw_pvt_map_properties_md_v where mapping_id=:a and text_type=''Filter''';
6176 if g_debug then
6177 write_to_log_file_n('Going to execute '||l_stmt||' using '||p_mapping_id);
6178 end if;
6179 open cv for l_stmt using p_mapping_id;
6180 fetch cv into l_filter_stmt;
6181 close cv;
6182 if g_debug then
6183 write_to_log_file_n('l_filter_stmt='||l_filter_stmt);
6184 end if;
6185 if l_filter_stmt is not null then
6186 l_len:=length(l_filter_stmt);
6187 for i in 1..l_sec_source_number loop
6188 if l_sec_source(i)=g_dim_name then
6189 l_start:=1;
6190 l_end:=1;
6191 loop
6192 l_end:=instr(l_filter_stmt,l_sec_source_usage_name(i)||'.',l_start);
6193 if l_end=0 then
6194 exit;
6195 end if;
6196 l_start:=l_end+length(l_sec_source_usage_name(i)||'.');
6197 l_end:=instr(l_filter_stmt,' ',l_start);
6198 if l_end=0 then
6199 exit;
6200 end if;
6201 l_col:=substr(l_filter_stmt,l_start,(l_end-l_start));
6202 if g_debug then
6203 write_to_log_file_n('Coulmn from filter for '||l_sec_source_usage_name(i)||' '||l_col);
6204 end if;
6205 g_num_dim_derv_col_map_all:=g_num_dim_derv_col_map_all+1;
6206 g_dim_derv_col_map_all(g_num_dim_derv_col_map_all):=p_mapping_id;
6207 if EDW_OWB_COLLECTION_UTIL.value_in_table(g_dim_derv_col,g_number_dim_derv_col,l_col)=false then
6208 g_number_dim_derv_col:=g_number_dim_derv_col+1;
6209 g_dim_derv_col(g_number_dim_derv_col):=l_col;
6210 g_dim_derv_col_map(g_number_dim_derv_col):=p_mapping_id;
6211 end if;
6212 l_start:=l_end;
6213 end loop;
6214 end if;
6215 end loop;
6216 end if;
6217
6218 --get the level also with the columns and see if any snapshot log has changed
6219 for i in 1..g_number_dim_derv_col loop
6220 g_dim_derv_col_ltc(i):=get_ltc_for_dim_col(g_dim_derv_col(i));
6221 end loop;
6222 return true;
6223 Exception when others then
6224 g_status_message:=sqlerrm;
6225 write_to_log_file_n(g_status_message);
6226 g_status:=false;
6227 return false;
6228 End;
6229
6230 function get_before_update_table_name return boolean is
6231 Begin
6232 g_number_before_update_table:=1;
6233 loop
6234 g_before_update_table(g_number_before_update_table):=g_before_update_table_name||g_number_before_update_table;
6235 if EDW_OWB_COLLECTION_UTIL.check_table(g_before_update_table(g_number_before_update_table))=false then
6236 g_before_update_table_final:=g_before_update_table(g_number_before_update_table);
6237 exit;
6238 else
6239 g_number_before_update_table:=g_number_before_update_table+1;
6240 end if;
6241 end loop;
6242 return true;
6243 Exception when others then
6244 g_status_message:=sqlerrm;
6245 write_to_log_file_n('Error in get_before_update_table_name '||g_status_message);
6246 g_status:=false;
6247 return false;
6248 End;
6249
6250 /*
6251 log_before_update_data is called in each loop. we will analyze the table in the very end
6252 */
6253 function log_before_update_data return boolean is
6254 l_stmt varchar2(32000);
6255 --l_pk_table varchar2(200);
6256 --l_rowid_table varchar2(200);
6257 --l_count number;
6258 TYPE CurTyp IS REF CURSOR;
6259 cv CurTyp;
6260 Begin
6261 if g_debug then
6262 write_to_log_file_n('In log_before_update_data'||get_time);
6263 end if;
6264 /*
6265 for every run of the load, the update data goes into a new table
6266 */
6267 if EDW_OWB_COLLECTION_UTIL.check_table(g_before_update_table_final)=false then
6268 if create_before_update_table=false then
6269 return false;
6270 end if;
6271 end if;
6272 l_stmt:='insert into '||g_before_update_table_final||'('||g_dim_pk||','||g_dim_user_pk;
6273 for i in 1..g_number_dim_derv_col loop
6274 l_stmt:=l_stmt||','||g_dim_derv_col(i);
6275 end loop;
6276 for i in 1..g_number_dim_derv_pk_key loop
6277 if EDW_OWB_COLLECTION_UTIL.value_in_table(g_dim_derv_col,g_number_dim_derv_col,g_dim_derv_pk_key(i))=false then
6278 l_stmt:=l_stmt||','||g_dim_derv_pk_key(i);
6279 end if;
6280 end loop;
6281 l_stmt:=l_stmt||',LAST_UPDATE_DATE) select /*+ORDERED USE_NL('||g_dim_name||')*/ '; --use nl?
6282 if g_parallel is not null then
6283 l_stmt:=l_stmt||'/*+PARALLEL('||g_dim_name||','||g_parallel||')*/ ';
6284 end if;
6285 l_stmt:=l_stmt||g_dim_name||'.'||g_dim_pk||','||g_dim_name||'.'||g_dim_user_pk;
6286 for i in 1..g_number_dim_derv_col loop
6287 l_stmt:=l_stmt||','||g_dim_name||'.'||g_dim_derv_col(i);
6288 end loop;
6289 for i in 1..g_number_dim_derv_pk_key loop
6290 if EDW_OWB_COLLECTION_UTIL.value_in_table(g_dim_derv_col,g_number_dim_derv_col,g_dim_derv_pk_key(i))=false then
6291 l_stmt:=l_stmt||','||g_dim_name||'.'||g_dim_derv_pk_key(i);
6292 end if;
6293 end loop;
6294 l_stmt:=l_stmt||',SYSDATE from '||g_dim_name_hold||','||g_dim_name||
6295 ' where '||g_dim_name_hold||'.row_id='||g_dim_name||'.rowid'||
6296 ' and '||g_dim_name_hold||'.'||g_dim_pk||' not in (select '||g_dim_pk||' from '||g_bu_insert_prot_table_active||')';
6297 if g_debug then
6298 write_to_log_file_n('Going to execute '||l_stmt||get_time);
6299 end if;
6300 execute immediate l_stmt;
6301 if g_debug then
6302 write_to_log_file_n('Inserted '||sql%rowcount||' rows into '||
6303 g_before_update_table_final||get_time);
6304 end if;
6305 if log_pk_into_bu_insert_prot=false then
6306 return false;
6307 end if;
6308 return true;
6309 Exception when others then
6310 g_status_message:=sqlerrm;
6311 write_to_log_file_n(g_status_message);
6312 g_status:=false;
6313 return false;
6314 End;
6315
6316 function create_before_update_table return boolean is
6317 l_stmt varchar2(10000);
6318 l_next_extent number;
6319 Begin
6320 l_next_extent:=g_dim_next_extent/2;
6321 if l_next_extent>16777216 then --16M
6322 l_next_extent:=16777216;
6323 end if;
6324 if l_next_extent is null or l_next_extent=0 then
6325 l_next_extent:=8388608;
6326 end if;
6327 l_stmt:='create table '||g_before_update_table_final||' tablespace '||g_op_table_space||
6328 ' storage (initial '||l_next_extent||' next '||l_next_extent||' pctincrease 0 MAXEXTENTS 2147483645) ';
6329 if g_parallel is not null then
6330 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
6331 end if;
6332 l_stmt:=l_stmt||' as select '||g_dim_pk||','||g_dim_user_pk;
6333 for i in 1..g_number_dim_derv_col loop
6334 l_stmt:=l_stmt||','||g_dim_derv_col(i);
6335 end loop;
6336 for i in 1..g_number_dim_derv_pk_key loop
6337 if EDW_OWB_COLLECTION_UTIL.value_in_table(g_dim_derv_col,g_number_dim_derv_col,g_dim_derv_pk_key(i))=false then
6338 l_stmt:=l_stmt||','||g_dim_derv_pk_key(i);
6339 end if;
6340 end loop;
6341 l_stmt:=l_stmt||',LAST_UPDATE_DATE from '||g_dim_name||' where 1=2';
6342 if g_debug then
6343 write_to_log_file_n('Going to execute '||l_stmt);
6344 end if;
6345 begin
6346 execute immediate l_stmt;
6347 exception when others then
6348 if sqlcode=-00955 then
6349 --only here in case of multi threading
6350 if g_debug then
6351 write_to_log_file_n('Error creating '||g_before_update_table_final||' '||sqlerrm||get_time);
6352 write_to_log_file('This table '||g_before_update_table_final||' already exists! '||
6353 'Some other thread created it!');
6354 end if;
6355 else
6356 g_status_message:=sqlerrm;
6357 write_to_log_file_n(g_status_message);
6358 g_status:=false;
6359 return false;
6360 end if;
6361 end;
6362 l_stmt:='create unique index '||g_before_update_table_final||'u on '||
6363 g_before_update_table_final||'('||g_dim_pk||') tablespace '||g_op_table_space;
6364 --||' storage (initial '||l_next_extent/2||' next '||l_next_extent/2||' pctincrease 0 MAXEXTENTS 2147483645)';
6365 if g_parallel is not null then
6366 l_stmt:=l_stmt||' parallel '||g_parallel;
6367 end if;
6368 if g_debug then
6369 write_to_log_file_n('Going to execute '||l_stmt);
6370 end if;
6371 execute immediate l_stmt;
6372 return true;
6373 Exception when others then
6374 g_status_message:=sqlerrm;
6375 write_to_log_file_n(g_status_message);
6376 g_status:=false;
6377 return false;
6378 End;
6379
6380 function get_ltc_for_dim_col(p_col varchar2) return varchar2 is
6381 l_stmt varchar2(1000);
6382 TYPE CurTyp IS REF CURSOR;
6383 cv CurTyp;
6384 l_prefix varchar2(200);
6385 l_ltc varchar2(400);
6386 Begin
6387 l_prefix:=substr(p_col,1,instr(p_col,'_')-1);
6388 l_stmt:='select level_name||''_LTC'' from edw_levels_md_v where level_prefix=:a and dim_id=:b';
6389 open cv for l_stmt using l_prefix,g_dim_id;
6390 fetch cv into l_ltc;
6391 close cv;
6392 return l_ltc;
6393 Exception when others then
6394 g_status_message:=sqlerrm;
6395 write_to_log_file_n(g_status_message);
6396 g_status:=false;
6397 return null;
6398 End;
6399
6400 function get_max_fk_density(p_dim_id number,p_src_fact_id number,p_dim_derv_map_id number) return number is
6401 l_fk EDW_OWB_COLLECTION_UTIL.varcharTableType;
6402 l_pk EDW_OWB_COLLECTION_UTIL.varcharTableType;
6403 l_number_fk number;
6404 l_distcnt number;
6405 l_density number;
6406 l_nullcnt number;
6407 l_srec DBMS_STATS.StatRec;
6408 l_avgclen number;
6409 l_tot_density number;
6410 l_fact_name varchar2(400);
6411 l_owner varchar2(400);
6412 Begin
6413 if EDW_OWB_COLLECTION_UTIL.get_fk_pk(p_src_fact_id,p_dim_id,p_dim_derv_map_id,l_fk,l_pk,l_number_fk)=false then
6414 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
6415 g_status:=false;
6416 return null;
6417 end if;
6418 if g_debug then
6419 write_to_log_file_n('The fk and pk found for src fact '||p_src_fact_id||' with dim '||p_dim_id);
6420 for i in 1..l_number_fk loop
6421 write_to_log_file(l_fk(i)||'('||l_pk(i)||')');
6422 end loop;
6423 end if;
6424 --get the stats
6425 l_tot_density:=0;
6426 if g_debug then
6427 write_to_log_file_n('The fk and density');
6428 end if;
6429 for i in 1..l_number_fk loop
6430 l_fact_name:=EDW_OWB_COLLECTION_UTIL.get_object_name(p_src_fact_id);
6431 l_owner:=EDW_OWB_COLLECTION_UTIL.get_table_owner(l_fact_name);
6432 if EDW_OWB_COLLECTION_UTIL.get_column_stats(
6433 l_owner,
6434 l_fact_name,
6435 l_fk(i),
6436 l_distcnt,
6437 l_density,
6438 l_nullcnt,
6439 l_srec,
6440 l_avgclen)=false then
6441 null;
6442 end if;
6443 if g_debug then
6444 write_to_log_file(l_fk(i)||'('||l_density*100||')');
6445 end if;
6446 if l_tot_density<l_density then
6447 l_tot_density:=l_density;
6448 end if;
6449 end loop;
6450 if g_debug then
6451 write_to_log_file_n('Max density='||l_tot_density*100);
6452 end if;
6453 return l_tot_density*100;
6454 Exception when others then
6455 g_status_message:=sqlerrm;
6456 write_to_log_file_n(g_status_message);
6457 g_status:=false;
6458 return null;
6459 End;
6460
6461 function create_prot_table(p_table varchar2,p_table_active varchar2) return boolean is
6462 Begin
6463 if g_debug then
6464 write_to_log_file_n('In create_prot_table '||get_time);
6465 end if;
6466 if EDW_OWB_COLLECTION_UTIL.check_table(p_table)=false then
6467 g_stmt:='create table '||p_table||' tablespace '||g_op_table_space;
6468 if g_parallel is not null then
6469 g_stmt:=g_stmt||' parallel (degree '||g_parallel||') ';
6470 end if;
6471 g_stmt:=g_stmt||' as select '||g_dim_pk||' from '||g_dim_name||' where 1=2';
6472 if g_debug then
6473 write_to_log_file_n('Going to execute '||g_stmt);
6474 end if;
6475 execute immediate g_stmt;
6476 end if;
6477 g_stmt:='create table '||p_table_active||' tablespace '||g_op_table_space;
6478 if g_parallel is not null then
6479 g_stmt:=g_stmt||' parallel (degree '||g_parallel||') ';
6480 end if;
6481 g_stmt:=g_stmt||' as select * from '||p_table;
6482 if EDW_OWB_COLLECTION_UTIL.drop_table(p_table_active)=false then
6483 null;
6484 end if;
6485 if g_debug then
6486 write_to_log_file_n('Going to execute '||g_stmt);
6487 end if;
6488 execute immediate g_stmt;
6489 return true;
6490 Exception when others then
6491 g_status_message:=sqlerrm;
6492 write_to_log_file_n(g_status_message);
6493 g_status:=false;
6494 return false;
6495 End;
6496
6497 function drop_prot_table(p_table varchar2,p_table_active varchar2) return boolean is
6498 l_stmt varchar2(1000);
6499 Begin
6500 if g_debug then
6501 write_to_log_file_n('In drop_prot_table ');
6502 end if;
6503 if EDW_OWB_COLLECTION_UTIL.drop_table(p_table)=false then
6504 null;
6505 end if;
6506 if EDW_OWB_COLLECTION_UTIL.drop_table(p_table_active)=false then
6507 null;
6508 end if;
6509 return true;
6510 Exception when others then
6511 g_status_message:=sqlerrm;
6512 write_to_log_file_n(g_status_message);
6513 g_status:=false;
6514 return false;
6515 End;
6516
6517 function drop_restart_tables return boolean is
6518 l_count number:=1;
6519 Begin
6520 if g_debug then
6521 write_to_log_file_n('In drop_restart_tables');
6522 end if;
6523 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog)=false then
6524 null;
6525 end if;
6526 if EDW_OWB_COLLECTION_UTIL.drop_ilog_tables(g_ilog,'IL',g_bis_owner)=false then
6527 null;
6528 end if;
6529 loop
6530 if EDW_OWB_COLLECTION_UTIL.check_table(g_before_update_table_name||l_count) then
6531 if EDW_OWB_COLLECTION_UTIL.drop_table(g_before_update_table_name||l_count)=false then
6532 null;
6533 end if;
6534 l_count:=l_count+1;
6535 else
6536 exit;
6537 end if;
6538 end loop;
6539 if drop_prot_table(g_insert_prot_table,g_insert_prot_table_active)=false then
6540 null;
6541 end if;
6542 if drop_prot_table(g_bu_insert_prot_table,g_bu_insert_prot_table_active)=false then
6543 null;
6544 end if;
6545 return true;
6546 Exception when others then
6547 g_status_message:=sqlerrm;
6548 write_to_log_file_n(g_status_message);
6549 g_status:=false;
6550 return false;
6551 End;
6552
6553 function create_gilog_small return boolean is
6554 l_stmt varchar2(4000);
6555 Begin
6556 l_stmt:='create table '||g_ilog_small||' tablespace '||g_op_table_space;
6557 if g_parallel is not null then
6558 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
6559 end if;
6560 l_stmt:=l_stmt||' as select row_id from '||g_ilog||' where status=1';
6561 if g_debug then
6562 write_to_log_file_n('Going to execute '||l_stmt||get_time);
6563 end if;
6564 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog_small)=false then
6565 null;
6566 end if;
6567 execute immediate l_stmt;
6568 if g_debug then
6569 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
6570 end if;
6571 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_ilog_small,instr(g_ilog_small,'.')+1,
6572 length(g_ilog_small)),substr(g_ilog_small,1,instr(g_ilog_small,'.')-1));
6573 return true;
6574 Exception when others then
6575 g_status_message:=sqlerrm;
6576 write_to_log_file_n(g_status_message);
6577 g_status:=false;
6578 return false;
6579 End;
6580
6581 function create_dummy_ilog return boolean is
6582 l_stmt varchar2(5000);
6583 Begin
6584 if EDW_OWB_COLLECTION_UTIL.drop_table(g_ilog)=false then
6585 null;
6586 end if;
6587 l_stmt:='create table '||g_ilog||' tablespace '||g_op_table_space||
6588 ' as select rowid row_id, 1 status from dual ';
6589 if g_debug then
6590 write_to_log_file_n('Going to execute '||l_stmt||get_time);
6591 end if;
6592 execute immediate l_stmt;
6593 g_skip_ilog_update:=true;
6594 g_type_ilog_generation:='UPDATE';
6595 return true;
6596 Exception when others then
6597 g_status_message:=sqlerrm;
6598 write_to_log_file_n(g_status_message);
6599 return false;
6600 End;
6601
6602 function check_ll_snplog_col return number is
6603 Begin
6604 if g_debug then
6605 write_to_log_file_n('In check_ll_snplog_col');
6606 end if;
6607 for i in 1..g_number_levels loop
6608 if g_levels(i)=g_lowest_level_global then
6609 if EDW_OWB_COLLECTION_UTIL.is_column_in_table(g_level_snapshot_logs(i),g_ltc_pk,g_table_owner) then
6610 g_ll_snplog_has_pk:=true;
6611 if g_debug then
6612 write_to_log_file_n('g_ll_snplog_has_pk set to TRUE');
6613 end if;
6614 return 1;
6615 end if;
6616 end if;
6617 end loop;
6618 if g_debug then
6619 write_to_log_file_n('g_ll_snplog_has_pk set to FALSE');
6620 end if;
6621 return 0;
6622 Exception when others then
6623 g_status_message:=sqlerrm;
6624 write_to_log_file_n(g_status_message);
6625 return -1;
6626 End;
6627
6628 function set_level_I_flag return boolean is
6629 l_count number;
6630 l_flag boolean;
6631 l_avg_row_len number;
6632 l_number_fk number;
6633 l_byte_size number;
6634 l_size number;
6635 Begin
6636 if g_debug then
6637 write_to_log_file_n('In set_level_I_flag');
6638 end if;
6639 l_byte_size:=8;
6640 for i in 1..g_number_levels loop
6641 if EDW_OWB_COLLECTION_UTIL.get_table_avg_row_len(g_levels(i),g_table_owner,l_avg_row_len) then
6642 if g_debug then
6643 write_to_log_file_n('Level '||g_levels(i)||' avg_row_len='||l_avg_row_len);
6644 end if;
6645 if l_avg_row_len is not null and l_avg_row_len>0 then
6646 l_number_fk:=0;
6647 for j in 1..g_fk_pk_number loop
6648 if g_fk_pk_child_level(j)=g_levels(i) then
6649 l_number_fk:=l_number_fk+1;
6650 end if;
6651 end loop;
6652 l_size:=l_byte_size*(l_number_fk+2);
6653 l_flag:=EDW_OWB_COLLECTION_UTIL.get_join_nl(l_size,l_avg_row_len,g_ok_switch_update);
6654 if l_flag then
6655 g_use_ltc_ilog(i):=true;
6656 else
6657 g_use_ltc_ilog(i):=false;
6658 end if;
6659 else
6660 g_use_ltc_ilog(i):=false;
6661 end if;
6662 else
6663 g_use_ltc_ilog(i):=false;
6664 end if;
6665 end loop;
6666 return true;
6667 Exception when others then
6668 g_status_message:=sqlerrm;
6669 write_to_log_file_n(g_status_message);
6670 return false;
6671 End;
6672
6673 function create_ltc_copy_low_hd_ins(p_mode varchar2) return boolean is
6674 l_stmt varchar2(5000);
6675 l_mode number;
6676 Begin
6677 if g_debug then
6678 write_to_log_file_n('In create_ltc_copy_low_hd_ins mode '||p_mode);
6679 end if;
6680 if p_mode='INSERT' then
6681 l_mode:=0;
6682 elsif p_mode='UPDATE' then
6683 l_mode:=1;
6684 else
6685 l_mode:=2;
6686 end if;
6687 l_stmt:='create table '||g_levels_copy_low_hd_ins||' tablespace '||g_op_table_space;
6688 if g_parallel is not null then
6689 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
6690 end if;
6691 l_stmt:=l_stmt||' as select A.*,B.'||g_dim_pk||',B.'||g_dim_user_pk||',B.ROW_ID1 row_id1 from '||
6692 g_lowest_level||' A,'||g_dim_name_temp||' B where A.rowid=B.row_id3 and B.operation_code1='||l_mode;
6693 if g_debug then
6694 write_to_log_file_n('Going to execute '||l_stmt||get_time);
6695 end if;
6696 if EDW_OWB_COLLECTION_UTIL.drop_table(g_levels_copy_low_hd_ins)=false then
6697 null;
6698 end if;
6699 execute immediate l_stmt;
6700 if g_debug then
6701 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
6702 end if;
6703 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(g_levels_copy_low_hd_ins,instr(g_levels_copy_low_hd_ins,'.')+1,
6704 length(g_levels_copy_low_hd_ins)),substr(g_levels_copy_low_hd_ins,1,instr(g_levels_copy_low_hd_ins,'.')-1));
6705 return true;
6706 Exception when others then
6707 g_status_message:=sqlerrm;
6708 g_status:=false;
6709 write_to_log_file_n(g_status_message);
6710 return false;
6711 End;
6712
6713 function create_hold_table return boolean is
6714 Begin
6715 if g_debug then
6716 write_to_log_file_n('In create_hold_table');
6717 end if;
6718 if g_debug then
6719 write_to_log_file_n('Goin to execute '||g_hold_insert_stmt||' and 1=2');
6720 end if;
6721 execute immediate g_hold_insert_stmt||' and 1=2';
6722 return true;
6723 Exception when others then
6724 g_status_message:=sqlerrm;
6725 g_status:=false;
6726 write_to_log_file_n(g_status_message);
6727 return false;
6728 End;
6729
6730 --if insert into dim tables fails due to unique cons violation, we try and reset the op codes of the temp table
6731 --g_dim_name_temp.
6732 function reset_temp_opcode return boolean is
6733 l_stmt varchar2(20000);
6734 l_table1 varchar2(200);
6735 l_table2 varchar2(200);
6736 Begin
6737 if g_debug then
6738 write_to_log_file_n('In reset_temp_opcode');
6739 end if;
6740 l_table1:=g_dim_name_temp||'1';
6741 l_table2:=g_dim_name_temp||'2';
6742 l_stmt:='create table '||l_table1||' tablespace '||g_op_table_space;
6743 if g_parallel is not null then
6744 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
6745 end if;
6746 l_stmt:=l_stmt||' as select '||g_dim_pk||' from '||g_dim_name_temp||
6747 ' where operation_code1=0';
6748 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table1)=false then
6749 null;
6750 end if;
6751 if g_debug then
6752 write_to_log_file_n(l_stmt||get_time);
6753 end if;
6754 execute immediate l_stmt;
6755 if g_debug then
6756 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
6757 end if;
6758 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(l_table1,instr(l_table1,'.')+1,
6759 length(l_table1)),substr(l_table1,1,instr(l_table1,'.')-1));
6760 --4161164 : remove IOT , replace with ordinary table and index
6761 --l_stmt:='create table '||l_table2||'('||g_dim_pk||' primary key,row_id) organization index '||
6762 l_stmt:='create table '||l_table2||
6763 ' tablespace '||g_op_table_space;
6764 if g_parallel is not null then
6765 l_stmt:=l_stmt||' parallel (degree '||g_parallel||') ';
6766 end if;
6767 l_stmt:=l_stmt||' as select ';
6768 if g_parallel is not null then
6769 l_stmt:=l_stmt||' /*+parallel(B,'||g_parallel||')*/ ';
6770 end if;
6771 l_stmt:=l_stmt||'A.'||g_dim_pk||',B.rowid row_id from '||l_table1||' A,'||
6772 g_dim_name||' B where A.'||g_dim_pk||'=B.'||g_dim_pk;
6773 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table2)=false then
6774 null;
6775 end if;
6776 if g_debug then
6777 write_to_log_file_n(l_stmt||get_time);
6778 end if;
6779 execute immediate l_stmt;
6780 if g_debug then
6781 write_to_log_file_n('Created with '||sql%rowcount||' rows '||get_time);
6782 --4161164 : remove IOT , replace with ordinary table and index
6783 EDW_OWB_COLLECTION_UTIL.create_iot_index(l_table2,g_dim_pk,g_op_table_space,g_parallel); end if;
6784 EDW_OWB_COLLECTION_UTIL.analyze_table_stats(substr(l_table2,instr(l_table2,'.')+1,
6785 length(l_table2)),substr(l_table2,1,instr(l_table2,'.')-1));
6786 l_stmt:='update /*+ordered use_nl(AA)*/ '||g_dim_name_temp||' AA set(row_id1,operation_code1)=(select row_id,'||
6787 '1 from '||l_table2||' where '||l_table2||'.'||g_dim_pk||'=AA.'||g_dim_pk||') where AA.'||g_dim_pk||
6788 ' in (select '||g_dim_pk||' from '||l_table2||') ';
6789 if g_debug then
6790 write_to_log_file_n(l_stmt||get_time);
6791 end if;
6792 EDW_OWB_COLLECTION_UTIL.set_rollback(g_rollback);
6793 execute immediate l_stmt;
6794 if g_debug then
6795 write_to_log_file_n('Updated '||sql%rowcount||' rows '||get_time);
6796 end if;
6797 commit;
6798 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table1)=false then
6799 null;
6800 end if;
6801 if EDW_OWB_COLLECTION_UTIL.drop_table(l_table2)=false then
6802 null;
6803 end if;
6804 return true;
6805 Exception when others then
6806 g_status_message:=sqlerrm;
6807 g_status:=false;
6808 write_to_log_file_n('error in reset_temp_opcode '||g_status_message);
6809 return false;
6810 End;
6811
6812 function find_all_affected_levels(
6813 p_job_id number,
6814 p_affected_levels out NOCOPY EDW_OWB_COLLECTION_UTIL.varcharTableType,
6815 p_number_affected_levels out NOCOPY number) return boolean is
6816 l_hier EDW_OWB_COLLECTION_UTIL.varcharTableType;
6817 l_parent_ltc EDW_OWB_COLLECTION_UTIL.varcharTableType;
6818 l_parent_ltc_id EDW_OWB_COLLECTION_UTIL.numberTableType;
6819 l_child_ltc EDW_OWB_COLLECTION_UTIL.varcharTableType;
6820 l_child_ltc_id EDW_OWB_COLLECTION_UTIL.numberTableType;
6821 l_number_hier number;
6822 l_parent_flat EDW_OWB_COLLECTION_UTIL.varcharTableType;
6823 l_child_flat EDW_OWB_COLLECTION_UTIL.varcharTableType;
6824 l_number_flat number;
6825 l_children EDW_OWB_COLLECTION_UTIL.varcharTableType;
6826 l_number_children number;
6827 l_table varchar2(200);
6828 Begin
6829 if g_debug then
6830 write_to_log_file_n('In find_all_affected_levels '||get_time);
6831 end if;
6832 p_number_affected_levels:=0;
6833 if EDW_OWB_COLLECTION_UTIL.get_dim_hier_levels(g_dim_name,l_hier,l_parent_ltc,l_parent_ltc_id,
6834 l_child_ltc,l_child_ltc_id,l_number_hier)=false then
6835 g_status_message:=EDW_OWB_COLLECTION_UTIL.g_status_message;
6836 return false;
6837 end if;
6838 if g_debug then
6839 write_to_log_file_n('The hier and levels');
6840 for i in 1..l_number_hier loop
6841 write_to_log_file(l_hier(i)||' '||l_parent_ltc(i)||'('||l_parent_ltc_id(i)||') '||l_child_ltc(i)||'('||
6842 l_child_ltc_id(i)||')');
6843 end loop;
6844 end if;
6845 --find all the tables that fk change and get all the parent for it
6846 l_number_flat:=0;
6847 for i in 1..g_number_levels loop
6848 if get_parent(g_levels(i),l_parent_ltc,l_child_ltc,l_number_hier,l_children,l_number_children)=false then
6849 return false;
6850 end if;
6851 for j in 1..l_number_children loop
6852 if EDW_OWB_COLLECTION_UTIL.value_in_table(l_parent_flat,l_child_flat,l_number_flat,l_children(j),
6853 g_levels(i))=false then
6854 l_number_flat:=l_number_flat+1;
6855 l_parent_flat(l_number_flat):=l_children(j);
6856 l_child_flat(l_number_flat):=g_levels(i);
6857 end if;
6858 end loop;
6859 end loop;
6860 if g_debug then
6861 write_to_log_file_n('The flat hierarchy');
6862 for i in 1..l_number_flat loop
6863 write_to_log_file(l_child_flat(i)||' '||l_parent_flat(i));
6864 end loop;
6865 end if;
6866 --check for tables
6867 for i in 1..g_number_levels loop
6868 for j in 1..l_number_hier loop
6869 if l_child_ltc(j)=g_levels(i) then
6870 if p_job_id is null then
6871 l_table:=g_bis_owner||'.LTFC_'||l_child_ltc_id(j)||'_'||l_parent_ltc_id(j);
6872 else
6873 l_table:=g_bis_owner||'.LTFC_'||l_child_ltc_id(j)||'_'||l_parent_ltc_id(j)||'_'||p_job_id;
6874 end if;
6875 if EDW_OWB_COLLECTION_UTIL.check_table(l_table) then
6876 g_number_objects_to_drop:=g_number_objects_to_drop+1;
6877 g_objects_to_drop(g_number_objects_to_drop):=l_table;
6878 if EDW_OWB_COLLECTION_UTIL.value_in_table(p_affected_levels,p_number_affected_levels,
6879 l_parent_ltc(j))=false then
6880 p_number_affected_levels:=p_number_affected_levels+1;
6881 p_affected_levels(p_number_affected_levels):=l_parent_ltc(j);
6882 end if;
6883 for k in 1..l_number_flat loop
6884 if l_child_flat(k)=l_parent_ltc(j) then
6885 if EDW_OWB_COLLECTION_UTIL.value_in_table(p_affected_levels,p_number_affected_levels,
6886 l_parent_flat(k))=false then
6887 p_number_affected_levels:=p_number_affected_levels+1;
6888 p_affected_levels(p_number_affected_levels):=l_parent_flat(k);
6889 end if;
6890 end if;
6891 end loop;
6892 end if;
6893 end if;
6894 end loop;
6895 end loop;
6896 if g_debug then
6897 write_to_log_file_n('Additional levels to be considered');
6898 for i in 1..p_number_affected_levels loop
6899 write_to_log_file(p_affected_levels(i));
6900 end loop;
6901 end if;
6902 return true;
6903 Exception when others then
6904 g_status_message:=sqlerrm;
6905 write_to_log_file_n('error in find_all_affected_levels '||g_status_message);
6906 return false;
6907 End;
6908
6909 function get_parent(p_child_level varchar2,p_parent_ltc EDW_OWB_COLLECTION_UTIL.varcharTableType,
6910 p_child_ltc EDW_OWB_COLLECTION_UTIL.varcharTableType, p_number_hier number,
6911 p_parent out NOCOPY EDW_OWB_COLLECTION_UTIL.varcharTableType, p_number_parent out NOCOPY number) return boolean is
6912 loop_end number;
6913 l_parent EDW_OWB_COLLECTION_UTIL.varcharTableType;
6914 l_number_parent number;
6915 Begin
6916 p_number_parent:=0;
6917 for i in 1..p_number_hier loop
6918 if p_child_level=p_child_ltc(i) then
6919 if EDW_OWB_COLLECTION_UTIL.value_in_table(p_parent,p_number_parent,p_parent_ltc(i))=false then
6920 p_number_parent:=p_number_parent+1;
6921 p_parent(p_number_parent):=p_parent_ltc(i);
6922 end if;
6923 end if;
6924 end loop;
6925 loop_end:=p_number_parent;
6926 for i in 1..loop_end loop
6927 if get_parent(p_parent(i),p_parent_ltc,p_child_ltc,p_number_hier,l_parent,l_number_parent)=false then
6928 return false;
6929 end if;
6930 for j in 1..l_number_parent loop
6931 p_number_parent:=p_number_parent+1;
6932 p_parent(p_number_parent):=l_parent(j);
6933 end loop;
6934 end loop;
6935 return true;
6936 Exception when others then
6937 g_status_message:=sqlerrm;
6938 write_to_log_file_n('error in get_parent '||g_status_message);
6939 return false;
6940 End;
6941
6942 function set_g_type_ilog_generation return boolean is
6943 l_percentage number;
6944 l_total_records number;
6945 l_table varchar2(200);
6946 l_owner varchar2(200);
6947 --cut off kept at 5%
6948 Begin
6949 l_table:=substr(g_ilog,instr(g_ilog,'.')+1,length(g_ilog));
6950 l_owner:=substr(g_ilog,1,instr(g_ilog,'.')-1);
6951 l_total_records:=EDW_OWB_COLLECTION_UTIL.get_table_count_stats(l_table,l_owner);
6952 if g_collection_size>0 then
6953 if l_total_records>0 then
6954 l_percentage:=100*(g_collection_size/l_total_records);
6955 if l_percentage<g_ok_switch_update then
6956 g_type_ilog_generation:='UPDATE';
6957 if g_debug then
6958 write_to_log_file_n('g_type_ok_generation made UPDATE');
6959 end if;
6960 end if;
6961 end if;
6962 end if;
6963 return true;
6964 Exception when others then
6965 g_status_message:=sqlerrm;
6966 write_to_log_file_n('error in set_g_type_ilog_generation '||g_status_message);
6967 return false;
6968 End;
6969
6970 function log_pk_into_insert_prot return boolean is
6971 Begin
6972 if g_debug then
6973 write_to_log_file_n('In log_pk_into_insert_prot');
6974 end if;
6975 g_stmt:='insert into '||g_insert_prot_table||'('||g_dim_pk||') select '||g_dim_pk||
6976 ' from '||g_dim_name_temp||' where slow_flag=1';
6977 if g_debug then
6978 write_to_log_file_n(g_stmt||get_time);
6979 end if;
6980 execute immediate g_stmt;
6981 if g_debug then
6982 write_to_log_file_n('Inserted '||sql%rowcount||' rows '||get_time);
6983 end if;
6984 commit;
6985 return true;
6986 Exception when others then
6987 g_status_message:=sqlerrm;
6988 write_to_log_file_n('Error in log_pk_into_insert_prot '||g_status_message);
6989 return false;
6990 End;
6991
6992 function log_pk_into_bu_insert_prot return boolean is
6993 Begin
6994 if g_debug then
6995 write_to_log_file_n('In log_pk_into_bu_insert_prot');
6996 end if;
6997 g_stmt:='insert into '||g_bu_insert_prot_table||'('||g_dim_pk||') select '||g_dim_pk||
6998 ' from '||g_dim_name_hold;
6999 if g_debug then
7000 write_to_log_file_n(g_stmt||get_time);
7001 end if;
7002 execute immediate g_stmt;
7003 if g_debug then
7004 write_to_log_file_n('Inserted '||sql%rowcount||' rows '||get_time);
7005 end if;
7006 commit;
7007 return true;
7008 Exception when others then
7009 g_status_message:=sqlerrm;
7010 write_to_log_file_n('Error in log_pk_into_bu_insert_prot '||g_status_message);
7011 return false;
7012 End;
7013
7014 function read_options_table(p_table_name varchar2) return boolean is
7015 TYPE CurTyp IS REF CURSOR;
7016 cv CurTyp;
7017 l_debug varchar2(2);
7018 l_exec_flag varchar2(2);
7019 l_fresh_restart varchar2(2);
7020 l_ltc_merge_use_nl varchar2(2);
7021 l_dim_inc_refresh_derv varchar2(2);
7022 l_check_fk_change varchar2(2);
7023 l_trace varchar2(2);
7024 l_read_cfig_options varchar2(2);
7025 l_skip_ilog_update varchar2(2);
7026 l_level_change varchar2(2);
7027 l_dim_empty_flag varchar2(2);
7028 l_error_rec_flag varchar2(2);
7029 l_use_ltc_ilog varchar2(2);
7030 l_level_table varchar2(80);
7031 l_level_child_table varchar2(80);
7032 l_skip_table varchar2(80);
7033 l_run number;
7034 l_consider_snapshot EDW_OWB_COLLECTION_UTIL.varcharTableType;
7035 Begin
7036 if g_debug then
7037 write_to_log_file_n('In read_options_table '||p_table_name);
7038 end if;
7039 l_level_table:=p_table_name||'_LT';
7040 l_level_child_table:=p_table_name||'_CT';
7041 l_skip_table:=p_table_name||'_SK';
7042 g_stmt:='select '||
7043 'conc_id,'||
7044 'conc_name,'||
7045 'debug,'||
7046 'exec_flag,'||
7047 'bis_owner,'||
7048 'parallel,'||
7049 'collection_size,'||
7050 'table_owner,'||
7051 'forall_size,'||
7052 'update_type,'||
7053 'load_pk,'||
7054 'fresh_restart,'||
7055 'op_table_space,'||
7056 'rollback,'||
7057 'ltc_merge_use_nl,'||
7058 'dim_inc_refresh_derv,'||
7059 'check_fk_change,'||
7060 'ok_switch_update,'||
7061 'join_nl_percentage,'||
7062 'max_threads,'||
7063 'min_job_load_size,'||
7064 'sleep_time,'||
7065 'job_status_table,'||
7066 'hash_area_size,'||
7067 'sort_area_size,'||
7068 'trace,'||
7069 'read_cfig_options,'||
7070 'ilog_table ,'||
7071 'skip_ilog_update,'||
7072 'level_change,'||
7073 'dim_empty_flag,'||
7074 'before_update_table_final,'||
7075 'error_rec_flag,'||
7076 'max_fk_density'||
7077 ' from '||p_table_name;
7078 if g_debug then
7079 write_to_log_file_n(g_stmt);
7080 end if;
7081 open cv for g_stmt;
7082 fetch cv into
7083 g_conc_id,
7084 g_conc_name,
7085 l_debug,
7086 l_exec_flag,
7087 g_bis_owner,
7088 g_parallel,
7089 g_collection_size,
7090 g_table_owner,
7091 g_forall_size,
7092 g_update_type,
7093 g_load_pk,
7094 l_fresh_restart,
7095 g_op_table_space,
7096 g_rollback,
7097 l_ltc_merge_use_nl,
7098 l_dim_inc_refresh_derv,
7099 l_check_fk_change,
7100 g_ok_switch_update,
7101 g_join_nl_percentage,
7102 g_max_threads,
7103 g_min_job_load_size,
7104 g_sleep_time,
7105 g_job_status_table,
7106 g_hash_area_size,
7107 g_sort_area_size,
7108 l_trace,
7109 l_read_cfig_options,
7110 g_ilog_main_name,
7111 l_skip_ilog_update,
7112 l_level_change,
7113 l_dim_empty_flag,
7114 g_before_update_table_final,
7115 l_error_rec_flag,
7116 g_max_fk_density;
7117 close cv;
7118 if g_debug then
7119 write_to_log_file('g_conc_id='||g_conc_id);
7120 write_to_log_file('g_conc_name='||g_conc_name);
7121 write_to_log_file('l_debug='||l_debug);
7122 write_to_log_file('l_exec_flag='||l_exec_flag);
7123 write_to_log_file('g_bis_owner='||g_bis_owner);
7124 write_to_log_file('g_parallel='||g_parallel);
7125 write_to_log_file('g_collection_size='||g_collection_size);
7126 write_to_log_file('g_table_owner='||g_table_owner);
7127 write_to_log_file('g_forall_size='||g_forall_size);
7128 write_to_log_file('g_update_type='||g_update_type);
7129 write_to_log_file('g_load_pk='||g_load_pk);
7130 write_to_log_file('l_fresh_restart='||l_fresh_restart);
7131 write_to_log_file('g_op_table_space='||g_op_table_space);
7132 write_to_log_file('g_rollback='||g_rollback);
7133 write_to_log_file('l_ltc_merge_use_nl='||l_ltc_merge_use_nl);
7134 write_to_log_file('l_dim_inc_refresh_derv='||l_dim_inc_refresh_derv);
7135 write_to_log_file('l_check_fk_change='||l_check_fk_change);
7136 write_to_log_file('g_ok_switch_update='||g_ok_switch_update);
7137 write_to_log_file('g_join_nl_percentage='||g_join_nl_percentage);
7138 write_to_log_file('g_max_threads='||g_max_threads);
7139 write_to_log_file('g_min_job_load_size='||g_min_job_load_size);
7140 write_to_log_file('g_sleep_time='||g_sleep_time);
7141 write_to_log_file('g_job_status_table='||g_job_status_table);
7142 write_to_log_file('g_hash_area_size='||g_hash_area_size);
7143 write_to_log_file('g_sort_area_size='||g_sort_area_size);
7144 write_to_log_file('l_trace='||l_trace);
7145 write_to_log_file('l_read_cfig_options='||l_read_cfig_options);
7146 write_to_log_file('g_ilog_main_name='||g_ilog_main_name);
7147 write_to_log_file('l_skip_ilog_update='||l_skip_ilog_update);
7148 write_to_log_file('l_level_change='||l_level_change);
7149 write_to_log_file('l_dim_empty_flag='||l_dim_empty_flag);
7150 write_to_log_file('g_before_update_table_final='||g_before_update_table_final);
7151 write_to_log_file('l_error_rec_flag='||l_error_rec_flag);
7152 write_to_log_file('g_max_fk_density='||g_max_fk_density);
7153 end if;
7154 g_debug:=false;
7155 g_exec_flag:=false;
7156 g_fresh_restart:=false;
7157 g_ltc_merge_use_nl:=false;
7158 g_dim_inc_refresh_derv:=false;
7159 g_check_fk_change:=false;
7160 g_trace:=false;
7161 g_read_cfig_options:=false;
7162 g_skip_ilog_update:=false;
7163 g_level_change:=false;
7164 g_dim_empty_flag:=false;
7165 g_error_rec_flag:=false;
7166 if l_debug='Y' then
7167 g_debug:=true;
7168 end if;
7169 if l_exec_flag='Y' then
7170 g_exec_flag:=true;
7171 end if;
7172 if l_fresh_restart='Y' then
7173 g_fresh_restart:=true;
7174 end if;
7175 if l_ltc_merge_use_nl='Y' then
7176 g_ltc_merge_use_nl:=true;
7177 end if;
7178 if l_dim_inc_refresh_derv='Y' then
7179 g_dim_inc_refresh_derv:=true;
7180 end if;
7181 if l_check_fk_change='Y' then
7182 g_check_fk_change:=true;
7183 end if;
7184 if l_trace='Y' then
7185 g_trace:=true;
7186 end if;
7187 if l_read_cfig_options='Y' then
7188 g_read_cfig_options:=true;
7189 end if;
7190 if l_skip_ilog_update='Y' then
7191 g_skip_ilog_update:=true;
7192 end if;
7193 if l_level_change='Y' then
7194 g_level_change:=true;
7195 end if;
7196 if l_dim_empty_flag='Y' then
7197 g_dim_empty_flag:=true;
7198 end if;
7199 if l_error_rec_flag='Y' then
7200 g_error_rec_flag:=true;
7201 end if;
7202 g_stmt:='select '||
7203 'levels,'||
7204 'child_level_number,'||
7205 'level_snapshot_logs,'||
7206 'level_order,'||
7207 'consider_snapshot,'||
7208 'levels_I, '||
7209 'use_ltc_ilog '||
7210 ' from '||l_level_table||' order by level_number';
7211 if g_debug then
7212 write_to_log_file_n(g_stmt);
7213 end if;
7214 open cv for g_stmt;
7215 g_number_levels:=1;
7216 loop
7217 fetch cv into g_levels(g_number_levels),g_child_level_number(g_number_levels),
7218 g_level_snapshot_logs(g_number_levels),g_level_order(g_number_levels),
7219 l_consider_snapshot(g_number_levels),g_levels_I(g_number_levels),
7220 l_use_ltc_ilog;
7221 exit when cv%notfound;
7222 if l_use_ltc_ilog='Y' then
7223 g_use_ltc_ilog(g_number_levels):=true;
7224 else
7225 g_use_ltc_ilog(g_number_levels):=false;
7226 end if;
7227 g_number_levels:=g_number_levels+1;
7228 end loop;
7229 close cv;
7230 g_number_levels:=g_number_levels-1;
7231 if g_debug then
7232 write_to_log_file_n('The levels and snp logs');
7233 for i in 1..g_number_levels loop
7234 write_to_log_file(g_levels(i)||' '||g_child_level_number(i)||' '||
7235 g_level_snapshot_logs(i)||' '||g_level_order(i)||' '||l_consider_snapshot(i)||' '||
7236 g_levels_I(i));
7237 if g_use_ltc_ilog(i) then
7238 write_to_log_file('g_use_ltc_ilog TRUE');
7239 else
7240 write_to_log_file('g_use_ltc_ilog FALSE');
7241 end if;
7242 end loop;
7243 end if;
7244 for i in 1..g_number_levels loop
7245 if l_consider_snapshot(i)='Y' then
7246 g_consider_snapshot(i):=true;
7247 else
7248 g_consider_snapshot(i):=false;
7249 end if;
7250 end loop;
7251 g_stmt:='select '||
7252 'child_levels,'||
7253 'child_fk,'||
7254 'parent_pk'||
7255 ' from '||l_level_child_table||' order by run_number';
7256 if g_debug then
7257 write_to_log_file_n(g_stmt);
7258 end if;
7259 open cv for g_stmt;
7260 l_run:=1;
7261 loop
7262 fetch cv into g_child_levels(l_run),g_child_fk(l_run),g_parent_pk(l_run);
7263 exit when cv%notfound;
7264 l_run:=l_run+1;
7265 end loop;
7266 close cv;
7267 l_run:=l_run-1;
7268 if g_debug then
7269 write_to_log_file_n('The levels fk pk');
7270 for i in 1..l_run loop
7271 write_to_log_file(g_child_levels(i)||' '||g_child_fk(i)||' '||g_parent_pk(i));
7272 end loop;
7273 end if;
7274 g_stmt:='select '||
7275 'skip_cols'||
7276 ' from '||l_skip_table;
7277 if g_debug then
7278 write_to_log_file_n(g_stmt);
7279 end if;
7280 g_number_skip_cols:=1;
7281 open cv for g_stmt;
7282 loop
7283 fetch cv into g_skip_cols(g_number_skip_cols);
7284 exit when cv%notfound;
7285 g_number_skip_cols:=g_number_skip_cols+1;
7286 end loop;
7287 close cv;
7288 g_number_skip_cols:=g_number_skip_cols-1;
7289 if g_debug then
7290 write_to_log_file_n('The skip columns');
7291 for i in 1..g_number_skip_cols loop
7292 write_to_log_file(g_skip_cols(i));
7293 end loop;
7294 end if;
7295 return true;
7296 Exception when others then
7297 g_status_message:=sqlerrm;
7298 write_to_log_file_n('Error in read_options_table '||g_status_message);
7299 return false;
7300 End;
7301
7302 --in case of multi threading. each job here
7303 function make_ok_from_main_ok(
7304 p_main_ok_table_name varchar2,
7305 p_low_end number,
7306 p_high_end number
7307 ) return boolean is
7308 l_ilog_number number;
7309 Begin
7310 if g_debug then
7311 write_to_log_file_n('In make_ok_from_main_ok '||p_main_ok_table_name||' '||p_low_end||' '||p_high_end);
7312 end if;
7313 if EDW_OWB_COLLECTION_UTIL.make_ilog_from_main_ilog(
7314 g_ilog,
7315 p_main_ok_table_name,
7316 p_low_end,
7317 p_high_end,
7318 g_op_table_space,
7319 g_bis_owner,
7320 g_parallel,
7321 l_ilog_number)=false then
7322 return false;
7323 end if;
7324 if EDW_OWB_COLLECTION_UTIL.does_table_have_data(g_ilog,' status=1 ')=2 then
7325 g_skip_ilog_update:=true;
7326 end if;
7327 return true;
7328 Exception when others then
7329 g_status_message:=sqlerrm;
7330 write_to_log_file_n('Error in make_ok_from_main_ok '||g_status_message);
7331 return false;
7332 End;
7333
7334 function drop_input_tables(p_table_name varchar2) return boolean is
7335 Begin
7336 if EDW_OWB_COLLECTION_UTIL.drop_table(p_table_name)=false then
7337 null;
7338 end if;
7339 if EDW_OWB_COLLECTION_UTIL.drop_table(p_table_name||'_LT')=false then
7340 null;
7341 end if;
7342 if EDW_OWB_COLLECTION_UTIL.drop_table(p_table_name||'_CT')=false then
7343 null;
7344 end if;
7345 if EDW_OWB_COLLECTION_UTIL.drop_table(p_table_name||'_SK')=false then
7346 null;
7347 end if;
7348 return true;
7349 Exception when others then
7350 g_status_message:=sqlerrm;
7351 write_to_log_file_n('Error in drop_input_tables '||g_status_message);
7352 return false;
7353 End;
7354
7355 /*
7356 called when being run as a job
7357 */
7358 function set_session_parameters return boolean is
7359 Begin
7360 if EDW_OWB_COLLECTION_UTIL.set_session_parameters(g_hash_area_size,g_sort_area_size,
7361 g_trace,g_parallel)=false then
7362 return false;
7363 end if;
7364 return true;
7365 Exception when others then
7366 g_status_message:=sqlerrm;
7367 write_to_log_file_n('Error in set_session_parameters '||g_status_message);
7368 return false;
7369 End;
7370
7371 /*
7372 this function is executed if there is multi threading.
7373 we need rownum in the ok table so that each child process can then take its part of the
7374 ok table
7375 */
7376 function put_rownum_in_ok_table return boolean is
7377 l_ilog_table varchar2(80);
7378 Begin
7379 if g_debug then
7380 write_to_log_file_n('In put_rownum_in_ok_table');
7381 end if;
7382 l_ilog_table:=g_ilog;
7383 if substr(g_ilog,length(g_ilog),1)='A' then
7384 g_ilog:=substr(g_ilog,1,length(g_ilog)-1);
7385 else
7386 g_ilog:=g_ilog||'A';
7387 end if;
7388 if EDW_OWB_COLLECTION_UTIL.put_rownum_in_ilog_table(
7389 g_ilog,
7390 l_ilog_table,
7391 g_op_table_space,
7392 g_parallel)=false then
7393 return false;
7394 end if;
7395 return true;
7396 Exception when others then
7397 g_status_message:=sqlerrm;
7398 write_to_log_file_n('Error in put_rownum_in_ok_table '||g_status_message);
7399 return false;
7400 End;
7401
7402 function create_conc_program(
7403 p_temp_conc_name varchar2,
7404 p_temp_conc_short_name varchar2,
7405 p_temp_exe_name varchar2,
7406 p_bis_short_name varchar2
7407 ) return boolean is
7408 l_exe_file_name varchar2(200);
7409 l_parameter EDW_OWB_COLLECTION_UTIL.varcharTableType;
7410 l_parameter_value_set EDW_OWB_COLLECTION_UTIL.varcharTableType;
7411 l_number_parameters number;
7412 Begin
7413 l_exe_file_name:='EDW_SUMMARY_COLLECT.COLLECT_DIMENSION';
7414 l_parameter(1):='p_dim_name';
7415 l_parameter_value_set(1):='FND_CHAR240';
7416 l_parameter(2):='p_table_name';
7417 l_parameter_value_set(2):='FND_CHAR240';
7418 l_parameter(3):='p_job_id';
7419 l_parameter_value_set(3):='FND_NUMBER';
7420 l_parameter(4):='p_ok_low_end';
7421 l_parameter_value_set(4):='FND_NUMBER';
7422 l_parameter(5):='p_ok_high_end';
7423 l_parameter_value_set(5):='FND_NUMBER';
7424 l_number_parameters:=5;
7425 if EDW_OWB_COLLECTION_UTIL.create_conc_program(
7426 p_temp_conc_name,
7427 p_temp_conc_short_name,
7428 p_temp_exe_name,
7429 l_exe_file_name,
7430 p_bis_short_name,
7431 l_parameter,
7432 l_parameter_value_set,
7433 l_number_parameters
7434 )=false then
7435 return false;
7436 end if;
7437 return true;
7438 Exception when others then
7439 g_status_message:=sqlerrm;
7440 write_to_log_file_n('Error in create_conc_program '||g_status_message);
7441 return false;
7442 End;
7443
7444 function insert_L_ilog_parallel_dd(p_multi_thread boolean) return boolean is
7445 --
7446 l_status edw_owb_collection_util.varcharTableType;
7447 l_num_status number;
7448 l_job_id number;
7449 l_job_running boolean;
7450 l_ul_table varchar2(200);
7451 l_ur_pattern varchar2(200);
7452 --
7453 --
7454 Begin
7455 if g_debug then
7456 write_to_log_file_n('In insert_L_ilog_parallel_dd'||get_time);
7457 end if;
7458 --see if the process for the lowest level has finished
7459 if edw_owb_collection_util.query_table_cols(g_dd_status_table,'status',' where parent_ltc_id='||g_lowest_level_id,
7460 l_status,l_num_status)=false then
7461 return false;
7462 end if;
7463 if substr(l_status(1),1,3)='ERR' then
7464 g_status_message:=substr(l_status(1),instr(l_status(1),'+')+1);
7465 return false;
7466 end if;
7467 if l_status(1)<>'DONE' then
7468 --job is still running
7469 l_num_status:=0;
7470 if edw_owb_collection_util.query_table_cols(g_dd_status_table,'job_id',' where parent_ltc_id='||g_lowest_level_id,
7471 l_status,l_num_status)=false then
7472 g_status_message:=edw_owb_collection_util.g_status_message;
7473 return false;
7474 end if;
7475 l_job_id:=to_number(l_status(1));
7476 l_job_running:=false;
7477 if edw_owb_collection_util.check_job_status(l_job_id)='Y' then
7478 if edw_owb_collection_util.check_table(g_bis_owner||'.TAB_MARKER_DD_'||g_lowest_level_id) then
7479 l_job_running:=true;
7480 end if;
7481 end if;
7482 if l_job_running then
7483 if edw_owb_collection_util.wait_on_jobs(l_job_id,g_sleep_time,'JOB')=false then
7484 return false;
7485 end if;
7486 if edw_owb_collection_util.query_table_cols(g_dd_status_table,'status',' where parent_ltc_id='||g_lowest_level_id,
7487 l_status,l_num_status)=false then
7488 return false;
7489 end if;
7490 if substr(l_status(1),1,3)='ERR' then
7491 g_status_message:=substr(l_status(1),instr(l_status(1),'+')+1);
7492 return false;
7493 end if;
7494 else
7495 --process has crashed
7496 if edw_owb_collection_util.terminate_job(l_job_id)=false then
7497 null;
7498 end if;
7499 if g_debug then
7500 write_to_log_file_n(l_job_id||' could have crashed or not started. Try serial');
7501 end if;
7502 --manual op
7503 l_ul_table:=g_bis_owner||'.TAB_'||g_lowest_level_id||'_UL';
7504 l_ur_pattern:='TAB_'||g_lowest_level_id||'_HDUR_%';
7505 edw_mapping_collect.drill_parent_to_children(g_lowest_level,g_lowest_level_id,
7506 g_dd_status_table,l_ul_table,l_ur_pattern,g_ltc_pk,
7507 null,null,null,null,null,null,null,null,null,null,0);
7508 --if the manual op also fails, then try the old method of looking at the snp logs
7509 end if;
7510 end if;
7511 if insert_into_ilog_from_L(p_multi_thread)=false then
7512 return false;
7513 end if;
7514 if drop_L_tables=false then
7515 return false;
7516 end if;
7517 return true;
7518 Exception when others then
7519 g_status_message:=sqlerrm;
7520 write_to_log_file_n('Error in insert_L_ilog_parallel_dd '||g_status_message);
7521 return false;
7522 End;
7523
7524 END EDW_SUMMARY_COLLECT;